]> git.lizzy.rs Git - bspwm.git/commitdiff
New settings: 'numlock_modifier' and 'capslock_modifier'
authorBastien Dejean <nihilhill@gmail.com>
Mon, 3 Dec 2012 18:30:48 +0000 (19:30 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Mon, 3 Dec 2012 18:30:48 +0000 (19:30 +0100)
README.md
bspwm.1
bspwm.c
bspwm.h
events.c
messages.c
settings.c
settings.h

index a3598c433ee717443c6109452635f19c9c47f345..76172a5dc032934170bcb043713f0bbfc4496da0 100644 (file)
--- a/README.md
+++ b/README.md
@@ -252,7 +252,13 @@ Colors are either [X color names](http://en.wikipedia.org/wiki/X11_color_names)
         The value that shall be used for the _NET_WM_NAME property of the root window.
 
     button_modifier
-        The modifier mask used for mouse bindings (possible values: 'mod1' ... 'mod5').
+        The modifier mask used for mouse bindings (possible values: 'shift', 'control', 'lock', 'mod1' ... 'mod5').
+
+    numlock_modifier
+        The modifier holding Num_Lock (cf. xmodmap).
+
+    capslock_modifier
+        The modifier holding Lock.
 
     borderless_monocle
         Whether to remove borders for tiled windows in monocle mode.
diff --git a/bspwm.1 b/bspwm.1
index b06219dd7346b4662a2f042e063b1dd9b5cd85f7..e47ef424acd918143cd7cf83bb0ca585d7f1681f 100644 (file)
--- a/bspwm.1
+++ b/bspwm.1
@@ -288,7 +288,14 @@ property of the root window.
 .TP
 .I button_modifier
 The modifier mask used for mouse bindings (possible values:
-.BR mod1 " ... " mod5 ).
+.BR shift ", " control ", " lock ", " mod1 " ... " mod5 ).
+.TP
+.I numlock_modifier
+The modifier holding Num_Lock (cf.
+.BR xmodmap (1).
+.TP
+.I capslock_modifier
+The modifier holding Lock (cf.
 .TP
 .I borderless_monocle
 Whether to remove borders for tiled windows in monocle mode.
diff --git a/bspwm.c b/bspwm.c
index 87456220a027bf18259943eaf466e03cdec5d893..6828bb66c3860818c6fb5fd67550b815fc3649fe 100644 (file)
--- a/bspwm.c
+++ b/bspwm.c
@@ -40,24 +40,31 @@ void register_events(void)
     }
 }
 
+void handle_buttons(bool grab)
+{
+    uint8_t buts[] = {XCB_BUTTON_INDEX_1, XCB_BUTTON_INDEX_2, XCB_BUTTON_INDEX_3};
+    uint16_t mods[] = {button_modifier, button_modifier | numlock_modifier, button_modifier | capslock_modifier, button_modifier | numlock_modifier | capslock_modifier};
+
+    for (unsigned int i = 0; i < LENGTH(buts); i++) {
+        uint8_t b = buts[i];
+        for (unsigned int j = 0; j < LENGTH(mods); j++) {
+            uint16_t m = mods[j];
+            if (grab)
+                xcb_grab_button(dpy, false, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, b, m);
+            else
+                xcb_ungrab_button(dpy, b, screen->root, m);
+        }
+    }
+}
+
 void grab_buttons(void)
 {
-    xcb_grab_button(dpy, false, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_1, button_modifier);
-    xcb_grab_button(dpy, false, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_2, button_modifier);
-    xcb_grab_button(dpy, false, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_3, button_modifier);
-    xcb_grab_button(dpy, false, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_1, button_modifier | XCB_MOD_MASK_LOCK);
-    xcb_grab_button(dpy, false, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_2, button_modifier | XCB_MOD_MASK_LOCK);
-    xcb_grab_button(dpy, false, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_3, button_modifier | XCB_MOD_MASK_LOCK);
+    handle_buttons(true);
 }
 
 void ungrab_buttons(void)
 {
-    xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_1, screen->root, button_modifier);
-    xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_2, screen->root, button_modifier);
-    xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_3, screen->root, button_modifier);
-    xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_1, screen->root, button_modifier | XCB_MOD_MASK_LOCK);
-    xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_2, screen->root, button_modifier | XCB_MOD_MASK_LOCK);
-    xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_3, screen->root, button_modifier | XCB_MOD_MASK_LOCK);
+    handle_buttons(false);
 }
 
 void setup(void)
diff --git a/bspwm.h b/bspwm.h
index 9f530b9d0dc9aa35f1ae2b965d97ae9b0d6a4eb5..d1600bbe25cd14b210d5ba013906cfde73fdab98 100644 (file)
--- a/bspwm.h
+++ b/bspwm.h
@@ -30,6 +30,7 @@ xcb_point_t pointer_position;
 bool running;
 
 void register_events(void);
+void handle_buttons(bool);
 void grab_buttons(void);
 void ungrab_buttons(void);
 void setup(void);
index 0915d39eae33580c15b2f9ba4d179881c2675154..24f0f14f9d6e2cdc0c98df11d611ae6e085acf93 100644 (file)
--- a/events.c
+++ b/events.c
@@ -246,7 +246,7 @@ void button_press(xcb_generic_event_t *evt)
     xcb_button_press_event_t *e = (xcb_button_press_event_t *) evt;
     xcb_window_t win = e->child;
 
-    PRINTF("button press %u %X\n", e->detail, win);
+    PRINTF("button press %u %u %X\n", e->detail, e->state, win);
 
     window_location_t loc;
     if (locate_window(win, &loc)) {
index c16cfa6eac0b9a9eb34078cc9434015be90614c0..457d44c2122c8e524a6ab95ee5f9a4f6c68998b7 100644 (file)
@@ -401,6 +401,22 @@ void set_setting(char *name, char *value, char *rsp)
             grab_buttons();
         }
         return;
+    } else if (strcmp(name, "numlock_modifier") == 0) {
+        unsigned int m;
+        if (parse_modifier_mask(value, &m)) {
+            ungrab_buttons();
+            numlock_modifier = m;
+            grab_buttons();
+        }
+        return;
+    } else if (strcmp(name, "capslock_modifier") == 0) {
+        unsigned int m;
+        if (parse_modifier_mask(value, &m)) {
+            ungrab_buttons();
+            capslock_modifier = m;
+            grab_buttons();
+        }
+        return;
     } else {
         snprintf(rsp, BUFSIZ, "unknown setting: %s", name);
         return;
@@ -462,6 +478,10 @@ void get_setting(char *name, char* rsp)
         snprintf(rsp, BUFSIZ, "%s", wm_name);
     else if (strcmp(name, "button_modifier") == 0)
         print_modifier_mask(rsp, button_modifier);
+    else if (strcmp(name, "numlock_modifier") == 0)
+        print_modifier_mask(rsp, numlock_modifier);
+    else if (strcmp(name, "capslock_modifier") == 0)
+        print_modifier_mask(rsp, capslock_modifier);
     else
         snprintf(rsp, BUFSIZ, "unknown setting: %s", name);
 }
@@ -621,7 +641,19 @@ bool parse_fence_move(char *s, fence_move_t *m)
 
 bool parse_modifier_mask(char *s, unsigned int *m)
 {
-    if (strcmp(s, "mod1") == 0) {
+    if (strcmp(s, "shift") == 0) {
+        *m = XCB_MOD_MASK_SHIFT;
+        return true;
+    } else if (strcmp(s, "control") == 0) {
+        *m = XCB_MOD_MASK_CONTROL;
+        return true;
+    } else if (strcmp(s, "lock") == 0) {
+        *m = XCB_MOD_MASK_LOCK;
+        return true;
+    } else if (strcmp(s, "mod1") == 0) {
+        *m = XCB_MOD_MASK_1;
+        return true;
+    } else if (strcmp(s, "mod1") == 0) {
         *m = XCB_MOD_MASK_1;
         return true;
     } else if (strcmp(s, "mod2") == 0) {
@@ -643,6 +675,15 @@ bool parse_modifier_mask(char *s, unsigned int *m)
 void print_modifier_mask(char *s, unsigned int m)
 {
     switch(m) {
+        case XCB_MOD_MASK_SHIFT:
+            snprintf(s, BUFSIZ, "shift");
+            break;
+        case XCB_MOD_MASK_CONTROL:
+            snprintf(s, BUFSIZ, "control");
+            break;
+        case XCB_MOD_MASK_LOCK:
+            snprintf(s, BUFSIZ, "lock");
+            break;
         case XCB_MOD_MASK_1:
             snprintf(s, BUFSIZ, "mod1");
             break;
index 1b4b1822e3c844b7d63c07fde92e8bd7d3df1573..6c4d062f84582df7a5105d035a22a975ad4143e5 100644 (file)
@@ -56,6 +56,8 @@ void load_settings(void)
 
     strncpy(wm_name, WM_NAME, sizeof(wm_name));
     button_modifier = BUTTON_MODIFIER;
+    numlock_modifier = NUMLOCK_MODIFIER;
+    capslock_modifier = CAPSLOCK_MODIFIER;
 
     inner_border_width = INNER_BORDER_WIDTH;
     main_border_width = MAIN_BORDER_WIDTH;
index 99cda23ed4c0695d6c18910e2e5e0f4c1b997e76..fbd0df5851eeaa34bef9fabd5a4ea7d87ca2d131 100644 (file)
@@ -6,6 +6,8 @@
 #define WM_NAME             "bspwm"
 #define AUTOSTART_FILE      "autostart"
 #define BUTTON_MODIFIER     XCB_MOD_MASK_4
+#define NUMLOCK_MODIFIER    XCB_MOD_MASK_2
+#define CAPSLOCK_MODIFIER   XCB_MOD_MASK_LOCK
 
 #define FOCUSED_BORDER_COLOR        "#7D7F8A"
 #define ACTIVE_BORDER_COLOR         "#7D7F8A"
@@ -72,6 +74,8 @@ bool focus_follows_mouse;
 
 char wm_name[MAXLEN];
 unsigned int button_modifier;
+unsigned int numlock_modifier;
+unsigned int capslock_modifier;
 
 void load_settings(void);
 void run_autostart(void);