commit d4ea60b

Michael Forney  ·  2014-08-09 20:33:11 +0000 UTC
parent 1b447a3
Remove window states from public API
6 files changed,  +34, -52
+3, -10
 1@@ -134,7 +134,6 @@ static void window_event(struct wl_listener * listener, void * data)
 2     struct swc_event * event = data;
 3     struct window * window = NULL, * next_focus;
 4 
 5-
 6     window = wl_container_of(listener, window, event_listener);
 7 
 8     switch (event->type)
 9@@ -160,15 +159,6 @@ static void window_event(struct wl_listener * listener, void * data)
10             screen_remove_window(window->screen, window);
11             free(window);
12             break;
13-        case SWC_WINDOW_STATE_CHANGED:
14-            /* When the window changes state to NORMAL, we can add it to the
15-             * current screen and then rearrange the windows on that screen. */
16-            if (window->swc->state == SWC_WINDOW_STATE_NORMAL)
17-            {
18-                screen_add_window(active_screen, window);
19-                focus(window);
20-            }
21-            break;
22         case SWC_WINDOW_ENTERED:
23             focus(window);
24             break;
25@@ -228,6 +218,9 @@ static void new_window(struct swc_window * swc)
26 
27     /* Register a listener for the window's event signal. */
28     wl_signal_add(&swc->event_signal, &window->event_listener);
29+
30+    screen_add_window(active_screen, window);
31+    focus(window);
32 }
33 
34 const struct swc_manager manager = { &new_screen, &new_window };
+5, -8
 1@@ -105,7 +105,7 @@ static void set_toplevel(struct wl_client * client,
 2 {
 3     struct shell_surface * shell_surface = wl_resource_get_user_data(resource);
 4 
 5-    window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
 6+    window_manage(&shell_surface->window);
 7     window_set_parent(&shell_surface->window, NULL);
 8 }
 9 
10@@ -123,11 +123,8 @@ static void set_transient(struct wl_client * client,
11     if (!parent_view || !parent_view->window)
12         return;
13 
14-    window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
15+    window_manage(&shell_surface->window);
16     window_set_parent(&shell_surface->window, parent_view->window);
17-    view_move(&shell_surface->window.view->base,
18-              parent_view->base.geometry.x + x,
19-              parent_view->base.geometry.y + y);
20 }
21 
22 static void set_fullscreen(struct wl_client * client,
23@@ -145,7 +142,7 @@ static void set_fullscreen(struct wl_client * client,
24 
25     /* TODO: Handle fullscreen windows. */
26 
27-    window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
28+    window_manage(&shell_surface->window);
29     window_set_parent(&shell_surface->window, NULL);
30 }
31 
32@@ -163,7 +160,7 @@ static void set_popup(struct wl_client * client, struct wl_resource * resource,
33     if (!parent_view || !parent_view->window)
34         return;
35 
36-    window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NONE);
37+    window_unmanage(&shell_surface->window);
38     window_set_parent(&shell_surface->window, parent_view->window);
39     view_move(&shell_surface->window.view->base,
40               parent_view->base.geometry.x + x,
41@@ -178,7 +175,7 @@ static void set_maximized(struct wl_client * client,
42 
43     /* TODO: Handle maximized windows. */
44 
45-    window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
46+    window_manage(&shell_surface->window);
47     window_set_parent(&shell_surface->window, NULL);
48 }
49 
+0, -17
 1@@ -102,14 +102,6 @@ enum
 2      */
 3     SWC_WINDOW_CLASS_CHANGED,
 4 
 5-    /**
 6-     * Sent when the window's state changes.
 7-     *
 8-     * The display server should adjust the window's placement and visibility
 9-     * accordingly.
10-     */
11-    SWC_WINDOW_STATE_CHANGED,
12-
13     /**
14      * Sent when the pointer enters the window.
15      */
16@@ -136,12 +128,6 @@ struct swc_window
17     char * title;
18     char * class;
19 
20-    enum
21-    {
22-        SWC_WINDOW_STATE_NONE,
23-        SWC_WINDOW_STATE_NORMAL
24-    } state;
25-
26     struct swc_window * parent;
27 };
28 
29@@ -304,9 +290,6 @@ struct swc_manager
30 
31     /**
32      * Called when a new window is created.
33-     *
34-     * The window begins in the WITHDRAWN state and should not be managed until
35-     * it changes to the TOPLEVEL state.
36      */
37     void (* new_window)(struct swc_window * window);
38 };
+20, -13
 1@@ -255,7 +255,6 @@ bool window_initialize(struct window * window, const struct window_impl * impl,
 2 
 3     window->base.title = NULL;
 4     window->base.class = NULL;
 5-    window->base.state = SWC_WINDOW_STATE_NONE;
 6     window->base.parent = NULL;
 7     wl_signal_init(&window->base.event_signal);
 8 
 9@@ -264,6 +263,7 @@ bool window_initialize(struct window * window, const struct window_impl * impl,
10 
11     window->impl = impl;
12     window->view->window = window;
13+    window->managed = false;
14     window->move.interaction.handler = (struct pointer_handler) {
15         .motion = &move_motion,
16         .button = &handle_button
17@@ -273,8 +273,6 @@ bool window_initialize(struct window * window, const struct window_impl * impl,
18         .button = &handle_button
19     };
20 
21-    swc.manager->new_window(&window->base);
22-
23     return true;
24 }
25 
26@@ -282,13 +280,31 @@ void window_finalize(struct window * window)
27 {
28     DEBUG("Finalizing window, %p\n", window);
29 
30-    swc_send_event(&window->base.event_signal, SWC_WINDOW_DESTROYED, NULL);
31+    window_unmanage(window);
32     compositor_view_destroy(window->view);
33     window->view->window = NULL;
34     free(window->base.title);
35     free(window->base.class);
36 }
37 
38+void window_manage(struct window * window)
39+{
40+    if (window->managed)
41+        return;
42+
43+    swc.manager->new_window(&window->base);
44+    window->managed = true;
45+}
46+
47+void window_unmanage(struct window * window)
48+{
49+    if (!window->managed)
50+        return;
51+
52+    swc_send_event(&window->base.event_signal, SWC_WINDOW_DESTROYED, NULL);
53+    window->managed = false;
54+}
55+
56 void window_set_title(struct window * window, const char * title, size_t length)
57 {
58     free(window->base.title);
59@@ -303,15 +319,6 @@ void window_set_class(struct window * window, const char * class)
60     swc_send_event(&window->base.event_signal, SWC_WINDOW_CLASS_CHANGED, NULL);
61 }
62 
63-void window_set_state(struct window * window, uint32_t state)
64-{
65-    if (window->base.state == state)
66-        return;
67-
68-    window->base.state = state;
69-    swc_send_event(&window->base.event_signal, SWC_WINDOW_STATE_CHANGED, NULL);
70-}
71-
72 void window_set_parent(struct window * window, struct window * parent)
73 {
74     if (window->base.parent == &parent->base)
+5, -2
 1@@ -41,6 +41,7 @@ struct window
 2     const struct window_impl * impl;
 3 
 4     struct compositor_view * view;
 5+    bool managed;
 6 
 7     struct
 8     {
 9@@ -71,13 +72,15 @@ bool window_initialize(struct window * window, const struct window_impl * impl,
10 
11 void window_finalize(struct window * window);
12 
13+void window_manage(struct window * window);
14+
15+void window_unmanage(struct window * window);
16+
17 void window_set_title(struct window * window,
18                       const char * title, size_t length);
19 
20 void window_set_class(struct window * window, const char * class);
21 
22-void window_set_state(struct window * window, uint32_t state);
23-
24 void window_set_parent(struct window * window, struct window * parent);
25 
26 void window_begin_move(struct window * window, struct button * button);
+1, -2
 1@@ -299,8 +299,7 @@ static bool manage_window(struct xwl_window * xwl_window)
 2         xcb_configure_window(xwm.connection, xwl_window->id, mask, values);
 3         update_name(xwl_window);
 4         update_protocols(xwl_window);
 5-
 6-        window_set_state(&xwl_window->window, SWC_WINDOW_STATE_NORMAL);
 7+        window_manage(&xwl_window->window);
 8     }
 9 
10     wl_list_remove(&xwl_window->link);