]> git.sur5r.net Git - i3/i3/blobdiff - src/match.c
Automatically call the migration script when the config does not look like v4
[i3/i3] / src / match.c
index 42eba26ea9ffda46a054365f1979f10f27829821..2449bad7a7e67f2eb755a91679f01f82d73936c2 100644 (file)
@@ -2,7 +2,7 @@
  * vim:ts=4:sw=4:expandtab
  *
  * i3 - an improved dynamic tiling window manager
- * © 2009-2010 Michael Stapelberg and contributors (see also: LICENSE)
+ * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
  *
  * A "match" is a data structure which acts like a mask or expression to match
  * certain windows or not. For example, when using commands, you can specify a
@@ -45,6 +45,25 @@ bool match_is_empty(Match *match) {
             match->floating == M_ANY);
 }
 
+/*
+ * Copies the data of a match from src to dest.
+ *
+ */
+void match_copy(Match *dest, Match *src) {
+    memcpy(dest, src, sizeof(Match));
+
+#define STRDUP(field) do { \
+    if (src->field != NULL) \
+        dest->field = sstrdup(src->field); \
+} while (0)
+
+    STRDUP(title);
+    STRDUP(mark);
+    STRDUP(application);
+    STRDUP(class);
+    STRDUP(instance);
+}
+
 /*
  * Check if a match data structure matches the given window.
  *
@@ -66,8 +85,19 @@ bool match_matches_window(Match *match, i3Window *window) {
         return true;
     }
 
+    /* TODO: pcre match */
+    if (match->title != NULL && window->name_json != NULL && strcasecmp(match->title, window->name_json) == 0) {
+        LOG("match made by title (%s)\n", window->name_json);
+        return true;
+    }
+
     LOG("match->dock = %d, window->dock = %d\n", match->dock, window->dock);
-    if (match->dock != -1 && window->dock == match->dock) {
+    if (match->dock != -1 &&
+        ((window->dock == W_DOCK_TOP && match->dock == M_DOCK_TOP) ||
+         (window->dock == W_DOCK_BOTTOM && match->dock == M_DOCK_BOTTOM) ||
+         ((window->dock == W_DOCK_TOP || window->dock == W_DOCK_BOTTOM) &&
+          match->dock == M_DOCK_ANY) ||
+         (window->dock == W_NODOCK && match->dock == M_NODOCK))) {
         LOG("match made by dock\n");
         return true;
     }
@@ -76,4 +106,3 @@ bool match_matches_window(Match *match, i3Window *window) {
 
     return false;
 }
-