aboutsummaryrefslogtreecommitdiffstats
path: root/compositor/compositor.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2010-12-06 16:43:16 -0500
committerKristian Høgsberg <krh@bitplanet.net>2010-12-06 16:43:16 -0500
commitc551bd2ae8bbb4cec52fd9576a217ae5e2cef43a (patch)
tree3be6a69eb2c3a5ec1bc40ff1d1f77b85386b2b08 /compositor/compositor.c
parentRefactor drm buffer creation a bit (diff)
downloadwayland-c551bd2ae8bbb4cec52fd9576a217ae5e2cef43a.tar
wayland-c551bd2ae8bbb4cec52fd9576a217ae5e2cef43a.tar.gz
wayland-c551bd2ae8bbb4cec52fd9576a217ae5e2cef43a.tar.bz2
wayland-c551bd2ae8bbb4cec52fd9576a217ae5e2cef43a.tar.lz
wayland-c551bd2ae8bbb4cec52fd9576a217ae5e2cef43a.tar.xz
wayland-c551bd2ae8bbb4cec52fd9576a217ae5e2cef43a.tar.zst
wayland-c551bd2ae8bbb4cec52fd9576a217ae5e2cef43a.zip
Add a surface destroy callback and use it for focus tracking
Diffstat (limited to 'compositor/compositor.c')
-rw-r--r--compositor/compositor.c70
1 files changed, 43 insertions, 27 deletions
diff --git a/compositor/compositor.c b/compositor/compositor.c
index d0cdcf2..7b1adec 100644
--- a/compositor/compositor.c
+++ b/compositor/compositor.c
@@ -129,6 +129,8 @@ wlsc_surface_create(struct wlsc_compositor *compositor,
if (surface == NULL)
return NULL;
+ wl_list_init(&surface->surface.destroy_listener_list);
+
glGenTextures(1, &surface->texture);
glBindTexture(GL_TEXTURE_2D, surface->texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -159,13 +161,17 @@ destroy_surface(struct wl_resource *resource, struct wl_client *client)
struct wlsc_surface *surface =
container_of(resource, struct wlsc_surface, surface.resource);
struct wlsc_compositor *compositor = surface->compositor;
- struct wlsc_listener *l;
+ struct wl_listener *l, *next;
wl_list_remove(&surface->link);
glDeleteTextures(1, &surface->texture);
wl_list_for_each(l, &compositor->surface_destroy_listener_list, link)
- l->func(l, surface);
+ l->func(l, &surface->surface);
+
+ wl_list_for_each_safe(l, next,
+ &surface->surface.destroy_listener_list, link)
+ l->func(l, &surface->surface);
free(surface);
@@ -574,7 +580,7 @@ get_time(void)
struct wlsc_drag {
struct wl_drag drag;
- struct wlsc_listener listener;
+ struct wl_listener listener;
};
static void
@@ -596,14 +602,14 @@ destroy_drag(struct wl_resource *resource, struct wl_client *client)
const static struct wl_drag_interface drag_interface;
static void
-drag_handle_surface_destroy(struct wlsc_listener *listener,
- struct wlsc_surface *surface)
+drag_handle_surface_destroy(struct wl_listener *listener,
+ struct wl_surface *surface)
{
struct wlsc_drag *drag =
container_of(listener, struct wlsc_drag, listener);
uint32_t time = get_time();
- if (drag->drag.pointer_focus == &surface->surface)
+ if (drag->drag.pointer_focus == surface)
wl_drag_set_pointer_focus(&drag->drag, NULL, time, 0, 0, 0, 0);
}
@@ -984,24 +990,6 @@ const static struct wl_input_device_interface input_device_interface = {
input_device_attach,
};
-static void
-handle_surface_destroy(struct wlsc_listener *listener,
- struct wlsc_surface *surface)
-{
- struct wlsc_input_device *device =
- container_of(listener, struct wlsc_input_device, listener);
- uint32_t time = get_time();
-
- if (device->input_device.keyboard_focus == &surface->surface)
- wl_input_device_set_keyboard_focus(&device->input_device, NULL, time);
- if (device->input_device.pointer_focus == &surface->surface)
- wl_input_device_set_pointer_focus(&device->input_device, NULL, time,
- 0, 0, 0, 0);
- if (device->input_device.pointer_focus == &surface->surface ||
- (device->input_device.pointer_focus == &wl_grab_surface &&
- device->grab_surface == surface))
- wlsc_input_device_end_grab(device, time);
-}
static void
wl_drag_set_pointer_focus(struct wl_drag *drag,
@@ -1165,6 +1153,32 @@ static const struct wl_drag_interface drag_interface = {
drag_cancel,
};
+static void
+lose_pointer_focus(struct wl_listener *listener,
+ struct wl_surface *surface)
+{
+ uint32_t time = get_time();
+ struct wlsc_input_device *device =
+ container_of(listener, struct wlsc_input_device,
+ input_device.pointer_focus_listener);
+
+ wl_input_device_set_pointer_focus(&device->input_device,
+ NULL, time, 0, 0, 0, 0);
+ wlsc_input_device_end_grab(device, time);
+}
+
+static void
+lose_keyboard_focus(struct wl_listener *listener,
+ struct wl_surface *surface)
+{
+ uint32_t time = get_time();
+ struct wlsc_input_device *device =
+ container_of(listener, struct wlsc_input_device,
+ input_device.keyboard_focus_listener);
+
+ wl_input_device_set_keyboard_focus(&device->input_device, NULL, time);
+}
+
void
wlsc_input_device_init(struct wlsc_input_device *device,
struct wlsc_compositor *ec)
@@ -1183,9 +1197,11 @@ wlsc_input_device_init(struct wlsc_input_device *device,
device->hotspot_x = 16;
device->hotspot_y = 16;
- device->listener.func = handle_surface_destroy;
- wl_list_insert(ec->surface_destroy_listener_list.prev,
- &device->listener.link);
+ wl_list_init(&device->input_device.pointer_focus_listener.link);
+ device->input_device.pointer_focus_listener.func = lose_pointer_focus;
+ wl_list_init(&device->input_device.keyboard_focus_listener.link);
+ device->input_device.keyboard_focus_listener.func = lose_keyboard_focus;
+
wl_list_insert(ec->input_device_list.prev, &device->link);
wlsc_input_device_set_pointer_image(device, WLSC_POINTER_LEFT_PTR);