]> git.lizzy.rs Git - bspwm.git/blobdiff - query.c
Implement ICCCM's WM_TAKE_FOCUS behavior
[bspwm.git] / query.c
diff --git a/query.c b/query.c
index 65d4a504a5a70f97a2b274111255b5fc42aa8237..237a9ada8fc640a3b7996121b97674971b2ff719 100644 (file)
--- a/query.c
+++ b/query.c
@@ -19,7 +19,7 @@ void query_monitors(coordinates_t loc, domain_t dom, char *rsp)
                 strncat(rsp, line, REMLEN(rsp));
                 continue;
             } else {
-                snprintf(line, sizeof(line), "%s %ux%u%+i%+i", m->name, m->rectangle.width, m->rectangle.height, m->rectangle.x, m->rectangle.y);
+                snprintf(line, sizeof(line), "%s %ux%u%+i%+i %i,%i,%i,%i", m->name, m->rectangle.width, m->rectangle.height, m->rectangle.x, m->rectangle.y, m->top_padding, m->right_padding, m->bottom_padding, m->left_padding);
                 strncat(rsp, line, REMLEN(rsp));
                 if (m == mon)
                     strncat(rsp, " #", REMLEN(rsp));
@@ -69,7 +69,7 @@ void query_tree(desktop_t *d, node_t *n, char *rsp, unsigned int depth)
 
     if (is_leaf(n)) {
         client_t *c = n->client;
-        snprintf(line, sizeof(line), "%c %s %X %u %ux%u%+i%+i %c%c%c%c%c", (n->birth_rotation == 90 ? 'a' : (n->birth_rotation == 270 ? 'c' : 'm')), c->class_name, c->window, c->border_width, c->floating_rectangle.width, c->floating_rectangle.height, c->floating_rectangle.x, c->floating_rectangle.y, (c->floating ? 'f' : '-'), (c->transient ? 't' : '-'), (c->fullscreen ? 'F' : '-'), (c->urgent ? 'u' : '-'), (c->locked ? 'l' : '-'));
+        snprintf(line, sizeof(line), "%c %s %X %u %ux%u%+i%+i %c%c%c%c%c%c", (n->birth_rotation == 90 ? 'a' : (n->birth_rotation == 270 ? 'c' : 'm')), c->class_name, c->window, c->border_width, c->floating_rectangle.width, c->floating_rectangle.height, c->floating_rectangle.x, c->floating_rectangle.y, (c->floating ? 'f' : '-'), (c->transient ? 't' : '-'), (c->fullscreen ? 'F' : '-'), (c->urgent ? 'u' : '-'), (c->locked ? 'l' : '-'), (n->split_mode ? 'p' : '-'));
     } else {
         snprintf(line, sizeof(line), "%c %c %.2f", (n->split_type == TYPE_HORIZONTAL ? 'H' : 'V'), (n->birth_rotation == 90 ? 'a' : (n->birth_rotation == 270 ? 'c' : 'm')), n->split_ratio);
     }
@@ -128,6 +128,8 @@ bool node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
     client_select_t sel;
     sel.type = CLIENT_TYPE_ALL;
     sel.class = CLIENT_CLASS_ALL;
+    sel.mode = CLIENT_MODE_ALL;
+    sel.urgency = CLIENT_URGENCY_ALL;
     char *tok;
     while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
         tok[0] = '\0';
@@ -140,6 +142,14 @@ bool node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
             sel.class = CLIENT_CLASS_EQUAL;
         } else if (streq("unlike", tok)) {
             sel.class = CLIENT_CLASS_DIFFER;
+        } else if (streq("automatic", tok)) {
+            sel.mode = CLIENT_MODE_AUTOMATIC;
+        } else if (streq("manual", tok)) {
+            sel.mode = CLIENT_MODE_MANUAL;
+        } else if (streq("urgent", tok)) {
+            sel.urgency = CLIENT_URGENCY_ON;
+        } else if (streq("nonurgent", tok)) {
+            sel.urgency = CLIENT_URGENCY_OFF;
         }
     }
 
@@ -154,10 +164,7 @@ bool node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
     } else if (parse_cycle_direction(desc, &cyc)) {
         dst->node = closest_node(ref->desktop, ref->node, cyc, sel);
     } else if (streq("last", desc)) {
-        int i = 1;
-        do {
-            dst->node = history_get(ref->desktop->history, i++);
-        } while (dst->node != NULL && (dst->node == ref->node || !node_matches(ref->node, dst->node, sel)));
+        dst->node = history_last(ref->desktop->history, ref->node, sel);
     } else if (streq("biggest", desc)) {
         dst->node = find_biggest(ref->desktop, ref->node, sel);
     } else if (streq("focused", desc)) {
@@ -178,24 +185,32 @@ bool node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
 bool desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
 {
     desktop_select_t sel;
-    sel = DESKTOP_ALL;
+    sel.status = DESKTOP_STATUS_ALL;
+    sel.urgency = DESKTOP_URGENCY_ALL;
     char *tok;
     while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
         tok[0] = '\0';
         tok++;
         if (streq("free", tok)) {
-            sel = DESKTOP_FREE;
+            sel.status = DESKTOP_STATUS_FREE;
         } else if (streq("occupied", tok)) {
-            sel = DESKTOP_OCCUPIED;
+            sel.status = DESKTOP_STATUS_OCCUPIED;
+        } else if (streq("urgent", tok)) {
+            sel.urgency = DESKTOP_URGENCY_ON;
+        } else if (streq("nonurgent", tok)) {
+            sel.urgency = DESKTOP_URGENCY_OFF;
         }
     }
 
     dst->desktop = NULL;
 
     cycle_dir_t cyc;
+    int idx;
     if (parse_cycle_direction(desc, &cyc)) {
         dst->monitor = ref->monitor;
         dst->desktop = closest_desktop(ref->monitor, ref->desktop, cyc, sel);
+    } else if (parse_index(desc, &idx)) {
+        desktop_from_index(idx, dst);
     } else if (streq("last", desc)) {
         if (mon->last_desk != NULL && desktop_matches(mon->last_desk, sel)) {
             dst->monitor = mon;
@@ -216,15 +231,16 @@ bool desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
 bool monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
 {
     desktop_select_t sel;
-    sel = DESKTOP_ALL;
+    sel.status = DESKTOP_STATUS_ALL;
+    sel.urgency = DESKTOP_URGENCY_ALL;
     char *tok;
     while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
         tok[0] = '\0';
         tok++;
         if (streq("free", tok)) {
-            sel = DESKTOP_FREE;
+            sel.status = DESKTOP_STATUS_FREE;
         } else if (streq("occupied", tok)) {
-            sel = DESKTOP_OCCUPIED;
+            sel.status = DESKTOP_STATUS_OCCUPIED;
         }
     }
 
@@ -232,10 +248,13 @@ bool monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
 
     direction_t dir;
     cycle_dir_t cyc;
+    int idx;
     if (parse_direction(desc, &dir)) {
         dst->monitor = nearest_monitor(ref->monitor, dir, sel);
     } else if (parse_cycle_direction(desc, &cyc)) {
         dst->monitor = closest_monitor(ref->monitor, cyc, sel);
+    } else if (parse_index(desc, &idx)) {
+        monitor_from_index(idx, dst);
     } else if (streq("last", desc)) {
         if (last_mon != NULL && desktop_matches(last_mon->desk, sel)) {
             dst->monitor = last_mon;
@@ -286,3 +305,28 @@ bool locate_monitor(char *name, coordinates_t *loc)
         }
     return false;
 }
+
+bool desktop_from_index(int i, coordinates_t *loc)
+{
+    for (monitor_t *m = mon_head; m != NULL; m = m->next)
+        for (desktop_t *d = m->desk_head; d != NULL; d = d->next, i--)
+            if (i == 1) {
+                loc->monitor = m;
+                loc->desktop = d;
+                loc->node = NULL;
+                return true;
+            }
+    return false;
+}
+
+bool monitor_from_index(int i, coordinates_t *loc)
+{
+    for (monitor_t *m = mon_head; m != NULL; m = m->next, i--)
+        if (i == 1) {
+            loc->monitor = m;
+            loc->desktop = NULL;
+            loc->node = NULL;
+            return true;
+        }
+    return false;
+}