aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-05-27 15:42:39 -0400
committerLibravatar GitHub <noreply@github.com>2018-05-27 15:42:39 -0400
commitb2c0ba5b180b75a18e622934bbed61b0f14b1661 (patch)
tree708dec223ee598dced2a22441a30ff3e8cf6459b
parentMerge pull request #2055 from RedSoxFan/output-destroy-workspace-ipc (diff)
parentImprove comment. (diff)
downloadsway-b2c0ba5b180b75a18e622934bbed61b0f14b1661.tar.gz
sway-b2c0ba5b180b75a18e622934bbed61b0f14b1661.tar.zst
sway-b2c0ba5b180b75a18e622934bbed61b0f14b1661.zip
Merge pull request #2050 from smlx/focus-fix
Focus containers only on entry.
-rw-r--r--include/sway/input/cursor.h5
-rw-r--r--sway/input/cursor.c43
-rw-r--r--sway/input/seat.c7
3 files changed, 22 insertions, 33 deletions
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h
index 42c894a4..5dd109ca 100644
--- a/include/sway/input/cursor.h
+++ b/include/sway/input/cursor.h
@@ -6,6 +6,9 @@
6struct sway_cursor { 6struct sway_cursor {
7 struct sway_seat *seat; 7 struct sway_seat *seat;
8 struct wlr_cursor *cursor; 8 struct wlr_cursor *cursor;
9 struct {
10 double x, y;
11 } previous;
9 struct wlr_xcursor_manager *xcursor_manager; 12 struct wlr_xcursor_manager *xcursor_manager;
10 13
11 struct wl_client *image_client; 14 struct wl_client *image_client;
@@ -30,7 +33,7 @@ struct sway_cursor {
30void sway_cursor_destroy(struct sway_cursor *cursor); 33void sway_cursor_destroy(struct sway_cursor *cursor);
31struct sway_cursor *sway_cursor_create(struct sway_seat *seat); 34struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
32void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, 35void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
33 bool allow_refocusing); 36 bool allow_refocusing);
34void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec, 37void dispatch_cursor_button(struct sway_cursor *cursor, uint32_t time_msec,
35 uint32_t button, enum wlr_button_state state); 38 uint32_t button, enum wlr_button_state state);
36 39
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 1cf432f3..6751931d 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -144,6 +144,14 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
144 struct wlr_seat *seat = cursor->seat->wlr_seat; 144 struct wlr_seat *seat = cursor->seat->wlr_seat;
145 struct wlr_surface *surface = NULL; 145 struct wlr_surface *surface = NULL;
146 double sx, sy; 146 double sx, sy;
147
148 // Find the container beneath the pointer's previous position
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
147 struct sway_container *c = container_at_coords(cursor->seat, 155 struct sway_container *c = container_at_coords(cursor->seat,
148 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); 156 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
149 if (c && config->focus_follows_mouse && allow_refocusing) { 157 if (c && config->focus_follows_mouse && allow_refocusing) {
@@ -162,33 +170,18 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
162 seat_set_focus_warp(cursor->seat, c, false); 170 seat_set_focus_warp(cursor->seat, c, false);
163 } 171 }
164 } else if (c->type == C_VIEW) { 172 } else if (c->type == C_VIEW) {
165 // Don't switch focus on title mouseover for 173 // Focus c if both of the following are true:
166 // stacked and tabbed layouts 174 // - cursor is over a new view, i.e. entered a new window; and
167 // If pointed container is in nested containers which are 175 // - the new view is visible, i.e. not hidden in a stack or tab.
168 // inside tabbed/stacked layout we should skip them 176 if (c != prev_c && view_is_visible(c->sway_view)) {
169 bool do_mouse_focus = true; 177 seat_set_focus_warp(cursor->seat, c, false);
170 bool is_visible = view_is_visible(c->sway_view); 178 } else {
171 struct sway_container *p = c->parent; 179 struct sway_container *next_focus =
172 while (p) { 180 seat_get_focus_inactive(cursor->seat, &root_container);
173 if ((p->layout == L_TABBED || p->layout == L_STACKED) 181 if (next_focus && next_focus->type == C_VIEW &&
174 && !is_visible) { 182 view_is_visible(next_focus->sway_view)) {
175 do_mouse_focus = false;
176 break;
177 }
178 p = p->parent;
179 }
180 if (!do_mouse_focus) {
181 struct sway_container *next_focus = seat_get_focus_inactive(
182 cursor->seat, p);
183 if(next_focus && !sway_assert(next_focus->type == C_VIEW,
184 "focus inactive container is not a view")) {
185 return;
186 }
187 if (next_focus && view_is_visible(next_focus->sway_view)) {
188 seat_set_focus_warp(cursor->seat, next_focus, false); 183 seat_set_focus_warp(cursor->seat, next_focus, false);
189 } 184 }
190 } else {
191 seat_set_focus_warp(cursor->seat, c, false);
192 } 185 }
193 } 186 }
194 } 187 }
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 7a3e928a..6cfbe8d4 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -730,13 +730,6 @@ struct sway_container *seat_get_active_child(struct sway_seat *seat,
730 return focus; 730 return focus;
731} 731}
732 732
733struct sway_container *sway_seat_get_focus(struct sway_seat *seat) {
734 if (!seat->has_focus) {
735 return NULL;
736 }
737 return seat_get_focus_inactive(seat, &root_container);
738}
739
740struct sway_container *seat_get_focus(struct sway_seat *seat) { 733struct sway_container *seat_get_focus(struct sway_seat *seat) {
741 if (!seat->has_focus) { 734 if (!seat->has_focus) {
742 return NULL; 735 return NULL;