]> git.sur5r.net Git - i3/i3/blobdiff - src/match.c
Merge branch 'next' into master
[i3/i3] / src / match.c
index f1bc8430d45fca43db596b293dd71bfed959304d..20af38f61b3c765cbf6ada30fab725a3979c3b9c 100644 (file)
@@ -48,6 +48,7 @@ bool match_is_empty(Match *match) {
             match->class == NULL &&
             match->instance == NULL &&
             match->window_role == NULL &&
+            match->workspace == NULL &&
             match->urgent == U_DONTCHECK &&
             match->id == XCB_NONE &&
             match->window_type == UINT32_MAX &&
@@ -78,6 +79,7 @@ void match_copy(Match *dest, Match *src) {
     DUPLICATE_REGEX(class);
     DUPLICATE_REGEX(instance);
     DUPLICATE_REGEX(window_role);
+    DUPLICATE_REGEX(workspace);
 }
 
 /*
@@ -88,8 +90,12 @@ bool match_matches_window(Match *match, i3Window *window) {
     LOG("Checking window 0x%08x (class %s)\n", window->id, window->class_class);
 
     if (match->class != NULL) {
-        if (window->class_class != NULL &&
-            regex_matches(match->class, window->class_class)) {
+        if (window->class_class == NULL)
+            return false;
+        if (strcmp(match->class->pattern, "__focused__") == 0 &&
+            strcmp(window->class_class, focused->window->class_class) == 0) {
+            LOG("window class matches focused window\n");
+        } else if (regex_matches(match->class, window->class_class)) {
             LOG("window class matches (%s)\n", window->class_class);
         } else {
             return false;
@@ -97,8 +103,12 @@ bool match_matches_window(Match *match, i3Window *window) {
     }
 
     if (match->instance != NULL) {
-        if (window->class_instance != NULL &&
-            regex_matches(match->instance, window->class_instance)) {
+        if (window->class_instance == NULL)
+            return false;
+        if (strcmp(match->instance->pattern, "__focused__") == 0 &&
+            strcmp(window->class_instance, focused->window->class_instance) == 0) {
+            LOG("window instance matches focused window\n");
+        } else if (regex_matches(match->instance, window->class_instance)) {
             LOG("window instance matches (%s)\n", window->class_instance);
         } else {
             return false;
@@ -115,17 +125,27 @@ bool match_matches_window(Match *match, i3Window *window) {
     }
 
     if (match->title != NULL) {
-        if (window->name != NULL &&
-            regex_matches(match->title, i3string_as_utf8(window->name))) {
-            LOG("title matches (%s)\n", i3string_as_utf8(window->name));
+        if (window->name == NULL)
+            return false;
+
+        const char *title = i3string_as_utf8(window->name);
+        if (strcmp(match->title->pattern, "__focused__") == 0 &&
+            strcmp(title, i3string_as_utf8(focused->window->name)) == 0) {
+            LOG("window title matches focused window\n");
+        } else if (regex_matches(match->title, title)) {
+            LOG("title matches (%s)\n", title);
         } else {
             return false;
         }
     }
 
     if (match->window_role != NULL) {
-        if (window->role != NULL &&
-            regex_matches(match->window_role, window->role)) {
+        if (window->role == NULL)
+            return false;
+        if (strcmp(match->window_role->pattern, "__focused__") == 0 &&
+            strcmp(window->role, focused->window->role) == 0) {
+            LOG("window role matches focused window\n");
+        } else if (regex_matches(match->window_role, window->role)) {
             LOG("window_role matches (%s)\n", window->role);
         } else {
             return false;
@@ -172,6 +192,24 @@ bool match_matches_window(Match *match, i3Window *window) {
         LOG("urgent matches oldest\n");
     }
 
+    if (match->workspace != NULL) {
+        if ((con = con_by_window_id(window->id)) == NULL)
+            return false;
+
+        Con *ws = con_get_workspace(con);
+        if (ws == NULL)
+            return false;
+
+        if (strcmp(match->workspace->pattern, "__focused__") == 0 &&
+            strcmp(ws->name, con_get_workspace(focused)->name) == 0) {
+            LOG("workspace matches focused workspace\n");
+        } else if (regex_matches(match->workspace, ws->name)) {
+            LOG("workspace matches (%s)\n", ws->name);
+        } else {
+            return false;
+        }
+    }
+
     if (match->dock != M_DONTCHECK) {
         if ((window->dock == W_DOCK_TOP && match->dock == M_DOCK_TOP) ||
             (window->dock == W_DOCK_BOTTOM && match->dock == M_DOCK_BOTTOM) ||