]> git.lizzy.rs Git - bspwm.git/commitdiff
New setting: 'button_modifier'
authorBastien Dejean <nihilhill@gmail.com>
Tue, 23 Oct 2012 10:42:40 +0000 (12:42 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Tue, 23 Oct 2012 10:42:40 +0000 (12:42 +0200)
README.md
bspwm.c
bspwm.h
messages.c
messages.h
settings.c
settings.h

index b6760b473738bea9b5ab648194674cf042722f05..09d70a131cd379af80604bf50a38db83e60fd8bb 100644 (file)
--- a/README.md
+++ b/README.md
@@ -256,6 +256,9 @@ Colors are either [X color names](http://en.wikipedia.org/wiki/X11_color_names)
     wm_name
         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').
+
     borderless_monocle 
         Whether to remove borders for tiled windows in monocle mode.
 
@@ -264,17 +267,15 @@ Colors are either [X color names](http://en.wikipedia.org/wiki/X11_color_names)
 
 ## Mouse Bindings
 
-    M4 + Left Button
+    button_modifier + left mouse button
         Move the window under the pointer.
 
-    M4 + Middle Button
+    button_modifier + middle mouse button
         Focus the window under the pointer.
 
-    M4 + Middle Button
+    button_modifier + right mouse button
         Resize the window under the pointer (by moving one of its four corners).
 
-Where *M4* is the fourth modifier mask (generally bound to *Super*).
-
 ## Panel
 
 `dzen2` fed with the output of `ewmhstatus`. Example: [launchpanel](https://github.com/baskerville/bin/blob/master/launchpanel).
diff --git a/bspwm.c b/bspwm.c
index bc3be55674ef98c1200c1f5dc4d96a151b5b85c8..62da73d51a283446dcd9025601c2023a2f93b74b 100644 (file)
--- a/bspwm.c
+++ b/bspwm.c
@@ -38,9 +38,13 @@ void register_events(void)
         err("another WM is already running\n");
     }
 
-    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);
+}
+
+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);
 }
 
 void setup(void)
@@ -157,6 +161,7 @@ int main(void)
     load_settings();
     run_autostart();
     ewmh_update_wm_name();
+    grab_buttons();
 
     while (running) {
 
diff --git a/bspwm.h b/bspwm.h
index 213d724d6242b404af1496e0982dd50151f345f3..38d3ba386e61b2aa32d37b62fd086a161ef79898 100644 (file)
--- a/bspwm.h
+++ b/bspwm.h
@@ -5,7 +5,6 @@
 
 #define ROOT_EVENT_MASK    (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY)
 #define CLIENT_EVENT_MASK  (XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_ENTER_WINDOW)
-#define BUTTON_MODIFIER    XCB_MOD_MASK_4
 
 xcb_connection_t *dpy;
 int default_screen, screen_width, screen_height;
@@ -29,6 +28,7 @@ pointer_state_t *frozen_pointer;
 bool running;
 
 void register_events(void);
+void grab_buttons(void);
 void handle_zombie(int);
 void setup(void);
 void quit(void);
index b831c41d6808aaa06bf7c7216b3f97b03db0826c..e174f5fe4a7ec0d001cc5b0a6d6ce2ccfa9df6fa 100644 (file)
@@ -356,6 +356,11 @@ void set_setting(char *name, char *value, char *rsp)
         strncpy(wm_name, value, sizeof(wm_name));
         ewmh_update_wm_name();
         return;
+    } else if (strcmp(name, "button_modifier") == 0) {
+        unsigned int m;
+        if (parse_modifier_mask(value, &m))
+            button_modifier = m;
+        return;
     } else {
         snprintf(rsp, BUFSIZ, "unknown setting: %s", name);
         return;
@@ -560,3 +565,24 @@ bool parse_fence_move(char *s, fence_move_t *m)
     }
     return false;
 }
+
+bool parse_modifier_mask(char *s, unsigned int *m)
+{
+    if (strcmp(s, "mod1") == 0) {
+        *m = XCB_MOD_MASK_1;
+        return true;
+    } else if (strcmp(s, "mod2") == 0) {
+        *m = XCB_MOD_MASK_2;
+        return true;
+    } else if (strcmp(s, "mod3") == 0) {
+        *m = XCB_MOD_MASK_3;
+        return true;
+    } else if (strcmp(s, "mod4") == 0) {
+        *m = XCB_MOD_MASK_4;
+        return true;
+    } else if (strcmp(s, "mod5") == 0) {
+        *m = XCB_MOD_MASK_5;
+        return true;
+    }
+    return false;
+}
index 39646c70ae90257465355089eec3c5c08b4f9438..cf3c7c92279644975ec780557c566f8fa2dd3fd4 100644 (file)
@@ -16,5 +16,6 @@ bool parse_skip_client(char *, skip_client_t *);
 bool parse_corner(char *, corner_t *);
 bool parse_rotate(char *, rotate_t *);
 bool parse_fence_move(char *, fence_move_t *);
+bool parse_modifier_mask(char *, unsigned int *);
 
 #endif
index 1d1b887905ead4881fcb7c9e66b35fa2722f6cd1..4ea3433cf20963fc4e19fe7fb4f2e3cd46f173d8 100644 (file)
@@ -53,6 +53,7 @@ void load_settings(void)
     urgent_border_color_pxl = get_color(urgent_border_color);
 
     strncpy(wm_name, WM_NAME, sizeof(wm_name));
+    button_modifier = BUTTON_MODIFIER;
 
     inner_border_width = INNER_BORDER_WIDTH;
     main_border_width = MAIN_BORDER_WIDTH;
index f7fe05cdbc2f00f20657112fd0fb0aca02bbcaee..1e8ee67de52d7cd94b22a9222664df94d90673aa 100644 (file)
@@ -5,6 +5,7 @@
 
 #define WM_NAME             "bspwm"
 #define AUTOSTART_FILE      "autostart"
+#define BUTTON_MODIFIER     XCB_MOD_MASK_4
 
 #define FOCUSED_BORDER_COLOR        "#7D7F8A"
 #define ACTIVE_BORDER_COLOR         "#7D7F8A"
@@ -68,6 +69,7 @@ bool borderless_monocle;
 bool focus_follows_mouse;
 
 char wm_name[MAXLEN];
+unsigned int button_modifier;
 
 void load_settings(void);
 void run_autostart(void);