diff options
| author | Akshay Nair <phenax5@gmail.com> | 2020-07-24 21:30:26 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2020-07-24 21:30:26 +0530 |
| commit | b4382369119c2bb30087f330f9be43dc111d2642 (patch) | |
| tree | 0d705b99094c400253d92aaf2635dfc117b5d79e | |
| parent | 45ff5f2ac7622f120b8037b2aab5babeb3af8d5a (diff) | |
| download | shotkey-b4382369119c2bb30087f330f9be43dc111d2642.tar.gz shotkey-b4382369119c2bb30087f330f9be43dc111d2642.zip | |
Adds mouse hotkeysfeature/mouse
| -rw-r--r-- | config.def.h | 6 | ||||
| -rw-r--r-- | shotkey.c | 27 |
2 files changed, 28 insertions, 5 deletions
diff --git a/config.def.h b/config.def.h index d93a341..4ab1775 100644 --- a/config.def.h +++ b/config.def.h @@ -34,6 +34,12 @@ Key keys[] = { { Mod1Mask, XF86XK_PowerOff, mode(Power, False) }, }; +Button buttons[] = { + { Button1Mask, Button3, cmd("notify-send wow_1") }, + { Mod1Mask, Button2, cmd("notify-send wow_2") }, + { Mod1Mask, Button3, cmd("notify-send wow_3") }, +}; + ModeProperties mode_properties[MODE_SIZE] = { [Music] = { "Music player" }, [Power] = { "Power menu" }, @@ -16,6 +16,12 @@ typedef struct Key { Command command; } Key; +typedef struct Button { + unsigned int mod; + unsigned int button; + Command command; +} Button; + typedef struct ModeProperties { char* label; } ModeProperties; @@ -28,7 +34,7 @@ typedef struct ModeProperties { #include "config.h" #define LENGTH(X) (sizeof X / sizeof X[0]) -#define CLEANMASK(mask) (mask & ~LockMask & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) +#define CLEANMASK(mask) (mask & ~LockMask & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask|Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask)) int current_mode = NormalMode; int is_mode_persistent = 0; @@ -44,7 +50,7 @@ void unbind_key(Display *dpy, Window win, unsigned int mod, KeySym key) { XUngrabKey(dpy, keycode, mod, win); } -void bind_mouse_button(Display *dpy, Window win, unsigned int mod, KeySym button) { +void bind_mouse_button(Display *dpy, Window win, unsigned int mod, unsigned int button) { XGrabButton(dpy, button, mod, win, False, ButtonPress, GrabModeSync, GrabModeAsync, None, None); } @@ -158,15 +164,23 @@ void keypress(Display *dpy, Window win, XKeyEvent *ev) { void buttonpress(Display* dpy, Window win, XButtonEvent* ev) { printf("Muse click\n"); + int i; + short int should_forward_event = False; + + for (i = 0; i < LENGTH(buttons); i++) { + if (buttons[i].button == ev->button && CLEANMASK(buttons[i].mod) == CLEANMASK(ev->state)) { + run(dpy, win, buttons[i].command); + } + } // Replay event - XAllowEvents(dpy, ReplayPointer, CurrentTime); + XAllowEvents(dpy, should_forward_event ? ReplayPointer : SyncPointer, CurrentTime); } int main() { XSetErrorHandler(error_handler); - int running = 1, i = 0; + int running = True, i = 0; Display *dpy = XOpenDisplay(0); Window root = DefaultRootWindow(dpy); @@ -176,7 +190,10 @@ int main() { bind_key(dpy, root, keys[i].mod, keys[i].key); } - bind_mouse_button(dpy, root, 0, Button1); + // Grab mouse buttons + for (i = 0; i < LENGTH(buttons); i++) { + bind_mouse_button(dpy, root, buttons[i].mod, buttons[i].button); + } long int event_mask = KeyPressMask | ButtonPressMask; XSelectInput(dpy, root, event_mask); |
