diff options
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/cursor.c | 31 | ||||
-rw-r--r-- | sway/input/seat.c | 16 |
2 files changed, 38 insertions, 9 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 9259c475..9a0b4f01 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -108,7 +108,7 @@ static struct sway_container *container_at_coords( | |||
108 | } | 108 | } |
109 | 109 | ||
110 | struct sway_container *c; | 110 | struct sway_container *c; |
111 | if ((c = container_at(ws, x, y, surface, sx, sy))) { | 111 | if ((c = container_at(ws, ox, oy, surface, sx, sy))) { |
112 | return c; | 112 | return c; |
113 | } | 113 | } |
114 | 114 | ||
@@ -135,7 +135,8 @@ static struct sway_container *container_at_coords( | |||
135 | return output->swayc; | 135 | return output->swayc; |
136 | } | 136 | } |
137 | 137 | ||
138 | void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec) { | 138 | void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, |
139 | bool allow_refocusing) { | ||
139 | if (time_msec == 0) { | 140 | if (time_msec == 0) { |
140 | time_msec = get_current_time_msec(); | 141 | time_msec = get_current_time_msec(); |
141 | } | 142 | } |
@@ -145,8 +146,24 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec) | |||
145 | double sx, sy; | 146 | double sx, sy; |
146 | struct sway_container *c = container_at_coords(cursor->seat, | 147 | struct sway_container *c = container_at_coords(cursor->seat, |
147 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); | 148 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); |
148 | if (c && config->focus_follows_mouse) { | 149 | if (c && config->focus_follows_mouse && allow_refocusing) { |
149 | seat_set_focus_warp(cursor->seat, c, false); | 150 | struct sway_container *focus = seat_get_focus(cursor->seat); |
151 | if (focus && c->type == C_WORKSPACE) { | ||
152 | // Only follow the mouse if it would move to a new output | ||
153 | // Otherwise we'll focus the workspace, which is probably wrong | ||
154 | if (focus->type != C_OUTPUT) { | ||
155 | focus = container_parent(focus, C_OUTPUT); | ||
156 | } | ||
157 | struct sway_container *output = c; | ||
158 | if (output->type != C_OUTPUT) { | ||
159 | output = container_parent(c, C_OUTPUT); | ||
160 | } | ||
161 | if (output != focus) { | ||
162 | seat_set_focus_warp(cursor->seat, c, false); | ||
163 | } | ||
164 | } else { | ||
165 | seat_set_focus_warp(cursor->seat, c, false); | ||
166 | } | ||
150 | } | 167 | } |
151 | 168 | ||
152 | // reset cursor if switching between clients | 169 | // reset cursor if switching between clients |
@@ -177,7 +194,7 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) { | |||
177 | struct wlr_event_pointer_motion *event = data; | 194 | struct wlr_event_pointer_motion *event = data; |
178 | wlr_cursor_move(cursor->cursor, event->device, | 195 | wlr_cursor_move(cursor->cursor, event->device, |
179 | event->delta_x, event->delta_y); | 196 | event->delta_x, event->delta_y); |
180 | cursor_send_pointer_motion(cursor, event->time_msec); | 197 | cursor_send_pointer_motion(cursor, event->time_msec, true); |
181 | } | 198 | } |
182 | 199 | ||
183 | static void handle_cursor_motion_absolute( | 200 | static void handle_cursor_motion_absolute( |
@@ -187,7 +204,7 @@ static void handle_cursor_motion_absolute( | |||
187 | wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); | 204 | wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); |
188 | struct wlr_event_pointer_motion_absolute *event = data; | 205 | struct wlr_event_pointer_motion_absolute *event = data; |
189 | wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); | 206 | wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); |
190 | cursor_send_pointer_motion(cursor, event->time_msec); | 207 | cursor_send_pointer_motion(cursor, event->time_msec, true); |
191 | } | 208 | } |
192 | 209 | ||
193 | void dispatch_cursor_button(struct sway_cursor *cursor, | 210 | void dispatch_cursor_button(struct sway_cursor *cursor, |
@@ -357,7 +374,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { | |||
357 | } | 374 | } |
358 | 375 | ||
359 | wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y); | 376 | wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y); |
360 | cursor_send_pointer_motion(cursor, event->time_msec); | 377 | cursor_send_pointer_motion(cursor, event->time_msec, true); |
361 | } | 378 | } |
362 | 379 | ||
363 | static void handle_tool_tip(struct wl_listener *listener, void *data) { | 380 | static void handle_tool_tip(struct wl_listener *listener, void *data) { |
diff --git a/sway/input/seat.c b/sway/input/seat.c index 9ac3e6a8..7a3e928a 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -602,7 +602,7 @@ void seat_set_focus_warp(struct sway_seat *seat, | |||
602 | wlr_output, seat->cursor->cursor->x, | 602 | wlr_output, seat->cursor->cursor->x, |
603 | seat->cursor->cursor->y)) { | 603 | seat->cursor->cursor->y)) { |
604 | wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); | 604 | wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); |
605 | cursor_send_pointer_motion(seat->cursor, 0); | 605 | cursor_send_pointer_motion(seat->cursor, 0, true); |
606 | } | 606 | } |
607 | } | 607 | } |
608 | } | 608 | } |
@@ -613,7 +613,7 @@ void seat_set_focus_warp(struct sway_seat *seat, | |||
613 | } | 613 | } |
614 | 614 | ||
615 | if (last_workspace && last_workspace != new_workspace) { | 615 | if (last_workspace && last_workspace != new_workspace) { |
616 | cursor_send_pointer_motion(seat->cursor, 0); | 616 | cursor_send_pointer_motion(seat->cursor, 0, true); |
617 | } | 617 | } |
618 | 618 | ||
619 | seat->has_focus = (container != NULL); | 619 | seat->has_focus = (container != NULL); |
@@ -718,6 +718,18 @@ struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, | |||
718 | return seat_get_focus_by_type(seat, container, C_TYPES); | 718 | return seat_get_focus_by_type(seat, container, C_TYPES); |
719 | } | 719 | } |
720 | 720 | ||
721 | struct sway_container *seat_get_active_child(struct sway_seat *seat, | ||
722 | struct sway_container *container) { | ||
723 | struct sway_container *focus = seat_get_focus_inactive(seat, container); | ||
724 | if (!focus) { | ||
725 | return NULL; | ||
726 | } | ||
727 | while (focus->parent != container) { | ||
728 | focus = focus->parent; | ||
729 | } | ||
730 | return focus; | ||
731 | } | ||
732 | |||
721 | struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { | 733 | struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { |
722 | if (!seat->has_focus) { | 734 | if (!seat->has_focus) { |
723 | return NULL; | 735 | return NULL; |