commit 7e72a86
Michael Forney
·
2013-07-01 05:20:15 +0000 UTC
parent 29ac393
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).
4 files changed,
+26,
-27
+25,
-2
1@@ -30,17 +30,24 @@ static inline void focus(struct swc_input_focus * input_focus,
2 struct swc_surface * surface,
3 struct wl_resource * resource)
4 {
5- if (resource)
6+ if (surface)
7 {
8- input_focus->handler->enter(input_focus->handler, resource, surface);
9+ wl_resource_add_destroy_listener
10+ (surface->resource, &input_focus->surface_destroy_listener);
11 }
12
13+ if (resource)
14+ input_focus->handler->enter(input_focus->handler, resource, surface);
15+
16 input_focus->surface = surface;
17 input_focus->resource = resource;
18 }
19
20 static inline void unfocus(struct swc_input_focus * input_focus)
21 {
22+ if (input_focus->surface)
23+ wl_list_remove(&input_focus->surface_destroy_listener.link);
24+
25 if (input_focus->resource)
26 {
27 input_focus->handler->leave(input_focus->handler, input_focus->resource,
28@@ -48,11 +55,27 @@ static inline void unfocus(struct swc_input_focus * input_focus)
29 }
30 }
31
32+static void handle_focus_surface_destroy(struct wl_listener * listener,
33+ void * data)
34+{
35+ struct swc_input_focus * input_focus;
36+
37+ printf("focus surface destroy\n");
38+
39+ input_focus = wl_container_of(listener, input_focus,
40+ surface_destroy_listener);
41+
42+ input_focus->surface = NULL;
43+ input_focus->resource = NULL;
44+}
45+
46 bool swc_input_focus_initialize(struct swc_input_focus * input_focus,
47 struct swc_input_focus_handler * handler)
48 {
49 input_focus->resource = NULL;
50 input_focus->surface = NULL;
51+ input_focus->surface_destroy_listener.notify
52+ = &handle_focus_surface_destroy;
53 input_focus->handler = handler;
54
55 wl_list_init(&input_focus->resources);
+1,
-0
1@@ -53,6 +53,7 @@ struct swc_input_focus
2 {
3 struct wl_resource * resource;
4 struct swc_surface * surface;
5+ struct wl_listener surface_destroy_listener;
6
7 struct swc_input_focus_handler * handler;
8 struct wl_list resources;
+0,
-24
1@@ -41,17 +41,6 @@ static void leave(struct swc_input_focus_handler * handler,
2 wl_pointer_send_leave(resource, serial, surface->resource);
3 }
4
5-static void handle_focus_surface_destroy(struct wl_listener * listener,
6- void * data)
7-{
8- struct swc_pointer * pointer;
9-
10- pointer = wl_container_of(listener, pointer,
11- focus_surface_destroy_listener);
12-
13- pointer->focus.surface = NULL;
14-}
15-
16 bool swc_pointer_initialize(struct swc_pointer * pointer)
17 {
18 wl_signal_init(&pointer->event_signal);
19@@ -62,9 +51,6 @@ bool swc_pointer_initialize(struct swc_pointer * pointer)
20 pointer->focus_handler.enter = &enter;
21 pointer->focus_handler.leave = &leave;
22
23- pointer->focus_surface_destroy_listener.notify
24- = &handle_focus_surface_destroy;
25-
26 swc_input_focus_initialize(&pointer->focus, &pointer->focus_handler);
27
28 return true;
29@@ -81,16 +67,6 @@ void swc_pointer_finish(struct swc_pointer * pointer)
30 void swc_pointer_set_focus(struct swc_pointer * pointer,
31 struct swc_surface * surface)
32 {
33- if (surface != pointer->focus.surface)
34- {
35- if (pointer->focus.surface)
36- wl_list_remove(&pointer->focus_surface_destroy_listener.link);
37-
38- if (surface)
39- wl_resource_add_destroy_listener
40- (surface->resource, &pointer->focus_surface_destroy_listener);
41- }
42-
43 swc_input_focus_set(&pointer->focus, surface);
44 }
45
+0,
-1
1@@ -25,7 +25,6 @@ struct swc_pointer
2 {
3 struct swc_input_focus focus;
4 struct swc_input_focus_handler focus_handler;
5- struct wl_listener focus_surface_destroy_listener;
6
7 struct wl_signal event_signal;
8