diff options
author | emersion <contact@emersion.fr> | 2018-09-02 21:41:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-02 21:41:24 +0200 |
commit | e438342157272f6a807ea28ef1b554e01530ead8 (patch) | |
tree | fb510fe69ef12a9de9d299fa1543c32b49a16e8e | |
parent | Merge pull request #2559 from RyanDwyer/xwayland-check-modal (diff) | |
parent | Rename fowa enum and use switch in view_request_activate (diff) | |
download | sway-e438342157272f6a807ea28ef1b554e01530ead8.tar.gz sway-e438342157272f6a807ea28ef1b554e01530ead8.tar.zst sway-e438342157272f6a807ea28ef1b554e01530ead8.zip |
Merge pull request #2560 from RyanDwyer/focus-on-window-activation
Implement focus_on_window_activation
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | include/sway/config.h | 11 | ||||
-rw-r--r-- | include/sway/tree/view.h | 6 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/focus_on_window_activation.c | 25 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 18 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/tree/view.c | 23 |
8 files changed, 86 insertions, 0 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index 8e91c158..b0b5ed0f 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -117,6 +117,7 @@ sway_cmd cmd_floating_modifier; | |||
117 | sway_cmd cmd_floating_scroll; | 117 | sway_cmd cmd_floating_scroll; |
118 | sway_cmd cmd_focus; | 118 | sway_cmd cmd_focus; |
119 | sway_cmd cmd_focus_follows_mouse; | 119 | sway_cmd cmd_focus_follows_mouse; |
120 | sway_cmd cmd_focus_on_window_activation; | ||
120 | sway_cmd cmd_focus_wrapping; | 121 | sway_cmd cmd_focus_wrapping; |
121 | sway_cmd cmd_font; | 122 | sway_cmd cmd_font; |
122 | sway_cmd cmd_for_window; | 123 | sway_cmd cmd_for_window; |
diff --git a/include/sway/config.h b/include/sway/config.h index 18d10faa..4ee8c3c2 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -58,6 +58,16 @@ struct sway_mouse_binding { | |||
58 | }; | 58 | }; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Focus on window activation. | ||
62 | */ | ||
63 | enum sway_fowa { | ||
64 | FOWA_SMART, | ||
65 | FOWA_URGENT, | ||
66 | FOWA_FOCUS, | ||
67 | FOWA_NONE, | ||
68 | }; | ||
69 | |||
70 | /** | ||
61 | * A "mode" of keybindings created via the `mode` command. | 71 | * A "mode" of keybindings created via the `mode` command. |
62 | */ | 72 | */ |
63 | struct sway_mode { | 73 | struct sway_mode { |
@@ -340,6 +350,7 @@ struct sway_config { | |||
340 | size_t font_height; | 350 | size_t font_height; |
341 | bool pango_markup; | 351 | bool pango_markup; |
342 | size_t urgent_timeout; | 352 | size_t urgent_timeout; |
353 | enum sway_fowa focus_on_window_activation; | ||
343 | 354 | ||
344 | // Flags | 355 | // Flags |
345 | bool focus_follows_mouse; | 356 | bool focus_follows_mouse; |
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index f73ce571..382ab6b9 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h | |||
@@ -167,6 +167,7 @@ struct sway_xwayland_view { | |||
167 | struct wl_listener request_maximize; | 167 | struct wl_listener request_maximize; |
168 | struct wl_listener request_configure; | 168 | struct wl_listener request_configure; |
169 | struct wl_listener request_fullscreen; | 169 | struct wl_listener request_fullscreen; |
170 | struct wl_listener request_activate; | ||
170 | struct wl_listener set_title; | 171 | struct wl_listener set_title; |
171 | struct wl_listener set_class; | 172 | struct wl_listener set_class; |
172 | struct wl_listener set_window_type; | 173 | struct wl_listener set_window_type; |
@@ -259,6 +260,11 @@ void view_autoconfigure(struct sway_view *view); | |||
259 | 260 | ||
260 | void view_set_activated(struct sway_view *view, bool activated); | 261 | void view_set_activated(struct sway_view *view, bool activated); |
261 | 262 | ||
263 | /** | ||
264 | * Called when the view requests to be focused. | ||
265 | */ | ||
266 | void view_request_activate(struct sway_view *view); | ||
267 | |||
262 | void view_set_tiled(struct sway_view *view, bool tiled); | 268 | void view_set_tiled(struct sway_view *view, bool tiled); |
263 | 269 | ||
264 | void view_close(struct sway_view *view); | 270 | void view_close(struct sway_view *view); |
diff --git a/sway/commands.c b/sway/commands.c index 13f5983e..359856cc 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -106,6 +106,7 @@ static struct cmd_handler handlers[] = { | |||
106 | { "floating_modifier", cmd_floating_modifier }, | 106 | { "floating_modifier", cmd_floating_modifier }, |
107 | { "focus", cmd_focus }, | 107 | { "focus", cmd_focus }, |
108 | { "focus_follows_mouse", cmd_focus_follows_mouse }, | 108 | { "focus_follows_mouse", cmd_focus_follows_mouse }, |
109 | { "focus_on_window_activation", cmd_focus_on_window_activation }, | ||
109 | { "focus_wrapping", cmd_focus_wrapping }, | 110 | { "focus_wrapping", cmd_focus_wrapping }, |
110 | { "font", cmd_font }, | 111 | { "font", cmd_font }, |
111 | { "for_window", cmd_for_window }, | 112 | { "for_window", cmd_for_window }, |
diff --git a/sway/commands/focus_on_window_activation.c b/sway/commands/focus_on_window_activation.c new file mode 100644 index 00000000..1fb07918 --- /dev/null +++ b/sway/commands/focus_on_window_activation.c | |||
@@ -0,0 +1,25 @@ | |||
1 | #include "sway/commands.h" | ||
2 | |||
3 | struct cmd_results *cmd_focus_on_window_activation(int argc, char **argv) { | ||
4 | struct cmd_results *error = NULL; | ||
5 | if ((error = checkarg(argc, "focus_on_window_activation", | ||
6 | EXPECTED_EQUAL_TO, 1))) { | ||
7 | return error; | ||
8 | } | ||
9 | |||
10 | if (strcmp(argv[0], "smart") == 0) { | ||
11 | config->focus_on_window_activation = FOWA_SMART; | ||
12 | } else if (strcmp(argv[0], "urgent") == 0) { | ||
13 | config->focus_on_window_activation = FOWA_URGENT; | ||
14 | } else if (strcmp(argv[0], "focus") == 0) { | ||
15 | config->focus_on_window_activation = FOWA_FOCUS; | ||
16 | } else if (strcmp(argv[0], "none") == 0) { | ||
17 | config->focus_on_window_activation = FOWA_NONE; | ||
18 | } else { | ||
19 | return cmd_results_new(CMD_INVALID, "focus_on_window_activation", | ||
20 | "Expected " | ||
21 | "'focus_on_window_activation smart|urgent|focus|none'"); | ||
22 | } | ||
23 | |||
24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
25 | } | ||
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 68d70b64..10faf91d 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -337,6 +337,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { | |||
337 | wl_list_remove(&xwayland_view->request_fullscreen.link); | 337 | wl_list_remove(&xwayland_view->request_fullscreen.link); |
338 | wl_list_remove(&xwayland_view->request_move.link); | 338 | wl_list_remove(&xwayland_view->request_move.link); |
339 | wl_list_remove(&xwayland_view->request_resize.link); | 339 | wl_list_remove(&xwayland_view->request_resize.link); |
340 | wl_list_remove(&xwayland_view->request_activate.link); | ||
340 | wl_list_remove(&xwayland_view->set_title.link); | 341 | wl_list_remove(&xwayland_view->set_title.link); |
341 | wl_list_remove(&xwayland_view->set_class.link); | 342 | wl_list_remove(&xwayland_view->set_class.link); |
342 | wl_list_remove(&xwayland_view->set_window_type.link); | 343 | wl_list_remove(&xwayland_view->set_window_type.link); |
@@ -463,6 +464,19 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { | |||
463 | seat_begin_resize_floating(seat, view->swayc, seat->last_button, e->edges); | 464 | seat_begin_resize_floating(seat, view->swayc, seat->last_button, e->edges); |
464 | } | 465 | } |
465 | 466 | ||
467 | static void handle_request_activate(struct wl_listener *listener, void *data) { | ||
468 | struct sway_xwayland_view *xwayland_view = | ||
469 | wl_container_of(listener, xwayland_view, request_activate); | ||
470 | struct sway_view *view = &xwayland_view->view; | ||
471 | struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; | ||
472 | if (!xsurface->mapped) { | ||
473 | return; | ||
474 | } | ||
475 | view_request_activate(view); | ||
476 | |||
477 | transaction_commit_dirty(); | ||
478 | } | ||
479 | |||
466 | static void handle_set_title(struct wl_listener *listener, void *data) { | 480 | static void handle_set_title(struct wl_listener *listener, void *data) { |
467 | struct sway_xwayland_view *xwayland_view = | 481 | struct sway_xwayland_view *xwayland_view = |
468 | wl_container_of(listener, xwayland_view, set_title); | 482 | wl_container_of(listener, xwayland_view, set_title); |
@@ -555,6 +569,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { | |||
555 | &xwayland_view->request_fullscreen); | 569 | &xwayland_view->request_fullscreen); |
556 | xwayland_view->request_fullscreen.notify = handle_request_fullscreen; | 570 | xwayland_view->request_fullscreen.notify = handle_request_fullscreen; |
557 | 571 | ||
572 | wl_signal_add(&xsurface->events.request_activate, | ||
573 | &xwayland_view->request_activate); | ||
574 | xwayland_view->request_activate.notify = handle_request_activate; | ||
575 | |||
558 | wl_signal_add(&xsurface->events.request_move, | 576 | wl_signal_add(&xsurface->events.request_move, |
559 | &xwayland_view->request_move); | 577 | &xwayland_view->request_move); |
560 | xwayland_view->request_move.notify = handle_request_move; | 578 | xwayland_view->request_move.notify = handle_request_move; |
diff --git a/sway/meson.build b/sway/meson.build index bcb44e8b..c14e58dd 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -46,6 +46,7 @@ sway_sources = files( | |||
46 | 'commands/floating_modifier.c', | 46 | 'commands/floating_modifier.c', |
47 | 'commands/focus.c', | 47 | 'commands/focus.c', |
48 | 'commands/focus_follows_mouse.c', | 48 | 'commands/focus_follows_mouse.c', |
49 | 'commands/focus_on_window_activation.c', | ||
49 | 'commands/focus_wrapping.c', | 50 | 'commands/focus_wrapping.c', |
50 | 'commands/font.c', | 51 | 'commands/font.c', |
51 | 'commands/for_window.c', | 52 | 'commands/for_window.c', |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 1a98c5f2..6bd0ef67 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -280,6 +280,29 @@ void view_set_activated(struct sway_view *view, bool activated) { | |||
280 | } | 280 | } |
281 | } | 281 | } |
282 | 282 | ||
283 | void view_request_activate(struct sway_view *view) { | ||
284 | struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); | ||
285 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
286 | |||
287 | switch (config->focus_on_window_activation) { | ||
288 | case FOWA_SMART: | ||
289 | if (workspace_is_visible(ws)) { | ||
290 | seat_set_focus(seat, view->swayc); | ||
291 | } else { | ||
292 | view_set_urgent(view, true); | ||
293 | } | ||
294 | break; | ||
295 | case FOWA_URGENT: | ||
296 | view_set_urgent(view, true); | ||
297 | break; | ||
298 | case FOWA_FOCUS: | ||
299 | seat_set_focus(seat, view->swayc); | ||
300 | break; | ||
301 | case FOWA_NONE: | ||
302 | break; | ||
303 | } | ||
304 | } | ||
305 | |||
283 | void view_set_tiled(struct sway_view *view, bool tiled) { | 306 | void view_set_tiled(struct sway_view *view, bool tiled) { |
284 | if (!tiled) { | 307 | if (!tiled) { |
285 | view->using_csd = true; | 308 | view->using_csd = true; |