]> git.lizzy.rs Git - bspwm.git/blobdiff - messages.c
New message: `remove_desktop`
[bspwm.git] / messages.c
index 2a6ee5de6bf7da9351216546839396a57f03056c..7f055d99cece4ffd8f409fbc5cc092a03dbbe087 100644 (file)
@@ -350,6 +350,11 @@ void process_message(char *msg, char *rsp)
             }
         }
         return;
+    } else if (strcmp(cmd, "biggest") == 0) {
+        node_t *n = find_biggest(mon->desk);
+        if (n != NULL)
+            snprintf(rsp, BUFSIZ, "0x%X", n->client->window);
+        return;
     } else if (strcmp(cmd, "circulate") == 0) {
         if (mon->desk->layout == LAYOUT_MONOCLE
                 || (mon->desk->focus != NULL && !is_tiled(mon->desk->focus->client)))
@@ -391,16 +396,12 @@ void process_message(char *msg, char *rsp)
                 remove_rule_by_uid(uid);
         return;
     } else if (strcmp(cmd, "swap") == 0) {
-        char *arg;
-        swap_arg_t a;
-        if ((arg = strtok(NULL, TOK_SEP)) != NULL) {
-            if (parse_swap_argument(arg, &a)) {
-                node_t *n = find_by_area(mon->desk, a);
-                swap_nodes(mon->desk->focus, n);
-            }
-        } else {
-            swap_nodes(mon->desk->focus, history_get(mon->desk->history, 1));
-        }
+        node_t *last_focus = history_get(mon->desk->history, 1);
+        swap_nodes(mon->desk->focus, last_focus);
+        char *opt = strtok(NULL, TOK_SEP);
+        swap_option_t o;
+        if (parse_swap_option(opt, &o) && o == SWAP_OPTION_SWAP_FOCUS)
+            focus_node(mon, mon->desk, last_focus);
     } else if (strcmp(cmd, "alternate") == 0) {
         focus_node(mon, mon->desk, history_get(mon->desk->history, 1));
         return;
@@ -416,12 +417,23 @@ void process_message(char *msg, char *rsp)
             monitor_t *m = find_monitor(name);
             if (m != NULL)
                 for (name = strtok(NULL, TOK_SEP); name != NULL; name = strtok(NULL, TOK_SEP))
-                    add_desktop(m, name);
+                    add_desktop(m, make_desktop(name));
         }
         return;
     } else if (strcmp(cmd, "add") == 0) {
         for (char *name = strtok(NULL, TOK_SEP); name != NULL; name = strtok(NULL, TOK_SEP))
-            add_desktop(mon, name);
+            add_desktop(mon, make_desktop(name));
+        return;
+    } else if (strcmp(cmd, "remove_desktop") == 0) {
+        for (char *name = strtok(NULL, TOK_SEP); name != NULL; name = strtok(NULL, TOK_SEP)) {
+            desktop_location_t loc;
+            if (locate_desktop(name, &loc)) {
+                if (loc.desktop->root == NULL && loc.monitor->desk_head != loc.monitor->desk_tail)
+                    remove_desktop(loc.monitor, loc.desktop);
+            }
+        }
+        desktop_show(mon->desk);
+        update_current();
         return;
     } else if (strcmp(cmd, "focus") == 0) {
         if (mon->desk->focus == NULL || mon->desk->focus->client->fullscreen)
@@ -674,18 +686,6 @@ bool parse_nearest_argument(char *s, nearest_arg_t *a)
     return false;
 }
 
-bool parse_swap_argument(char *s, swap_arg_t *a)
-{
-    if (strcmp(s, "biggest") == 0) {
-        *a = SWAP_BIGGEST;
-        return true;
-    } else if (strcmp(s, "smallest") == 0) {
-        *a = SWAP_SMALLEST;
-        return true;
-    }
-    return false;
-}
-
 bool parse_cycle_direction(char *s, cycle_dir_t *d)
 {
     if (strcmp(s, "prev") == 0) {
@@ -770,6 +770,18 @@ bool parse_send_option(char *s, send_option_t *o)
     return false;
 }
 
+bool parse_swap_option(char *s, swap_option_t *o)
+{
+    if (s == NULL || strcmp(s, "--swap-focus") == 0) {
+        *o = SWAP_OPTION_SWAP_FOCUS;
+        return true;
+    } else if (strcmp(s, "--keep-focus") == 0) {
+        *o = SWAP_OPTION_KEEP_FOCUS;
+        return true;
+    }
+    return false;
+}
+
 bool parse_rotate(char *s, rotate_t *r)
 {
     if (strcmp(s, "clockwise") == 0) {