Skip to content

Commit

Permalink
added animation config
Browse files Browse the repository at this point in the history
  • Loading branch information
WillPower3309 committed May 30, 2023
1 parent 2fe5642 commit 7ed7f29
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 6 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Sway is an incredible window manager, and certainly one of the most well establi

## New Configuration Options

+ Fade in / out animations: `animation_duration <val>`: specifies the length of the animation in seconds
+ Corner radius: `corner_radius <val>`
+ Smart corner radius: `smart_corner_radius enable|disable`
+ Window shadows:
Expand Down Expand Up @@ -50,7 +51,6 @@ Sway is an incredible window manager, and certainly one of the most well establi

## Roadmap

+ fade in / out animations
+ window movement animations

## Installation
Expand Down Expand Up @@ -113,4 +113,3 @@ Here's a quick outline of where most of our changes lie vs the main sway reposit
+ `sway/desktop/render.c`: the file that handles calling `fx_renderer` to render to the screen, handles damage tracking and scaling
+ `sway/desktop/fx_renderer.c`: the meat and potatoes of this project, structured as similarly to wlr_renderer as possible
+ `sway/desktop/shaders`: where all of the shaders that fx_renderer uses live

1 change: 1 addition & 0 deletions include/sway/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions include/sway/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions sway/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
21 changes: 21 additions & 0 deletions sway/commands/animation_duration.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <string.h>
#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);
}
2 changes: 2 additions & 0 deletions sway/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 1 addition & 4 deletions sway/desktop/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,16 +521,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);
Expand Down
1 change: 1 addition & 0 deletions sway/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ sway_sources = files(
'config/seat.c',
'config/input.c',

'commands/animation_duration.c',
'commands/assign.c',
'commands/bar.c',
'commands/bind.c',
Expand Down
3 changes: 3 additions & 0 deletions sway/sway.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ set|plus|minus|toggle <amount>
The following commands may be used either in the configuration file or at
runtime.

*animation_duration <seconds>*
Specifies the length of the animation in seconds, between 0 and 1 second.

*assign* <criteria> [] [workspace] [number] <workspace>
Assigns views matching _criteria_ (see *CRITERIA* for details) to
_workspace_. The → (U+2192) is optional and cosmetic. This command is
Expand Down

0 comments on commit 7ed7f29

Please sign in to comment.