From 988fb247107c469bb98ce3088ad189fa12db7cdd Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Wed, 7 Dec 2022 06:10:11 +0100 Subject: [Feature] Dim inactive windows (#66) --- sway/commands/dim_inactive.c | 29 +++++++++++++++++++++++++++ sway/commands/dim_inactive_colors.c | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 sway/commands/dim_inactive.c create mode 100644 sway/commands/dim_inactive_colors.c (limited to 'sway/commands') diff --git a/sway/commands/dim_inactive.c b/sway/commands/dim_inactive.c new file mode 100644 index 00000000..c7c03caa --- /dev/null +++ b/sway/commands/dim_inactive.c @@ -0,0 +1,29 @@ +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "log.h" +#include "sway/output.h" + +struct cmd_results *cmd_dim_inactive(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "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, "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); + } + } + + return cmd_results_new(CMD_SUCCESS, NULL); +} diff --git a/sway/commands/dim_inactive_colors.c b/sway/commands/dim_inactive_colors.c new file mode 100644 index 00000000..db8cc299 --- /dev/null +++ b/sway/commands/dim_inactive_colors.c @@ -0,0 +1,40 @@ +#include "log.h" +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/output.h" +#include "sway/tree/container.h" +#include "util.h" + +static struct cmd_results *handle_command(int argc, char **argv, char *cmd_name, + float config_option[4]) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, cmd_name, EXPECTED_AT_LEAST, 1))) { + return error; + } + + uint32_t color; + if (!parse_color(argv[0], &color)) { + return cmd_results_new(CMD_INVALID, "Invalid %s color %s", + cmd_name, argv[0]); + } + color_to_rgba(config_option, color); + + 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); +} + +struct cmd_results *cmd_dim_inactive_colors_unfocused(int argc, char **argv) { + return handle_command(argc, argv, "dim_inactive_colors.unfocused", + config->dim_inactive_colors.unfocused); +} + +struct cmd_results *cmd_dim_inactive_colors_urgent(int argc, char **argv) { + return handle_command(argc, argv, "dim_inactive_colors.urgent", + config->dim_inactive_colors.urgent); +} -- cgit v1.2.3