commit 0494b4c

Michael Forney  ·  2013-12-04 07:53:00 +0000 UTC
parent debb520
Handle NULL window in swc_window_focus
2 files changed,  +20, -5
+16, -2
 1@@ -70,10 +70,24 @@ void swc_window_hide(struct swc_window * window)
 2 EXPORT
 3 void swc_window_focus(struct swc_window * window)
 4 {
 5-    if (INTERNAL(window)->impl->focus)
 6+    struct swc_surface * new_focus = window ? INTERNAL(window)->surface : NULL,
 7+                       * old_focus = swc.seat->keyboard->focus.surface;
 8+
 9+    /* If the keyboard already has a focused window, and we are changing the
10+     * focus to either NULL, or a window with a different implementation, set
11+     * the focus of the previous focus window's implementation to NULL. */
12+    if (old_focus && old_focus->window
13+        && !(window && INTERNAL(window)->impl
14+                    == INTERNAL(old_focus->window)->impl)
15+        && INTERNAL(old_focus->window)->impl->focus)
16+    {
17+        INTERNAL(old_focus->window)->impl->focus(NULL);
18+    }
19+
20+    if (window && INTERNAL(window)->impl->focus)
21         INTERNAL(window)->impl->focus(window);
22 
23-    swc_keyboard_set_focus(swc.seat->keyboard, INTERNAL(window)->surface);
24+    swc_keyboard_set_focus(swc.seat->keyboard, new_focus);
25 }
26 
27 EXPORT
+4, -3
 1@@ -281,11 +281,12 @@ static void configure(struct swc_window * window,
 2 
 3 static void focus(struct swc_window * window)
 4 {
 5-    struct xwl_window * xwl_window
 6-        = CONTAINER_OF(window, typeof(*xwl_window), window.base);
 7+    xcb_window_t id = window ? CONTAINER_OF(window, struct xwl_window,
 8+                                            window.base)->id
 9+                             : XCB_NONE;
10 
11     xcb_set_input_focus(xwm.connection, XCB_INPUT_FOCUS_NONE,
12-                        xwl_window->id, XCB_CURRENT_TIME);
13+                        id, XCB_CURRENT_TIME);
14     xcb_flush(xwm.connection);
15 }
16