From fe2ab9c1da9f2c021e17ae03164f69ab6813e360 Mon Sep 17 00:00:00 2001 From: Erik Reider Date: Fri, 21 Apr 2023 23:47:56 +0200 Subject: [PATCH] Add layer_effects command --- README.md | 2 ++ include/sway/commands.h | 1 + include/sway/config.h | 8 ++++++ include/sway/layers.h | 5 ++-- sway/commands.c | 1 + sway/commands/layer_effects.c | 54 +++++++++++++++++++++++++++++++++++ sway/config.c | 10 +++++++ sway/desktop/layer_shell.c | 12 ++++---- sway/desktop/output.c | 11 ++++--- sway/meson.build | 1 + sway/sway.5.scd | 8 ++++++ 11 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 sway/commands/layer_effects.c diff --git a/README.md b/README.md index 679ef5dd..d4f52e2a 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ Sway is an incredible window manager, and certainly one of the most well establi - `blur_xray enable|disable` - `blur_passes ` - `blur_radius ` ++ LayerShell effects: *ONLY ON SWAYFX-GIT, NOT YET RELEASED* + - `layer_effects blur corner_radius` + Dim unfocused windows: - `default_dim_inactive ` - `for_window [CRITERIA_HERE] dim_inactive ` diff --git a/include/sway/commands.h b/include/sway/commands.h index b895d5f2..924297ae 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -157,6 +157,7 @@ sway_cmd cmd_input; sway_cmd cmd_seat; sway_cmd cmd_ipc; sway_cmd cmd_kill; +sway_cmd cmd_layer_effects; sway_cmd cmd_layout; sway_cmd cmd_log_colors; sway_cmd cmd_mark; diff --git a/include/sway/config.h b/include/sway/config.h index cabc9cf5..43736b5d 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -475,6 +475,12 @@ struct blur_parameters { int radius; }; +struct layer_effects { + char *namespace; + bool blur; + bool corner_radius; +}; + /** * The configuration struct. The result of loading a config file. */ @@ -500,6 +506,8 @@ struct sway_config { bool titlebar_separator; bool scratchpad_minimize; + list_t *layer_effects; + char *swaynag_command; struct swaynag_instance swaynag_config_errors; list_t *symbols; diff --git a/include/sway/layers.h b/include/sway/layers.h index c5b7f284..6ebdbfab 100644 --- a/include/sway/layers.h +++ b/include/sway/layers.h @@ -3,6 +3,7 @@ #include #include #include +#include "sway/config.h" enum layer_parent { LAYER_PARENT_LAYER, @@ -28,9 +29,7 @@ struct sway_layer_surface { struct wl_list subsurfaces; - bool should_blur; - bool should_corner_radius; - bool should_shadow; + struct layer_effects *effects; }; struct sway_layer_popup { diff --git a/sway/commands.c b/sway/commands.c index 8e2d8f89..2b515228 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -119,6 +119,7 @@ static const struct cmd_handler handlers[] = { static const struct cmd_handler config_handlers[] = { { "default_orientation", cmd_default_orientation }, { "include", cmd_include }, + { "layer_effects", cmd_layer_effects }, { "scratchpad_minimize", cmd_scratchpad_minimize }, { "swaybg_command", cmd_swaybg_command }, { "swaynag_command", cmd_swaynag_command }, diff --git a/sway/commands/layer_effects.c b/sway/commands/layer_effects.c new file mode 100644 index 00000000..96b16db1 --- /dev/null +++ b/sway/commands/layer_effects.c @@ -0,0 +1,54 @@ +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/output.h" +#include "util.h" + +struct cmd_results *cmd_layer_effects(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "layer_effects", EXPECTED_AT_LEAST, 2))) { + return error; + } + + struct layer_effects *effect = malloc(sizeof(struct layer_effects)); + size_t len = sizeof(argv[0]); + effect->namespace = malloc(len + 1); + memcpy(effect->namespace, argv[0], len); + effect->blur = false; + effect->corner_radius = false; + + // Parse the commands + for (int i = 1; i < argc; i++) { + char *arg = argv[i]; + if (strcmp(arg, "blur") == 0) { + effect->blur = true; + continue; + } else if (strcmp(arg, "corner_rounding") == 0) { + effect->corner_radius = true; + continue; + } + return cmd_results_new(CMD_INVALID, "Invalid layer_effects effect! Got \"%s\"", arg); + } + + if (!effect->blur && !effect->corner_radius) { + return cmd_results_new(CMD_SUCCESS, NULL); + } + + // Check if the rule already exists + list_t *effects = config->layer_effects; + for (int i = 0; i < effects->length; ++i) { + struct layer_effects *existing = effects->items[i]; + // Replace the duplicate entry + if (strcmp(existing->namespace, effect->namespace) == 0) { + memcpy(existing, effect, sizeof(struct layer_effects)); + free(effect); + effect = NULL; + break; + } + } + + if (effect) { + list_add(config->layer_effects, effect); + } + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/config.c b/sway/config.c index 85e53679..66db4149 100644 --- a/sway/config.c +++ b/sway/config.c @@ -157,6 +157,14 @@ void free_config(struct sway_config *config) { } list_free(config->criteria); } + if (config->layer_effects) { + for (int i = 0; i < config->layer_effects->length; ++i) { + struct layer_effects *effect = config->criteria->items[i]; + free(effect->namespace); + free(effect); + } + list_free(config->layer_effects); + } list_free(config->no_focus); list_free(config->active_bar_modifiers); list_free_items_and_destroy(config->config_chain); @@ -354,6 +362,8 @@ static void config_defaults(struct sway_config *config) { config->titlebar_separator = true; config->scratchpad_minimize = true; + if (!(config->layer_effects = create_list())) goto cleanup; + // The keysym to keycode translation struct xkb_rule_names rules = {0}; config->keysym_translation_state = diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index 288dad09..8a9da029 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -686,12 +686,14 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { layer_surface->data = sway_layer; enum zwlr_layer_shell_v1_layer layer = layer_surface->current.layer; - // TODO: Effects bool in config? if (layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM && layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) { - printf("Namespace: %s\n", layer_surface->namespace); - sway_layer->should_blur = true; - sway_layer->should_corner_radius = true; - sway_layer->should_shadow = true; + for (int i = 0; i < config->layer_effects->length; ++i) { + struct layer_effects *effect = config->layer_effects->items[i]; + if (strcmp(effect->namespace, layer_surface->namespace) == 0) { + sway_layer->effects = effect; + break; + } + } } struct sway_output *output = layer_surface->output->data; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index be5051c4..ec77eaa7 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -200,10 +200,13 @@ void output_layer_for_each_toplevel_surface(struct sway_output *output, struct wlr_layer_surface_v1 *wlr_layer_surface_v1 = layer_surface->layer_surface; struct fx_render_data *data = user_data; - data->deco_data.blur = layer_surface->should_blur; - data->deco_data.corner_radius = - layer_surface->should_corner_radius? config->corner_radius: 0; - data->is_toplevel_surface = true; + struct layer_effects *effects = layer_surface->effects; + if (effects) { + data->deco_data.blur = effects->blur; + data->deco_data.corner_radius = + effects->corner_radius? config->corner_radius: 0; + data->is_toplevel_surface = true; + } output_surface_for_each_surface(output, wlr_layer_surface_v1->surface, layer_surface->geo.x, layer_surface->geo.y, iterator, diff --git a/sway/meson.build b/sway/meson.build index 54e41072..5d3f8b09 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -91,6 +91,7 @@ sway_sources = files( 'commands/include.c', 'commands/input.c', 'commands/layout.c', + 'commands/layer_effects.c', 'commands/mode.c', 'commands/mouse_warping.c', 'commands/move.c', diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 2288346b..b45cd095 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -71,6 +71,14 @@ 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. +*layer_effects* + Apply effects on specific layer shell surfaces, eg waybar or rofi. + At least one effect needs to be provided. + + Effects: + - *blur* + - *corner_rounding* + *scratchpad_minimize* enable|disable Adjusts if minimized windows should be moved into the scratchpad. Must be set at config-time (when starting sway).