aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-03-30 15:33:16 -0400
committerLibravatar emersion <contact@emersion.fr>2018-03-30 15:33:16 -0400
commit03255fd20209bc26ca54ae6c1562feb0a157c5e3 (patch)
treef1ae7f319d0a90bd2279612ebd69ab0f768f150f /sway/input/cursor.c
parentMerge pull request #1664 from swaywm/xwayland-add-to-focused (diff)
downloadsway-03255fd20209bc26ca54ae6c1562feb0a157c5e3.tar.gz
sway-03255fd20209bc26ca54ae6c1562feb0a157c5e3.tar.zst
sway-03255fd20209bc26ca54ae6c1562feb0a157c5e3.zip
Fix pointer events for hidden workspaces
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c83
1 files changed, 47 insertions, 36 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index d57ac3e3..4abc61ea 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -6,10 +6,11 @@
6#endif 6#endif
7#include <wlr/types/wlr_cursor.h> 7#include <wlr/types/wlr_cursor.h>
8#include <wlr/types/wlr_xcursor_manager.h> 8#include <wlr/types/wlr_xcursor_manager.h>
9#include "sway/input/cursor.h"
10#include "sway/tree/view.h"
11#include "list.h" 9#include "list.h"
12#include "log.h" 10#include "log.h"
11#include "sway/input/cursor.h"
12#include "sway/output.h"
13#include "sway/tree/view.h"
13 14
14static void cursor_update_position(struct sway_cursor *cursor) { 15static void cursor_update_position(struct sway_cursor *cursor) {
15 double x = cursor->cursor->x; 16 double x = cursor->cursor->x;
@@ -19,16 +20,12 @@ static void cursor_update_position(struct sway_cursor *cursor) {
19 cursor->y = y; 20 cursor->y = y;
20} 21}
21 22
22static void cursor_send_pointer_motion(struct sway_cursor *cursor, 23static struct sway_container *cursor_at(struct sway_cursor *cursor,
23 uint32_t time) { 24 struct wlr_surface **surface, double *sx, double *sy) {
24 struct wlr_seat *seat = cursor->seat->wlr_seat;
25 struct wlr_surface *surface = NULL;
26 double sx, sy;
27
28 // check for unmanaged views first 25 // check for unmanaged views first
26 struct wl_list *unmanaged = &root_container.sway_root->unmanaged_views;
29 struct sway_view *view; 27 struct sway_view *view;
30 wl_list_for_each_reverse(view, &root_container.sway_root->unmanaged_views, 28 wl_list_for_each_reverse(view, unmanaged, unmanaged_view_link) {
31 unmanaged_view_link) {
32 if (view->type == SWAY_XWAYLAND_VIEW) { 29 if (view->type == SWAY_XWAYLAND_VIEW) {
33 struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; 30 struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
34 struct wlr_box box = { 31 struct wlr_box box = {
@@ -39,19 +36,42 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor,
39 }; 36 };
40 37
41 if (wlr_box_contains_point(&box, cursor->x, cursor->y)) { 38 if (wlr_box_contains_point(&box, cursor->x, cursor->y)) {
42 surface = xsurface->surface; 39 *surface = xsurface->surface;
43 sx = cursor->x - box.x; 40 *sx = cursor->x - box.x;
44 sy = cursor->y - box.y; 41 *sy = cursor->y - box.y;
45 wlr_seat_pointer_notify_enter(seat, surface, sx, sy); 42 return view->swayc;
46 wlr_seat_pointer_notify_motion(seat, time, sx, sy);
47 return;
48 } 43 }
49 } 44 }
50 } 45 }
51 46
52 struct sway_container *swayc = 47 // find the output the cursor is on
53 container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); 48 struct wlr_output_layout *output_layout =
54 if (swayc) { 49 root_container.sway_root->output_layout;
50 struct wlr_output *wlr_output =
51 wlr_output_layout_output_at(output_layout, cursor->x, cursor->y);
52 if (wlr_output == NULL) {
53 return NULL;
54 }
55 struct sway_output *output = wlr_output->data;
56
57 // find the focused workspace on the output for this seat
58 struct sway_container *workspace =
59 sway_seat_get_focus_inactive(cursor->seat, output->swayc);
60 if (workspace->type != C_WORKSPACE) {
61 workspace = container_parent(workspace, C_WORKSPACE);
62 }
63
64 return container_at(workspace, cursor->x, cursor->y, surface, sx, sy);
65}
66
67static void cursor_send_pointer_motion(struct sway_cursor *cursor,
68 uint32_t time) {
69 struct wlr_seat *seat = cursor->seat->wlr_seat;
70 struct wlr_surface *surface = NULL;
71 double sx, sy;
72 struct sway_container *cont = cursor_at(cursor, &surface, &sx, &sy);
73
74 if (cont) {
55 wlr_seat_pointer_notify_enter(seat, surface, sx, sy); 75 wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
56 wlr_seat_pointer_notify_motion(seat, time, sx, sy); 76 wlr_seat_pointer_notify_motion(seat, time, sx, sy);
57 } else { 77 } else {
@@ -60,8 +80,7 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor,
60} 80}
61 81
62static void handle_cursor_motion(struct wl_listener *listener, void *data) { 82static void handle_cursor_motion(struct wl_listener *listener, void *data) {
63 struct sway_cursor *cursor = 83 struct sway_cursor *cursor = wl_container_of(listener, cursor, motion);
64 wl_container_of(listener, cursor, motion);
65 struct wlr_event_pointer_motion *event = data; 84 struct wlr_event_pointer_motion *event = data;
66 wlr_cursor_move(cursor->cursor, event->device, 85 wlr_cursor_move(cursor->cursor, event->device,
67 event->delta_x, event->delta_y); 86 event->delta_x, event->delta_y);
@@ -80,16 +99,13 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener,
80} 99}
81 100
82static void handle_cursor_button(struct wl_listener *listener, void *data) { 101static void handle_cursor_button(struct wl_listener *listener, void *data) {
83 struct sway_cursor *cursor = 102 struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
84 wl_container_of(listener, cursor, button);
85 struct wlr_event_pointer_button *event = data; 103 struct wlr_event_pointer_button *event = data;
86 104
87 if (event->button == BTN_LEFT) { 105 if (event->button == BTN_LEFT) {
88 struct wlr_surface *surface = NULL; 106 struct wlr_surface *surface = NULL;
89 double sx, sy; 107 double sx, sy;
90 struct sway_container *swayc = 108 struct sway_container *swayc = cursor_at(cursor, &surface, &sx, &sy);
91 container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy);
92
93 sway_seat_set_focus(cursor->seat, swayc); 109 sway_seat_set_focus(cursor->seat, swayc);
94 } 110 }
95 111
@@ -98,23 +114,20 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
98} 114}
99 115
100static void handle_cursor_axis(struct wl_listener *listener, void *data) { 116static void handle_cursor_axis(struct wl_listener *listener, void *data) {
101 struct sway_cursor *cursor = 117 struct sway_cursor *cursor = wl_container_of(listener, cursor, axis);
102 wl_container_of(listener, cursor, axis);
103 struct wlr_event_pointer_axis *event = data; 118 struct wlr_event_pointer_axis *event = data;
104 wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec, 119 wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec,
105 event->orientation, event->delta); 120 event->orientation, event->delta);
106} 121}
107 122
108static void handle_touch_down(struct wl_listener *listener, void *data) { 123static void handle_touch_down(struct wl_listener *listener, void *data) {
109 struct sway_cursor *cursor = 124 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down);
110 wl_container_of(listener, cursor, touch_down);
111 struct wlr_event_touch_down *event = data; 125 struct wlr_event_touch_down *event = data;
112 wlr_log(L_DEBUG, "TODO: handle touch down event: %p", event); 126 wlr_log(L_DEBUG, "TODO: handle touch down event: %p", event);
113} 127}
114 128
115static void handle_touch_up(struct wl_listener *listener, void *data) { 129static void handle_touch_up(struct wl_listener *listener, void *data) {
116 struct sway_cursor *cursor = 130 struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up);
117 wl_container_of(listener, cursor, touch_up);
118 struct wlr_event_touch_up *event = data; 131 struct wlr_event_touch_up *event = data;
119 wlr_log(L_DEBUG, "TODO: handle touch up event: %p", event); 132 wlr_log(L_DEBUG, "TODO: handle touch up event: %p", event);
120} 133}
@@ -127,15 +140,13 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
127} 140}
128 141
129static void handle_tool_axis(struct wl_listener *listener, void *data) { 142static void handle_tool_axis(struct wl_listener *listener, void *data) {
130 struct sway_cursor *cursor = 143 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis);
131 wl_container_of(listener, cursor, tool_axis);
132 struct wlr_event_tablet_tool_axis *event = data; 144 struct wlr_event_tablet_tool_axis *event = data;
133 wlr_log(L_DEBUG, "TODO: handle tool axis event: %p", event); 145 wlr_log(L_DEBUG, "TODO: handle tool axis event: %p", event);
134} 146}
135 147
136static void handle_tool_tip(struct wl_listener *listener, void *data) { 148static void handle_tool_tip(struct wl_listener *listener, void *data) {
137 struct sway_cursor *cursor = 149 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip);
138 wl_container_of(listener, cursor, tool_tip);
139 struct wlr_event_tablet_tool_tip *event = data; 150 struct wlr_event_tablet_tool_tip *event = data;
140 wlr_log(L_DEBUG, "TODO: handle tool tip event: %p", event); 151 wlr_log(L_DEBUG, "TODO: handle tool tip event: %p", event);
141} 152}