From 9f20a5263814f325035d3569768060e04c7dcb96 Mon Sep 17 00:00:00 2001 From: famfo <44938471+famfo@users.noreply.github.com> Date: Wed, 15 Feb 2023 01:19:02 +0000 Subject: Implement for_window support for dim_inactive (#109) * Implement for_window support for dim_inactive * Update file names, add check if the container is null, add docs * Fix typo * Update meson.build * Update commands.c * Update render.c * Update container.c * Update render.c * Update container.h --- sway/commands/default_dim_inactive.c | 30 ++++++++++++++++++++++++++++++ sway/commands/dim_inactive.c | 14 ++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 sway/commands/default_dim_inactive.c (limited to 'sway/commands') diff --git a/sway/commands/default_dim_inactive.c b/sway/commands/default_dim_inactive.c new file mode 100644 index 00000000..04d8acdf --- /dev/null +++ b/sway/commands/default_dim_inactive.c @@ -0,0 +1,30 @@ +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "log.h" +#include "sway/output.h" + + +struct cmd_results *cmd_default_dim_inactive(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "default_dim_inactive", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + char *err; + float val = strtof(argv[0], &err); + if (*err || val < 0.0f || val > 1.0f) { + return cmd_results_new(CMD_INVALID, "default_dim_inactive float invalid"); + } + + config->default_dim_inactive = val; + + if (config->active) { + for (int i = 0; i < root->outputs->length; ++i) { + struct sway_output *output = root->outputs->items[i]; + output_damage_whole(output); + } + } + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/commands/dim_inactive.c b/sway/commands/dim_inactive.c index c7c03caa..e287ba4d 100644 --- a/sway/commands/dim_inactive.c +++ b/sway/commands/dim_inactive.c @@ -3,6 +3,7 @@ #include "sway/config.h" #include "log.h" #include "sway/output.h" +#include "sway/tree/container.h" struct cmd_results *cmd_dim_inactive(int argc, char **argv) { struct cmd_results *error = NULL; @@ -16,14 +17,11 @@ struct cmd_results *cmd_dim_inactive(int argc, char **argv) { return cmd_results_new(CMD_INVALID, "dim_inactive float invalid"); } - config->dim_inactive = val; - - if (config->active) { - for (int i = 0; i < root->outputs->length; ++i) { - struct sway_output *output = root->outputs->items[i]; - output_damage_whole(output); - } - } + struct sway_container *container = config->handler_context.container; + if (!container) { + return cmd_results_new(CMD_INVALID, "cmd_dim cannot be used without a for_window rule"); + } + container->dim = val; return cmd_results_new(CMD_SUCCESS, NULL); } -- cgit v1.2.3