]> git.sur5r.net Git - i3/i3/commitdiff
Handle transient hint and window class dialog to mark clients as floating
authorMichael Stapelberg <michael@stapelberg.de>
Fri, 12 Jun 2009 20:59:23 +0000 (22:59 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Fri, 12 Jun 2009 20:59:23 +0000 (22:59 +0200)
include/handlers.h
include/i3.h
include/xcb.h
src/handlers.c
src/mainx.c
src/manage.c

index c160b6007fd05f89539d036e15e8918504e77ba7..b4b2c99aa7d803ce874d7ed5d2928f95a271be7b 100644 (file)
@@ -124,4 +124,14 @@ int handle_window_type(void *data, xcb_connection_t *conn, uint8_t state, xcb_wi
 int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
                         xcb_atom_t name, xcb_get_property_reply_t *reply);
 
+/**
+ * Handles the transient for hints set by a window, signalizing that this window is a popup window
+ * for some other window.
+ *
+ * See ICCCM 4.1.2.6 for more details
+ *
+ */
+int handle_transient_for(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
+                         xcb_atom_t name, xcb_get_property_reply_t *reply);
+
 #endif
index 4f285b7c0b8be480570aeca438b823ba795bf03a..7bbab415d5dd3cafa0f75c5ff727bb6968a811f0 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef _I3_H
 #define _I3_H
 
-#define NUM_ATOMS 13
+#define NUM_ATOMS 14
 
 extern char **start_argv;
 extern Display *xkbdpy;
index bc335121f4b2e14b861cc99165ecb61c05c42775..7f89caaf144881f8abc1226560bcd87a78ff768f 100644 (file)
@@ -49,6 +49,7 @@ enum { _NET_SUPPORTED = 0,
         _NET_WM_STATE,
         _NET_WM_WINDOW_TYPE,
         _NET_WM_WINDOW_TYPE_DOCK,
+        _NET_WM_WINDOW_TYPE_DIALOG,
         _NET_WM_DESKTOP,
         _NET_WM_STRUT_PARTIAL,
         WM_PROTOCOLS,
index 010dcaa5e5da97a836c132e43ab1d5aff97d2a38..1aaf4f5a80c53f215c1c9d900dd3dd9e05c3ca75 100644 (file)
@@ -761,8 +761,8 @@ int handle_windowclass_change(void *data, xcb_connection_t *conn, uint8_t state,
                 return 1;
         }
 
-        if (strcmp(new_class, "tools") == 0) {
-                LOG("tool window, should we put it floating?\n");
+        if (strcmp(new_class, "tools") == 0 || strcmp(new_class, "Dialog") == 0) {
+                LOG("tool/dialog window, should we put it floating?\n");
                 if (client->floating == FLOATING_AUTO_OFF)
                         toggle_floating_mode(conn, client, true);
         }
@@ -901,6 +901,11 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w
         else
                 xcb_get_wm_normal_hints_reply(conn, xcb_get_wm_normal_hints_unchecked(conn, client->child), &size_hints, NULL);
 
+        if ((size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)) {
+                LOG("min size set\n");
+                LOG("gots min_width = %d, min_height = %d\n", size_hints.min_width, size_hints.min_height);
+        }
+
         /* If no aspect ratio was set or if it was invalid, we ignore the hints */
         if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) ||
             (size_hints.min_aspect_num <= 0) ||
@@ -955,3 +960,42 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w
 
         return 1;
 }
+
+/*
+ * Handles the transient for hints set by a window, signalizing that this window is a popup window
+ * for some other window.
+ *
+ * See ICCCM 4.1.2.6 for more details
+ *
+ */
+int handle_transient_for(void *data, xcb_connection_t *conn, uint8_t state, xcb_window_t window,
+                         xcb_atom_t name, xcb_get_property_reply_t *reply) {
+        LOG("Transient hint!\n");
+        Client *client = table_get(&by_child, window);
+        if (client == NULL) {
+                LOG("No such client\n");
+                return 1;
+        }
+
+        xcb_window_t transient_for;
+
+        if (reply != NULL) {
+                if (!xcb_get_wm_transient_for_from_reply(&transient_for, reply)) {
+                        LOG("Not transient for any window\n");
+                        return 1;
+                }
+        } else {
+                if (!xcb_get_wm_transient_for_reply(conn, xcb_get_wm_transient_for_unchecked(conn, window),
+                                                    &transient_for, NULL)) {
+                        LOG("Not transient for any window\n");
+                        return 1;
+                }
+        }
+
+        if (client->floating == FLOATING_AUTO_OFF) {
+                LOG("This is a popup window, putting into floating\n");
+                toggle_floating_mode(conn, client, true);
+        }
+
+        return 1;
+}
index cadd51252f97c9dc894ccb18511f7b2a60ee88fb..5e9bf0776d0a96730bc6ad6330a1b9539101d050 100644 (file)
@@ -275,6 +275,9 @@ int main(int argc, char *argv[], char *env[]) {
         /* Watch _NET_WM_NAME (= title of the window in UTF-8) property */
         xcb_property_set_handler(&prophs, atoms[_NET_WM_NAME], 128, handle_windowname_change, NULL);
 
+        /* Watch WM_TRANSIENT_FOR property (to which client this popup window belongs) */
+        xcb_property_set_handler(&prophs, WM_TRANSIENT_FOR, UINT_MAX, handle_transient_for, NULL);
+
         /* Watch WM_NAME (= title of the window in compound text) property for legacy applications */
         xcb_watch_wm_name(&prophs, 128, handle_windowname_change_legacy, NULL);
 
index de258c017ccec55ca3e5e4b6ebd76b61e30444e1..09cf66eb5cf1ae5ab372f0a9308705d71ed48cc0 100644 (file)
@@ -113,6 +113,7 @@ void manage_window(xcb_property_handlers_t *prophs, xcb_connection_t *conn, xcb_
         xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_CLASS);
         xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_NAME);
         xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_NORMAL_HINTS);
+        xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, WM_TRANSIENT_FOR);
         xcb_property_changed(prophs, XCB_PROPERTY_NEW_VALUE, window, atoms[_NET_WM_NAME]);
 
         free(geom);
@@ -169,6 +170,10 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
         new->container = CUR_CELL;
         new->workspace = new->container->workspace;
 
+        /* Minimum useful size for managed windows is 75x50 (primarily affects floating) */
+        width = max(width, 75);
+        height = max(height, 50);
+
         new->frame = xcb_generate_id(conn);
         new->child = child;
         new->rect.width = width;
@@ -243,16 +248,19 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
         xcb_atom_t *atom;
         xcb_get_property_reply_t *preply = xcb_get_property_reply(conn, wm_type_cookie, NULL);
         if (preply != NULL && preply->value_len > 0 && (atom = xcb_get_property_value(preply))) {
-                for (int i = 0; i < xcb_get_property_value_length(preply); i++) {
-                        if (atom[i] != atoms[_NET_WM_WINDOW_TYPE_DOCK])
-                                continue;
-                        LOG("Window is a dock.\n");
-                        new->dock = true;
-                        new->titlebar_position = TITLEBAR_OFF;
-                        new->force_reconfigure = true;
-                        new->container = NULL;
-                        SLIST_INSERT_HEAD(&(c_ws->screen->dock_clients), new, dock_clients);
-                }
+                for (int i = 0; i < xcb_get_property_value_length(preply); i++)
+                        if (atom[i] == atoms[_NET_WM_WINDOW_TYPE_DOCK]) {
+                                LOG("Window is a dock.\n");
+                                new->dock = true;
+                                new->titlebar_position = TITLEBAR_OFF;
+                                new->force_reconfigure = true;
+                                new->container = NULL;
+                                SLIST_INSERT_HEAD(&(c_ws->screen->dock_clients), new, dock_clients);
+                        } else if (atom[i] == atoms[_NET_WM_WINDOW_TYPE_DIALOG]) {
+                                /* Set the dialog window to automatically floating, will be used below */
+                                new->floating = FLOATING_AUTO_ON;
+                                LOG("dialog window, automatically floating\n");
+                        }
         }
 
         if (new->dock) {
@@ -336,7 +344,7 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
         }
 
         /* Insert into the currently active container, if it’s not a dock window */
-        if (!new->dock) {
+        if (!new->dock && new->floating <= FLOATING_USER_OFF) {
                 /* Insert after the old active client, if existing. If it does not exist, the
                    container is empty and it does not matter, where we insert it */
                 if (old_focused != NULL && !old_focused->dock)
@@ -358,6 +366,17 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
                 }
         }
 
+        if (new->floating >= FLOATING_AUTO_ON) {
+                new->floating_rect.x = new->rect.x;
+                new->floating_rect.y = new->rect.y;
+                LOG("copying size from tiling (%d, %d) size (%d, %d)\n",
+                                new->floating_rect.x, new->floating_rect.y,
+                                new->floating_rect.width, new->floating_rect.height);
+
+                /* Make sure it is on top of the other windows */
+                xcb_raise_window(conn, new->frame);
+        }
+
         new->initialized = true;
 
         /* Check if the window already got the fullscreen hint set */