]> git.sur5r.net Git - i3/i3/blobdiff - src/con.c
Merge pull request #1961 from Airblader/bug-1957
[i3/i3] / src / con.c
index 7a8ccd5830f9a0ad519c85b9498f7c937fadecca..d1148301f5d5bb9d37e8f69a00112493b67a718c 100644 (file)
--- a/src/con.c
+++ b/src/con.c
@@ -519,6 +519,79 @@ Con *con_by_mark(const char *mark) {
     return NULL;
 }
 
+/*
+ * Toggles the mark on a container.
+ * If the container already has this mark, the mark is removed.
+ * Otherwise, the mark is assigned to the container.
+ *
+ */
+void con_mark_toggle(Con *con, const char *mark) {
+    assert(con != NULL);
+    DLOG("Toggling mark \"%s\" on con = %p.\n", mark, con);
+
+    if (con->mark != NULL && strcmp(con->mark, mark) == 0) {
+        con_unmark(mark);
+    } else {
+        con_mark(con, mark);
+    }
+}
+
+/*
+ * Assigns a mark to the container.
+ *
+ */
+void con_mark(Con *con, const char *mark) {
+    assert(con != NULL);
+    DLOG("Setting mark \"%s\" on con = %p.\n", mark, con);
+
+    FREE(con->mark);
+    con->mark = sstrdup(mark);
+    con->mark_changed = true;
+
+    DLOG("Clearing the mark from all other windows.\n");
+    Con *other;
+    TAILQ_FOREACH(other, &all_cons, all_cons) {
+        /* Skip the window we actually handled since we took care of it already. */
+        if (con == other)
+            continue;
+
+        if (other->mark != NULL && strcmp(other->mark, mark) == 0) {
+            FREE(other->mark);
+            other->mark_changed = true;
+        }
+    }
+}
+
+/*
+ * If mark is NULL, this removes all existing marks.
+ * Otherwise, it will only remove the given mark (if it is present).
+ *
+ */
+void con_unmark(const char *mark) {
+    Con *con;
+    if (mark == NULL) {
+        DLOG("Unmarking all containers.\n");
+        TAILQ_FOREACH(con, &all_cons, all_cons) {
+            if (con->mark == NULL)
+                continue;
+
+            FREE(con->mark);
+            con->mark_changed = true;
+        }
+    } else {
+        DLOG("Removing mark \"%s\".\n", mark);
+        con = con_by_mark(mark);
+        if (con == NULL) {
+            DLOG("No container found with this mark, so there is nothing to do.\n");
+            return;
+        }
+
+        DLOG("Found mark on con = %p. Removing it now.\n", con);
+        FREE(con->mark);
+        con->mark_changed = true;
+    }
+}
+
 /*
  * Returns the first container below 'con' which wants to swallow this window
  * TODO: priority
@@ -658,14 +731,13 @@ static void con_set_fullscreen_mode(Con *con, fullscreen_mode_t fullscreen_mode)
     if (con->window == NULL)
         return;
 
-    uint32_t values[1];
-    unsigned int num = 0;
-
-    if (con->fullscreen_mode != CF_NONE)
-        values[num++] = A__NET_WM_STATE_FULLSCREEN;
-
-    xcb_change_property(conn, XCB_PROP_MODE_REPLACE, con->window->id,
-                        A__NET_WM_STATE, XCB_ATOM_ATOM, 32, num, values);
+    if (con->fullscreen_mode != CF_NONE) {
+        DLOG("Setting _NET_WM_STATE_FULLSCREEN for con = %p / window = %d.\n", con, con->window->id);
+        xcb_add_property_atom(conn, con->window->id, A__NET_WM_STATE, A__NET_WM_STATE_FULLSCREEN);
+    } else {
+        DLOG("Removing _NET_WM_STATE_FULLSCREEN for con = %p / window = %d.\n", con, con->window->id);
+        xcb_remove_property_atom(conn, con->window->id, A__NET_WM_STATE, A__NET_WM_STATE_FULLSCREEN);
+    }
 }
 
 /*
@@ -956,8 +1028,8 @@ bool con_move_to_mark(Con *con, const char *mark) {
         target = TAILQ_FIRST(&(target->focus_head));
     }
 
-    if (con == target) {
-        DLOG("cannot move the container to itself, aborting.\n");
+    if (con == target || con == target->parent) {
+        DLOG("cannot move the container to or inside itself, aborting.\n");
         return false;
     }