]> git.sur5r.net Git - i3/i3/blobdiff - src/window.c
Merge pull request #1515 from Airblader/feature-commands-error-messages
[i3/i3] / src / window.c
index 219e64ce78639532d4b55869cce098fbdf11d0e5..ace109e3e068e7e95dc383a33a0a9c16771d6bd5 100644 (file)
@@ -34,7 +34,8 @@ void window_update_class(i3Window *win, xcb_get_property_reply_t *prop, bool bef
     win->class_instance = sstrdup(new_class);
     if ((strlen(new_class) + 1) < (size_t)xcb_get_property_value_length(prop))
         win->class_class = sstrdup(new_class + strlen(new_class) + 1);
-    else win->class_class = NULL;
+    else
+        win->class_class = NULL;
     LOG("WM_CLASS changed to %s (instance), %s (class)\n",
         win->class_instance, win->class_class);
 
@@ -124,7 +125,8 @@ void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bo
  */
 void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop) {
     if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
-        DLOG("CLIENT_LEADER not set.\n");
+        DLOG("CLIENT_LEADER not set on window 0x%08x.\n", win->id);
+        win->leader = XCB_NONE;
         FREE(prop);
         return;
     }
@@ -148,7 +150,8 @@ void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop) {
  */
 void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop) {
     if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
-        DLOG("TRANSIENT_FOR not set.\n");
+        DLOG("TRANSIENT_FOR not set on window 0x%08x.\n", win->id);
+        win->transient_for = XCB_NONE;
         FREE(prop);
         return;
     }
@@ -159,7 +162,7 @@ void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop)
         return;
     }
 
-    DLOG("Transient for changed to %08x\n", transient_for);
+    DLOG("Transient for changed to 0x%08x (window 0x%08x)\n", transient_for, win->id);
 
     win->transient_for = transient_for;
 
@@ -186,7 +189,7 @@ void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop)
     DLOG("Reserved pixels changed to: left = %d, right = %d, top = %d, bottom = %d\n",
          strut[0], strut[1], strut[2], strut[3]);
 
-    win->reserved = (struct reservedpx){ strut[0], strut[1], strut[2], strut[3] };
+    win->reserved = (struct reservedpx){strut[0], strut[1], strut[2], strut[3]};
 
     free(prop);
 }
@@ -204,7 +207,7 @@ void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool befo
 
     char *new_role;
     if (asprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
-                 (char*)xcb_get_property_value(prop)) == -1) {
+                 (char *)xcb_get_property_value(prop)) == -1) {
         perror("asprintf()");
         DLOG("Could not get WM_WINDOW_ROLE\n");
         free(prop);
@@ -254,3 +257,59 @@ void window_update_hints(i3Window *win, xcb_get_property_reply_t *prop, bool *ur
 
     free(prop);
 }
+
+/*
+ * Updates the MOTIF_WM_HINTS. The container's border style should be set to
+ * `motif_border_style' if border style is not BS_NORMAL.
+ *
+ * i3 only uses this hint when it specifies a window should have no
+ * title bar, or no decorations at all, which is how most window managers
+ * handle it.
+ *
+ * The EWMH spec intended to replace Motif hints with _NET_WM_WINDOW_TYPE, but
+ * it is still in use by popular widget toolkits such as GTK+ and Java AWT.
+ *
+ */
+void window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, border_style_t *motif_border_style) {
+/* This implementation simply mirrors Gnome's Metacity. Official
+     * documentation of this hint is nowhere to be found.
+     * For more information see:
+     * https://people.gnome.org/~tthurman/docs/metacity/xprops_8h-source.html
+     * http://stackoverflow.com/questions/13787553/detect-if-a-x11-window-has-decorations
+     */
+#define MWM_HINTS_DECORATIONS (1 << 1)
+#define MWM_DECOR_ALL (1 << 0)
+#define MWM_DECOR_BORDER (1 << 1)
+#define MWM_DECOR_TITLE (1 << 3)
+
+    if (motif_border_style != NULL)
+        *motif_border_style = BS_NORMAL;
+
+    if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
+        FREE(prop);
+        return;
+    }
+
+    /* The property consists of an array of 5 uint64_t's. The first value is a bit
+     * mask of what properties the hint will specify. We are only interested in
+     * MWM_HINTS_DECORATIONS because it indicates that the second value of the
+     * array tells us which decorations the window should have, each flag being
+     * a particular decoration. */
+    uint64_t *motif_hints = (uint64_t *)xcb_get_property_value(prop);
+
+    if (motif_border_style != NULL && motif_hints[0] & MWM_HINTS_DECORATIONS) {
+        if (motif_hints[1] & MWM_DECOR_ALL || motif_hints[1] & MWM_DECOR_TITLE)
+            *motif_border_style = BS_NORMAL;
+        else if (motif_hints[1] & MWM_DECOR_BORDER)
+            *motif_border_style = BS_PIXEL;
+        else
+            *motif_border_style = BS_NONE;
+    }
+
+    FREE(prop);
+
+#undef MWM_HINTS_DECORATIONS
+#undef MWM_DECOR_ALL
+#undef MWM_DECOR_BORDER
+#undef MWM_DECOR_TITLE
+}