diff options
author | Scott Leggett <scott@sl.id.au> | 2018-05-27 14:52:40 +1000 |
---|---|---|
committer | Scott Leggett <scott@sl.id.au> | 2018-05-27 15:29:48 +1000 |
commit | 06098bef98ec515584ab8007cbf7a104f2d67980 (patch) | |
tree | f99df174b233ca266270afa3ef83d2627cf03bec | |
parent | Replace oft-failing abort with if statement (diff) | |
download | sway-06098bef98ec515584ab8007cbf7a104f2d67980.tar.gz sway-06098bef98ec515584ab8007cbf7a104f2d67980.tar.zst sway-06098bef98ec515584ab8007cbf7a104f2d67980.zip |
Focus containers only on entry.
-rw-r--r-- | include/sway/input/cursor.h | 4 | ||||
-rw-r--r-- | sway/commands/border.c | 2 | ||||
-rw-r--r-- | sway/commands/seat/cursor.c | 4 | ||||
-rw-r--r-- | sway/input/cursor.c | 54 | ||||
-rw-r--r-- | sway/input/seat.c | 4 |
5 files changed, 43 insertions, 25 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 42c894a4..2141361d 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h | |||
@@ -29,8 +29,8 @@ struct sway_cursor { | |||
29 | 29 | ||
30 | void sway_cursor_destroy(struct sway_cursor *cursor); | 30 | void sway_cursor_destroy(struct sway_cursor *cursor); |
31 | struct sway_cursor *sway_cursor_create(struct sway_seat *seat); | 31 | struct sway_cursor *sway_cursor_create(struct sway_seat *seat); |
32 | void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | 32 | void cursor_send_pointer_motion(struct sway_cursor *cursor, |
33 | bool allow_refocusing); | 33 | double delta_x, double delta_y, uint32_t time_msec, bool allow_refocusing); |
34 | void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, | 34 | void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, |
35 | uint32_t button, enum wlr_button_state state); | 35 | uint32_t button, enum wlr_button_state state); |
36 | 36 | ||
diff --git a/sway/commands/border.c b/sway/commands/border.c index 4ba361da..5160eaa6 100644 --- a/sway/commands/border.c +++ b/sway/commands/border.c | |||
@@ -41,7 +41,7 @@ struct cmd_results *cmd_border(int argc, char **argv) { | |||
41 | 41 | ||
42 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 42 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
43 | if (seat->cursor) { | 43 | if (seat->cursor) { |
44 | cursor_send_pointer_motion(seat->cursor, 0, false); | 44 | cursor_send_pointer_motion(seat->cursor, 0, 0, 0, false); |
45 | } | 45 | } |
46 | 46 | ||
47 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 47 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
diff --git a/sway/commands/seat/cursor.c b/sway/commands/seat/cursor.c index 4d0a22c7..81fee31f 100644 --- a/sway/commands/seat/cursor.c +++ b/sway/commands/seat/cursor.c | |||
@@ -36,7 +36,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
36 | int delta_x = strtol(argv[1], NULL, 10); | 36 | int delta_x = strtol(argv[1], NULL, 10); |
37 | int delta_y = strtol(argv[2], NULL, 10); | 37 | int delta_y = strtol(argv[2], NULL, 10); |
38 | wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); | 38 | wlr_cursor_move(cursor->cursor, NULL, delta_x, delta_y); |
39 | cursor_send_pointer_motion(cursor, 0, true); | 39 | cursor_send_pointer_motion(cursor, 0, 0, 0, true); |
40 | } else if (strcasecmp(argv[0], "set") == 0) { | 40 | } else if (strcasecmp(argv[0], "set") == 0) { |
41 | if (argc < 3) { | 41 | if (argc < 3) { |
42 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 42 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
@@ -45,7 +45,7 @@ struct cmd_results *seat_cmd_cursor(int argc, char **argv) { | |||
45 | float x = strtof(argv[1], NULL) / root_container.width; | 45 | float x = strtof(argv[1], NULL) / root_container.width; |
46 | float y = strtof(argv[2], NULL) / root_container.height; | 46 | float y = strtof(argv[2], NULL) / root_container.height; |
47 | wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); | 47 | wlr_cursor_warp_absolute(cursor->cursor, NULL, x, y); |
48 | cursor_send_pointer_motion(cursor, 0, true); | 48 | cursor_send_pointer_motion(cursor, 0, 0, 0, true); |
49 | } else { | 49 | } else { |
50 | if (argc < 2) { | 50 | if (argc < 2) { |
51 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); | 51 | return cmd_results_new(CMD_INVALID, "cursor", expected_syntax); |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 1cf432f3..cc8d344f 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -135,15 +135,25 @@ 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, |
139 | bool allow_refocusing) { | 139 | double delta_x, double delta_y, uint32_t time_msec, 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 | |||
140 | if (time_msec == 0) { | 152 | if (time_msec == 0) { |
141 | time_msec = get_current_time_msec(); | 153 | time_msec = get_current_time_msec(); |
142 | } | 154 | } |
143 | 155 | ||
144 | struct wlr_seat *seat = cursor->seat->wlr_seat; | 156 | struct wlr_seat *seat = cursor->seat->wlr_seat; |
145 | struct wlr_surface *surface = NULL; | ||
146 | double sx, sy; | ||
147 | struct sway_container *c = container_at_coords(cursor->seat, | 157 | struct sway_container *c = container_at_coords(cursor->seat, |
148 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); | 158 | cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); |
149 | if (c && config->focus_follows_mouse && allow_refocusing) { | 159 | if (c && config->focus_follows_mouse && allow_refocusing) { |
@@ -162,20 +172,27 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | |||
162 | seat_set_focus_warp(cursor->seat, c, false); | 172 | seat_set_focus_warp(cursor->seat, c, false); |
163 | } | 173 | } |
164 | } else if (c->type == C_VIEW) { | 174 | } else if (c->type == C_VIEW) { |
165 | // Don't switch focus on title mouseover for | ||
166 | // stacked and tabbed layouts | ||
167 | // If pointed container is in nested containers which are | ||
168 | // inside tabbed/stacked layout we should skip them | ||
169 | bool do_mouse_focus = true; | 175 | bool do_mouse_focus = true; |
170 | bool is_visible = view_is_visible(c->sway_view); | ||
171 | struct sway_container *p = c->parent; | 176 | struct sway_container *p = c->parent; |
172 | while (p) { | 177 | // Don't switch focus unless we have moved from one container to another. |
173 | if ((p->layout == L_TABBED || p->layout == L_STACKED) | 178 | if (c && prev_c && c == prev_c) { |
174 | && !is_visible) { | 179 | do_mouse_focus = false; |
175 | do_mouse_focus = false; | 180 | } |
176 | break; | 181 | // Skip check if we already know not to focus. |
182 | if (do_mouse_focus) { | ||
183 | // Don't switch focus on title mouseover for | ||
184 | // stacked and tabbed layouts | ||
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) { | ||
189 | if ((p->layout == L_TABBED || p->layout == L_STACKED) | ||
190 | && !is_visible) { | ||
191 | do_mouse_focus = false; | ||
192 | break; | ||
193 | } | ||
194 | p = p->parent; | ||
177 | } | 195 | } |
178 | p = p->parent; | ||
179 | } | 196 | } |
180 | if (!do_mouse_focus) { | 197 | if (!do_mouse_focus) { |
181 | struct sway_container *next_focus = seat_get_focus_inactive( | 198 | struct sway_container *next_focus = seat_get_focus_inactive( |
@@ -221,7 +238,8 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) { | |||
221 | struct wlr_event_pointer_motion *event = data; | 238 | struct wlr_event_pointer_motion *event = data; |
222 | wlr_cursor_move(cursor->cursor, event->device, | 239 | wlr_cursor_move(cursor->cursor, event->device, |
223 | event->delta_x, event->delta_y); | 240 | event->delta_x, event->delta_y); |
224 | cursor_send_pointer_motion(cursor, event->time_msec, true); | 241 | cursor_send_pointer_motion(cursor, event->delta_x, event->delta_y, |
242 | event->time_msec, true); | ||
225 | } | 243 | } |
226 | 244 | ||
227 | static void handle_cursor_motion_absolute( | 245 | static void handle_cursor_motion_absolute( |
@@ -231,7 +249,7 @@ static void handle_cursor_motion_absolute( | |||
231 | wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); | 249 | wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat); |
232 | struct wlr_event_pointer_motion_absolute *event = data; | 250 | struct wlr_event_pointer_motion_absolute *event = data; |
233 | wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); | 251 | wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); |
234 | cursor_send_pointer_motion(cursor, event->time_msec, true); | 252 | cursor_send_pointer_motion(cursor, 0, 0, event->time_msec, true); |
235 | } | 253 | } |
236 | 254 | ||
237 | void dispatch_cursor_button(struct sway_cursor *cursor, | 255 | void dispatch_cursor_button(struct sway_cursor *cursor, |
@@ -401,7 +419,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) { | |||
401 | } | 419 | } |
402 | 420 | ||
403 | wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y); | 421 | wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y); |
404 | cursor_send_pointer_motion(cursor, event->time_msec, true); | 422 | cursor_send_pointer_motion(cursor, 0, 0, event->time_msec, true); |
405 | } | 423 | } |
406 | 424 | ||
407 | static void handle_tool_tip(struct wl_listener *listener, void *data) { | 425 | static void handle_tool_tip(struct wl_listener *listener, void *data) { |
diff --git a/sway/input/seat.c b/sway/input/seat.c index 7a3e928a..bb583286 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, true); | 605 | cursor_send_pointer_motion(seat->cursor, 0, 0, 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, true); | 616 | cursor_send_pointer_motion(seat->cursor, 0, 0, 0, true); |
617 | } | 617 | } |
618 | 618 | ||
619 | seat->has_focus = (container != NULL); | 619 | seat->has_focus = (container != NULL); |