From 1e0459f7f7a6a266f7c65ba638db3fe3f4a53635 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 31 Aug 2018 19:49:12 +1000 Subject: [PATCH 1/7] Fix crash when running deferred commands Fixes #2541 --- sway/input/seat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/input/seat.c b/sway/input/seat.c index 36e1d2329..6a6e30962 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -635,7 +635,7 @@ void seat_set_focus_warp(struct sway_seat *seat, // find new output's old workspace, which might have to be removed if empty struct sway_container *new_output_last_ws = NULL; - if (last_output != new_output) { + if (new_output && last_output != new_output) { new_output_last_ws = seat_get_active_child(seat, new_output); } From 407c12fdddf31d7eb7d3a15c936f8daaa5717dbd Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 1 Sep 2018 19:33:24 +0200 Subject: [PATCH 2/7] Update for swaywm/wlroots#1216 --- sway/server.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sway/server.c b/sway/server.c index 7fa6007ec..8b5bc93cc 100644 --- a/sway/server.c +++ b/sway/server.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -117,7 +116,6 @@ bool server_init(struct sway_server *server) { server->server_decoration.notify = handle_server_decoration; wl_list_init(&server->decorations); - wlr_linux_dmabuf_v1_create(server->wl_display, renderer); wlr_export_dmabuf_manager_v1_create(server->wl_display); wlr_screencopy_manager_v1_create(server->wl_display); From 69cd1dfacaab9172fecfe0da8dce23e503483622 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 2 Sep 2018 13:27:32 +1000 Subject: [PATCH 3/7] Check modal state when determining whether an xwayland view should float Depends on https://github.com/swaywm/wlroots/pull/1222. I don't know of a program that sets the state to modal without setting the window type, but I know the modal property works because logging the property shows it's true for the Firefox Open File dialog. --- sway/desktop/xwayland.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 2adc28c54..68d70b64b 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -218,7 +218,9 @@ static bool wants_floating(struct sway_view *view) { struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface; struct sway_xwayland *xwayland = &server.xwayland; - // TODO: return true if the NET_WM_STATE is MODAL + if (surface->modal) { + return true; + } for (size_t i = 0; i < surface->window_type_len; ++i) { xcb_atom_t type = surface->window_type[i]; From f057a0195ee79dfcaeddbcab026c06e310998c75 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 2 Sep 2018 15:03:58 +1000 Subject: [PATCH 4/7] Implement focus_on_window_activation Depends on https://github.com/swaywm/wlroots/pull/1223 --- include/sway/commands.h | 1 + include/sway/config.h | 11 ++++++++++ include/sway/tree/view.h | 6 ++++++ sway/commands.c | 1 + sway/commands/focus_on_window_activation.c | 25 ++++++++++++++++++++++ sway/desktop/xwayland.c | 18 ++++++++++++++++ sway/meson.build | 1 + sway/tree/view.c | 23 ++++++++++++++++++++ 8 files changed, 86 insertions(+) create mode 100644 sway/commands/focus_on_window_activation.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 8e91c158f..b0b5ed0f8 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -117,6 +117,7 @@ sway_cmd cmd_floating_modifier; sway_cmd cmd_floating_scroll; sway_cmd cmd_focus; sway_cmd cmd_focus_follows_mouse; +sway_cmd cmd_focus_on_window_activation; sway_cmd cmd_focus_wrapping; sway_cmd cmd_font; sway_cmd cmd_for_window; diff --git a/include/sway/config.h b/include/sway/config.h index 18d10faa3..45fa73c4f 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -57,6 +57,16 @@ struct sway_mouse_binding { char *command; }; +/** + * Focus on window activation. + */ +enum fowa { + FOWA_SMART, + FOWA_URGENT, + FOWA_FOCUS, + FOWA_NONE, +}; + /** * A "mode" of keybindings created via the `mode` command. */ @@ -340,6 +350,7 @@ struct sway_config { size_t font_height; bool pango_markup; size_t urgent_timeout; + enum fowa focus_on_window_activation; // Flags bool focus_follows_mouse; diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index f73ce571a..382ab6b9a 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -167,6 +167,7 @@ struct sway_xwayland_view { struct wl_listener request_maximize; struct wl_listener request_configure; struct wl_listener request_fullscreen; + struct wl_listener request_activate; struct wl_listener set_title; struct wl_listener set_class; struct wl_listener set_window_type; @@ -259,6 +260,11 @@ void view_autoconfigure(struct sway_view *view); void view_set_activated(struct sway_view *view, bool activated); +/** + * Called when the view requests to be focused. + */ +void view_request_activate(struct sway_view *view); + void view_set_tiled(struct sway_view *view, bool tiled); void view_close(struct sway_view *view); diff --git a/sway/commands.c b/sway/commands.c index 13f5983e7..359856cc7 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -106,6 +106,7 @@ static struct cmd_handler handlers[] = { { "floating_modifier", cmd_floating_modifier }, { "focus", cmd_focus }, { "focus_follows_mouse", cmd_focus_follows_mouse }, + { "focus_on_window_activation", cmd_focus_on_window_activation }, { "focus_wrapping", cmd_focus_wrapping }, { "font", cmd_font }, { "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 000000000..1fb079186 --- /dev/null +++ b/sway/commands/focus_on_window_activation.c @@ -0,0 +1,25 @@ +#include "sway/commands.h" + +struct cmd_results *cmd_focus_on_window_activation(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "focus_on_window_activation", + EXPECTED_EQUAL_TO, 1))) { + return error; + } + + if (strcmp(argv[0], "smart") == 0) { + config->focus_on_window_activation = FOWA_SMART; + } else if (strcmp(argv[0], "urgent") == 0) { + config->focus_on_window_activation = FOWA_URGENT; + } else if (strcmp(argv[0], "focus") == 0) { + config->focus_on_window_activation = FOWA_FOCUS; + } else if (strcmp(argv[0], "none") == 0) { + config->focus_on_window_activation = FOWA_NONE; + } else { + return cmd_results_new(CMD_INVALID, "focus_on_window_activation", + "Expected " + "'focus_on_window_activation smart|urgent|focus|none'"); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 68d70b64b..10faf91d5 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) { wl_list_remove(&xwayland_view->request_fullscreen.link); wl_list_remove(&xwayland_view->request_move.link); wl_list_remove(&xwayland_view->request_resize.link); + wl_list_remove(&xwayland_view->request_activate.link); wl_list_remove(&xwayland_view->set_title.link); wl_list_remove(&xwayland_view->set_class.link); wl_list_remove(&xwayland_view->set_window_type.link); @@ -463,6 +464,19 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { seat_begin_resize_floating(seat, view->swayc, seat->last_button, e->edges); } +static void handle_request_activate(struct wl_listener *listener, void *data) { + struct sway_xwayland_view *xwayland_view = + wl_container_of(listener, xwayland_view, request_activate); + struct sway_view *view = &xwayland_view->view; + struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; + if (!xsurface->mapped) { + return; + } + view_request_activate(view); + + transaction_commit_dirty(); +} + static void handle_set_title(struct wl_listener *listener, void *data) { struct sway_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, set_title); @@ -555,6 +569,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { &xwayland_view->request_fullscreen); xwayland_view->request_fullscreen.notify = handle_request_fullscreen; + wl_signal_add(&xsurface->events.request_activate, + &xwayland_view->request_activate); + xwayland_view->request_activate.notify = handle_request_activate; + wl_signal_add(&xsurface->events.request_move, &xwayland_view->request_move); xwayland_view->request_move.notify = handle_request_move; diff --git a/sway/meson.build b/sway/meson.build index bcb44e8b1..c14e58dd0 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -46,6 +46,7 @@ sway_sources = files( 'commands/floating_modifier.c', 'commands/focus.c', 'commands/focus_follows_mouse.c', + 'commands/focus_on_window_activation.c', 'commands/focus_wrapping.c', 'commands/font.c', 'commands/for_window.c', diff --git a/sway/tree/view.c b/sway/tree/view.c index 1a98c5f2e..c6ed68f67 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) { } } +void view_request_activate(struct sway_view *view) { + if (config->focus_on_window_activation == FOWA_NONE) { + return; + } + if (config->focus_on_window_activation == FOWA_FOCUS) { + struct sway_seat *seat = input_manager_current_seat(input_manager); + seat_set_focus(seat, view->swayc); + return; + } + if (config->focus_on_window_activation == FOWA_URGENT) { + view_set_urgent(view, true); + return; + } + // FOWA_SMART + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); + if (workspace_is_visible(ws)) { + struct sway_seat *seat = input_manager_current_seat(input_manager); + seat_set_focus(seat, view->swayc); + } else { + view_set_urgent(view, true); + } +} + void view_set_tiled(struct sway_view *view, bool tiled) { if (!tiled) { view->using_csd = true; From 6fb03817c9d2bd29697a91f92d680b0c6a2c5996 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 2 Sep 2018 18:25:45 +1000 Subject: [PATCH 5/7] Rename fowa enum and use switch in view_request_activate --- include/sway/config.h | 4 ++-- sway/tree/view.c | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index 45fa73c4f..4ee8c3c28 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -60,7 +60,7 @@ struct sway_mouse_binding { /** * Focus on window activation. */ -enum fowa { +enum sway_fowa { FOWA_SMART, FOWA_URGENT, FOWA_FOCUS, @@ -350,7 +350,7 @@ struct sway_config { size_t font_height; bool pango_markup; size_t urgent_timeout; - enum fowa focus_on_window_activation; + enum sway_fowa focus_on_window_activation; // Flags bool focus_follows_mouse; diff --git a/sway/tree/view.c b/sway/tree/view.c index c6ed68f67..6bd0ef670 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -281,25 +281,25 @@ void view_set_activated(struct sway_view *view, bool activated) { } void view_request_activate(struct sway_view *view) { - if (config->focus_on_window_activation == FOWA_NONE) { - return; - } - if (config->focus_on_window_activation == FOWA_FOCUS) { - struct sway_seat *seat = input_manager_current_seat(input_manager); - seat_set_focus(seat, view->swayc); - return; - } - if (config->focus_on_window_activation == FOWA_URGENT) { - view_set_urgent(view, true); - return; - } - // FOWA_SMART struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); - if (workspace_is_visible(ws)) { - struct sway_seat *seat = input_manager_current_seat(input_manager); - seat_set_focus(seat, view->swayc); - } else { + struct sway_seat *seat = input_manager_current_seat(input_manager); + + switch (config->focus_on_window_activation) { + case FOWA_SMART: + if (workspace_is_visible(ws)) { + seat_set_focus(seat, view->swayc); + } else { + view_set_urgent(view, true); + } + break; + case FOWA_URGENT: view_set_urgent(view, true); + break; + case FOWA_FOCUS: + seat_set_focus(seat, view->swayc); + break; + case FOWA_NONE: + break; } } From 7795f733d8c72f3467c2ac04e3d2633c79601935 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 2 Sep 2018 22:58:15 +1000 Subject: [PATCH 6/7] Use dashes in meson option names --- meson.build | 10 +++++----- meson_options.txt | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/meson.build b/meson.build index d5b33e6ba..56f1141e3 100644 --- a/meson.build +++ b/meson.build @@ -106,7 +106,7 @@ endif add_project_arguments('-DSYSCONFDIR="/@0@"'.format(sysconfdir), language : 'c') -version = get_option('sway_version') +version = get_option('sway-version') if version != '' version = '"@0@"'.format(version) else @@ -168,7 +168,7 @@ install_data( install_dir: datadir + '/wayland-sessions' ) -if (get_option('default_wallpaper')) +if (get_option('default-wallpaper')) wallpaper_files = files( 'assets/Sway_Wallpaper_Blue_768x1024.png', 'assets/Sway_Wallpaper_Blue_768x1024_Portrait.png', @@ -184,7 +184,7 @@ if (get_option('default_wallpaper')) install_data(wallpaper_files, install_dir: wallpaper_install_dir) endif -if (get_option('zsh_completions')) +if (get_option('zsh-completions')) zsh_files = files( 'completions/zsh/_sway', 'completions/zsh/_swaylock', @@ -195,7 +195,7 @@ if (get_option('zsh_completions')) install_data(zsh_files, install_dir: zsh_install_dir) endif -if (get_option('bash_completions')) +if (get_option('bash-completions')) bash_files = files( 'completions/bash/sway', 'completions/bash/swayidle', @@ -207,7 +207,7 @@ if (get_option('bash_completions')) install_data(bash_files, install_dir: bash_install_dir) endif -if (get_option('fish_completions')) +if (get_option('fish-completions')) fish_files = files( 'completions/fish/sway.fish', 'completions/fish/swaylock.fish', diff --git a/meson_options.txt b/meson_options.txt index 5e54607f7..911be2d61 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,6 +1,6 @@ -option('sway_version', type : 'string', description: 'The version string reported in `sway --version`.') -option('default_wallpaper', type: 'boolean', value: true, description: 'Install the default wallpaper.') -option('zsh_completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') -option('bash_completions', type: 'boolean', value: true, description: 'Install bash shell completions.') -option('fish_completions', type: 'boolean', value: true, description: 'Install fish shell completions.') +option('sway-version', type : 'string', description: 'The version string reported in `sway --version`.') +option('default-wallpaper', type: 'boolean', value: true, description: 'Install the default wallpaper.') +option('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') +option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.') +option('fish-completions', type: 'boolean', value: true, description: 'Install fish shell completions.') option('enable-xwayland', type: 'boolean', value: true, description: 'Enable support for X11 applications') From 4ece26e511eaabca55fff216aa2f925d2c28ad44 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 2 Sep 2018 23:07:47 +1000 Subject: [PATCH 7/7] Add ld-library-path meson option --- meson.build | 2 ++ meson_options.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/meson.build b/meson.build index 56f1141e3..eb5cba846 100644 --- a/meson.build +++ b/meson.build @@ -120,6 +120,8 @@ else endif add_project_arguments('-DSWAY_VERSION=@0@'.format(version), language: 'c') +add_project_arguments('-D_LD_LIBRARY_PATH="@0@"'.format(get_option('ld-library-path')), language: 'c') + sway_inc = include_directories('include') subdir('include') diff --git a/meson_options.txt b/meson_options.txt index 911be2d61..50d646fd3 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,4 +1,5 @@ option('sway-version', type : 'string', description: 'The version string reported in `sway --version`.') +option('ld-library-path', type: 'string', value: '', description: 'The LD_LIBRARY_PATH environment variable.') option('default-wallpaper', type: 'boolean', value: true, description: 'Install the default wallpaper.') option('zsh-completions', type: 'boolean', value: true, description: 'Install zsh shell completions.') option('bash-completions', type: 'boolean', value: true, description: 'Install bash shell completions.')