commit 3bd6988

Michael Forney  ·  2014-02-24 22:36:13 +0000 UTC
parent 8187fc8
example/wm: Remove focus workaround

Now that keyboard/pointer focus revert to NULL on view destruction
rather than surface destruction, we can safely change focus on window
destruction, which happens before view destruction.
1 files changed,  +5, -34
+5, -34
 1@@ -52,7 +52,6 @@ static const uint32_t border_color_normal = 0xff888888;
 2 static struct screen * active_screen;
 3 static struct window * focused_window;
 4 static struct wl_event_loop * event_loop;
 5-static struct wl_event_source * focus_idle_source;
 6 
 7 /* This is a basic grid arrange function that tries to give each window an
 8  * equal space. */
 9@@ -110,41 +109,8 @@ static void screen_remove_window(struct screen * screen, struct window * window)
10     arrange(screen);
11 }
12 
13-/*
14- * We can't immediately change the focus when the currently focused window is
15- * being destroyed. This is because the keyboard registers a destroy listener
16- * for the current focus so it can correctly keep track of it's focus
17- * internally and set it to NULL. However, now we have two separate destroy
18- * listeners which want to change the focus to two different things, and it
19- * isn't defined which order they happen (and if they are adjacent, we end up
20- * breaking the linked list traversal).
21- *
22- * To prevent this, instead of changing the focus immediately, we register an
23- * idle event so that the focus is changed in the next iteration of the event
24- * loop.
25- *
26- * Another way to solve this issue is internally in swc by requiring that all
27- * window managers maintain a valid focus at all times. This way, the keyboard
28- * does not need to register a destroy listener for the focus because it knows
29- * that the window manager will provide a new focus before the old one becomes
30- * invalid.
31- */
32-static void commit_focus(void * data)
33-{
34-    swc_window_focus(focused_window ? focused_window->swc : NULL);
35-    focus_idle_source = NULL;
36-}
37-
38 static void focus(struct window * window)
39 {
40-    /* Add an idle source (if one doesn't already exist) to the event loop to
41-     * actually change the keyboard focus. */
42-    if (!focus_idle_source)
43-    {
44-        focus_idle_source = wl_event_loop_add_idle(event_loop,
45-                                                   &commit_focus, NULL);
46-    }
47-
48     if (focused_window)
49     {
50         swc_window_set_border(focused_window->swc,
51@@ -152,7 +118,12 @@ static void focus(struct window * window)
52     }
53 
54     if (window)
55+    {
56         swc_window_set_border(window->swc, border_color_active, border_width);
57+        swc_window_focus(window->swc);
58+    }
59+    else
60+        swc_window_focus(NULL);
61 
62     focused_window = window;
63 }