diff options
author | Johannes Bensmann <johannesbensmann@gmx.de> | 2019-06-08 20:48:18 +0200 |
---|---|---|
committer | Johannes Bensmann <johannesbensmann@gmx.de> | 2019-06-08 20:48:18 +0200 |
commit | 51eb5c314df7e383d31968d1825984348a590780 (patch) | |
tree | edc5508bd7d4bd27b0e21ec58945db4bf34607b3 /xmouseless.c | |
parent | 6d56714629eb48640ad66f8f849f38c66d0afc84 (diff) |
moved configuration to config.h
Diffstat (limited to 'xmouseless.c')
-rw-r--r-- | xmouseless.c | 122 |
1 files changed, 68 insertions, 54 deletions
diff --git a/xmouseless.c b/xmouseless.c index 197be5b..65f3e13 100644 --- a/xmouseless.c +++ b/xmouseless.c @@ -8,26 +8,28 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xos.h> +#include <X11/XKBlib.h> #include <X11/extensions/XTest.h> +#include "config.h" -int MOVE_RATE = 30; -int SPEED = 10; +#define LENGTH(X) (sizeof X / sizeof X[0]) Display *dpy; int screen; Window root; pthread_t movethread; +unsigned int speed = DEFAULT_SPEED; + struct { int x; int y; - int movex; - int movey; + int move_x; + int move_y; } mouseinfo; - int getrootptr(int *x, int *y); void moverelative(int x, int y); void click(int button, int is_press); @@ -76,66 +78,81 @@ void close_x() { void *moveforever(void *val) { /* this is executed in a thread */ while (1) { - if (mouseinfo.movex != 0 || mouseinfo.movey != 0) { - moverelative(SPEED * mouseinfo.movex, SPEED * mouseinfo.movey); + if (mouseinfo.move_x != 0 || mouseinfo.move_y != 0) { + moverelative(speed * mouseinfo.move_x, speed * mouseinfo.move_y); } usleep(1000000 / MOVE_RATE); } } void handle_keypress(XKeyEvent event) { - if (event.keycode == 24 || event.keycode == 0x09) { + unsigned int i; + KeySym keysym; + + keysym = XkbKeycodeToKeysym(dpy, event.keycode, + 0, event.state & ShiftMask ? 1 : 0); + + /* exit */ + if (keysym == EXIT_KEY) { close_x(); exit(0); } - else if (event.keycode == 45) { - mouseinfo.movex = 0; - mouseinfo.movey = 0; - } - else if (event.keycode == 44) { - mouseinfo.movex -= 1; - } - else if (event.keycode == 46) { - mouseinfo.movex += 1; - } - else if (event.keycode == 31) { - mouseinfo.movey -= 1; - } - else if (event.keycode == 59) { - mouseinfo.movey += 1; - } - else if (event.keycode == 64) { - SPEED = 40; + + /* move bindings */ + for (i = 0; i < LENGTH(move_bindings); i++) { + if (move_bindings[i].keysym == keysym) { + printf("move: %i, %i\n", move_bindings[i].x, move_bindings[i].y); + mouseinfo.move_x += move_bindings[i].x; + mouseinfo.move_y += move_bindings[i].y; + } } - else if (event.keycode == 41) { - click(1, True); + + /* click bindings */ + for (i = 0; i < LENGTH(click_bindings); i++) { + if (click_bindings[i].keysym == keysym) { + printf("click: %i\n", click_bindings[i].button); + click(click_bindings[i].button, True); + } } - else if (event.keycode == 39) { - click(3, True); + + /* speed bindings */ + for (i = 0; i < LENGTH(speed_bindings); i++) { + if (speed_bindings[i].keysym == keysym) { + printf("speed: %i\n", speed_bindings[i].speed); + speed = speed_bindings[i].speed; + } } } void handle_keyrelease(XKeyEvent event) { - if (event.keycode == 44) { - mouseinfo.movex += 1; - } - else if (event.keycode == 46) { - mouseinfo.movex -= 1; - } - else if (event.keycode == 31) { - mouseinfo.movey += 1; - } - else if (event.keycode == 59) { - mouseinfo.movey -= 1; - } - else if (event.keycode == 64) { - SPEED = 10; + unsigned int i; + KeySym keysym; + + keysym = XkbKeycodeToKeysym(dpy, event.keycode, + 0, event.state & ShiftMask ? 1 : 0); + + /* move bindings */ + for (i = 0; i < LENGTH(move_bindings); i++) { + if (move_bindings[i].keysym == keysym) { + mouseinfo.move_x -= move_bindings[i].x; + mouseinfo.move_y -= move_bindings[i].y; + } } - else if (event.keycode == 41) { - click(1, False); + + /* click bindings */ + for (i = 0; i < LENGTH(click_bindings); i++) { + if (click_bindings[i].keysym == keysym) { + printf("click release: %i\n", click_bindings[i].button); + click(click_bindings[i].button, False); + } } - else if (event.keycode == 39) { - click(3, False); + + /* speed bindings */ + for (i = 0; i < LENGTH(speed_bindings); i++) { + if (speed_bindings[i].keysym == keysym) { + printf("speed: %i\n", DEFAULT_SPEED); + speed = DEFAULT_SPEED; + } } } @@ -146,8 +163,8 @@ int main () { init_x(); getrootptr(&mouseinfo.x, &mouseinfo.y); - mouseinfo.movex = 0; - mouseinfo.movey = 0; + mouseinfo.move_x = 0; + mouseinfo.move_y = 0; // start the thread for mouse movement rc = pthread_create(&movethread, NULL, &moveforever, NULL); @@ -162,14 +179,11 @@ int main () { switch (event.type) { case KeyPress: getrootptr(&mouseinfo.x, &mouseinfo.y); - printf("You pressed %i\n", event.xkey.keycode); - handle_keypress(event.xkey); break; case KeyRelease: - printf("You released %i\n", event.xkey.keycode); - + getrootptr(&mouseinfo.x, &mouseinfo.y); handle_keyrelease(event.xkey); break; } |