summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Bensmann <johannesbensmann@gmx.de>2019-06-09 14:52:00 +0200
committerJohannes Bensmann <johannesbensmann@gmx.de>2019-06-09 15:00:02 +0200
commit130540cbbf154f349cd1afaa837c07e3a69d3e28 (patch)
tree3d716d8589bf418a6e31ff630f751a0398742804
parent6ea9fa0d3cceb38fa67c021e95449e2c87a431c6 (diff)
restructured some code
-rw-r--r--TODO1
-rw-r--r--config.h44
-rw-r--r--xmouseless.c31
3 files changed, 41 insertions, 35 deletions
diff --git a/TODO b/TODO
index a28fb6b..e69de29 100644
--- a/TODO
+++ b/TODO
@@ -1 +0,0 @@
-- check if key repeat is enabled at start
diff --git a/config.h b/config.h
index 6cbba3c..a9eabba 100644
--- a/config.h
+++ b/config.h
@@ -1,27 +1,16 @@
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
/* the rate at which the mouse moves */
-#define MOVE_RATE 30
+static const unsigned int move_rate = 30;
/* the speed with no modifier */
-#define DEFAULT_SPEED 10
+static const unsigned int default_speed = 20;
-typedef struct {
- KeySym keysym;
- int x;
- int y;
-} MoveBinding;
-
-typedef struct {
- KeySym keysym;
- int button;
-} ClickBinding;
-
-typedef struct {
- KeySym keysym;
- int speed;
-} SpeedBindings;
+static SpeedBindings speed_bindings[] = {
+ /* key speed */
+ { XK_Super_L, 100 },
+ { XK_Alt_L, 50 },
+ { XK_a, 2 },
+};
static MoveBinding move_bindings[] = {
/* key x y */
@@ -35,23 +24,22 @@ static MoveBinding move_bindings[] = {
{ XK_period, 1, 1 },
};
+/* 1: left
+ * 2: middle
+ * 3: right
+ * 4: scroll up
+ * 5: scroll down */
static ClickBinding click_bindings[] = {
/* key button */
{ XK_space, 1 },
{ XK_f, 1 },
{ XK_d, 2 },
{ XK_s, 3 },
- { XK_minus, 4 },
- { XK_plus, 5 },
-};
-
-static SpeedBindings speed_bindings[] = {
- /* key speed */
- { XK_Super_L, 200 },
- { XK_Alt_L, 50 },
- { XK_a, 2 },
+ { XK_plus, 4 },
+ { XK_minus, 5 },
};
+/* exits on key release which allows click and exit with one key */
static unsigned int exit_keys[] = {
XK_Escape, XK_q, XK_space
};
diff --git a/xmouseless.c b/xmouseless.c
index 0eb54f0..90dd4b1 100644
--- a/xmouseless.c
+++ b/xmouseless.c
@@ -11,16 +11,35 @@
#include <X11/XKBlib.h>
#include <X11/extensions/XTest.h>
+#define LENGTH(X) (sizeof X / sizeof X[0])
+
+
+typedef struct {
+ KeySym keysym;
+ int x;
+ int y;
+} MoveBinding;
+
+typedef struct {
+ KeySym keysym;
+ int button;
+} ClickBinding;
+
+typedef struct {
+ KeySym keysym;
+ int speed;
+} SpeedBindings;
+
+/* load configuration */
#include "config.h"
-#define LENGTH(X) (sizeof X / sizeof X[0])
Display *dpy;
int screen;
Window root;
pthread_t movethread;
-unsigned int speed = DEFAULT_SPEED;
+static unsigned int speed = default_speed;
struct {
int x;
@@ -84,7 +103,7 @@ void *moveforever(void *val) {
if (mouseinfo.move_x != 0 || mouseinfo.move_y != 0) {
moverelative(speed * mouseinfo.move_x, speed * mouseinfo.move_y);
}
- usleep(1000000 / MOVE_RATE);
+ usleep(1000000 / move_rate);
}
}
@@ -115,8 +134,8 @@ void handle_keypress(XKeyEvent event) {
/* 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;
+ printf("speed: %i\n", speed);
}
}
}
@@ -147,8 +166,8 @@ void handle_keyrelease(XKeyEvent event) {
/* 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;
+ speed = default_speed;
+ printf("speed: %i\n", speed);
}
}