aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
authorLibravatar Scott Leggett <scott@sl.id.au>2018-05-27 22:45:14 +1000
committerLibravatar Scott Leggett <scott@sl.id.au>2018-05-28 01:37:43 +1000
commit4cd304e4bacb255694bf63f8f1ccacd352a96144 (patch)
tree94fe3761d10f4dcd3ae01a058f0927be882f5827 /sway/input/cursor.c
parentFocus containers only on entry. (diff)
downloadsway-4cd304e4bacb255694bf63f8f1ccacd352a96144.tar.gz
sway-4cd304e4bacb255694bf63f8f1ccacd352a96144.tar.zst
sway-4cd304e4bacb255694bf63f8f1ccacd352a96144.zip
Store previous position in sway_cursor.
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c84
1 files changed, 44 insertions, 40 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index cc8d344f..a318bbd4 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -135,25 +135,23 @@ static struct sway_container *container_at_coords(
135 return output->swayc; 135 return output->swayc;
136} 136}
137 137
138void cursor_send_pointer_motion(struct sway_cursor *cursor, 138void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
139 double delta_x, double delta_y, uint32_t time_msec, bool allow_refocusing) { 139 bool allow_refocusing) {
140 struct sway_container *prev_c = NULL;
141 struct wlr_surface *surface = NULL;
142 double sx, sy;
143
144 if (delta_x != 0 || delta_y != 0) {
145 // Use the motion delta to find the container the pointer was previously
146 // over.
147 prev_c = container_at_coords(cursor->seat,
148 cursor->cursor->x - delta_x, cursor->cursor->y - delta_y,
149 &surface, &sx, &sy);
150 }
151
152 if (time_msec == 0) { 140 if (time_msec == 0) {
153 time_msec = get_current_time_msec(); 141 time_msec = get_current_time_msec();
154 } 142 }
155 143
156 struct wlr_seat *seat = cursor->seat->wlr_seat; 144 struct wlr_seat *seat = cursor->seat->wlr_seat;
145 struct wlr_surface *surface = NULL;
146 double sx, sy;
147
148 // Find the container the pointer was previously over
149 struct sway_container *prev_c = container_at_coords(cursor->seat,
150 cursor->previous->x, cursor->previous->y, &surface, &sx, &sy);
151 // Update the stored previous position
152 cursor->previous->x = cursor->cursor->x;
153 cursor->previous->y = cursor->cursor->y;
154
157 struct sway_container *c = container_at_coords(cursor->seat, 155 struct sway_container *c = container_at_coords(cursor->seat,
158 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); 156 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
159 if (c && config->focus_follows_mouse && allow_refocusing) { 157 if (c && config->focus_follows_mouse && allow_refocusing) {
@@ -173,39 +171,38 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor,
173 } 171 }
174 } else if (c->type == C_VIEW) { 172 } else if (c->type == C_VIEW) {
175 bool do_mouse_focus = true; 173 bool do_mouse_focus = true;
174 bool is_visible = view_is_visible(c->sway_view);
176 struct sway_container *p = c->parent; 175 struct sway_container *p = c->parent;
177 // Don't switch focus unless we have moved from one container to another. 176 // Don't switch focus unless we have moved from one container to another
178 if (c && prev_c && c == prev_c) { 177 if (c && c == prev_c) {
179 do_mouse_focus = false; 178 do_mouse_focus = false;
180 } 179 }
181 // Skip check if we already know not to focus. 180 // Don't switch focus on title mouseover for stacked and tabbed layouts
182 if (do_mouse_focus) { 181 // If pointed container is in nested containers which are inside
183 // Don't switch focus on title mouseover for 182 // tabbed/stacked layout we should skip them
184 // stacked and tabbed layouts 183 if (do_mouse_focus && !is_visible) {
185 // If pointed container is in nested containers which are
186 // inside tabbed/stacked layout we should skip them
187 bool is_visible = view_is_visible(c->sway_view);
188 while (p) { 184 while (p) {
189 if ((p->layout == L_TABBED || p->layout == L_STACKED) 185 if ((p->layout == L_TABBED || p->layout == L_STACKED)) {
190 && !is_visible) {
191 do_mouse_focus = false; 186 do_mouse_focus = false;
192 break; 187 break;
193 } 188 }
194 p = p->parent; 189 p = p->parent;
195 } 190 }
196 } 191 }
197 if (!do_mouse_focus) { 192 if (do_mouse_focus) {
198 struct sway_container *next_focus = seat_get_focus_inactive(
199 cursor->seat, p);
200 if(next_focus && !sway_assert(next_focus->type == C_VIEW,
201 "focus inactive container is not a view")) {
202 return;
203 }
204 if (next_focus && view_is_visible(next_focus->sway_view)) {
205 seat_set_focus_warp(cursor->seat, next_focus, false);
206 }
207 } else {
208 seat_set_focus_warp(cursor->seat, c, false); 193 seat_set_focus_warp(cursor->seat, c, false);
194 } else {
195 struct sway_container *next_focus =
196 seat_get_focus_inactive(cursor->seat, &root_container);
197 if (next_focus) {
198 if (!sway_assert(next_focus->type == C_VIEW,
199 "focus inactive container is not a view")) {
200 return;
201 }
202 if (view_is_visible(next_focus->sway_view)) {
203 seat_set_focus_warp(cursor->seat, next_focus, false);
204 }
205 }
209 } 206 }
210 } 207 }
211 } 208 }
@@ -238,8 +235,7 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) {
238 struct wlr_event_pointer_motion *event = data; 235 struct wlr_event_pointer_motion *event = data;
239 wlr_cursor_move(cursor->cursor, event->device, 236 wlr_cursor_move(cursor->cursor, event->device,
240 event->delta_x, event->delta_y); 237 event->delta_x, event->delta_y);
241 cursor_send_pointer_motion(cursor, event->delta_x, event->delta_y, 238 cursor_send_pointer_motion(cursor, event->time_msec, true);
242 event->time_msec, true);
243} 239}
244 240
245static void handle_cursor_motion_absolute( 241static void handle_cursor_motion_absolute(
@@ -249,7 +245,7 @@ static void handle_cursor_motion_absolute(
249 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); 245 wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
250 struct wlr_event_pointer_motion_absolute *event = data; 246 struct wlr_event_pointer_motion_absolute *event = data;
251 wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); 247 wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y);
252 cursor_send_pointer_motion(cursor, 0, 0, event->time_msec, true); 248 cursor_send_pointer_motion(cursor, event->time_msec, true);
253} 249}
254 250
255void dispatch_cursor_button(struct sway_cursor *cursor, 251void dispatch_cursor_button(struct sway_cursor *cursor,
@@ -419,7 +415,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) {
419 } 415 }
420 416
421 wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y); 417 wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y);
422 cursor_send_pointer_motion(cursor, 0, 0, event->time_msec, true); 418 cursor_send_pointer_motion(cursor, event->time_msec, true);
423} 419}
424 420
425static void handle_tool_tip(struct wl_listener *listener, void *data) { 421static void handle_tool_tip(struct wl_listener *listener, void *data) {
@@ -496,8 +492,15 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
496 return NULL; 492 return NULL;
497 } 493 }
498 494
495 struct cursor_position *previous = calloc(1, sizeof(struct cursor_position));
496 if (!sway_assert(previous, "could not allocate sway cursor position")) {
497 free(cursor);
498 return NULL;
499 }
500
499 struct wlr_cursor *wlr_cursor = wlr_cursor_create(); 501 struct wlr_cursor *wlr_cursor = wlr_cursor_create();
500 if (!sway_assert(wlr_cursor, "could not allocate wlr cursor")) { 502 if (!sway_assert(wlr_cursor, "could not allocate wlr cursor")) {
503 free(previous);
501 free(cursor); 504 free(cursor);
502 return NULL; 505 return NULL;
503 } 506 }
@@ -548,6 +551,7 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
548 cursor->request_set_cursor.notify = handle_request_set_cursor; 551 cursor->request_set_cursor.notify = handle_request_set_cursor;
549 552
550 cursor->cursor = wlr_cursor; 553 cursor->cursor = wlr_cursor;
554 cursor->previous = previous;
551 555
552 return cursor; 556 return cursor;
553} 557}