]> git.lizzy.rs Git - bspwm.git/blobdiff - messages.c
Remove message: 'magnetise'
[bspwm.git] / messages.c
index 6395a233549956d823b748ec7e3af5b037221e68..ed5e8bb013141c0fc0977a6bbb07b671779c7be7 100644 (file)
@@ -27,7 +27,7 @@ void process_message(char *msg, char *rsp)
         char *value = strtok(NULL, TOKEN_SEP);
         set_setting(name, value, rsp);
         return;
-    } else if (strcmp(cmd, "dump") == 0) {
+    } else if (strcmp(cmd, "list") == 0) {
         dump_tree(mon->desk, mon->desk->root, rsp, 0);
         return;
     } else if (strcmp(cmd, "list_monitors") == 0) {
@@ -36,13 +36,13 @@ void process_message(char *msg, char *rsp)
         if (parse_list_option(arg, &opt))
             list_monitors(opt, rsp);
         return;
-    } else if (strcmp(cmd, "list") == 0) {
+    } else if (strcmp(cmd, "list_desktops") == 0) {
         char *arg = strtok(NULL, TOKEN_SEP);
         list_option_t opt;
         if (parse_list_option(arg, &opt))
             list_desktops(mon, opt, 0, rsp);
         return;
-    } else if (strcmp(cmd, "windows") == 0) {
+    } else if (strcmp(cmd, "list_windows") == 0) {
         list_windows(rsp);
         return;
     } else if (strcmp(cmd, "close") == 0) {
@@ -50,14 +50,6 @@ void process_message(char *msg, char *rsp)
         return;
     } else if (strcmp(cmd, "kill") == 0) {
         window_kill(mon->desk, mon->desk->focus);
-    } else if (strcmp(cmd, "magnetise") == 0) {
-        char *cor = strtok(NULL, TOKEN_SEP);
-        if (cor != NULL) {
-            corner_t c;
-            if (parse_corner(cor, &c)) {
-                magnetise_tree(mon->desk->root, c);
-            }
-        }
     } else if (strcmp(cmd, "rotate") == 0) {
         char *deg = strtok(NULL, TOKEN_SEP);
         if (deg != NULL) {
@@ -89,7 +81,7 @@ void process_message(char *msg, char *rsp)
         }
     } else if (strcmp(cmd, "toggle_fullscreen") == 0) {
         if (mon->desk->focus != NULL)
-            toggle_fullscreen(mon->desk->focus->client);
+            toggle_fullscreen(mon, mon->desk->focus->client);
     } else if (strcmp(cmd, "toggle_floating") == 0) {
         split_mode = MODE_AUTOMATIC;
         toggle_floating(mon->desk->focus);
@@ -195,8 +187,12 @@ void process_message(char *msg, char *rsp)
         char *dir = strtok(NULL, TOKEN_SEP);
         if (dir != NULL) {
             cycle_dir_t d;
-            if (parse_cycle_direction(dir, &d))
-                cycle_desktop(d);
+            if (parse_cycle_direction(dir, &d)) {
+                skip_desktop_t k;
+                char *skip = strtok(NULL, TOKEN_SEP);
+                if (parse_skip_desktop(skip, &k))
+                    cycle_desktop(mon, mon->desk, d, k);
+            }
         }
     } else if (strcmp(cmd, "cycle") == 0) {
         if (mon->desk->focus != NULL && mon->desk->focus->client->fullscreen)
@@ -208,10 +204,36 @@ void process_message(char *msg, char *rsp)
                 skip_client_t k;
                 char *skip = strtok(NULL, TOKEN_SEP);
                 if (parse_skip_client(skip, &k))
-                    cycle_leaf(d, k);
+                    cycle_leaf(mon, mon->desk, mon->desk->focus, d, k);
             }
         }
-        return;
+        if (mon->desk->layout == LAYOUT_TILED)
+            return;
+    } else if (strcmp(cmd, "nearest") == 0) {
+        if (mon->desk->focus != NULL && mon->desk->focus->client->fullscreen)
+            return;
+        char *arg = strtok(NULL, TOKEN_SEP);
+        if (arg != NULL) {
+            nearest_arg_t a;
+            if (parse_nearest_argument(arg, &a)) {
+                skip_client_t k;
+                char *skip = strtok(NULL, TOKEN_SEP);
+                if (parse_skip_client(skip, &k))
+                    nearest_leaf(mon, mon->desk, mon->desk->focus, a, k);
+            }
+        }
+        if (mon->desk->layout == LAYOUT_TILED)
+            return;
+    } else if (strcmp(cmd, "circulate") == 0) {
+        if (mon->desk->layout == LAYOUT_MONOCLE
+                || (mon->desk->focus != NULL && !is_tiled(mon->desk->focus->client)))
+            return;
+        char *dir = strtok(NULL, TOKEN_SEP);
+        if (dir != NULL) {
+            circulate_dir_t d;
+            if (parse_circulate_direction(dir, &d))
+                circulate_leaves(mon, mon->desk, d);
+        }
     } else if (strcmp(cmd, "rule") == 0) {
         char *name = strtok(NULL, TOKEN_SEP);
         if (name != NULL) {
@@ -227,16 +249,25 @@ void process_message(char *msg, char *rsp)
             rule_head = rule;
         }
         return;
-    } else if (strcmp(cmd, "alternate_monitor") == 0) {
-        select_monitor(last_mon);
     } else if (strcmp(cmd, "alternate") == 0) {
+        focus_node(mon, mon->desk, mon->desk->last_focus, true);
+    } else if (strcmp(cmd, "alternate_desktop") == 0) {
         select_desktop(mon->last_desk);
-    } else if (strcmp(cmd, "add") == 0) {
+    } else if (strcmp(cmd, "alternate_monitor") == 0) {
+        select_monitor(last_mon);
+    } else if (strcmp(cmd, "add_in") == 0) {
         char *name = strtok(NULL, TOKEN_SEP);
         if (name != NULL) {
-            add_desktop(mon, name);
+            monitor_t *m = find_monitor(name);
+            if (m != NULL)
+                for (name = strtok(NULL, TOKEN_SEP); name != NULL; name = strtok(NULL, TOKEN_SEP))
+                    add_desktop(m, name);
         }
         return;
+    } else if (strcmp(cmd, "add") == 0) {
+        for (char *name = strtok(NULL, TOKEN_SEP); name != NULL; name = strtok(NULL, TOKEN_SEP))
+            add_desktop(mon, name);
+        return;
     } else if (strcmp(cmd, "focus") == 0) {
         if (mon->desk->focus != NULL && mon->desk->focus->client->fullscreen)
             return;
@@ -248,7 +279,10 @@ void process_message(char *msg, char *rsp)
                 focus_node(mon, mon->desk, n, true);
             }
         }
-        return;
+        if (mon->desk->layout == LAYOUT_TILED)
+            return;
+    } else if (strcmp(cmd, "adopt_orphans") == 0) {
+        adopt_orphans();
     } else if (strcmp(cmd, "reload") == 0) {
         load_settings();
         run_autostart();
@@ -283,19 +317,14 @@ void set_setting(char *name, char *value, char *rsp)
         border_width = inner_border_width + main_border_width + outer_border_width;
     } else if (strcmp(name, "window_gap") == 0) {
         sscanf(value, "%i", &window_gap);
-        update_root_dimensions();
     } else if (strcmp(name, "left_padding") == 0) {
         sscanf(value, "%i", &left_padding);
-        update_root_dimensions();
     } else if (strcmp(name, "right_padding") == 0) {
         sscanf(value, "%i", &right_padding);
-        update_root_dimensions();
     } else if (strcmp(name, "top_padding") == 0) {
         sscanf(value, "%i", &top_padding);
-        update_root_dimensions();
     } else if (strcmp(name, "bottom_padding") == 0) {
         sscanf(value, "%i", &bottom_padding);
-        update_root_dimensions();
     } else if (strcmp(name, "focused_border_color") == 0) {
         strncpy(focused_border_color, value, sizeof(focused_border_color));
         focused_border_color_pxl = get_color(focused_border_color);
@@ -330,10 +359,26 @@ void set_setting(char *name, char *value, char *rsp)
         bool b;
         if (parse_bool(value, &b))
             borderless_monocle = b;
+    } else if (strcmp(name, "gapless_monocle") == 0) {
+        bool b;
+        if (parse_bool(value, &b))
+            gapless_monocle = b;
+    } else if (strcmp(name, "focus_follows_mouse") == 0) {
+        bool b;
+        if (parse_bool(value, &b))
+            focus_follows_mouse = b;
     } else if (strcmp(name, "wm_name") == 0) {
         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)) {
+            ungrab_buttons();
+            button_modifier = m;
+            grab_buttons();
+        }
+        return;
     } else {
         snprintf(rsp, BUFSIZ, "unknown setting: %s", name);
         return;
@@ -387,8 +432,14 @@ void get_setting(char *name, char* rsp)
         snprintf(rsp, BUFSIZ, "%s (%06X)", urgent_border_color, urgent_border_color_pxl);
     else if (strcmp(name, "borderless_monocle") == 0)
         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(borderless_monocle));
+    else if (strcmp(name, "gapless_monocle") == 0)
+        snprintf(rsp, BUFSIZ, "%s", BOOLSTR(gapless_monocle));
+    else if (strcmp(name, "focus_follows_mouse") == 0)
+        snprintf(rsp, BUFSIZ, "%s", BOOLSTR(focus_follows_mouse));
     else if (strcmp(name, "wm_name") == 0)
         snprintf(rsp, BUFSIZ, "%s", wm_name);
+    else if (strcmp(name, "button_modifier") == 0)
+        print_modifier_mask(rsp, button_modifier);
     else
         snprintf(rsp, BUFSIZ, "unknown setting: %s", name);
 }
@@ -435,6 +486,18 @@ bool parse_direction(char *s, direction_t *d)
     return false;
 }
 
+bool parse_nearest_argument(char *s, nearest_arg_t *a)
+{
+    if (strcmp(s, "older") == 0) {
+        *a = NEAREST_OLDER;
+        return true;
+    } else if (strcmp(s, "newer") == 0) {
+        *a = NEAREST_NEWER;
+        return true;
+    }
+    return false;
+}
+
 bool parse_cycle_direction(char *s, cycle_dir_t *d)
 {
     if (strcmp(s, "prev") == 0) {
@@ -447,52 +510,61 @@ bool parse_cycle_direction(char *s, cycle_dir_t *d)
     return false;
 }
 
+bool parse_circulate_direction(char *s, circulate_dir_t *d)
+{
+    if (strcmp(s, "forward") == 0) {
+        *d = CIRCULATE_FORWARD;
+        return true;
+    } else if (strcmp(s, "backward") == 0) {
+        *d = CIRCULATE_BACKWARD;
+        return true;
+    }
+    return false;
+}
+
 bool parse_skip_client(char *s, skip_client_t *k)
 {
-    if (s == NULL || strcmp(s, "--skip-none") == 0) {
-        *k = SKIP_NONE;
+    if (s == NULL) {
+        *k = CLIENT_SKIP_NONE;
         return true;
     } else if (strcmp(s, "--skip-floating") == 0) {
-        *k = SKIP_FLOATING;
+        *k = CLIENT_SKIP_FLOATING;
         return true;
     } else if (strcmp(s, "--skip-tiled") == 0) {
-        *k = SKIP_TILED;
+        *k = CLIENT_SKIP_TILED;
         return true;
     } else if (strcmp(s, "--skip-class-equal") == 0) {
-        *k = SKIP_CLASS_EQUAL;
+        *k = CLIENT_SKIP_CLASS_EQUAL;
         return true;
     } else if (strcmp(s, "--skip-class-differ") == 0) {
-        *k = SKIP_CLASS_DIFFER;
+        *k = CLIENT_SKIP_CLASS_DIFFER;
         return true;
     }
     return false;
 }
 
-bool parse_list_option(char *s, list_option_t *o)
+bool parse_skip_desktop(char *s, skip_desktop_t *k)
 {
-    if (s == NULL || strcmp(s, "--verbose") == 0) {
-        *o = LIST_OPTION_VERBOSE;
+    if (s == NULL) {
+        *k = DESKTOP_SKIP_NONE;
         return true;
-    } else if (strcmp(s, "--quiet") == 0) {
-        *o = LIST_OPTION_QUIET;
+    } else if (strcmp(s, "--skip-free") == 0) {
+        *k = DESKTOP_SKIP_FREE;
+        return true;
+    } else if (strcmp(s, "--skip-occupied") == 0) {
+        *k = DESKTOP_SKIP_OCCUPIED;
         return true;
     }
     return false;
 }
 
-bool parse_corner(char *s, corner_t *c)
+bool parse_list_option(char *s, list_option_t *o)
 {
-    if (strcmp(s, "top_left") == 0) {
-        *c = TOP_LEFT;
-        return true;
-    } else if (strcmp(s, "top_right") == 0) {
-        *c = TOP_RIGHT;
-        return true;
-    } else if (strcmp(s, "bottom_left") == 0) {
-        *c = BOTTOM_LEFT;
+    if (s == NULL || strcmp(s, "--verbose") == 0) {
+        *o = LIST_OPTION_VERBOSE;
         return true;
-    } else if (strcmp(s, "bottom_right") == 0) {
-        *c = BOTTOM_RIGHT;
+    } else if (strcmp(s, "--quiet") == 0) {
+        *o = LIST_OPTION_QUIET;
         return true;
     }
     return false;
@@ -524,3 +596,45 @@ 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;
+}
+
+void print_modifier_mask(char *s, unsigned int m)
+{
+    switch(m) {
+        case XCB_MOD_MASK_1:
+            snprintf(s, BUFSIZ, "mod1");
+            break;
+        case XCB_MOD_MASK_2:
+            snprintf(s, BUFSIZ, "mod2");
+            break;
+        case XCB_MOD_MASK_3:
+            snprintf(s, BUFSIZ, "mod3");
+            break;
+        case XCB_MOD_MASK_4:
+            snprintf(s, BUFSIZ, "mod4");
+            break;
+        case XCB_MOD_MASK_5:
+            snprintf(s, BUFSIZ, "mod5");
+            break;
+    }
+}