diff options
-rw-r--r-- | include/sway/input/cursor.h | 4 | ||||
-rw-r--r-- | sway/input/cursor.c | 67 | ||||
-rw-r--r-- | sway/input/seat.c | 12 |
3 files changed, 72 insertions, 11 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 64917ce5..8f907dcd 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h | |||
@@ -1,6 +1,6 @@ | |||
1 | #ifndef _SWAY_INPUT_CURSOR_H | 1 | #ifndef _SWAY_INPUT_CURSOR_H |
2 | #define _SWAY_INPUT_CURSOR_H | 2 | #define _SWAY_INPUT_CURSOR_H |
3 | 3 | #include <stdint.h> | |
4 | #include "sway/input/seat.h" | 4 | #include "sway/input/seat.h" |
5 | 5 | ||
6 | struct sway_cursor { | 6 | struct sway_cursor { |
@@ -22,6 +22,8 @@ struct sway_cursor { | |||
22 | 22 | ||
23 | struct wl_listener tool_axis; | 23 | struct wl_listener tool_axis; |
24 | struct wl_listener tool_tip; | 24 | struct wl_listener tool_tip; |
25 | struct wl_listener tool_button; | ||
26 | uint32_t tool_buttons; | ||
25 | 27 | ||
26 | struct wl_listener request_set_cursor; | 28 | struct wl_listener request_set_cursor; |
27 | }; | 29 | }; |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 6db615b1..cdded1c7 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -179,10 +179,8 @@ static void handle_cursor_motion_absolute( | |||
179 | cursor_send_pointer_motion(cursor, event->time_msec); | 179 | cursor_send_pointer_motion(cursor, event->time_msec); |
180 | } | 180 | } |
181 | 181 | ||
182 | static void handle_cursor_button(struct wl_listener *listener, void *data) { | 182 | static void dispatch_cursor_button(struct sway_cursor *cursor, |
183 | struct sway_cursor *cursor = wl_container_of(listener, cursor, button); | 183 | uint32_t time_msec, uint32_t button, enum wlr_button_state state) { |
184 | struct wlr_event_pointer_button *event = data; | ||
185 | |||
186 | struct wlr_surface *surface = NULL; | 184 | struct wlr_surface *surface = NULL; |
187 | double sx, sy; | 185 | double sx, sy; |
188 | struct sway_container *cont = | 186 | struct sway_container *cont = |
@@ -215,8 +213,15 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { | |||
215 | seat_set_focus(cursor->seat, cont); | 213 | seat_set_focus(cursor->seat, cont); |
216 | } | 214 | } |
217 | 215 | ||
218 | wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, | 216 | wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, |
219 | event->button, event->state); | 217 | time_msec, button, state); |
218 | } | ||
219 | |||
220 | static void handle_cursor_button(struct wl_listener *listener, void *data) { | ||
221 | struct sway_cursor *cursor = wl_container_of(listener, cursor, button); | ||
222 | struct wlr_event_pointer_button *event = data; | ||
223 | dispatch_cursor_button(cursor, | ||
224 | event->time_msec, event->button, event->state); | ||
220 | } | 225 | } |
221 | 226 | ||
222 | static void handle_cursor_axis(struct wl_listener *listener, void *data) { | 227 | static void handle_cursor_axis(struct wl_listener *listener, void *data) { |
@@ -248,13 +253,53 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { | |||
248 | static void handle_tool_axis(struct wl_listener *listener, void *data) { | 253 | static void handle_tool_axis(struct wl_listener *listener, void *data) { |
249 | struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); | 254 | struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); |
250 | struct wlr_event_tablet_tool_axis *event = data; | 255 | struct wlr_event_tablet_tool_axis *event = data; |
251 | wlr_log(L_DEBUG, "TODO: handle tool axis event: %p", event); | 256 | |
257 | if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && | ||
258 | (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { | ||
259 | wlr_cursor_warp_absolute(cursor->cursor, event->device, | ||
260 | event->x, event->y); | ||
261 | cursor_update_position(cursor); | ||
262 | cursor_send_pointer_motion(cursor, event->time_msec); | ||
263 | } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { | ||
264 | wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1); | ||
265 | cursor_update_position(cursor); | ||
266 | cursor_send_pointer_motion(cursor, event->time_msec); | ||
267 | } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { | ||
268 | wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y); | ||
269 | cursor_update_position(cursor); | ||
270 | cursor_send_pointer_motion(cursor, event->time_msec); | ||
271 | } | ||
252 | } | 272 | } |
253 | 273 | ||
254 | static void handle_tool_tip(struct wl_listener *listener, void *data) { | 274 | static void handle_tool_tip(struct wl_listener *listener, void *data) { |
255 | struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip); | 275 | struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip); |
256 | struct wlr_event_tablet_tool_tip *event = data; | 276 | struct wlr_event_tablet_tool_tip *event = data; |
257 | wlr_log(L_DEBUG, "TODO: handle tool tip event: %p", event); | 277 | dispatch_cursor_button(cursor, event->time_msec, |
278 | BTN_LEFT, event->state == WLR_TABLET_TOOL_TIP_DOWN ? | ||
279 | WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED); | ||
280 | } | ||
281 | |||
282 | static void handle_tool_button(struct wl_listener *listener, void *data) { | ||
283 | struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button); | ||
284 | struct wlr_event_tablet_tool_button *event = data; | ||
285 | // TODO: the user may want to configure which tool buttons are mapped to | ||
286 | // which simulated pointer buttons | ||
287 | switch (event->state) { | ||
288 | case WLR_BUTTON_PRESSED: | ||
289 | if (cursor->tool_buttons == 0) { | ||
290 | dispatch_cursor_button(cursor, | ||
291 | event->time_msec, BTN_RIGHT, event->state); | ||
292 | } | ||
293 | cursor->tool_buttons++; | ||
294 | break; | ||
295 | case WLR_BUTTON_RELEASED: | ||
296 | if (cursor->tool_buttons == 1) { | ||
297 | dispatch_cursor_button(cursor, | ||
298 | event->time_msec, BTN_RIGHT, event->state); | ||
299 | } | ||
300 | cursor->tool_buttons--; | ||
301 | break; | ||
302 | } | ||
258 | } | 303 | } |
259 | 304 | ||
260 | static void handle_request_set_cursor(struct wl_listener *listener, | 305 | static void handle_request_set_cursor(struct wl_listener *listener, |
@@ -332,6 +377,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { | |||
332 | &cursor->touch_motion); | 377 | &cursor->touch_motion); |
333 | cursor->touch_motion.notify = handle_touch_motion; | 378 | cursor->touch_motion.notify = handle_touch_motion; |
334 | 379 | ||
380 | // TODO: tablet protocol support | ||
381 | // Note: We should emulate pointer events for clients that don't support the | ||
382 | // tablet protocol when the time comes | ||
335 | wl_signal_add(&wlr_cursor->events.tablet_tool_axis, | 383 | wl_signal_add(&wlr_cursor->events.tablet_tool_axis, |
336 | &cursor->tool_axis); | 384 | &cursor->tool_axis); |
337 | cursor->tool_axis.notify = handle_tool_axis; | 385 | cursor->tool_axis.notify = handle_tool_axis; |
@@ -339,6 +387,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { | |||
339 | wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &cursor->tool_tip); | 387 | wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &cursor->tool_tip); |
340 | cursor->tool_tip.notify = handle_tool_tip; | 388 | cursor->tool_tip.notify = handle_tool_tip; |
341 | 389 | ||
390 | wl_signal_add(&wlr_cursor->events.tablet_tool_button, &cursor->tool_button); | ||
391 | cursor->tool_button.notify = handle_tool_button; | ||
392 | |||
342 | wl_signal_add(&seat->wlr_seat->events.request_set_cursor, | 393 | wl_signal_add(&seat->wlr_seat->events.request_set_cursor, |
343 | &cursor->request_set_cursor); | 394 | &cursor->request_set_cursor); |
344 | cursor->request_set_cursor.notify = handle_request_set_cursor; | 395 | cursor->request_set_cursor.notify = handle_request_set_cursor; |
diff --git a/sway/input/seat.c b/sway/input/seat.c index b94e3291..c34da5e5 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -245,6 +245,12 @@ static void seat_configure_keyboard(struct sway_seat *seat, | |||
245 | } | 245 | } |
246 | } | 246 | } |
247 | 247 | ||
248 | static void seat_configure_tablet_tool(struct sway_seat *seat, | ||
249 | struct sway_seat_device *sway_device) { | ||
250 | wlr_cursor_attach_input_device(seat->cursor->cursor, | ||
251 | sway_device->input_device->wlr_device); | ||
252 | } | ||
253 | |||
248 | static struct sway_seat_device *seat_get_device(struct sway_seat *seat, | 254 | static struct sway_seat_device *seat_get_device(struct sway_seat *seat, |
249 | struct sway_input_device *input_device) { | 255 | struct sway_input_device *input_device) { |
250 | struct sway_seat_device *seat_device = NULL; | 256 | struct sway_seat_device *seat_device = NULL; |
@@ -272,9 +278,11 @@ void seat_configure_device(struct sway_seat *seat, | |||
272 | case WLR_INPUT_DEVICE_KEYBOARD: | 278 | case WLR_INPUT_DEVICE_KEYBOARD: |
273 | seat_configure_keyboard(seat, seat_device); | 279 | seat_configure_keyboard(seat, seat_device); |
274 | break; | 280 | break; |
275 | case WLR_INPUT_DEVICE_TOUCH: | ||
276 | case WLR_INPUT_DEVICE_TABLET_PAD: | ||
277 | case WLR_INPUT_DEVICE_TABLET_TOOL: | 281 | case WLR_INPUT_DEVICE_TABLET_TOOL: |
282 | seat_configure_tablet_tool(seat, seat_device); | ||
283 | break; | ||
284 | case WLR_INPUT_DEVICE_TABLET_PAD: | ||
285 | case WLR_INPUT_DEVICE_TOUCH: | ||
278 | wlr_log(L_DEBUG, "TODO: configure other devices"); | 286 | wlr_log(L_DEBUG, "TODO: configure other devices"); |
279 | break; | 287 | break; |
280 | } | 288 | } |