]> git.sur5r.net Git - i3/i3/blobdiff - src/handlers.c
add missing docs/layout-saving-1.png
[i3/i3] / src / handlers.c
index 084a728561ae1db27e0be907ec8f68141fccb9f5..8c3bb48665626a24966efe90d6a20e330ef8fff7 100644 (file)
@@ -528,6 +528,17 @@ static void handle_destroy_notify_event(xcb_destroy_notify_event_t *event) {
     handle_unmap_notify_event(&unmap);
 }
 
+static bool window_name_changed(i3Window *window, char *old_name) {
+    if ((old_name == NULL) && (window->name == NULL))
+        return false;
+
+    /* Either the old or the new one is NULL, but not both. */
+    if ((old_name == NULL) ^ (window->name == NULL))
+        return true;
+
+    return (strcmp(old_name, i3string_as_utf8(window->name)) != 0);
+}
+
 /*
  * Called when a window changes its title
  *
@@ -538,10 +549,17 @@ static bool handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t
     if ((con = con_by_window_id(window)) == NULL || con->window == NULL)
         return false;
 
+    char *old_name = (con->window->name != NULL ? sstrdup(i3string_as_utf8(con->window->name)) : NULL);
+
     window_update_name(con->window, prop, false);
 
     x_push_changes(croot);
 
+    if (window_name_changed(con->window, old_name))
+        ipc_send_window_event("title", con);
+
+    FREE(old_name);
+
     return true;
 }
 
@@ -556,10 +574,17 @@ static bool handle_windowname_change_legacy(void *data, xcb_connection_t *conn,
     if ((con = con_by_window_id(window)) == NULL || con->window == NULL)
         return false;
 
+    char *old_name = (con->window->name != NULL ? sstrdup(i3string_as_utf8(con->window->name)) : NULL);
+
     window_update_name_legacy(con->window, prop, false);
 
     x_push_changes(croot);
 
+    if (window_name_changed(con->window, old_name))
+        ipc_send_window_event("title", con);
+
+    FREE(old_name);
+
     return true;
 }
 
@@ -682,6 +707,11 @@ static void handle_client_message(xcb_client_message_event_t *event) {
             return;
         }
 
+        if (con_is_internal(ws)) {
+            DLOG("Workspace is internal, ignoring _NET_ACTIVE_WINDOW\n");
+            return;
+        }
+
         if (ws != con_get_workspace(focused))
             workspace_show(ws);
 
@@ -706,35 +736,26 @@ static void handle_client_message(xcb_client_message_event_t *event) {
         xcb_flush(conn);
         free(reply);
     } else if (event->type == A__NET_REQUEST_FRAME_EXTENTS) {
-        // A client can request an estimate for the frame size which the window
-        // manager will put around it before actually mapping its window. Java
-        // does this (as of openjdk-7).
-        //
-        // Note that the calculation below is not entirely accurate — once you
-        // set a different border type, it’s off. We _could_ request all the
-        // window properties (which have to be set up at this point according
-        // to EWMH), but that seems rather elaborate. The standard explicitly
-        // says the application must cope with an estimate that is not entirely
-        // accurate.
+        /*
+         * A client can request an estimate for the frame size which the window
+         * manager will put around it before actually mapping its window. Java
+         * does this (as of openjdk-7).
+         *
+         * Note that the calculation below is not entirely accurate — once you
+         * set a different border type, it’s off. We _could_ request all the
+         * window properties (which have to be set up at this point according
+         * to EWMH), but that seems rather elaborate. The standard explicitly
+         * says the application must cope with an estimate that is not entirely
+         * accurate.
+         */
         DLOG("_NET_REQUEST_FRAME_EXTENTS for window 0x%08x\n", event->window);
-        xcb_get_geometry_reply_t *geometry;
-        xcb_get_geometry_cookie_t cookie = xcb_get_geometry(conn, event->window);
-
-        if (!(geometry = xcb_get_geometry_reply(conn, cookie, NULL))) {
-            ELOG("Could not get geometry of X11 window 0x%08x while handling "
-                 "the _NET_REQUEST_FRAME_EXTENTS ClientMessage\n",
-                 event->window);
-            return;
-        }
-
-        DLOG("Current geometry = x=%d, y=%d, width=%d, height=%d\n",
-             geometry->x, geometry->y, geometry->width, geometry->height);
 
+        /* The reply data: approximate frame size */
         Rect r = {
-            0, // left
-            geometry->width + 4, // right
-            0, // top
-            geometry->height + config.font.height + 5, // bottom
+            config.default_border_width, /* left */
+            config.default_border_width, /* right */
+            config.font.height + 5, /* top */
+            config.default_border_width /* bottom */
         };
         xcb_change_property(
                 conn,
@@ -1038,7 +1059,7 @@ static void property_notify(uint8_t state, xcb_window_t window, xcb_atom_t atom)
     struct property_handler_t *handler = NULL;
     xcb_get_property_reply_t *propr = NULL;
 
-    for (int c = 0; c < sizeof(property_handlers) / sizeof(struct property_handler_t); c++) {
+    for (size_t c = 0; c < sizeof(property_handlers) / sizeof(struct property_handler_t); c++) {
         if (property_handlers[c].atom != atom)
             continue;