]> git.lizzy.rs Git - bspwm.git/blobdiff - messages.c
New setting: 'apply_shadow_property'
[bspwm.git] / messages.c
index ea1bc1b008a9fb7137d4d131b1bebb143fb751e0..fab5fc9140238453d40d966a6631a5ad18e5203f 100644 (file)
@@ -9,7 +9,9 @@
 #include "ewmh.h"
 #include "helpers.h"
 #include "window.h"
+#include "events.h"
 #include "tree.h"
+#include "rules.h"
 
 void process_message(char *msg, char *rsp)
 {
@@ -32,9 +34,9 @@ void process_message(char *msg, char *rsp)
         if (name != NULL) {
             desktop_location_t loc;
             if (locate_desktop(name, &loc))
-                dump_tree(loc.desktop, loc.desktop->root, rsp, 0);
+                list(loc.desktop, loc.desktop->root, rsp, 0);
         } else {
-            dump_tree(mon->desk, mon->desk->root, rsp, 0);
+            list(mon->desk, mon->desk->root, rsp, 0);
         }
         return;
     } else if (strcmp(cmd, "list_monitors") == 0) {
@@ -52,6 +54,9 @@ void process_message(char *msg, char *rsp)
     } else if (strcmp(cmd, "list_windows") == 0) {
         list_windows(rsp);
         return;
+    } else if (strcmp(cmd, "list_rules") == 0) {
+        list_rules(rsp);
+        return;
     } else if (strcmp(cmd, "close") == 0) {
         window_close(mon->desk->focus);
         return;
@@ -65,6 +70,26 @@ void process_message(char *msg, char *rsp)
                 rotate_tree(mon->desk->root, r);
             }
         }
+    } else if (strcmp(cmd, "grab_pointer") == 0) {
+        char *pac = strtok(NULL, TOK_SEP);
+        if (pac != NULL) {
+            pointer_action_t a;
+            if (parse_pointer_action(pac, &a))
+                grab_pointer(a);
+        }
+    } else if (strcmp(cmd, "track_pointer") == 0) {
+        char *arg1 = strtok(NULL, TOK_SEP);
+        if (arg1 == NULL)
+            return;
+        char *arg2 = strtok(NULL, TOK_SEP);
+        if (arg2 == NULL)
+            return;
+        int root_x, root_y;
+        if (sscanf(arg1, "%i", &root_x) == 1 && sscanf(arg2, "%i", &root_y) == 1)
+            track_pointer(root_x, root_y);
+        return;
+    } else if (strcmp(cmd, "ungrab_pointer") == 0) {
+        ungrab_pointer();
     } else if (strcmp(cmd, "layout") == 0) {
         char *lyt = strtok(NULL, TOK_SEP);
         if (lyt != NULL) {
@@ -106,6 +131,8 @@ void process_message(char *msg, char *rsp)
     } else if (strcmp(cmd, "toggle_locked") == 0) {
         if (mon->desk->focus != NULL)
             toggle_locked(mon->desk->focus->client);
+    } else if (strcmp(cmd, "toggle_visibility") == 0) {
+        toggle_visibility();
     } else if (strcmp(cmd, "pad") == 0) {
         char *name = strtok(NULL, TOK_SEP);
         if (name != NULL) {
@@ -158,6 +185,24 @@ void process_message(char *msg, char *rsp)
                 move_fence(mon->desk->focus, d, m);
             }
         }
+    } else if (strcmp(cmd, "drop_to_monitor") == 0) {
+        char *dir = strtok(NULL, TOK_SEP);
+        if (dir != NULL) {
+            cycle_dir_t d;
+            if (parse_cycle_direction(dir, &d)) {
+                monitor_t *m;
+                if (d == CYCLE_NEXT)
+                    m = ((mon->next == NULL ? mon_head : mon->next));
+                else
+                    m = ((mon->prev == NULL ? mon_tail : mon->prev));
+                transfer_node(mon, mon->desk, m, m->desk, mon->desk->focus);
+                arrange(m, m->desk);
+                char *opt = strtok(NULL, TOK_SEP);
+                send_option_t o;
+                if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW)
+                    select_monitor(m);
+            }
+        }
     } else if (strcmp(cmd, "send_to_monitor") == 0) {
         char *name = strtok(NULL, TOK_SEP);
         if (name != NULL) {
@@ -165,6 +210,27 @@ void process_message(char *msg, char *rsp)
             if (m != NULL && m != mon) {
                 transfer_node(mon, mon->desk, m, m->desk, mon->desk->focus);
                 arrange(m, m->desk);
+                char *opt = strtok(NULL, TOK_SEP);
+                send_option_t o;
+                if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW)
+                    select_monitor(m);
+            }
+        } 
+    } else if (strcmp(cmd, "drop_to") == 0) {
+        char *dir = strtok(NULL, TOK_SEP);
+        if (dir != NULL) {
+            cycle_dir_t c;
+            if (parse_cycle_direction(dir, &c)) {
+                desktop_t *d;
+                if (c == CYCLE_NEXT)
+                    d = ((mon->desk->next == NULL ? mon->desk_head : mon->desk->next));
+                else
+                    d = ((mon->desk->prev == NULL ? mon->desk_tail : mon->desk->prev));
+                transfer_node(mon, mon->desk, mon, d, mon->desk->focus);
+                char *opt = strtok(NULL, TOK_SEP);
+                send_option_t o;
+                if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW)
+                    select_desktop(d);
             }
         }
     } else if (strcmp(cmd, "send_to") == 0) {
@@ -175,6 +241,12 @@ void process_message(char *msg, char *rsp)
                 transfer_node(mon, mon->desk, loc.monitor, loc.desktop, mon->desk->focus);
                 if (mon != loc.monitor && loc.monitor->desk == loc.desktop)
                     arrange(loc.monitor, loc.desktop);
+                char *opt = strtok(NULL, TOK_SEP);
+                send_option_t o;
+                if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW) {
+                    select_monitor(loc.monitor);
+                    select_desktop(loc.desktop);
+                }
             }
         }
     } else if (strcmp(cmd, "rename_monitor") == 0) {
@@ -292,10 +364,18 @@ void process_message(char *msg, char *rsp)
                 }
                 arg = strtok(NULL, TOK_SEP);
             }
-            rule->next = rule_head;
-            rule_head = rule;
+            add_rule(rule);
         }
         return;
+    } else if (strcmp(cmd, "remove_rule") == 0) {
+        char *arg;
+        unsigned int uid;
+        while ((arg = strtok(NULL, TOK_SEP)) != NULL)
+            if (sscanf(arg, "%X", &uid) > 0)
+                remove_rule_by_uid(uid);
+        return;
+    } else if (strcmp(cmd, "swap") == 0) {
+        swap_nodes(mon->desk->focus, mon->desk->last_focus);
     } else if (strcmp(cmd, "alternate") == 0) {
         focus_node(mon, mon->desk, mon->desk->last_focus, true);
         return;
@@ -331,14 +411,17 @@ void process_message(char *msg, char *rsp)
             return;
     } else if (strcmp(cmd, "adopt_orphans") == 0) {
         adopt_orphans();
-    } else if (strcmp(cmd, "reload") == 0) {
-        load_settings();
-        run_autostart();
     } else if (strcmp(cmd, "reload_autostart") == 0) {
         run_autostart();
     } else if (strcmp(cmd, "reload_settings") == 0) {
         load_settings();
+    } else if (strcmp(cmd, "restore") == 0) {
+        char *arg = strtok(NULL, TOK_SEP);
+        restore(arg);
     } else if (strcmp(cmd, "quit") == 0) {
+        char *arg = strtok(NULL, TOK_SEP);
+        if (arg != NULL)
+            sscanf(arg, "%i", &exit_status);
         quit();
         return;
     } else {
@@ -411,42 +494,31 @@ void set_setting(char *name, char *value, char *rsp)
         bool b;
         if (parse_bool(value, &b))
             gapless_monocle = b;
-    } else if (strcmp(name, "focus_follows_mouse") == 0) {
+    } else if (strcmp(name, "focus_follows_pointer") == 0) {
         bool b;
-        if (parse_bool(value, &b))
-            focus_follows_mouse = b;
+        if (parse_bool(value, &b)) {
+            if (b != focus_follows_pointer) {
+                uint32_t values[] = {(focus_follows_pointer ? CLIENT_EVENT_MASK : CLIENT_EVENT_MASK_FFP)};
+                for (monitor_t *m = mon_head; m != NULL; m = m->next)
+                    for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
+                        for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n))
+                            xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
+
+            }
+            focus_follows_pointer = b;
+        }
     } else if (strcmp(name, "adaptative_raise") == 0) {
         bool b;
         if (parse_bool(value, &b))
             adaptative_raise = b;
+    } else if (strcmp(name, "apply_shadow_property") == 0) {
+        bool b;
+        if (parse_bool(value, &b))
+            apply_shadow_property = 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 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;
@@ -502,18 +574,14 @@ void get_setting(char *name, char* rsp)
         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, "focus_follows_pointer") == 0)
+        snprintf(rsp, BUFSIZ, "%s", BOOLSTR(focus_follows_pointer));
     else if (strcmp(name, "adaptative_raise") == 0)
         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(adaptative_raise));
+    else if (strcmp(name, "apply_shadow_property") == 0)
+        snprintf(rsp, BUFSIZ, "%s", BOOLSTR(apply_shadow_property));
     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 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);
 }
@@ -644,6 +712,18 @@ bool parse_list_option(char *s, list_option_t *o)
     return false;
 }
 
+bool parse_send_option(char *s, send_option_t *o)
+{
+    if (s == NULL) {
+        *o = SEND_OPTION_DONT_FOLLOW;
+        return true;
+    } else if (strcmp(s, "--follow") == 0) {
+        *o = SEND_OPTION_FOLLOW;
+        return true;
+    }
+    return false;
+}
+
 bool parse_rotate(char *s, rotate_t *r)
 {
     if (strcmp(s, "clockwise") == 0) {
@@ -671,62 +751,17 @@ bool parse_fence_move(char *s, fence_move_t *m)
     return false;
 }
 
-bool parse_modifier_mask(char *s, unsigned int *m)
+bool parse_pointer_action(char *s, pointer_action_t *a)
 {
-    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;
+    if (strcmp(s, "move") == 0) {
+        *a = ACTION_MOVE;
         return true;
-    } else if (strcmp(s, "mod2") == 0) {
-        *m = XCB_MOD_MASK_2;
+    } else if (strcmp(s, "focus") == 0) {
+        *a = ACTION_FOCUS;
         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;
+    } else if (strcmp(s, "resize") == 0) {
+        *a = ACTION_RESIZE;
         return true;
     }
     return false;
 }
-
-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;
-        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;
-    }
-}