diff options
author | 2016-07-06 08:45:05 -0400 | |
---|---|---|
committer | 2016-07-06 08:45:05 -0400 | |
commit | 378149b59c8d2a6d2b0bab7f2bb507dbac990734 (patch) | |
tree | d7a5edd481a0b8961eee20d3008b1fbf6ba51ee1 /wayland | |
parent | Merge pull request #740 from zandrmartin/json-fixes (diff) | |
parent | Fix formatting guide violations (spaces instead of tabs) (diff) | |
download | sway-378149b59c8d2a6d2b0bab7f2bb507dbac990734.tar.gz sway-378149b59c8d2a6d2b0bab7f2bb507dbac990734.tar.zst sway-378149b59c8d2a6d2b0bab7f2bb507dbac990734.zip |
Merge pull request #739 from deklov/swaybar-pointer-01
Enable windows to register to get notified of pointer button events
Diffstat (limited to 'wayland')
-rw-r--r-- | wayland/registry.c | 35 | ||||
-rw-r--r-- | wayland/window.c | 10 |
2 files changed, 40 insertions, 5 deletions
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, |