commit d4ea60b7461cc1d1c7fb811fea8e445536c20a45
parent 1b447a367081414b05072922bc007ef6f35d3071
Author: Michael Forney <mforney@mforney.org>
Date: Sat, 9 Aug 2014 13:33:11 -0700
Remove window states from public API
Diffstat:
6 files changed, 34 insertions(+), 52 deletions(-)
diff --git a/example/wm.c b/example/wm.c
@@ -134,7 +134,6 @@ static void window_event(struct wl_listener * listener, void * data)
struct swc_event * event = data;
struct window * window = NULL, * next_focus;
-
window = wl_container_of(listener, window, event_listener);
switch (event->type)
@@ -160,15 +159,6 @@ static void window_event(struct wl_listener * listener, void * data)
screen_remove_window(window->screen, window);
free(window);
break;
- case SWC_WINDOW_STATE_CHANGED:
- /* When the window changes state to NORMAL, we can add it to the
- * current screen and then rearrange the windows on that screen. */
- if (window->swc->state == SWC_WINDOW_STATE_NORMAL)
- {
- screen_add_window(active_screen, window);
- focus(window);
- }
- break;
case SWC_WINDOW_ENTERED:
focus(window);
break;
@@ -228,6 +218,9 @@ static void new_window(struct swc_window * swc)
/* Register a listener for the window's event signal. */
wl_signal_add(&swc->event_signal, &window->event_listener);
+
+ screen_add_window(active_screen, window);
+ focus(window);
}
const struct swc_manager manager = { &new_screen, &new_window };
diff --git a/libswc/shell_surface.c b/libswc/shell_surface.c
@@ -105,7 +105,7 @@ static void set_toplevel(struct wl_client * client,
{
struct shell_surface * shell_surface = wl_resource_get_user_data(resource);
- window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
+ window_manage(&shell_surface->window);
window_set_parent(&shell_surface->window, NULL);
}
@@ -123,11 +123,8 @@ static void set_transient(struct wl_client * client,
if (!parent_view || !parent_view->window)
return;
- window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
+ window_manage(&shell_surface->window);
window_set_parent(&shell_surface->window, parent_view->window);
- view_move(&shell_surface->window.view->base,
- parent_view->base.geometry.x + x,
- parent_view->base.geometry.y + y);
}
static void set_fullscreen(struct wl_client * client,
@@ -145,7 +142,7 @@ static void set_fullscreen(struct wl_client * client,
/* TODO: Handle fullscreen windows. */
- window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
+ window_manage(&shell_surface->window);
window_set_parent(&shell_surface->window, NULL);
}
@@ -163,7 +160,7 @@ static void set_popup(struct wl_client * client, struct wl_resource * resource,
if (!parent_view || !parent_view->window)
return;
- window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NONE);
+ window_unmanage(&shell_surface->window);
window_set_parent(&shell_surface->window, parent_view->window);
view_move(&shell_surface->window.view->base,
parent_view->base.geometry.x + x,
@@ -178,7 +175,7 @@ static void set_maximized(struct wl_client * client,
/* TODO: Handle maximized windows. */
- window_set_state(&shell_surface->window, SWC_WINDOW_STATE_NORMAL);
+ window_manage(&shell_surface->window);
window_set_parent(&shell_surface->window, NULL);
}
diff --git a/libswc/swc.h b/libswc/swc.h
@@ -103,14 +103,6 @@ enum
SWC_WINDOW_CLASS_CHANGED,
/**
- * Sent when the window's state changes.
- *
- * The display server should adjust the window's placement and visibility
- * accordingly.
- */
- SWC_WINDOW_STATE_CHANGED,
-
- /**
* Sent when the pointer enters the window.
*/
SWC_WINDOW_ENTERED,
@@ -136,12 +128,6 @@ struct swc_window
char * title;
char * class;
- enum
- {
- SWC_WINDOW_STATE_NONE,
- SWC_WINDOW_STATE_NORMAL
- } state;
-
struct swc_window * parent;
};
@@ -304,9 +290,6 @@ struct swc_manager
/**
* Called when a new window is created.
- *
- * The window begins in the WITHDRAWN state and should not be managed until
- * it changes to the TOPLEVEL state.
*/
void (* new_window)(struct swc_window * window);
};
diff --git a/libswc/window.c b/libswc/window.c
@@ -255,7 +255,6 @@ bool window_initialize(struct window * window, const struct window_impl * impl,
window->base.title = NULL;
window->base.class = NULL;
- window->base.state = SWC_WINDOW_STATE_NONE;
window->base.parent = NULL;
wl_signal_init(&window->base.event_signal);
@@ -264,6 +263,7 @@ bool window_initialize(struct window * window, const struct window_impl * impl,
window->impl = impl;
window->view->window = window;
+ window->managed = false;
window->move.interaction.handler = (struct pointer_handler) {
.motion = &move_motion,
.button = &handle_button
@@ -273,8 +273,6 @@ bool window_initialize(struct window * window, const struct window_impl * impl,
.button = &handle_button
};
- swc.manager->new_window(&window->base);
-
return true;
}
@@ -282,13 +280,31 @@ void window_finalize(struct window * window)
{
DEBUG("Finalizing window, %p\n", window);
- swc_send_event(&window->base.event_signal, SWC_WINDOW_DESTROYED, NULL);
+ window_unmanage(window);
compositor_view_destroy(window->view);
window->view->window = NULL;
free(window->base.title);
free(window->base.class);
}
+void window_manage(struct window * window)
+{
+ if (window->managed)
+ return;
+
+ swc.manager->new_window(&window->base);
+ window->managed = true;
+}
+
+void window_unmanage(struct window * window)
+{
+ if (!window->managed)
+ return;
+
+ swc_send_event(&window->base.event_signal, SWC_WINDOW_DESTROYED, NULL);
+ window->managed = false;
+}
+
void window_set_title(struct window * window, const char * title, size_t length)
{
free(window->base.title);
@@ -303,15 +319,6 @@ void window_set_class(struct window * window, const char * class)
swc_send_event(&window->base.event_signal, SWC_WINDOW_CLASS_CHANGED, NULL);
}
-void window_set_state(struct window * window, uint32_t state)
-{
- if (window->base.state == state)
- return;
-
- window->base.state = state;
- swc_send_event(&window->base.event_signal, SWC_WINDOW_STATE_CHANGED, NULL);
-}
-
void window_set_parent(struct window * window, struct window * parent)
{
if (window->base.parent == &parent->base)
diff --git a/libswc/window.h b/libswc/window.h
@@ -41,6 +41,7 @@ struct window
const struct window_impl * impl;
struct compositor_view * view;
+ bool managed;
struct
{
@@ -71,13 +72,15 @@ bool window_initialize(struct window * window, const struct window_impl * impl,
void window_finalize(struct window * window);
+void window_manage(struct window * window);
+
+void window_unmanage(struct window * window);
+
void window_set_title(struct window * window,
const char * title, size_t length);
void window_set_class(struct window * window, const char * class);
-void window_set_state(struct window * window, uint32_t state);
-
void window_set_parent(struct window * window, struct window * parent);
void window_begin_move(struct window * window, struct button * button);
diff --git a/libswc/xwm.c b/libswc/xwm.c
@@ -299,8 +299,7 @@ static bool manage_window(struct xwl_window * xwl_window)
xcb_configure_window(xwm.connection, xwl_window->id, mask, values);
update_name(xwl_window);
update_protocols(xwl_window);
-
- window_set_state(&xwl_window->window, SWC_WINDOW_STATE_NORMAL);
+ window_manage(&xwl_window->window);
}
wl_list_remove(&xwl_window->link);