summaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c83
1 files changed, 65 insertions, 18 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 6db615b1..4bcf72fc 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -52,17 +52,13 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
52 wl_list_for_each_reverse(unmanaged_surface, unmanaged, link) { 52 wl_list_for_each_reverse(unmanaged_surface, unmanaged, link) {
53 struct wlr_xwayland_surface *xsurface = 53 struct wlr_xwayland_surface *xsurface =
54 unmanaged_surface->wlr_xwayland_surface; 54 unmanaged_surface->wlr_xwayland_surface;
55 struct wlr_box box = { 55
56 .x = unmanaged_surface->lx, 56 double _sx = cursor->x - unmanaged_surface->lx;
57 .y = unmanaged_surface->ly, 57 double _sy = cursor->y - unmanaged_surface->ly;
58 .width = xsurface->width, 58 if (wlr_surface_point_accepts_input(xsurface->surface, _sx, _sy)) {
59 .height = xsurface->height,
60 };
61
62 if (wlr_box_contains_point(&box, cursor->x, cursor->y)) {
63 *surface = xsurface->surface; 59 *surface = xsurface->surface;
64 *sx = cursor->x - box.x; 60 *sx = _sx;
65 *sy = cursor->y - box.y; 61 *sy = _sy;
66 return NULL; 62 return NULL;
67 } 63 }
68 } 64 }
@@ -179,10 +175,8 @@ static void handle_cursor_motion_absolute(
179 cursor_send_pointer_motion(cursor, event->time_msec); 175 cursor_send_pointer_motion(cursor, event->time_msec);
180} 176}
181 177
182static void handle_cursor_button(struct wl_listener *listener, void *data) { 178static void dispatch_cursor_button(struct sway_cursor *cursor,
183 struct sway_cursor *cursor = wl_container_of(listener, cursor, button); 179 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; 180 struct wlr_surface *surface = NULL;
187 double sx, sy; 181 double sx, sy;
188 struct sway_container *cont = 182 struct sway_container *cont =
@@ -215,8 +209,15 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
215 seat_set_focus(cursor->seat, cont); 209 seat_set_focus(cursor->seat, cont);
216 } 210 }
217 211
218 wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, 212 wlr_seat_pointer_notify_button(cursor->seat->wlr_seat,
219 event->button, event->state); 213 time_msec, button, state);
214}
215
216static void handle_cursor_button(struct wl_listener *listener, void *data) {
217 struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
218 struct wlr_event_pointer_button *event = data;
219 dispatch_cursor_button(cursor,
220 event->time_msec, event->button, event->state);
220} 221}
221 222
222static void handle_cursor_axis(struct wl_listener *listener, void *data) { 223static void handle_cursor_axis(struct wl_listener *listener, void *data) {
@@ -248,13 +249,53 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
248static void handle_tool_axis(struct wl_listener *listener, void *data) { 249static void handle_tool_axis(struct wl_listener *listener, void *data) {
249 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); 250 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis);
250 struct wlr_event_tablet_tool_axis *event = data; 251 struct wlr_event_tablet_tool_axis *event = data;
251 wlr_log(L_DEBUG, "TODO: handle tool axis event: %p", event); 252
253 if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
254 (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
255 wlr_cursor_warp_absolute(cursor->cursor, event->device,
256 event->x, event->y);
257 cursor_update_position(cursor);
258 cursor_send_pointer_motion(cursor, event->time_msec);
259 } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
260 wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1);
261 cursor_update_position(cursor);
262 cursor_send_pointer_motion(cursor, event->time_msec);
263 } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
264 wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y);
265 cursor_update_position(cursor);
266 cursor_send_pointer_motion(cursor, event->time_msec);
267 }
252} 268}
253 269
254static void handle_tool_tip(struct wl_listener *listener, void *data) { 270static void handle_tool_tip(struct wl_listener *listener, void *data) {
255 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip); 271 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip);
256 struct wlr_event_tablet_tool_tip *event = data; 272 struct wlr_event_tablet_tool_tip *event = data;
257 wlr_log(L_DEBUG, "TODO: handle tool tip event: %p", event); 273 dispatch_cursor_button(cursor, event->time_msec,
274 BTN_LEFT, event->state == WLR_TABLET_TOOL_TIP_DOWN ?
275 WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED);
276}
277
278static void handle_tool_button(struct wl_listener *listener, void *data) {
279 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button);
280 struct wlr_event_tablet_tool_button *event = data;
281 // TODO: the user may want to configure which tool buttons are mapped to
282 // which simulated pointer buttons
283 switch (event->state) {
284 case WLR_BUTTON_PRESSED:
285 if (cursor->tool_buttons == 0) {
286 dispatch_cursor_button(cursor,
287 event->time_msec, BTN_RIGHT, event->state);
288 }
289 cursor->tool_buttons++;
290 break;
291 case WLR_BUTTON_RELEASED:
292 if (cursor->tool_buttons == 1) {
293 dispatch_cursor_button(cursor,
294 event->time_msec, BTN_RIGHT, event->state);
295 }
296 cursor->tool_buttons--;
297 break;
298 }
258} 299}
259 300
260static void handle_request_set_cursor(struct wl_listener *listener, 301static void handle_request_set_cursor(struct wl_listener *listener,
@@ -332,6 +373,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
332 &cursor->touch_motion); 373 &cursor->touch_motion);
333 cursor->touch_motion.notify = handle_touch_motion; 374 cursor->touch_motion.notify = handle_touch_motion;
334 375
376 // TODO: tablet protocol support
377 // Note: We should emulate pointer events for clients that don't support the
378 // tablet protocol when the time comes
335 wl_signal_add(&wlr_cursor->events.tablet_tool_axis, 379 wl_signal_add(&wlr_cursor->events.tablet_tool_axis,
336 &cursor->tool_axis); 380 &cursor->tool_axis);
337 cursor->tool_axis.notify = handle_tool_axis; 381 cursor->tool_axis.notify = handle_tool_axis;
@@ -339,6 +383,9 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
339 wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &cursor->tool_tip); 383 wl_signal_add(&wlr_cursor->events.tablet_tool_tip, &cursor->tool_tip);
340 cursor->tool_tip.notify = handle_tool_tip; 384 cursor->tool_tip.notify = handle_tool_tip;
341 385
386 wl_signal_add(&wlr_cursor->events.tablet_tool_button, &cursor->tool_button);
387 cursor->tool_button.notify = handle_tool_button;
388
342 wl_signal_add(&seat->wlr_seat->events.request_set_cursor, 389 wl_signal_add(&seat->wlr_seat->events.request_set_cursor,
343 &cursor->request_set_cursor); 390 &cursor->request_set_cursor);
344 cursor->request_set_cursor.notify = handle_request_set_cursor; 391 cursor->request_set_cursor.notify = handle_request_set_cursor;