diff options
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/focus_follows_mouse.c | 12 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/input/cursor.c | 53 | ||||
-rw-r--r-- | sway/meson.build | 1 |
6 files changed, 41 insertions, 28 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index ac1105b4..03b51948 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -304,7 +304,6 @@ struct sway_config { | |||
304 | bool reloading; | 304 | bool reloading; |
305 | bool reading; | 305 | bool reading; |
306 | bool auto_back_and_forth; | 306 | bool auto_back_and_forth; |
307 | bool seamless_mouse; | ||
308 | bool show_marks; | 307 | bool show_marks; |
309 | 308 | ||
310 | bool edge_gaps; | 309 | bool edge_gaps; |
diff --git a/sway/commands.c b/sway/commands.c index d983dcbb..90544220 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -98,6 +98,7 @@ static struct cmd_handler handlers[] = { | |||
98 | { "bindsym", cmd_bindsym }, | 98 | { "bindsym", cmd_bindsym }, |
99 | { "exec", cmd_exec }, | 99 | { "exec", cmd_exec }, |
100 | { "exec_always", cmd_exec_always }, | 100 | { "exec_always", cmd_exec_always }, |
101 | { "focus_follows_mouse", cmd_focus_follows_mouse }, | ||
101 | { "include", cmd_include }, | 102 | { "include", cmd_include }, |
102 | { "input", cmd_input }, | 103 | { "input", cmd_input }, |
103 | { "mode", cmd_mode }, | 104 | { "mode", cmd_mode }, |
diff --git a/sway/commands/focus_follows_mouse.c b/sway/commands/focus_follows_mouse.c new file mode 100644 index 00000000..661e7852 --- /dev/null +++ b/sway/commands/focus_follows_mouse.c | |||
@@ -0,0 +1,12 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | |||
5 | struct cmd_results *cmd_focus_follows_mouse(int argc, char **argv) { | ||
6 | struct cmd_results *error = NULL; | ||
7 | if ((error = checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1))) { | ||
8 | return error; | ||
9 | } | ||
10 | config->focus_follows_mouse = !strcasecmp(argv[0], "yes"); | ||
11 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
12 | } | ||
diff --git a/sway/config.c b/sway/config.c index e9e7057d..0eecf7f6 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -178,7 +178,6 @@ static void config_defaults(struct sway_config *config) { | |||
178 | config->active = false; | 178 | config->active = false; |
179 | config->failed = false; | 179 | config->failed = false; |
180 | config->auto_back_and_forth = false; | 180 | config->auto_back_and_forth = false; |
181 | config->seamless_mouse = true; | ||
182 | config->reading = false; | 181 | config->reading = false; |
183 | config->show_marks = true; | 182 | config->show_marks = true; |
184 | 183 | ||
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 9cdd66d8..35dd5dc8 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -125,7 +125,10 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor, | |||
125 | struct wlr_seat *seat = cursor->seat->wlr_seat; | 125 | struct wlr_seat *seat = cursor->seat->wlr_seat; |
126 | struct wlr_surface *surface = NULL; | 126 | struct wlr_surface *surface = NULL; |
127 | double sx, sy; | 127 | double sx, sy; |
128 | container_at_cursor(cursor, &surface, &sx, &sy); | 128 | struct sway_container *c = container_at_cursor(cursor, &surface, &sx, &sy); |
129 | if (c && config->focus_follows_mouse) { | ||
130 | sway_seat_set_focus(cursor->seat, c); | ||
131 | } | ||
129 | 132 | ||
130 | // reset cursor if switching between clients | 133 | // reset cursor if switching between clients |
131 | struct wl_client *client = NULL; | 134 | struct wl_client *client = NULL; |
@@ -170,33 +173,31 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) { | |||
170 | struct sway_cursor *cursor = wl_container_of(listener, cursor, button); | 173 | struct sway_cursor *cursor = wl_container_of(listener, cursor, button); |
171 | struct wlr_event_pointer_button *event = data; | 174 | struct wlr_event_pointer_button *event = data; |
172 | 175 | ||
173 | if (event->button == BTN_LEFT) { | 176 | struct wlr_surface *surface = NULL; |
174 | struct wlr_surface *surface = NULL; | 177 | double sx, sy; |
175 | double sx, sy; | 178 | struct sway_container *cont = |
176 | struct sway_container *cont = | 179 | container_at_cursor(cursor, &surface, &sx, &sy); |
177 | container_at_cursor(cursor, &surface, &sx, &sy); | 180 | // Avoid moving keyboard focus from a surface that accepts it to one |
178 | // Avoid moving keyboard focus from a surface that accepts it to one | 181 | // that does not unless the change would move us to a new workspace. |
179 | // that does not unless the change would move us to a new workspace. | 182 | // |
180 | // | 183 | // This prevents, for example, losing focus when clicking on swaybar. |
181 | // This prevents, for example, losing focus when clicking on swaybar. | 184 | // |
182 | // | 185 | // TODO: Replace this condition with something like |
183 | // TODO: Replace this condition with something like | 186 | // !surface_accepts_keyboard_input |
184 | // !surface_accepts_keyboard_input | 187 | if (surface && cont && cont->type != C_VIEW) { |
185 | if (surface && cont && cont->type != C_VIEW) { | 188 | struct sway_container *new_ws = cont; |
186 | struct sway_container *new_ws = cont; | 189 | if (new_ws && new_ws->type != C_WORKSPACE) { |
187 | if (new_ws && new_ws->type != C_WORKSPACE) { | 190 | new_ws = container_parent(new_ws, C_WORKSPACE); |
188 | new_ws = container_parent(new_ws, C_WORKSPACE); | 191 | } |
189 | } | 192 | struct sway_container *old_ws = sway_seat_get_focus(cursor->seat); |
190 | struct sway_container *old_ws = sway_seat_get_focus(cursor->seat); | 193 | if (old_ws && old_ws->type != C_WORKSPACE) { |
191 | if (old_ws && old_ws->type != C_WORKSPACE) { | 194 | old_ws = container_parent(old_ws, C_WORKSPACE); |
192 | old_ws = container_parent(old_ws, C_WORKSPACE); | 195 | } |
193 | } | 196 | if (new_ws != old_ws) { |
194 | if (new_ws != old_ws) { | ||
195 | sway_seat_set_focus(cursor->seat, cont); | ||
196 | } | ||
197 | } else { | ||
198 | sway_seat_set_focus(cursor->seat, cont); | 197 | sway_seat_set_focus(cursor->seat, cont); |
199 | } | 198 | } |
199 | } else { | ||
200 | sway_seat_set_focus(cursor->seat, cont); | ||
200 | } | 201 | } |
201 | 202 | ||
202 | wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, | 203 | wlr_seat_pointer_notify_button(cursor->seat->wlr_seat, event->time_msec, |
diff --git a/sway/meson.build b/sway/meson.build index 5bc57964..0cc620ea 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -13,6 +13,7 @@ sway_sources = files( | |||
13 | 'commands/exec.c', | 13 | 'commands/exec.c', |
14 | 'commands/exec_always.c', | 14 | 'commands/exec_always.c', |
15 | 'commands/focus.c', | 15 | 'commands/focus.c', |
16 | 'commands/focus_follows_mouse.c', | ||
16 | 'commands/kill.c', | 17 | 'commands/kill.c', |
17 | 'commands/include.c', | 18 | 'commands/include.c', |
18 | 'commands/input.c', | 19 | 'commands/input.c', |