summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h11
-rw-r--r--include/sway/tree/view.h6
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/focus_on_window_activation.c25
-rw-r--r--sway/desktop/xwayland.c18
-rw-r--r--sway/meson.build1
-rw-r--r--sway/tree/view.c23
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;
117sway_cmd cmd_floating_scroll; 117sway_cmd cmd_floating_scroll;
118sway_cmd cmd_focus; 118sway_cmd cmd_focus;
119sway_cmd cmd_focus_follows_mouse; 119sway_cmd cmd_focus_follows_mouse;
120sway_cmd cmd_focus_on_window_activation;
120sway_cmd cmd_focus_wrapping; 121sway_cmd cmd_focus_wrapping;
121sway_cmd cmd_font; 122sway_cmd cmd_font;
122sway_cmd cmd_for_window; 123sway_cmd cmd_for_window;
diff --git a/include/sway/config.h b/include/sway/config.h
index 18d10faa..45fa73c4 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 */
63enum 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 */
63struct sway_mode { 73struct 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 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
260void view_set_activated(struct sway_view *view, bool activated); 261void view_set_activated(struct sway_view *view, bool activated);
261 262
263/**
264 * Called when the view requests to be focused.
265 */
266void view_request_activate(struct sway_view *view);
267
262void view_set_tiled(struct sway_view *view, bool tiled); 268void view_set_tiled(struct sway_view *view, bool tiled);
263 269
264void view_close(struct sway_view *view); 270void 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
3struct 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
467static 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
466static void handle_set_title(struct wl_listener *listener, void *data) { 480static 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..c6ed68f6 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
283void view_request_activate(struct sway_view *view) {
284 if (config->focus_on_window_activation == FOWA_NONE) {
285 return;
286 }
287 if (config->focus_on_window_activation == FOWA_FOCUS) {
288 struct sway_seat *seat = input_manager_current_seat(input_manager);
289 seat_set_focus(seat, view->swayc);
290 return;
291 }
292 if (config->focus_on_window_activation == FOWA_URGENT) {
293 view_set_urgent(view, true);
294 return;
295 }
296 // FOWA_SMART
297 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
298 if (workspace_is_visible(ws)) {
299 struct sway_seat *seat = input_manager_current_seat(input_manager);
300 seat_set_focus(seat, view->swayc);
301 } else {
302 view_set_urgent(view, true);
303 }
304}
305
283void view_set_tiled(struct sway_view *view, bool tiled) { 306void 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;