diff options
author | David Eklov <david.eklov@gmail.com> | 2016-07-04 23:21:11 -0500 |
---|---|---|
committer | David Eklov <david.eklov@gmail.com> | 2016-07-06 01:03:00 -0500 |
commit | 9889b14511e95b29855aa265c19e57e9cd86cd1b (patch) | |
tree | 0f0b0bd4e9181b19c068892e2943446edfe8bc78 /wayland | |
parent | Merge pull request #740 from zandrmartin/json-fixes (diff) | |
download | sway-9889b14511e95b29855aa265c19e57e9cd86cd1b.tar.gz sway-9889b14511e95b29855aa265c19e57e9cd86cd1b.tar.zst sway-9889b14511e95b29855aa265c19e57e9cd86cd1b.zip |
Check capabilities before using pointer and keyboard
Diffstat (limited to 'wayland')
-rw-r--r-- | wayland/registry.c | 35 |
1 files changed, 30 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)); |