swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 7e72a86703e29869a6e6b535d83f8a42a7e91730
parent 29ac3936fe7e2524282e82220e3a75a46dedee38
Author: Michael Forney <mforney@mforney.org>
Date:   Sun, 30 Jun 2013 22:20:15 -0700

Move focus destroy handling to input_focus

Now that shells can have their own destructor guaranteed to go last, we
don't have to worry about the focus trying to unset and change to
something else at the same time (if a shell changed keyboard focus when
the old focus got destroyed).

Diffstat:
Minput_focus.c | 27+++++++++++++++++++++++++--
Minput_focus.h | 1+
Mpointer.c | 24------------------------
Mpointer.h | 1-
4 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/input_focus.c b/input_focus.c @@ -30,17 +30,24 @@ static inline void focus(struct swc_input_focus * input_focus, struct swc_surface * surface, struct wl_resource * resource) { - if (resource) + if (surface) { - input_focus->handler->enter(input_focus->handler, resource, surface); + wl_resource_add_destroy_listener + (surface->resource, &input_focus->surface_destroy_listener); } + if (resource) + input_focus->handler->enter(input_focus->handler, resource, surface); + input_focus->surface = surface; input_focus->resource = resource; } static inline void unfocus(struct swc_input_focus * input_focus) { + if (input_focus->surface) + wl_list_remove(&input_focus->surface_destroy_listener.link); + if (input_focus->resource) { input_focus->handler->leave(input_focus->handler, input_focus->resource, @@ -48,11 +55,27 @@ static inline void unfocus(struct swc_input_focus * input_focus) } } +static void handle_focus_surface_destroy(struct wl_listener * listener, + void * data) +{ + struct swc_input_focus * input_focus; + + printf("focus surface destroy\n"); + + input_focus = wl_container_of(listener, input_focus, + surface_destroy_listener); + + input_focus->surface = NULL; + input_focus->resource = NULL; +} + bool swc_input_focus_initialize(struct swc_input_focus * input_focus, struct swc_input_focus_handler * handler) { input_focus->resource = NULL; input_focus->surface = NULL; + input_focus->surface_destroy_listener.notify + = &handle_focus_surface_destroy; input_focus->handler = handler; wl_list_init(&input_focus->resources); diff --git a/input_focus.h b/input_focus.h @@ -53,6 +53,7 @@ struct swc_input_focus { struct wl_resource * resource; struct swc_surface * surface; + struct wl_listener surface_destroy_listener; struct swc_input_focus_handler * handler; struct wl_list resources; diff --git a/pointer.c b/pointer.c @@ -41,17 +41,6 @@ static void leave(struct swc_input_focus_handler * handler, wl_pointer_send_leave(resource, serial, surface->resource); } -static void handle_focus_surface_destroy(struct wl_listener * listener, - void * data) -{ - struct swc_pointer * pointer; - - pointer = wl_container_of(listener, pointer, - focus_surface_destroy_listener); - - pointer->focus.surface = NULL; -} - bool swc_pointer_initialize(struct swc_pointer * pointer) { wl_signal_init(&pointer->event_signal); @@ -62,9 +51,6 @@ bool swc_pointer_initialize(struct swc_pointer * pointer) pointer->focus_handler.enter = &enter; pointer->focus_handler.leave = &leave; - pointer->focus_surface_destroy_listener.notify - = &handle_focus_surface_destroy; - swc_input_focus_initialize(&pointer->focus, &pointer->focus_handler); return true; @@ -81,16 +67,6 @@ void swc_pointer_finish(struct swc_pointer * pointer) void swc_pointer_set_focus(struct swc_pointer * pointer, struct swc_surface * surface) { - if (surface != pointer->focus.surface) - { - if (pointer->focus.surface) - wl_list_remove(&pointer->focus_surface_destroy_listener.link); - - if (surface) - wl_resource_add_destroy_listener - (surface->resource, &pointer->focus_surface_destroy_listener); - } - swc_input_focus_set(&pointer->focus, surface); } diff --git a/pointer.h b/pointer.h @@ -25,7 +25,6 @@ struct swc_pointer { struct swc_input_focus focus; struct swc_input_focus_handler focus_handler; - struct wl_listener focus_surface_destroy_listener; struct wl_signal event_signal;