commit 1c1bc119f035318ee4aa3c167717b2cf773c35ed
parent 9f45312eb651247d167f7660da3182c41e56258e
Author: Michael Forney <mforney@mforney.org>
Date: Tue, 3 Sep 2013 16:24:05 -0700
pointer: Handle cursor surface destroys
Diffstat:
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/libswc/pointer.c b/libswc/pointer.c
@@ -41,6 +41,15 @@ static void leave(struct swc_input_focus_handler * handler,
wl_pointer_send_leave(resource, serial, surface->resource);
}
+static void handle_cursor_surface_destroy(struct wl_listener * listener,
+ void * data)
+{
+ struct swc_pointer * pointer = swc_container_of(listener, typeof(*pointer),
+ cursor.destroy_listener);
+
+ pointer->cursor.surface = NULL;
+}
+
bool swc_pointer_initialize(struct swc_pointer * pointer)
{
wl_signal_init(&pointer->event_signal);
@@ -51,6 +60,8 @@ bool swc_pointer_initialize(struct swc_pointer * pointer)
pointer->focus_handler.enter = &enter;
pointer->focus_handler.leave = &leave;
+ pointer->cursor.destroy_listener.notify = &handle_cursor_surface_destroy;
+
swc_input_focus_initialize(&pointer->focus, &pointer->focus_handler);
return true;
@@ -80,6 +91,9 @@ static void set_cursor(struct wl_client * client,
printf("set_cursor\n");
+ if (pointer->cursor.surface)
+ wl_list_remove(&pointer->cursor.destroy_listener.link);
+
surface = surface_resource ? wl_resource_get_user_data(surface_resource)
: NULL;
@@ -87,6 +101,8 @@ static void set_cursor(struct wl_client * client,
{
surface->geometry.x = wl_fixed_to_int(pointer->x) - hotspot_x;
surface->geometry.y = wl_fixed_to_int(pointer->y) - hotspot_y;
+ wl_resource_add_destroy_listener(surface->resource,
+ &pointer->cursor.destroy_listener);
}
pointer->cursor.surface = surface;
diff --git a/libswc/pointer.h b/libswc/pointer.h
@@ -32,6 +32,7 @@ struct swc_pointer
{
struct swc_surface * surface;
int32_t hotspot_x, hotspot_y;
+ struct wl_listener destroy_listener;
} cursor;
struct swc_pointer_handler * handler;