diff options
author | emersion <contact@emersion.fr> | 2018-03-30 19:04:06 -0400 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-03-30 19:04:06 -0400 |
commit | 96656427656118f2e4d725359cc880270b0e51be (patch) | |
tree | e2596e9cfa113efa43f2a411176c31e6208a58b1 /sway/input/cursor.c | |
parent | Handle set_cursor requests from clients (diff) | |
parent | Merge pull request #1665 from emersion/damage-tracking-lite (diff) | |
download | sway-96656427656118f2e4d725359cc880270b0e51be.tar.gz sway-96656427656118f2e4d725359cc880270b0e51be.tar.zst sway-96656427656118f2e4d725359cc880270b0e51be.zip |
Merge branch 'wlroots' into client-cursors
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r-- | sway/input/cursor.c | 99 |
1 files changed, 58 insertions, 41 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index cded0005..d814e08e 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 | ||
14 | static void cursor_update_position(struct sway_cursor *cursor) { | 15 | static void cursor_update_position(struct sway_cursor *cursor) { |
15 | double x = cursor->cursor->x; | 16 | double x = cursor->cursor->x; |
@@ -19,18 +20,16 @@ static void cursor_update_position(struct sway_cursor *cursor) { | |||
19 | cursor->y = y; | 20 | cursor->y = y; |
20 | } | 21 | } |
21 | 22 | ||
22 | static void cursor_send_pointer_motion(struct sway_cursor *cursor, | 23 | /** |
23 | uint32_t time) { | 24 | * Returns the container at the cursor's position. If the container is a view, |
24 | struct wlr_seat *seat = cursor->seat->wlr_seat; | 25 | * stores the surface at the cursor's position in `*surface`. |
25 | struct wlr_surface *surface = NULL; | 26 | */ |
26 | double sx, sy; | 27 | static struct sway_container *container_at_cursor(struct sway_cursor *cursor, |
27 | 28 | struct wlr_surface **surface, double *sx, double *sy) { | |
28 | struct sway_container *focus = NULL; | ||
29 | |||
30 | // check for unmanaged views first | 29 | // check for unmanaged views first |
30 | struct wl_list *unmanaged = &root_container.sway_root->unmanaged_views; | ||
31 | struct sway_view *view; | 31 | struct sway_view *view; |
32 | wl_list_for_each_reverse(view, &root_container.sway_root->unmanaged_views, | 32 | wl_list_for_each_reverse(view, unmanaged, unmanaged_view_link) { |
33 | unmanaged_view_link) { | ||
34 | if (view->type == SWAY_XWAYLAND_VIEW) { | 33 | if (view->type == SWAY_XWAYLAND_VIEW) { |
35 | struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; | 34 | struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; |
36 | struct wlr_box box = { | 35 | struct wlr_box box = { |
@@ -41,24 +40,50 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor, | |||
41 | }; | 40 | }; |
42 | 41 | ||
43 | if (wlr_box_contains_point(&box, cursor->x, cursor->y)) { | 42 | if (wlr_box_contains_point(&box, cursor->x, cursor->y)) { |
44 | focus = view->swayc; | 43 | *surface = xsurface->surface; |
45 | surface = xsurface->surface; | 44 | *sx = cursor->x - box.x; |
46 | sx = cursor->x - box.x; | 45 | *sy = cursor->y - box.y; |
47 | sy = cursor->y - box.y; | 46 | return view->swayc; |
48 | break; | ||
49 | } | 47 | } |
50 | } | 48 | } |
51 | } | 49 | } |
52 | 50 | ||
53 | // then check for managed views | 51 | // find the output the cursor is on |
54 | if (focus == NULL) { | 52 | struct wlr_output_layout *output_layout = |
55 | focus = container_at(&root_container, cursor->x, cursor->y, &surface, | 53 | root_container.sway_root->output_layout; |
56 | &sx, &sy); | 54 | struct wlr_output *wlr_output = |
55 | wlr_output_layout_output_at(output_layout, cursor->x, cursor->y); | ||
56 | if (wlr_output == NULL) { | ||
57 | return NULL; | ||
58 | } | ||
59 | struct sway_output *output = wlr_output->data; | ||
60 | |||
61 | // find the focused workspace on the output for this seat | ||
62 | struct sway_container *workspace_cont = | ||
63 | sway_seat_get_focus_inactive(cursor->seat, output->swayc); | ||
64 | if (workspace_cont != NULL && workspace_cont->type != C_WORKSPACE) { | ||
65 | workspace_cont = container_parent(workspace_cont, C_WORKSPACE); | ||
66 | } | ||
67 | if (workspace_cont == NULL) { | ||
68 | return output->swayc; | ||
57 | } | 69 | } |
58 | 70 | ||
71 | struct sway_container *view_cont = container_at(workspace_cont, | ||
72 | cursor->x, cursor->y, surface, sx, sy); | ||
73 | return view_cont != NULL ? view_cont : workspace_cont; | ||
74 | } | ||
75 | |||
76 | static void cursor_send_pointer_motion(struct sway_cursor *cursor, | ||
77 | uint32_t time) { | ||
78 | struct wlr_seat *seat = cursor->seat->wlr_seat; | ||
79 | struct wlr_surface *surface = NULL; | ||
80 | double sx, sy; | ||
81 | struct sway_container *cont = | ||
82 | container_at_cursor(cursor, &surface, &sx, &sy); | ||
83 | |||
59 | // reset cursor if switching between clients | 84 | // reset cursor if switching between clients |
60 | struct wl_client *client = NULL; | 85 | struct wl_client *client = NULL; |
61 | if (focus) { | 86 | if (surface != NULL) { |
62 | client = wl_resource_get_client(surface->resource); | 87 | client = wl_resource_get_client(surface->resource); |
63 | } | 88 | } |
64 | if (client != cursor->image_client) { | 89 | if (client != cursor->image_client) { |
@@ -68,7 +93,7 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor, | |||
68 | } | 93 | } |
69 | 94 | ||
70 | // send pointer enter/leave | 95 | // send pointer enter/leave |
71 | if (focus) { | 96 | if (cont != NULL && surface != NULL) { |
72 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); | 97 | wlr_seat_pointer_notify_enter(seat, surface, sx, sy); |
73 | wlr_seat_pointer_notify_motion(seat, time, sx, sy); | 98 | wlr_seat_pointer_notify_motion(seat, time, sx, sy); |
74 | } else { | 99 | } else { |
@@ -77,8 +102,7 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor, | |||
77 | } | 102 | } |
78 | 103 | ||
79 | static void handle_cursor_motion(struct wl_listener *listener, void *data) { | 104 | static void handle_cursor_motion(struct wl_listener *listener, void *data) { |
80 | struct sway_cursor *cursor = | 105 | struct sway_cursor *cursor = wl_container_of(listener, cursor, motion); |
81 | wl_container_of(listener, cursor, motion); | ||
82 | struct wlr_event_pointer_motion *event = data; | 106 | struct wlr_event_pointer_motion *event = data; |
83 | wlr_cursor_move(cursor->cursor, event->device, | 107 | wlr_cursor_move(cursor->cursor, event->device, |
84 | event->delta_x, event->delta_y); | 108 | event->delta_x, event->delta_y); |
@@ -97,17 +121,15 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener, | |||
97 | } | 121 | } |
98 | 122 | ||
99 | static void handle_cursor_button(struct wl_listener *listener, void *data) { | 123 | static void handle_cursor_button(struct wl_listener *listener, void *data) { |
100 | struct sway_cursor *cursor = | 124 | struct sway_cursor *cursor = wl_container_of(listener, cursor, button); |
101 | wl_container_of(listener, cursor, button); | ||
102 | struct wlr_event_pointer_button *event = data; | 125 | struct wlr_event_pointer_button *event = data; |
103 | 126 | ||
104 | if (event->button == BTN_LEFT) { | 127 | if (event->button == BTN_LEFT) { |
105 | struct wlr_surface *surface = NULL; | 128 | struct wlr_surface *surface = NULL; |
106 | double sx, sy; | 129 | double sx, sy; |
107 | struct sway_container *swayc = | 130 | struct sway_container *cont = |
108 | container_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy); | 131 | container_at_cursor(cursor, &surface, &sx, &sy); |
109 | 132 | sway_seat_set_focus(cursor->seat, cont); | |
110 | sway_seat_set_focus(cursor->seat, swayc); | ||
111 | } | 133 | } |
112 | 134 | ||
113 | wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, | 135 | wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, |
@@ -115,23 +137,20 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { | |||
115 | } | 137 | } |
116 | 138 | ||
117 | static void handle_cursor_axis(struct wl_listener *listener, void *data) { | 139 | static void handle_cursor_axis(struct wl_listener *listener, void *data) { |
118 | struct sway_cursor *cursor = | 140 | struct sway_cursor *cursor = wl_container_of(listener, cursor, axis); |
119 | wl_container_of(listener, cursor, axis); | ||
120 | struct wlr_event_pointer_axis *event = data; | 141 | struct wlr_event_pointer_axis *event = data; |
121 | wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec, | 142 | wlr_seat_pointer_notify_axis(cursor->seat->wlr_seat, event->time_msec, |
122 | event->orientation, event->delta); | 143 | event->orientation, event->delta); |
123 | } | 144 | } |
124 | 145 | ||
125 | static void handle_touch_down(struct wl_listener *listener, void *data) { | 146 | static void handle_touch_down(struct wl_listener *listener, void *data) { |
126 | struct sway_cursor *cursor = | 147 | struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down); |
127 | wl_container_of(listener, cursor, touch_down); | ||
128 | struct wlr_event_touch_down *event = data; | 148 | struct wlr_event_touch_down *event = data; |
129 | wlr_log(L_DEBUG, "TODO: handle touch down event: %p", event); | 149 | wlr_log(L_DEBUG, "TODO: handle touch down event: %p", event); |
130 | } | 150 | } |
131 | 151 | ||
132 | static void handle_touch_up(struct wl_listener *listener, void *data) { | 152 | static void handle_touch_up(struct wl_listener *listener, void *data) { |
133 | struct sway_cursor *cursor = | 153 | struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up); |
134 | wl_container_of(listener, cursor, touch_up); | ||
135 | struct wlr_event_touch_up *event = data; | 154 | struct wlr_event_touch_up *event = data; |
136 | wlr_log(L_DEBUG, "TODO: handle touch up event: %p", event); | 155 | wlr_log(L_DEBUG, "TODO: handle touch up event: %p", event); |
137 | } | 156 | } |
@@ -144,15 +163,13 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { | |||
144 | } | 163 | } |
145 | 164 | ||
146 | static void handle_tool_axis(struct wl_listener *listener, void *data) { | 165 | static void handle_tool_axis(struct wl_listener *listener, void *data) { |
147 | struct sway_cursor *cursor = | 166 | struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); |
148 | wl_container_of(listener, cursor, tool_axis); | ||
149 | struct wlr_event_tablet_tool_axis *event = data; | 167 | struct wlr_event_tablet_tool_axis *event = data; |
150 | wlr_log(L_DEBUG, "TODO: handle tool axis event: %p", event); | 168 | wlr_log(L_DEBUG, "TODO: handle tool axis event: %p", event); |
151 | } | 169 | } |
152 | 170 | ||
153 | static void handle_tool_tip(struct wl_listener *listener, void *data) { | 171 | static void handle_tool_tip(struct wl_listener *listener, void *data) { |
154 | struct sway_cursor *cursor = | 172 | struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip); |
155 | wl_container_of(listener, cursor, tool_tip); | ||
156 | struct wlr_event_tablet_tool_tip *event = data; | 173 | struct wlr_event_tablet_tool_tip *event = data; |
157 | wlr_log(L_DEBUG, "TODO: handle tool tip event: %p", event); | 174 | wlr_log(L_DEBUG, "TODO: handle tool tip event: %p", event); |
158 | } | 175 | } |