summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-02 15:03:58 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-02 18:20:34 +1000
commitf057a0195ee79dfcaeddbcab026c06e310998c75 (patch)
tree5c09cc286ae3a6d852341a0ae4796d28bb6155b0 /sway
parentMerge pull request #2559 from RyanDwyer/xwayland-check-modal (diff)
downloadsway-f057a0195ee79dfcaeddbcab026c06e310998c75.tar.gz
sway-f057a0195ee79dfcaeddbcab026c06e310998c75.tar.zst
sway-f057a0195ee79dfcaeddbcab026c06e310998c75.zip
Implement focus_on_window_activation
Depends on https://github.com/swaywm/wlroots/pull/1223
Diffstat (limited to 'sway')
-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
5 files changed, 68 insertions, 0 deletions
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;