]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Correctly handle unmap, don’t apply attribute XCB_EVENT_MASK_BUTTON_PRESS
authorMichael Stapelberg <michael+git@stapelberg.de>
Sat, 14 Feb 2009 18:55:18 +0000 (19:55 +0100)
committerMichael Stapelberg <michael+git@stapelberg.de>
Sat, 14 Feb 2009 18:55:18 +0000 (19:55 +0100)
Those two fix problems seen with mplayer

include/data.h
src/handlers.c
src/mainx.c

index 32a693079804ee61fa092cea9318e30bff4a7086..96a57b290102bb26f3ffa9832f03c9210eb13ec1 100644 (file)
@@ -129,6 +129,10 @@ struct Client {
            will reconfigure the client. */
         bool force_reconfigure;
 
+        /* When reparenting a window, an unmap-notify is sent. As we delete windows when they’re
+           unmapped, we need to ignore that one. Therefore, this flag is set when reparenting. */
+        bool awaiting_useless_unmap;
+
         /* XCB contexts */
         xcb_window_t frame; /* Our window: The frame around the client */
         xcb_gcontext_t titlegc; /* The titlebar’s graphic context inside the frame */
index 793c88a90f913893c95beed7fdd23e649ca6ce6b..01f5efef047132531eb24af840fa677ed9131be6 100644 (file)
@@ -299,32 +299,29 @@ int handle_map_notify_event(void *prophs, xcb_connection_t *conn, xcb_map_notify
  *
  */
 int handle_unmap_notify_event(void *data, xcb_connection_t *c, xcb_unmap_notify_event_t *e) {
-        Client *client = table_remove(byChild, e->event);
-        xcb_window_t root;
+        xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(c)).data->root;
+
+        Client *client = table_get(byChild, e->window);
+        /* First, we need to check if the client is awaiting an unmap-request which
+           was generated by us reparenting the window. In that case, we just ignore it. */
+        if (client != NULL && client->awaiting_useless_unmap) {
+                printf("Dropping this unmap request, it was generated by reparenting\n");
+                client->awaiting_useless_unmap = false;
+                return 1;
+        }
+        client = table_remove(byChild, e->window);
+
         printf("UnmapNotify for 0x%08x (received from 0x%08x): ", e->window, e->event);
-        if(!client)
-        {
+        if(client == NULL) {
                 printf("not a managed window. Ignoring.\n");
                 return 0;
         }
 
-        int rows, cols;
-        Client *con_client;
-        /* TODO: clear this up */
-        for (cols = 0; cols < c_ws->cols; cols++)
-                for (rows = 0; rows < c_ws->rows; rows++)
-                        CIRCLEQ_FOREACH(con_client, &(CUR_TABLE[cols][rows]->clients), clients)
-                                if (con_client == client) {
-                                        printf("removing from container\n");
-                                        if (client->container->currently_focused == client)
-                                                client->container->currently_focused = NULL;
-                                        CIRCLEQ_REMOVE(&(CUR_TABLE[cols][rows]->clients), con_client, clients);
-                                        break;
-                                }
-
 
+        if (client->container->currently_focused == client)
+                client->container->currently_focused = NULL;
+        CIRCLEQ_REMOVE(&(client->container->clients), client, clients);
 
-        root = xcb_setup_roots_iterator(xcb_get_setup(c)).data->root;
         printf("child of 0x%08x.\n", client->frame);
         xcb_reparent_window(c, client->child, root, 0, 0);
         xcb_destroy_window(c, client->frame);
index 8966c15b3d1cc90ed0633e12a980f84d67644a1f..92b9468f8b85a82663f5a0c9761f8f54d407fcdb 100644 (file)
@@ -49,9 +49,6 @@ Display *xkbdpy;
 TAILQ_HEAD(bindings_head, Binding) bindings;
 xcb_event_handlers_t evenths;
 
-/* hm, xcb_wm wants us to implement this. */
-table_t *byChild = 0;
-table_t *byParent = 0;
 xcb_window_t root_win;
 xcb_atom_t atoms[6];
 
@@ -194,15 +191,17 @@ void reparent_window(xcb_connection_t *conn, xcb_window_t child,
         table_put(byChild, child, new);
 
         /* Moves the original window into the new frame we've created for it */
-        xcb_reparent_window(conn, child, new->frame, 0, font->height);
+        new->awaiting_useless_unmap = true;
+        cookie = xcb_reparent_window_checked(conn, child, new->frame, 0, font->height);
+        check_error(conn, cookie, "Could not reparent window");
 
         /* We are interested in property changes */
         mask = XCB_CW_EVENT_MASK;
         values[0] =     XCB_EVENT_MASK_PROPERTY_CHANGE |
                         XCB_EVENT_MASK_STRUCTURE_NOTIFY |
-                        XCB_EVENT_MASK_ENTER_WINDOW |
-                        XCB_EVENT_MASK_BUTTON_PRESS;
-        xcb_change_window_attributes(conn, child, mask, values);
+                        XCB_EVENT_MASK_ENTER_WINDOW;
+        cookie = xcb_change_window_attributes_checked(conn, child, mask, values);
+        check_error(conn, cookie, "Could not change window attributes");
 
         /* We need to grab the mouse buttons for click to focus */
         xcb_grab_button(conn, false, child, XCB_EVENT_MASK_BUTTON_PRESS,