summaryrefslogtreecommitdiff
path: root/src/shell.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-04-12 09:55:26 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-04-12 09:55:26 -0400
commit40f55bdd74aaada07c4f0ad980899ee10cb1f3c1 (patch)
treecf21df4b6947f838076a961cd468794cc8ff10d0 /src/shell.c
parent86842ea8cf906da01d10bd0dee53c99cc67f18b7 (diff)
compositor: Add a destroy signal and turn weston_shell into signals
Diffstat (limited to 'src/shell.c')
-rw-r--r--src/shell.c83
1 files changed, 41 insertions, 42 deletions
diff --git a/src/shell.c b/src/shell.c
index 671c3a7d..dae6426b 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -40,7 +40,10 @@ struct shell_surface;
struct wl_shell {
struct weston_compositor *compositor;
- struct weston_shell shell;
+
+ struct wl_listener lock_listener;
+ struct wl_listener unlock_listener;
+ struct wl_listener destroy_listener;
struct weston_layer fullscreen_layer;
struct weston_layer panel_layer;
@@ -98,6 +101,7 @@ struct shell_surface {
struct weston_surface *surface;
struct wl_listener surface_destroy_listener;
struct shell_surface *parent;
+ struct wl_shell *shell;
enum shell_surface_type type;
int32_t saved_x, saved_y;
@@ -515,10 +519,7 @@ shell_surface_set_transient(struct wl_client *client,
static struct wl_shell *
shell_surface_get_shell(struct shell_surface *shsurf)
{
- struct weston_surface *es = shsurf->surface;
- struct weston_shell *shell = es->compositor->shell;
-
- return (struct wl_shell *)container_of(shell, struct wl_shell, shell);
+ return shsurf->shell;
}
static int
@@ -918,6 +919,7 @@ shell_get_shell_surface(struct wl_client *client,
(void (**)(void)) &shell_surface_implementation;
shsurf->resource.data = shsurf;
+ shsurf->shell = resource->data;
shsurf->saved_position_valid = false;
shsurf->surface = surface;
shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
@@ -1472,18 +1474,13 @@ rotate_binding(struct wl_input_device *device, uint32_t time,
}
static void
-activate(struct weston_shell *base, struct weston_surface *es,
+activate(struct wl_shell *shell, struct weston_surface *es,
struct weston_input_device *device)
{
- struct wl_shell *shell = container_of(base, struct wl_shell, shell);
- struct weston_compositor *compositor = shell->compositor;
struct weston_surface *surf, *prev;
weston_surface_activate(es, device);
- if (compositor->wxs)
- weston_xserver_surface_activate(es);
-
switch (get_shell_surface_type(es)) {
case SHELL_SURFACE_BACKGROUND:
case SHELL_SURFACE_PANEL:
@@ -1540,7 +1537,7 @@ click_to_activate_binding(struct wl_input_device *device,
uint32_t button, uint32_t axis, int32_t state, void *data)
{
struct weston_input_device *wd = (struct weston_input_device *) device;
- struct weston_compositor *compositor = data;
+ struct wl_shell *shell = data;
struct weston_surface *focus;
struct weston_surface *upper;
@@ -1552,13 +1549,14 @@ click_to_activate_binding(struct wl_input_device *device,
focus = upper;
if (state && device->pointer_grab == &device->default_pointer_grab)
- activate(compositor->shell, focus, wd);
+ activate(shell, focus, wd);
}
static void
-lock(struct weston_shell *base)
+lock(struct wl_listener *listener, void *data)
{
- struct wl_shell *shell = container_of(base, struct wl_shell, shell);
+ struct wl_shell *shell =
+ container_of(listener, struct wl_shell, lock_listener);
struct weston_input_device *device;
struct shell_surface *shsurf;
struct weston_output *output;
@@ -1609,9 +1607,10 @@ lock(struct weston_shell *base)
}
static void
-unlock(struct weston_shell *base)
+unlock(struct wl_listener *listener, void *data)
{
- struct wl_shell *shell = container_of(base, struct wl_shell, shell);
+ struct wl_shell *shell =
+ container_of(listener, struct wl_shell, unlock_listener);
if (!shell->locked || shell->lock_surface) {
weston_compositor_wake(shell->compositor);
@@ -1642,10 +1641,9 @@ center_on_output(struct weston_surface *surface, struct weston_output *output)
}
static void
-map(struct weston_shell *base, struct weston_surface *surface,
+map(struct wl_shell *shell, struct weston_surface *surface,
int32_t width, int32_t height, int32_t sx, int32_t sy)
{
- struct wl_shell *shell = container_of(base, struct wl_shell, shell);
struct weston_compositor *compositor = shell->compositor;
struct shell_surface *shsurf;
enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
@@ -1746,7 +1744,7 @@ map(struct weston_shell *base, struct weston_surface *surface,
case SHELL_SURFACE_FULLSCREEN:
case SHELL_SURFACE_MAXIMIZED:
if (!shell->locked)
- activate(base, surface,
+ activate(shell, surface,
(struct weston_input_device *)
compositor->input_device);
break;
@@ -1759,10 +1757,9 @@ map(struct weston_shell *base, struct weston_surface *surface,
}
static void
-configure(struct weston_shell *base, struct weston_surface *surface,
+configure(struct wl_shell *shell, struct weston_surface *surface,
GLfloat x, GLfloat y, int32_t width, int32_t height)
{
- struct wl_shell *shell = container_of(base, struct wl_shell, shell);
enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
enum shell_surface_type prev_surface_type = SHELL_SURFACE_NONE;
struct shell_surface *shsurf;
@@ -1812,8 +1809,8 @@ configure(struct weston_shell *base, struct weston_surface *surface,
static void
shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
{
- struct weston_shell *shell = es->compositor->shell;
struct shell_surface *shsurf = get_shell_surface(es);
+ struct wl_shell *shell = shsurf->shell;
if (!weston_surface_is_mapped(es)) {
map(shell, es, es->buffer->width, es->buffer->height, sx, sy);
@@ -1977,7 +1974,7 @@ bind_screensaver(struct wl_client *client,
}
struct switcher {
- struct weston_compositor *compositor;
+ struct wl_shell *shell;
struct weston_surface *current;
struct wl_listener listener;
struct wl_keyboard_grab grab;
@@ -1986,7 +1983,7 @@ struct switcher {
static void
switcher_next(struct switcher *switcher)
{
- struct weston_compositor *compositor = switcher->compositor;
+ struct weston_compositor *compositor = switcher->shell->compositor;
struct weston_surface *surface;
struct weston_surface *first = NULL, *prev = NULL, *next = NULL;
struct shell_surface *shsurf;
@@ -2047,7 +2044,7 @@ switcher_handle_surface_destroy(struct wl_listener *listener,
static void
switcher_destroy(struct switcher *switcher, uint32_t time)
{
- struct weston_compositor *compositor = switcher->compositor;
+ struct weston_compositor *compositor = switcher->shell->compositor;
struct weston_surface *surface;
struct weston_input_device *device =
(struct weston_input_device *) switcher->grab.input_device;
@@ -2058,7 +2055,7 @@ switcher_destroy(struct switcher *switcher, uint32_t time)
}
if (switcher->current)
- activate(compositor->shell, switcher->current, device);
+ activate(switcher->shell, switcher->current, device);
wl_list_remove(&switcher->listener.link);
wl_input_device_end_keyboard_grab(&device->input_device);
free(switcher);
@@ -2088,11 +2085,11 @@ switcher_binding(struct wl_input_device *device, uint32_t time,
uint32_t key, uint32_t button, uint32_t axis,
int32_t state, void *data)
{
- struct weston_compositor *compositor = data;
+ struct wl_shell *shell = data;
struct switcher *switcher;
switcher = malloc(sizeof *switcher);
- switcher->compositor = compositor;
+ switcher->shell = shell;
switcher->current = NULL;
switcher->listener.notify = switcher_handle_surface_destroy;
wl_list_init(&switcher->listener.link);
@@ -2140,9 +2137,8 @@ static void
debug_repaint_binding(struct wl_input_device *device, uint32_t time,
uint32_t key, uint32_t button, uint32_t axis, int32_t state, void *data)
{
- struct weston_compositor *compositor = data;
- struct wl_shell *shell =
- container_of(compositor->shell, struct wl_shell, shell);
+ struct wl_shell *shell = data;
+ struct weston_compositor *compositor = shell->compositor;
struct weston_surface *surface;
if (shell->debug_repaint_surface) {
@@ -2172,9 +2168,10 @@ debug_repaint_binding(struct wl_input_device *device, uint32_t time,
}
static void
-shell_destroy(struct weston_shell *base)
+shell_destroy(struct wl_listener *listener, void *data)
{
- struct wl_shell *shell = container_of(base, struct wl_shell, shell);
+ struct wl_shell *shell =
+ container_of(listener, struct wl_shell, destroy_listener);
if (shell->child.client)
wl_client_destroy(shell->child.client);
@@ -2197,9 +2194,13 @@ shell_init(struct weston_compositor *ec)
memset(shell, 0, sizeof *shell);
shell->compositor = ec;
- shell->shell.lock = lock;
- shell->shell.unlock = unlock;
- shell->shell.destroy = shell_destroy;
+
+ shell->destroy_listener.notify = shell_destroy;
+ wl_signal_add(&ec->destroy_signal, &shell->destroy_listener);
+ shell->lock_listener.notify = lock;
+ wl_signal_add(&ec->lock_signal, &shell->lock_listener);
+ shell->unlock_listener.notify = unlock;
+ wl_signal_add(&ec->unlock_signal, &shell->unlock_listener);
wl_list_init(&shell->backgrounds);
wl_list_init(&shell->panels);
@@ -2239,7 +2240,7 @@ shell_init(struct weston_compositor *ec)
MODIFIER_CTRL | MODIFIER_ALT,
terminate_binding, ec);
weston_compositor_add_binding(ec, 0, BTN_LEFT, 0, 0,
- click_to_activate_binding, ec);
+ click_to_activate_binding, shell);
weston_compositor_add_binding(ec, 0, 0, WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL,
MODIFIER_SUPER | MODIFIER_ALT,
surface_opacity_binding, NULL);
@@ -2249,7 +2250,7 @@ shell_init(struct weston_compositor *ec)
MODIFIER_SUPER | MODIFIER_ALT,
rotate_binding, NULL);
weston_compositor_add_binding(ec, KEY_TAB, 0, 0, MODIFIER_SUPER,
- switcher_binding, ec);
+ switcher_binding, shell);
/* brightness */
weston_compositor_add_binding(ec, KEY_F9, 0, 0, MODIFIER_CTRL,
@@ -2262,9 +2263,7 @@ shell_init(struct weston_compositor *ec)
backlight_binding, ec);
weston_compositor_add_binding(ec, KEY_SPACE, 0, 0, MODIFIER_SUPER,
- debug_repaint_binding, ec);
-
- ec->shell = &shell->shell;
+ debug_repaint_binding, shell);
return 0;
}