From 64e76f16124c10076ab86973bbefc3ee0f6f8a48 Mon Sep 17 00:00:00 2001 From: Erik Reider Date: Tue, 21 Mar 2023 16:24:19 +0100 Subject: [PATCH] Added config option with default being off --- README.md | 1 + config.in | 3 +++ include/sway/commands.h | 1 + include/sway/config.h | 1 + sway/commands.c | 1 + sway/commands/scratchpad_minimize.c | 18 ++++++++++++++ sway/config.c | 1 + sway/desktop/xdg_shell.c | 5 ++++ sway/desktop/xwayland.c | 38 +++++++++++++++++------------ sway/meson.build | 1 + sway/sway.5.scd | 4 +++ sway/tree/view.c | 2 ++ 12 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 sway/commands/scratchpad_minimize.c diff --git a/README.md b/README.md index 1ac57fda..65a95572 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Sway is an incredible window manager, and certainly one of the most well establi - `dim_inactive_colors.urgent ex, #900000FF` + Application saturation: `for_window [CRITERIA HERE] saturation 2.0>` + Keep/remove separator border between titlebar and content: `titlebar_separator enable|disable` ++ Treat Scratchpad as minimized: `scratchpad_minimize on|off` ## Roadmap diff --git a/config.in b/config.in index dc451f23..fd54c364 100644 --- a/config.in +++ b/config.in @@ -34,6 +34,9 @@ dim_inactive 0.0 dim_inactive_colors.unfocused #000000FF dim_inactive_colors.urgent #900000FF +# Move minimized windows into Scratchpad +scratchpad_minimize off + ### Output configuration # # Default wallpaper (more resolutions are available in @datadir@/backgrounds/sway/) diff --git a/include/sway/commands.h b/include/sway/commands.h index 84d44e27..91b1fc58 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -176,6 +176,7 @@ sway_cmd cmd_reload; sway_cmd cmd_rename; sway_cmd cmd_resize; sway_cmd cmd_scratchpad; +sway_cmd cmd_scratchpad_minimize; sway_cmd cmd_seamless_mouse; sway_cmd cmd_set; sway_cmd cmd_shortcuts_inhibitor; diff --git a/include/sway/config.h b/include/sway/config.h index 60c810e1..2dc4b52d 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -488,6 +488,7 @@ struct sway_config { int shadow_blur_sigma; float shadow_color[4]; bool titlebar_separator; + bool scratchpad_minimize; char *swaynag_command; struct swaynag_instance swaynag_config_errors; diff --git a/sway/commands.c b/sway/commands.c index b8b98e99..fbe17039 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -115,6 +115,7 @@ static const struct cmd_handler handlers[] = { static const struct cmd_handler config_handlers[] = { { "default_orientation", cmd_default_orientation }, { "include", cmd_include }, + { "scratchpad_minimize", cmd_scratchpad_minimize }, { "swaybg_command", cmd_swaybg_command }, { "swaynag_command", cmd_swaynag_command }, { "workspace_layout", cmd_workspace_layout }, diff --git a/sway/commands/scratchpad_minimize.c b/sway/commands/scratchpad_minimize.c new file mode 100644 index 00000000..1245e1d5 --- /dev/null +++ b/sway/commands/scratchpad_minimize.c @@ -0,0 +1,18 @@ +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "log.h" +#include "stringop.h" +#include "util.h" + +struct cmd_results *cmd_scratchpad_minimize(int argc, char **argv) { + struct cmd_results *error = checkarg(argc, "scratchpad_minimize", EXPECTED_AT_LEAST, 1); + + if (error) { + return error; + } + + config->scratchpad_minimize = parse_boolean(argv[0], config->scratchpad_minimize); + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/config.c b/sway/config.c index d1949a3a..1bb4c07a 100644 --- a/sway/config.c +++ b/sway/config.c @@ -344,6 +344,7 @@ static void config_defaults(struct sway_config *config) { config->shadow_blur_sigma = 20.0f; color_to_rgba(config->shadow_color, 0x0000007F); config->titlebar_separator = true; + config->scratchpad_minimize = false; // The keysym to keycode translation struct xkb_rule_names rules = {0}; diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 0f9d3868..96066f4b 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -336,6 +336,11 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) { static void handle_request_minimize(struct wl_listener *listener, void *data) { struct sway_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, request_minimize); + if (!config->scratchpad_minimize) { + struct wlr_xdg_toplevel *toplevel = xdg_shell_view->view.wlr_xdg_toplevel; + wlr_xdg_surface_schedule_configure(toplevel->base); + return; + } struct sway_container *container = xdg_shell_view->view.container; if (!container->pending.workspace) { diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 3c1f213a..55a14c0b 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -586,24 +586,30 @@ static void handle_request_minimize(struct wl_listener *listener, void *data) { } struct wlr_xwayland_minimize_event *e = data; - struct sway_container *container = view->container; - if (!container->pending.workspace) { - while (container->pending.parent) { - container = container->pending.parent; + if (config->scratchpad_minimize) { + struct sway_container *container = view->container; + if (!container->pending.workspace) { + while (container->pending.parent) { + container = container->pending.parent; + } } + if(e->minimize) { + if (!container->scratchpad) { + root_scratchpad_add_container(container, NULL); + } else if (container->pending.workspace) { + root_scratchpad_hide(container); + } + } else { + if(container->scratchpad) { + root_scratchpad_show(container); + } + } + transaction_commit_dirty(); + return; } - if(e->minimize) { - if (!container->scratchpad) { - root_scratchpad_add_container(container, NULL); - } else if (container->pending.workspace) { - root_scratchpad_hide(container); - } - } else { - if(container->scratchpad) { - root_scratchpad_show(container); - } - } - transaction_commit_dirty(); + struct sway_seat *seat = input_manager_current_seat(); + bool focused = seat_get_focus(seat) == &view->container->node; + wlr_xwayland_surface_set_minimized(xsurface, !focused && e->minimize); } static void handle_request_move(struct wl_listener *listener, void *data) { diff --git a/sway/meson.build b/sway/meson.build index d1b47271..b6f63c16 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -98,6 +98,7 @@ sway_sources = files( 'commands/resize.c', 'commands/saturation.c', 'commands/scratchpad.c', + 'commands/scratchpad_minimize.c', 'commands/seat.c', 'commands/seat/attach.c', 'commands/seat/cursor.c', diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 0b860920..43fd5220 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -71,6 +71,10 @@ The following commands may only be used in the configuration file. *wordexp*(3) for details). The same include file can only be included once; subsequent attempts will be ignored. +*scratchpad_minimize* + Adjusts if minimized windows should be moved into the scratchpad (on|off). + Must be set at config-time (when starting sway). + *swaybg_command* Executes custom background _command_. Default is _swaybg_. Refer to *sway-output*(5) for more information. diff --git a/sway/tree/view.c b/sway/tree/view.c index 7d4dbaeb..397f317e 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -712,6 +712,8 @@ static void handle_foreign_fullscreen_request( static void handle_foreign_minimize( struct wl_listener *listener, void *data) { + if (!config->scratchpad_minimize) return; + struct sway_view *view = wl_container_of( listener, view, foreign_minimize); struct wlr_foreign_toplevel_handle_v1_minimized_event *event = data;