]> git.sur5r.net Git - i3/i3/commitdiff
Support a special value "__focused__" as a command criterion pattern for class, insta...
authorIngo Bürk <ingo.buerk@tngtech.com>
Fri, 28 Aug 2015 06:26:27 +0000 (08:26 +0200)
committerIngo Bürk <ingo.buerk@tngtech.com>
Fri, 28 Aug 2015 08:07:12 +0000 (10:07 +0200)
This special value will match if the window's property equals that of the currently focused window.

relates to #1770

docs/userguide
src/match.c

index 25f5a4ba0036752b39fdf1465f2f04c1fbcd179e..e24294490436cced7af501d819fd7cb3d0aa9f98 100644 (file)
@@ -1604,25 +1604,35 @@ for_window [class="^evil-app$"] floating enable, move container to workspace 4
 The criteria which are currently implemented are:
 
 class::
-       Compares the window class (the second part of WM_CLASS)
+       Compares the window class (the second part of WM_CLASS). Use the
+       special value +__focused__+ to match all windows having the same window
+       class as the currently focused window.
 instance::
-       Compares the window instance (the first part of WM_CLASS)
+       Compares the window instance (the first part of WM_CLASS). Use the
+       special value +__focused__+ to match all windows having the same window
+       instance as the currently focused window.
 window_role::
-       Compares the window role (WM_WINDOW_ROLE).
+       Compares the window role (WM_WINDOW_ROLE). Use the special value
+       +__focused__+ to match all windows having the same window role as the
+       currently focused window.
 window_type::
-        Compare the window type (_NET_WM_WINDOW_TYPE). Possible values are
-        +normal+, +dialog+, +utility+, +toolbar+, +splash+, +menu+, +dropdown_menu+,
-        +popup_menu+ and +toolti+.
+       Compare the window type (_NET_WM_WINDOW_TYPE). Possible values are
+       +normal+, +dialog+, +utility+, +toolbar+, +splash+, +menu+, +dropdown_menu+,
+       +popup_menu+ and +toolti+.
 id::
        Compares the X11 window ID, which you can get via +xwininfo+ for example.
 title::
        Compares the X11 window title (_NET_WM_NAME or WM_NAME as fallback).
+       Use the special value +__focused__+ to match all windows having the
+       same window title as the currently focused window.
 urgent::
        Compares the urgent state of the window. Can be "latest" or "oldest".
        Matches the latest or oldest urgent window, respectively.
        (The following aliases are also available: newest, last, recent, first)
 workspace::
-       Compares the workspace name of the workspace the window belongs to.
+       Compares the workspace name of the workspace the window belongs to. Use
+       the special value +__focused__+ to match all windows in the currently
+       focused workspace.
 con_mark::
        Compares the mark set for this container, see <<vim_like_marks>>.
 con_id::
index b95cf2342bf61bbebdd90c7aebb5c4e9de89e39d..20af38f61b3c765cbf6ada30fab725a3979c3b9c 100644 (file)
@@ -90,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;
@@ -99,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;
@@ -117,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;
@@ -182,7 +200,10 @@ bool match_matches_window(Match *match, i3Window *window) {
         if (ws == NULL)
             return false;
 
-        if (regex_matches(match->workspace, ws->name)) {
+        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;