commit b9f6dd5
Michael Forney
·
2013-07-01 05:05:47 +0000 UTC
parent ae4bd84
Rename input.{c,h} to input_focus.{c,h}
+1,
-1
1@@ -13,7 +13,7 @@ libswc_la_SOURCES = \
2 surface.c surface.h \
3 region.c region.h \
4 renderer.c renderer.h \
5- input.c input.h \
6+ input_focus.c input_focus.h \
7 keyboard.c keyboard.h \
8 pointer.c pointer.h \
9 seat.c seat.h \
D
input.c
+0,
-108
1@@ -1,108 +0,0 @@
2-#include "input.h"
3-#include "surface.h"
4-
5-#include <assert.h>
6-
7-#include "util.h"
8-
9-static inline void focus(struct swc_input * input,
10- struct swc_surface * surface,
11- struct wl_resource * resource)
12-{
13- if (resource)
14- {
15- input->handler->enter(input->handler, resource, surface);
16- }
17-
18- input->focus.surface = surface;
19- input->focus.resource = resource;
20-}
21-
22-static inline void unfocus(struct swc_input * input)
23-{
24- if (input->focus.resource)
25- {
26- input->handler->leave(input->handler, input->focus.resource,
27- input->focus.surface);
28- }
29-}
30-
31-bool swc_input_initialize(struct swc_input * input,
32- struct swc_input_handler * handler)
33-{
34- input->focus.resource = NULL;
35- input->focus.surface = NULL;
36- input->handler = handler;
37-
38- wl_list_init(&input->resources);
39-
40- return true;
41-}
42-
43-void swc_input_finish(struct swc_input * input)
44-{
45- /* XXX: Destroy resources? */
46-}
47-
48-void swc_input_add_resource(struct swc_input * input,
49- struct wl_resource * resource)
50-{
51- /* If this new input resource corresponds to our focus, set it as our
52- * focus. */
53- if (input->focus.surface)
54- {
55- struct wl_client * client, * surface_client;
56-
57- client = wl_resource_get_client(resource);
58- surface_client = wl_resource_get_client(input->focus.surface->resource);
59-
60- if (client == surface_client)
61- {
62- unfocus(input);
63- focus(input, input->focus.surface, resource);
64- }
65- }
66-
67- wl_list_insert(&input->resources, wl_resource_get_link(resource));
68-}
69-
70-void swc_input_remove_resource(struct swc_input * input,
71- struct wl_resource * resource)
72-{
73- if (resource == input->focus.resource)
74- input->focus.resource = NULL;
75-
76- swc_remove_resource(resource);
77-}
78-
79-void swc_input_set_focus(struct swc_input * input,
80- struct swc_surface * surface)
81-{
82- struct wl_client * client;
83- struct wl_display * display;
84- struct wl_resource * resource;
85- uint32_t serial;
86-
87- if (surface == input->focus.surface)
88- return;
89-
90- /* Unfocus previously focused surface. */
91- unfocus(input);
92-
93- /* Focus new surface, if given. */
94- if (surface)
95- {
96- client = wl_resource_get_client(surface->resource);
97- resource = wl_resource_find_for_client(&input->resources, client);
98-
99- focus(input, surface, resource);
100- }
101- else
102- {
103- input->focus.surface = NULL;
104- input->focus.resource = NULL;
105- }
106-
107- return;
108-}
109-
D
input.h
+0,
-46
1@@ -1,46 +0,0 @@
2-#ifndef SWC_INPUT_H
3-#define SWC_INPUT_H 1
4-
5-#include <stdbool.h>
6-#include <wayland-server.h>
7-
8-struct swc_surface;
9-
10-struct swc_input_handler
11-{
12- void (* enter)(struct swc_input_handler * handler,
13- struct wl_resource * resource,
14- struct swc_surface * surface);
15- void (* leave)(struct swc_input_handler * handler,
16- struct wl_resource * resource,
17- struct swc_surface * surface);
18-};
19-
20-struct swc_input
21-{
22- struct
23- {
24- struct wl_resource * resource;
25- struct swc_surface * surface;
26- } focus;
27-
28- struct swc_input_handler * handler;
29- struct wl_list resources;
30-};
31-
32-bool swc_input_initialize(struct swc_input * input,
33- struct swc_input_handler * input_handler);
34-
35-void swc_input_finish(struct swc_input * input);
36-
37-void swc_input_add_resource(struct swc_input * input,
38- struct wl_resource * resource);
39-
40-void swc_input_remove_resource(struct swc_input * input,
41- struct wl_resource * resource);
42-
43-void swc_input_set_focus(struct swc_input * input,
44- struct swc_surface * surface);
45-
46-#endif
47-
+128,
-0
1@@ -0,0 +1,128 @@
2+/* swc: input_focus.c
3+ *
4+ * Copyright (c) 2013 Michael Forney
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#include "input_focus.h"
26+#include "surface.h"
27+#include "util.h"
28+
29+static inline void focus(struct swc_input_focus * input_focus,
30+ struct swc_surface * surface,
31+ struct wl_resource * resource)
32+{
33+ if (resource)
34+ {
35+ input_focus->handler->enter(input_focus->handler, resource, surface);
36+ }
37+
38+ input_focus->surface = surface;
39+ input_focus->resource = resource;
40+}
41+
42+static inline void unfocus(struct swc_input_focus * input_focus)
43+{
44+ if (input_focus->resource)
45+ {
46+ input_focus->handler->leave(input_focus->handler, input_focus->resource,
47+ input_focus->surface);
48+ }
49+}
50+
51+bool swc_input_focus_initialize(struct swc_input_focus * input_focus,
52+ struct swc_input_focus_handler * handler)
53+{
54+ input_focus->resource = NULL;
55+ input_focus->surface = NULL;
56+ input_focus->handler = handler;
57+
58+ wl_list_init(&input_focus->resources);
59+
60+ return true;
61+}
62+
63+void swc_input_focus_finish(struct swc_input_focus * input_focus)
64+{
65+ /* XXX: Destroy resources? */
66+}
67+
68+void swc_input_focus_add_resource(struct swc_input_focus * input_focus,
69+ struct wl_resource * resource)
70+{
71+ /* If this new input resource corresponds to our focus, set it as our
72+ * focus. */
73+ if (input_focus->surface)
74+ {
75+ struct wl_client * client, * surface_client;
76+
77+ client = wl_resource_get_client(resource);
78+ surface_client = wl_resource_get_client(input_focus->surface->resource);
79+
80+ if (client == surface_client)
81+ {
82+ unfocus(input_focus);
83+ focus(input_focus, input_focus->surface, resource);
84+ }
85+ }
86+
87+ wl_list_insert(&input_focus->resources, wl_resource_get_link(resource));
88+}
89+
90+void swc_input_focus_remove_resource(struct swc_input_focus * input_focus,
91+ struct wl_resource * resource)
92+{
93+ if (resource == input_focus->resource)
94+ input_focus->resource = NULL;
95+
96+ swc_remove_resource(resource);
97+}
98+
99+void swc_input_focus_set(struct swc_input_focus * input_focus,
100+ struct swc_surface * surface)
101+{
102+ struct wl_client * client;
103+ struct wl_display * display;
104+ struct wl_resource * resource;
105+ uint32_t serial;
106+
107+ if (surface == input_focus->surface)
108+ return;
109+
110+ /* Unfocus previously focused surface. */
111+ unfocus(input_focus);
112+
113+ /* Focus new surface, if given. */
114+ if (surface)
115+ {
116+ client = wl_resource_get_client(surface->resource);
117+ resource = wl_resource_find_for_client(&input_focus->resources, client);
118+
119+ focus(input_focus, surface, resource);
120+ }
121+ else
122+ {
123+ input_focus->surface = NULL;
124+ input_focus->resource = NULL;
125+ }
126+
127+ return;
128+}
129+
+66,
-0
1@@ -0,0 +1,66 @@
2+/* swc: input_focus.h
3+ *
4+ * Copyright (c) 2013 Michael Forney
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#ifndef SWC_INPUT_FOCUS_H
26+#define SWC_INPUT_FOCUS_H 1
27+
28+#include <stdbool.h>
29+#include <wayland-server.h>
30+
31+struct swc_surface;
32+
33+struct swc_input_focus_handler
34+{
35+ void (* enter)(struct swc_input_focus_handler * handler,
36+ struct wl_resource * resource,
37+ struct swc_surface * surface);
38+ void (* leave)(struct swc_input_focus_handler * handler,
39+ struct wl_resource * resource,
40+ struct swc_surface * surface);
41+};
42+
43+struct swc_input_focus
44+{
45+ struct wl_resource * resource;
46+ struct swc_surface * surface;
47+
48+ struct swc_input_focus_handler * handler;
49+ struct wl_list resources;
50+};
51+
52+bool swc_input_focus_initialize(struct swc_input_focus * input_focus,
53+ struct swc_input_focus_handler * input_handler);
54+
55+void swc_input_focus_finish(struct swc_input_focus * input_focus);
56+
57+void swc_input_focus_add_resource(struct swc_input_focus * input_focus,
58+ struct wl_resource * resource);
59+
60+void swc_input_focus_remove_resource(struct swc_input_focus * input_focus,
61+ struct wl_resource * resource);
62+
63+void swc_input_focus_set(struct swc_input_focus * input_focus,
64+ struct swc_surface * surface);
65+
66+#endif
67+
+10,
-10
1@@ -3,7 +3,7 @@
2
3 #include <stdio.h>
4
5-static void enter(struct swc_input_handler * handler,
6+static void enter(struct swc_input_focus_handler * handler,
7 struct wl_resource * resource, struct swc_surface * surface)
8 {
9 struct swc_keyboard * keyboard;
10@@ -11,7 +11,7 @@ static void enter(struct swc_input_handler * handler,
11 struct wl_display * display;
12 uint32_t serial;
13
14- keyboard = wl_container_of(handler, keyboard, input_handler);
15+ keyboard = wl_container_of(handler, keyboard, focus_handler);
16 client = wl_resource_get_client(resource);
17 display = wl_client_get_display(client);
18 serial = wl_display_next_serial(display);
19@@ -20,7 +20,7 @@ static void enter(struct swc_input_handler * handler,
20 &keyboard->keys);
21 }
22
23-static void leave(struct swc_input_handler * handler,
24+static void leave(struct swc_input_focus_handler * handler,
25 struct wl_resource * resource, struct swc_surface * surface)
26 {
27 struct wl_client * client;
28@@ -38,10 +38,10 @@ bool swc_keyboard_initialize(struct swc_keyboard * keyboard)
29 {
30 wl_array_init(&keyboard->keys);
31
32- keyboard->input_handler.enter = &enter;
33- keyboard->input_handler.leave = &leave;
34+ keyboard->focus_handler.enter = &enter;
35+ keyboard->focus_handler.leave = &leave;
36
37- swc_input_initialize(&keyboard->input, &keyboard->input_handler);
38+ swc_input_focus_initialize(&keyboard->focus, &keyboard->focus_handler);
39
40 return true;
41 }
42@@ -49,7 +49,7 @@ bool swc_keyboard_initialize(struct swc_keyboard * keyboard)
43 void swc_keyboard_finish(struct swc_keyboard * keyboard)
44 {
45 wl_array_release(&keyboard->keys);
46- swc_input_finish(&keyboard->input);
47+ swc_input_focus_finish(&keyboard->focus);
48 }
49
50 /**
51@@ -58,14 +58,14 @@ void swc_keyboard_finish(struct swc_keyboard * keyboard)
52 void swc_keyboard_set_focus(struct swc_keyboard * keyboard,
53 struct swc_surface * surface)
54 {
55- swc_input_set_focus(&keyboard->input, surface);
56+ swc_input_focus_set(&keyboard->focus, surface);
57 }
58
59 static void unbind(struct wl_resource * resource)
60 {
61 struct swc_keyboard * keyboard = wl_resource_get_user_data(resource);
62
63- swc_input_remove_resource(&keyboard->input, resource);
64+ swc_input_focus_remove_resource(&keyboard->focus, resource);
65 }
66
67 struct wl_resource * swc_keyboard_bind(struct swc_keyboard * keyboard,
68@@ -76,7 +76,7 @@ struct wl_resource * swc_keyboard_bind(struct swc_keyboard * keyboard,
69 client_resource = wl_client_add_object(client, &wl_keyboard_interface,
70 NULL, id, keyboard);
71 wl_resource_set_destructor(client_resource, &unbind);
72- swc_input_add_resource(&keyboard->input, client_resource);
73+ swc_input_focus_add_resource(&keyboard->focus, client_resource);
74
75 return client_resource;
76 }
+3,
-3
1@@ -2,7 +2,7 @@
2 #define SWC_KEYBOARD_H 1
3
4 #include "surface.h"
5-#include "input.h"
6+#include "input_focus.h"
7
8 #include <wayland-server.h>
9
10@@ -19,8 +19,8 @@ struct swc_keyboard_handler
11
12 struct swc_keyboard
13 {
14- struct swc_input input;
15- struct swc_input_handler input_handler;
16+ struct swc_input_focus focus;
17+ struct swc_input_focus_handler focus_handler;
18
19 struct swc_keyboard_handler * handler;
20
+13,
-13
1@@ -4,7 +4,7 @@
2
3 #include <stdio.h>
4
5-static void enter(struct swc_input_handler * handler,
6+static void enter(struct swc_input_focus_handler * handler,
7 struct wl_resource * resource, struct swc_surface * surface)
8 {
9 struct swc_pointer * pointer;
10@@ -13,7 +13,7 @@ static void enter(struct swc_input_handler * handler,
11 uint32_t serial;
12 wl_fixed_t surface_x, surface_y;
13
14- pointer = wl_container_of(handler, pointer, input_handler);
15+ pointer = wl_container_of(handler, pointer, focus_handler);
16 client = wl_resource_get_client(resource);
17 display = wl_client_get_display(client);
18 serial = wl_display_next_serial(display);
19@@ -26,7 +26,7 @@ static void enter(struct swc_input_handler * handler,
20 surface_x, surface_y);
21 }
22
23-static void leave(struct swc_input_handler * handler,
24+static void leave(struct swc_input_focus_handler * handler,
25 struct wl_resource * resource, struct swc_surface * surface)
26 {
27 struct wl_client * client;
28@@ -49,7 +49,7 @@ static void handle_focus_surface_destroy(struct wl_listener * listener,
29 pointer = wl_container_of(listener, pointer,
30 focus_surface_destroy_listener);
31
32- pointer->input.focus.surface = NULL;
33+ pointer->focus.surface = NULL;
34 }
35
36 bool swc_pointer_initialize(struct swc_pointer * pointer)
37@@ -59,20 +59,20 @@ bool swc_pointer_initialize(struct swc_pointer * pointer)
38 pointer->x = wl_fixed_from_int(0);
39 pointer->y = wl_fixed_from_int(0);
40
41- pointer->input_handler.enter = &enter;
42- pointer->input_handler.leave = &leave;
43+ pointer->focus_handler.enter = &enter;
44+ pointer->focus_handler.leave = &leave;
45
46 pointer->focus_surface_destroy_listener.notify
47 = &handle_focus_surface_destroy;
48
49- swc_input_initialize(&pointer->input, &pointer->input_handler);
50+ swc_input_focus_initialize(&pointer->focus, &pointer->focus_handler);
51
52 return true;
53 }
54
55 void swc_pointer_finish(struct swc_pointer * pointer)
56 {
57- swc_input_finish(&pointer->input);
58+ swc_input_focus_finish(&pointer->focus);
59 }
60
61 /**
62@@ -81,9 +81,9 @@ void swc_pointer_finish(struct swc_pointer * pointer)
63 void swc_pointer_set_focus(struct swc_pointer * pointer,
64 struct swc_surface * surface)
65 {
66- if (surface != pointer->input.focus.surface)
67+ if (surface != pointer->focus.surface)
68 {
69- if (pointer->input.focus.surface)
70+ if (pointer->focus.surface)
71 wl_list_remove(&pointer->focus_surface_destroy_listener.link);
72
73 if (surface)
74@@ -91,7 +91,7 @@ void swc_pointer_set_focus(struct swc_pointer * pointer,
75 (surface->resource, &pointer->focus_surface_destroy_listener);
76 }
77
78- swc_input_set_focus(&pointer->input, surface);
79+ swc_input_focus_set(&pointer->focus, surface);
80 }
81
82 static void set_cursor(struct wl_client * client,
83@@ -132,7 +132,7 @@ static void unbind(struct wl_resource * resource)
84 {
85 struct swc_pointer * pointer = wl_resource_get_user_data(resource);
86
87- swc_input_remove_resource(&pointer->input, resource);
88+ swc_input_focus_remove_resource(&pointer->focus, resource);
89 }
90
91 struct wl_resource * swc_pointer_bind(struct swc_pointer * pointer,
92@@ -145,7 +145,7 @@ struct wl_resource * swc_pointer_bind(struct swc_pointer * pointer,
93 client_resource = wl_client_add_object(client, &wl_pointer_interface,
94 &pointer_implementation, id, pointer);
95 wl_resource_set_destructor(client_resource, &unbind);
96- swc_input_add_resource(&pointer->input, client_resource);
97+ swc_input_focus_add_resource(&pointer->focus, client_resource);
98
99 return client_resource;
100 }
+3,
-3
1@@ -2,7 +2,7 @@
2 #define SWC_POINTER_H 1
3
4 #include "surface.h"
5-#include "input.h"
6+#include "input_focus.h"
7
8 #include <wayland-server.h>
9
10@@ -23,8 +23,8 @@ enum swc_pointer_event
11
12 struct swc_pointer
13 {
14- struct swc_input input;
15- struct swc_input_handler input_handler;
16+ struct swc_input_focus focus;
17+ struct swc_input_focus_handler focus_handler;
18 struct wl_listener focus_surface_destroy_listener;
19
20 struct wl_signal event_signal;
M
seat.c
+6,
-6
1@@ -27,10 +27,10 @@ static void handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
2 uint32_t serial;
3 enum xkb_key_direction direction;
4
5- if (keyboard->input.focus.resource)
6+ if (keyboard->focus.resource)
7 {
8 struct wl_client * client
9- = wl_resource_get_client(keyboard->input.focus.resource);
10+ = wl_resource_get_client(keyboard->focus.resource);
11 display = wl_client_get_display(client);
12 }
13
14@@ -70,10 +70,10 @@ static void handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
15 if (!(keyboard->handler && keyboard->handler->key)
16 || !keyboard->handler->key(keyboard, time, key, state))
17 {
18- if (keyboard->input.focus.resource)
19+ if (keyboard->focus.resource)
20 {
21 serial = wl_display_next_serial(display);
22- wl_keyboard_send_key(keyboard->input.focus.resource, serial, time,
23+ wl_keyboard_send_key(keyboard->focus.resource, serial, time,
24 key, state);
25
26 if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
27@@ -102,10 +102,10 @@ static void handle_key(struct swc_seat * seat, uint32_t time, uint32_t key,
28 || mods_locked != keyboard->modifiers.mods_locked
29 || group != keyboard->modifiers.group)
30 {
31- if (keyboard->input.focus.resource)
32+ if (keyboard->focus.resource)
33 {
34 serial = wl_display_next_serial(display);
35- wl_keyboard_send_modifiers(keyboard->input.focus.resource,
36+ wl_keyboard_send_modifiers(keyboard->focus.resource,
37 serial, mods_depressed, mods_latched,
38 mods_locked, group);
39 }