-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 221c21b
Showing
10 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.v] | ||
indent_style = tab | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* text=auto eol=lf | ||
*.bat eol=crlf | ||
|
||
**/*.v linguist-language=V | ||
**/*.vv linguist-language=V | ||
**/*.vsh linguist-language=V | ||
**/v.mod linguist-language=V |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Binaries for programs and plugins | ||
main | ||
mouse | ||
*.exe | ||
*.exe~ | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Ignore binary output folders | ||
bin/ | ||
|
||
# Ignore common editor/system specific metadata | ||
.DS_Store | ||
.idea/ | ||
.vscode/ | ||
*.iml | ||
|
||
# ENV | ||
.env | ||
|
||
# vweb and database | ||
*.db | ||
*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Position is a point on an X, Y axis used to | ||
// represent the location of the mouse pointer. | ||
struct Position { | ||
int x, y; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// See .h for comments. | ||
#include "mouse_linux.h" | ||
|
||
struct Position get_mouse_pos() { | ||
struct Position pos = {-1, -1}; | ||
|
||
Display *dpy; | ||
Window root_window; | ||
int root_id = 0, | ||
child_id = 0, | ||
win_x = 0, | ||
win_y = 0, | ||
mask = 0; | ||
dpy = XOpenDisplay(0); | ||
root_window = XRootWindow(dpy, 0); | ||
XQueryPointer(dpy, root_window, &root_id, &child_id, &pos.x, &pos.y, &win_x, &win_y, &mask); | ||
|
||
return pos; | ||
} | ||
|
||
void set_mouse_pos(int x, int y) { | ||
Display *dpy; | ||
Window root_window; | ||
|
||
dpy = XOpenDisplay(0); | ||
root_window = XRootWindow(dpy, 0); | ||
XSelectInput(dpy, root_window, KeyReleaseMask); | ||
XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, x, y); | ||
XFlush(dpy); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
#include <X11/X.h> | ||
#include <X11/Xlib.h> | ||
#include <X11/Xutil.h> | ||
#include "mouse.h" | ||
|
||
// get_mouse_pos gets the mouse position and returns it. | ||
struct Position get_mouse_pos(); | ||
// set_mouse_pos moves the position of the mouse to X, Y. | ||
void set_mouse_pos(int x, int y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// See .h for comments. | ||
#include "mouse_windows.h" | ||
|
||
struct Position get_mouse_pos() { | ||
struct Position pos = {-1, -1}; | ||
|
||
|
||
|
||
return pos; | ||
} | ||
|
||
void set_mouse_pos(int x, int y) { | ||
// int nX = x * 65535 / GetSystemMetrics(SM_CXSCREEN); | ||
// int nY = y * 65535 / GetSystemMetrics(SM_CYSCREEN); | ||
// mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, nX, nY, 0, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <windows.h> | ||
#include "mouse.h" | ||
|
||
// get_mouse_pos gets the mouse position and returns it. | ||
struct Position get_mouse_pos(); | ||
// set_mouse_pos moves the position of the mouse to X, Y. | ||
void set_mouse_pos(int x, int y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module main | ||
|
||
#flag -I @VMODROOT/src/c | ||
#flag linux -lX11 | ||
#flag linux @VMODROOT/src/c/mouse_linux.o | ||
#flag windows @VMODROOT/src/c/mouse_windows.o | ||
|
||
$if linux { | ||
#include "mouse_linux.h" | ||
} $else $if windows { | ||
#include "mouse_windows.h" | ||
} $else $if macos { | ||
|
||
} | ||
|
||
// See .c files for comments. | ||
struct C.Position { | ||
x int | ||
y int | ||
} | ||
|
||
fn C.get_mouse_pos() C.Position | ||
fn C.set_mouse_pos(int, int) | ||
|
||
[inline] | ||
pub fn get() (int, int) { | ||
pos := C.get_mouse_pos() | ||
return pos.x, pos.y | ||
} | ||
|
||
[inline] | ||
pub fn get_opt() ?(int, int) { | ||
x, y := get() | ||
if -1 in [x, y] { | ||
return none | ||
} | ||
return x, y | ||
} | ||
|
||
[inline] | ||
pub fn set(x int, y int) { | ||
C.set_mouse_pos(x, y) | ||
} | ||
|
||
fn main() { | ||
println(get()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Module { | ||
name: 'mouse' | ||
description: 'Set and get mouse position.' | ||
version: '0.1' | ||
license: 'MIT' | ||
dependencies: [] | ||
} |