aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-04-08 10:48:13 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-04-08 10:48:13 -0400
commit9114d3b84cf4e5ba0513a8f4d4a018a6de3d6223 (patch)
tree58353f3bf78f12345fbe47bc9680273059564644 /sway/input/cursor.c
parentFixup for #1773 (diff)
downloadsway-9114d3b84cf4e5ba0513a8f4d4a018a6de3d6223.tar.gz
sway-9114d3b84cf4e5ba0513a8f4d4a018a6de3d6223.tar.zst
sway-9114d3b84cf4e5ba0513a8f4d4a018a6de3d6223.zip
Implement tablet tool support
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c67
1 files changed, 59 insertions, 8 deletions
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
182static void handle_cursor_button(struct wl_listener *listener, void *data) { 182static 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
220static 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
222static void handle_cursor_axis(struct wl_listener *listener, void *data) { 227static 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) {
248static void handle_tool_axis(struct wl_listener *listener, void *data) { 253static 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
254static void handle_tool_tip(struct wl_listener *listener, void *data) { 274static 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
282static 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
260static void handle_request_set_cursor(struct wl_listener *listener, 305static 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;