]> git.lizzy.rs Git - bspwm.git/commitdiff
Don't assume the uniqueness of desktop names
authorBastien Dejean <nihilhill@gmail.com>
Tue, 22 Aug 2017 09:54:15 +0000 (11:54 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Tue, 22 Aug 2017 09:54:15 +0000 (11:54 +0200)
Fixes #698.

src/query.c
src/query.h

index b6d1a2b29d32d8d856c5d02a307520ce5003368a..7498812870d9a54f69cec429faa8436ea6e57c50 100644 (file)
@@ -653,16 +653,17 @@ int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
                        return SELECTOR_INVALID;
                }
        } else {
-               if (locate_desktop(desc, dst)) {
+               int hits = 0;
+               if (desktop_from_name(desc, ref, dst, sel, &hits)) {
                        free(desc_copy);
-                       if (desktop_matches(dst, ref, sel)) {
-                               return SELECTOR_OK;
-                       } else {
-                               return SELECTOR_INVALID;
-                       }
+                       return SELECTOR_OK;
                } else {
                        free(desc_copy);
-                       return SELECTOR_BAD_DESCRIPTOR;
+                       if (hits > 0) {
+                               return SELECTOR_INVALID;
+                       } else {
+                               return SELECTOR_BAD_DESCRIPTOR;
+                       }
                }
        }
 
@@ -830,6 +831,26 @@ bool desktop_from_id(uint32_t id, coordinates_t *loc, monitor_t *mm)
        return false;
 }
 
+bool desktop_from_name(char *name, coordinates_t *ref, coordinates_t *dst, desktop_select_t sel, int *hits)
+{
+       for (monitor_t *m = mon_head; m != NULL; m = m->next) {
+               for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
+                       if (streq(d->name, name)) {
+                               if (hits != NULL) {
+                                       (*hits)++;
+                               }
+                               coordinates_t loc = {m, d, NULL};
+                               if (desktop_matches(&loc, ref, sel)) {
+                                       dst->monitor = m;
+                                       dst->desktop = d;
+                                       return true;
+                               }
+                       }
+               }
+       }
+       return false;
+}
+
 bool desktop_from_index(uint16_t idx, coordinates_t *loc, monitor_t *mm)
 {
        for (monitor_t *m = mon_head; m != NULL; m = m->next) {
index 38da7c6bf2597549d7e773e4b386dbf9c80abd96..b26ddf6798c9c602623986006c8c5bdb4e364df6 100644 (file)
@@ -77,6 +77,7 @@ bool locate_window(xcb_window_t win, coordinates_t *loc);
 bool locate_desktop(char *name, coordinates_t *loc);
 bool locate_monitor(char *name, coordinates_t *loc);
 bool desktop_from_id(uint32_t id, coordinates_t *loc, monitor_t *mm);
+bool desktop_from_name(char *name, coordinates_t *ref, coordinates_t *dst, desktop_select_t sel, int *hits);
 bool desktop_from_index(uint16_t idx, coordinates_t *loc, monitor_t *mm);
 bool monitor_from_id(uint32_t id, coordinates_t *loc);
 bool monitor_from_index(int idx, coordinates_t *loc);