From 5bfa2e030e06af7b4bb3550cc25f0120678a1f71 Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Tue, 30 May 2023 00:49:32 -0400 Subject: [PATCH] added animation config --- README.md | 10 ++++++++-- include/sway/commands.h | 1 + include/sway/config.h | 2 ++ sway/commands.c | 1 + sway/commands/animation_duration.c | 21 +++++++++++++++++++++ sway/config.c | 2 ++ sway/desktop/output.c | 5 +---- sway/meson.build | 1 + sway/sway.5.scd | 3 +++ 9 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 sway/commands/animation_duration.c diff --git a/README.md b/README.md index f69e2cb2..5a7bb82b 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,14 @@ Sway is an incredible window manager, and certainly one of the most well establi ## New Configuration Options ++ Fade in / out animations: `animation_duration `: specifies the length of the animation in seconds ++ Corner radius: `corner_radius ` ++ Smart corner radius: `smart_corner_radius enable|disable` ++ Window shadows: + - `shadows enable|disable` + - `shadows_on_csd enable|disable` (**Note**: The shadow might not fit some windows) + - `shadow_blur_radius ` + - `shadow_color ex, #0000007F` + Window blur: - `blur enable|disable` - `blur_xray enable|disable`: this will set floating windows to blur based on the background, not the windows below. You probably want to set this to `disable` :) @@ -58,7 +66,6 @@ Sway is an incredible window manager, and certainly one of the most well establi ## Roadmap -+ fade in / out animations + window movement animations ## Compiling From Source @@ -127,4 +134,3 @@ We would also like to thank the talented artists in our community for contibutin + spooky_skeleton for the swayfx logo, and [Basil](https://basil.cafe) for making some fine adjustments to it Lastly, we would like to thank you, the community, for enjoying and using window manager that we have spent so much time maintaining. - diff --git a/include/sway/commands.h b/include/sway/commands.h index 920e8596..e5c28af7 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -108,6 +108,7 @@ bool cmd_corner_radius_parse_value(char *arg, int* result); sway_cmd cmd_exec_validate; sway_cmd cmd_exec_process; +sway_cmd cmd_animation_duration; sway_cmd cmd_assign; sway_cmd cmd_bar; sway_cmd cmd_bindcode; diff --git a/include/sway/config.h b/include/sway/config.h index 04e2969e..1c3f4e37 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -479,6 +479,8 @@ struct blur_parameters { * The configuration struct. The result of loading a config file. */ struct sway_config { + float animation_duration; + int corner_radius; bool smart_corner_radius; diff --git a/sway/commands.c b/sway/commands.c index 34bb08c3..9924148f 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -43,6 +43,7 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type /* Keep alphabetized */ static const struct cmd_handler handlers[] = { + { "animation_duration", cmd_animation_duration }, { "assign", cmd_assign }, { "bar", cmd_bar }, { "bindcode", cmd_bindcode }, diff --git a/sway/commands/animation_duration.c b/sway/commands/animation_duration.c new file mode 100644 index 00000000..fc8a65cb --- /dev/null +++ b/sway/commands/animation_duration.c @@ -0,0 +1,21 @@ +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "log.h" + +struct cmd_results *cmd_animation_duration(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "animation_duration", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + char *err; + float value = strtof(argv[0], &err); + if (*err || value < 0.0f || value > 1.0f) { + return cmd_results_new(CMD_FAILURE, "animation_duration value invalid"); + } + + config->animation_duration = value; + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/config.c b/sway/config.c index 82085d03..ee947fd9 100644 --- a/sway/config.c +++ b/sway/config.c @@ -341,6 +341,8 @@ static void config_defaults(struct sway_config *config) { color_to_rgba(config->border_colors.background, 0xFFFFFFFF); // SwayFX defaults + config->animation_duration = 0; + config->corner_radius = 0; config->smart_corner_radius = true; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index ba778934..115172db 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -522,16 +522,13 @@ static bool scan_out_fullscreen_view(struct sway_output *output, } static void containers_tick_alpha(list_t *containers, struct sway_output *output) { - // TODO: config for animation_duration - float animation_duration = 0.5; - float alpha_step; for (int i = 0; i < containers->length; ++i) { struct sway_container *con = containers->items[i]; if (con->pending.children) { containers_tick_alpha(con->pending.children, output); } else if (con->alpha < con->target_alpha) { - alpha_step = (con->target_alpha * output->refresh_sec) / animation_duration; + alpha_step = (con->target_alpha * output->refresh_sec) / config->animation_duration; // ensure that the alpha does not exceed the target_alpha con->alpha = MIN(con->alpha + alpha_step, con->target_alpha); output_damage_whole_container(output, con); diff --git a/sway/meson.build b/sway/meson.build index 528cdd99..bea9f083 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -49,6 +49,7 @@ sway_sources = files( 'config/seat.c', 'config/input.c', + 'commands/animation_duration.c', 'commands/assign.c', 'commands/bar.c', 'commands/bind.c', diff --git a/sway/sway.5.scd b/sway/sway.5.scd index a68eee5c..606cc151 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -378,6 +378,9 @@ set|plus|minus|toggle The following commands may be used either in the configuration file or at runtime. +*animation_duration * + Specifies the length of the animation in seconds, between 0 and 1 second. + *assign* [→] [workspace] [number] Assigns views matching _criteria_ (see *CRITERIA* for details) to _workspace_. The → (U+2192) is optional and cosmetic. This command is