diff options
-rw-r--r-- | include/client/window.h | 50 | ||||
-rw-r--r-- | wayland/registry.c | 35 | ||||
-rw-r--r-- | wayland/window.c | 10 |
3 files changed, 70 insertions, 25 deletions
diff --git a/include/client/window.h b/include/client/window.h index e48ec4f3..7be4fff3 100644 --- a/include/client/window.h +++ b/include/client/window.h | |||
@@ -9,33 +9,43 @@ | |||
9 | #include "list.h" | 9 | #include "list.h" |
10 | #include "client/registry.h" | 10 | #include "client/registry.h" |
11 | 11 | ||
12 | struct window; | ||
13 | |||
12 | struct buffer { | 14 | struct buffer { |
13 | struct wl_buffer *buffer; | 15 | struct wl_buffer *buffer; |
14 | cairo_surface_t *surface; | 16 | cairo_surface_t *surface; |
15 | cairo_t *cairo; | 17 | cairo_t *cairo; |
16 | PangoContext *pango; | 18 | PangoContext *pango; |
17 | uint32_t width, height; | 19 | uint32_t width, height; |
18 | bool busy; | 20 | bool busy; |
19 | }; | 21 | }; |
20 | 22 | ||
21 | struct cursor { | 23 | struct cursor { |
22 | struct wl_surface *surface; | 24 | struct wl_surface *surface; |
23 | struct wl_cursor_theme *cursor_theme; | 25 | struct wl_cursor_theme *cursor_theme; |
24 | struct wl_cursor *cursor; | 26 | struct wl_cursor *cursor; |
25 | struct wl_poitner *pointer; | 27 | struct wl_poitner *pointer; |
28 | }; | ||
29 | |||
30 | struct pointer_input { | ||
31 | wl_fixed_t last_x; | ||
32 | wl_fixed_t last_y; | ||
33 | |||
34 | void (*notify)(struct window *window, wl_fixed_t x, wl_fixed_t y, uint32_t button); | ||
26 | }; | 35 | }; |
27 | 36 | ||
28 | struct window { | 37 | struct window { |
29 | struct registry *registry; | 38 | struct registry *registry; |
30 | struct buffer buffers[2]; | 39 | struct buffer buffers[2]; |
31 | struct buffer *buffer; | 40 | struct buffer *buffer; |
32 | struct wl_surface *surface; | 41 | struct wl_surface *surface; |
33 | struct wl_shell_surface *shell_surface; | 42 | struct wl_shell_surface *shell_surface; |
34 | struct wl_callback *frame_cb; | 43 | struct wl_callback *frame_cb; |
35 | struct cursor cursor; | 44 | struct cursor cursor; |
36 | uint32_t width, height; | 45 | uint32_t width, height; |
37 | char *font; | 46 | char *font; |
38 | cairo_t *cairo; | 47 | cairo_t *cairo; |
48 | struct pointer_input pointer_input; | ||
39 | }; | 49 | }; |
40 | 50 | ||
41 | struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, bool shell_surface); | 51 | struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, bool shell_surface); |
diff --git a/wayland/registry.c b/wayland/registry.c index 46814bb7..622571f0 100644 --- a/wayland/registry.c +++ b/wayland/registry.c | |||
@@ -174,6 +174,35 @@ static const struct wl_keyboard_listener keyboard_listener = { | |||
174 | .repeat_info = keyboard_handle_repeat_info | 174 | .repeat_info = keyboard_handle_repeat_info |
175 | }; | 175 | }; |
176 | 176 | ||
177 | static void seat_handle_capabilities(void *data, struct wl_seat *seat, | ||
178 | enum wl_seat_capability caps) { | ||
179 | struct registry *reg = data; | ||
180 | |||
181 | if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !reg->pointer) { | ||
182 | reg->pointer = wl_seat_get_pointer(reg->seat); | ||
183 | } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && reg->pointer) { | ||
184 | wl_pointer_destroy(reg->pointer); | ||
185 | reg->pointer = NULL; | ||
186 | } | ||
187 | |||
188 | if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !reg->keyboard) { | ||
189 | reg->keyboard = wl_seat_get_keyboard(reg->seat); | ||
190 | wl_keyboard_add_listener(reg->keyboard, &keyboard_listener, reg); | ||
191 | } else if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && reg->keyboard) { | ||
192 | wl_keyboard_destroy(reg->keyboard); | ||
193 | reg->keyboard = NULL; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | static void seat_handle_name(void *data, struct wl_seat *seat, const char *name) { | ||
198 | // this space intentionally left blank | ||
199 | } | ||
200 | |||
201 | static const struct wl_seat_listener seat_listener = { | ||
202 | .capabilities = seat_handle_capabilities, | ||
203 | .name = seat_handle_name, | ||
204 | }; | ||
205 | |||
177 | static void registry_global(void *data, struct wl_registry *registry, | 206 | static void registry_global(void *data, struct wl_registry *registry, |
178 | uint32_t name, const char *interface, uint32_t version) { | 207 | uint32_t name, const char *interface, uint32_t version) { |
179 | struct registry *reg = data; | 208 | struct registry *reg = data; |
@@ -186,11 +215,7 @@ static void registry_global(void *data, struct wl_registry *registry, | |||
186 | reg->shell = wl_registry_bind(registry, name, &wl_shell_interface, version); | 215 | reg->shell = wl_registry_bind(registry, name, &wl_shell_interface, version); |
187 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { | 216 | } else if (strcmp(interface, wl_seat_interface.name) == 0) { |
188 | reg->seat = wl_registry_bind(registry, name, &wl_seat_interface, version); | 217 | reg->seat = wl_registry_bind(registry, name, &wl_seat_interface, version); |
189 | reg->pointer = wl_seat_get_pointer(reg->seat); | 218 | wl_seat_add_listener(reg->seat, &seat_listener, reg); |
190 | reg->keyboard = wl_seat_get_keyboard(reg->seat); | ||
191 | if (reg->keyboard) { | ||
192 | wl_keyboard_add_listener(reg->keyboard, &keyboard_listener, reg); | ||
193 | } | ||
194 | } else if (strcmp(interface, wl_output_interface.name) == 0) { | 219 | } else if (strcmp(interface, wl_output_interface.name) == 0) { |
195 | struct wl_output *output = wl_registry_bind(registry, name, &wl_output_interface, version); | 220 | struct wl_output *output = wl_registry_bind(registry, name, &wl_output_interface, version); |
196 | struct output_state *ostate = malloc(sizeof(struct output_state)); | 221 | struct output_state *ostate = malloc(sizeof(struct output_state)); |
diff --git a/wayland/window.c b/wayland/window.c index 7ca9e4ec..e055e244 100644 --- a/wayland/window.c +++ b/wayland/window.c | |||
@@ -30,10 +30,20 @@ static void pointer_handle_leave(void *data, struct wl_pointer *pointer, | |||
30 | 30 | ||
31 | static void pointer_handle_motion(void *data, struct wl_pointer *pointer, | 31 | static void pointer_handle_motion(void *data, struct wl_pointer *pointer, |
32 | uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) { | 32 | uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) { |
33 | struct window *window = data; | ||
34 | |||
35 | window->pointer_input.last_x = sx_w; | ||
36 | window->pointer_input.last_y = sy_w; | ||
33 | } | 37 | } |
34 | 38 | ||
35 | static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial, | 39 | static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial, |
36 | uint32_t time, uint32_t button, uint32_t state_w) { | 40 | uint32_t time, uint32_t button, uint32_t state_w) { |
41 | struct window *window = data; | ||
42 | struct pointer_input *input = &window->pointer_input; | ||
43 | |||
44 | if (window->pointer_input.notify) { | ||
45 | window->pointer_input.notify(window, input->last_x, input->last_y, button); | ||
46 | } | ||
37 | } | 47 | } |
38 | 48 | ||
39 | static void pointer_handle_axis(void *data, struct wl_pointer *pointer, | 49 | static void pointer_handle_axis(void *data, struct wl_pointer *pointer, |