diff options
author | Johannes Bensmann <johannesbensmann@gmx.de> | 2019-06-14 21:27:29 +0200 |
---|---|---|
committer | Johannes Bensmann <johannesbensmann@gmx.de> | 2019-06-14 21:30:05 +0200 |
commit | 96fcc4c27c89f6f531af40426d768184dd0eb58a (patch) | |
tree | e52f67924c58ca515d3154e01a970b92567c1344 | |
parent | cfc732b796c4e48e44aa08f0b3f1e586d1ad095a (diff) |
made speed independent of move rate
-rw-r--r-- | config.h | 17 | ||||
-rw-r--r-- | xmouseless.c | 34 |
2 files changed, 27 insertions, 24 deletions
@@ -1,17 +1,16 @@ -/* the rate at which the mouse moves in Hz - * also affects the speed */ -static const unsigned int move_rate = 30; +/* the rate at which the mouse moves in Hz */ +static const unsigned int move_rate = 50; -/* the speed with no modifier */ -static const unsigned int default_speed = 15; +/* the speed with no modifier (pixels per second) */ +static const unsigned int default_speed = 300; static SpeedBindings speed_bindings[] = { /* key speed */ - { XK_Super_L, 100 }, - { XK_Alt_L, 50 }, - { XK_a, 3 }, - { XK_Control_L, 1 }, + { XK_Super_L, 2000 }, + { XK_Alt_L, 1000 }, + { XK_a, 60 }, + { XK_Control_L, 10 }, }; static MoveBinding move_bindings[] = { diff --git a/xmouseless.c b/xmouseless.c index f1f169e..ab0ba19 100644 --- a/xmouseless.c +++ b/xmouseless.c @@ -17,8 +17,8 @@ typedef struct { KeySym keysym; - int x; - int y; + float x; + float y; } MoveBinding; typedef struct { @@ -47,33 +47,36 @@ pthread_t movethread; static unsigned int speed = default_speed; struct { - int x; - int y; + float x; + float y; int speed_x; int speed_y; } mouseinfo; -void getrootptr(int *x, int *y); -void moverelative(int x, int y); +void get_pointer(); +void moverelative(float x, float y); void click(unsigned int button, Bool is_press); -void handle_keypress(XKeyEvent event); -void handle_keyrelease(XKeyEvent event); +void handle_key(XKeyEvent event); void init_x(); void close_x(); -void getrootptr(int *x, int *y) { +void get_pointer() { + int x, y; int di; unsigned int dui; Window dummy; - XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui); + XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui); + mouseinfo.x = x; + mouseinfo.y = y; } -void moverelative(int x, int y) { +void moverelative(float x, float y) { mouseinfo.x += x; mouseinfo.y += y; - XWarpPointer(dpy, None, root, 0, 0, 0, 0, mouseinfo.x, mouseinfo.y); + XWarpPointer(dpy, None, root, 0, 0, 0, 0, + (int) mouseinfo.x, (int) mouseinfo.y); XFlush(dpy); } @@ -120,7 +123,8 @@ void *moveforever(void *val) { /* this function is executed in a seperate thread */ while (1) { if (mouseinfo.speed_x != 0 || mouseinfo.speed_y != 0) { - moverelative(speed * mouseinfo.speed_x, speed * mouseinfo.speed_y); + moverelative((float) mouseinfo.speed_x * speed / move_rate, + (float) mouseinfo.speed_y * speed / move_rate); } usleep(1000000 / move_rate); } @@ -187,7 +191,7 @@ int main () { init_x(); - getrootptr(&mouseinfo.x, &mouseinfo.y); + get_pointer(); mouseinfo.speed_x = 0; mouseinfo.speed_y = 0; @@ -204,7 +208,7 @@ int main () { switch (event.type) { case KeyPress: case KeyRelease: - getrootptr(&mouseinfo.x, &mouseinfo.y); + get_pointer(); handle_key(event.xkey); break; } |