summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfamfo <[email protected]>2023-02-15 01:19:02 +0000
committerGitHub <[email protected]>2023-02-14 20:19:02 -0500
commit9f20a5263814f325035d3569768060e04c7dcb96 (patch)
treefc95512b91dd6f4cde541495ea8bea442ad8c041
parente78fc3364b0440ff82becbec4ae57458374a145f (diff)
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
-rw-r--r--README.md3
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h2
-rw-r--r--include/sway/tree/container.h2
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/default_dim_inactive.c30
-rw-r--r--sway/commands/dim_inactive.c14
-rw-r--r--sway/config.c2
-rw-r--r--sway/desktop/render.c11
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway.5.scd7
-rw-r--r--sway/tree/container.c1
12 files changed, 58 insertions, 17 deletions
diff --git a/README.md b/README.md
index 108a5499..f907be92 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,8 @@ Sway is an incredible window manager, and certainly one of the most well establi
- `shadow_blur_radius <integer value 0 - 100>`
- `shadow_color <hex color with alpha> ex, #0000007F`
+ Dim unfocused windows:
- - `dim_inactive <float value 0.0 - 1.0>`
+ - `default_dim_inactive <float value 0.0 - 1.0>`
+ - `for_window [CRITERIA_HERE] dim_inactive <float value 0.0 - 1.0>`
- `dim_inactive_colors.unfocused <hex color> ex, #000000FF`
- `dim_inactive_colors.urgent <hex color> ex, #900000FF`
diff --git a/include/sway/commands.h b/include/sway/commands.h
index bd3cd471..68b316b4 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -122,6 +122,7 @@ sway_cmd cmd_commands;
sway_cmd cmd_corner_radius;
sway_cmd cmd_create_output;
sway_cmd cmd_default_border;
+sway_cmd cmd_default_dim_inactive;
sway_cmd cmd_default_floating_border;
sway_cmd cmd_default_orientation;
sway_cmd cmd_dim_inactive;
diff --git a/include/sway/config.h b/include/sway/config.h
index c8ba7162..77df2568 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -477,7 +477,7 @@ struct sway_config {
// SwayFX config options
int corner_radius;
bool smart_corner_radius;
- float dim_inactive;
+ float default_dim_inactive;
// dim_inactive colors
struct {
float unfocused[4];
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 91448ac7..1d8e5a36 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -120,6 +120,8 @@ struct sway_container {
float alpha;
int corner_radius;
+
+ float dim;
struct wlr_texture *title_focused;
struct wlr_texture *title_focused_inactive;
diff --git a/sway/commands.c b/sway/commands.c
index 79dca98b..f7312dc7 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -58,6 +58,7 @@ static const struct cmd_handler handlers[] = {
{ "client.urgent", cmd_client_urgent },
{ "corner_radius", cmd_corner_radius },
{ "default_border", cmd_default_border },
+ { "default_dim_inactive", cmd_default_dim_inactive },
{ "default_floating_border", cmd_default_floating_border },
{ "dim_inactive", cmd_dim_inactive },
{ "dim_inactive_colors.unfocused", cmd_dim_inactive_colors_unfocused },
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 <string.h>
+#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);
}
diff --git a/sway/config.c b/sway/config.c
index 98141266..54bddda2 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -336,7 +336,7 @@ static void config_defaults(struct sway_config *config) {
// SwayFX defaults
config->corner_radius = 0;
config->smart_corner_radius = true;
- config->dim_inactive = 0.0f;
+ config->default_dim_inactive = 0.0f;
color_to_rgba(config->dim_inactive_colors.unfocused, 0x000000FF);
color_to_rgba(config->dim_inactive_colors.urgent, 0x900000FF);
config->shadow_enabled = false;
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index cdc77ed2..c03265fa 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -1011,12 +1011,13 @@ static void render_containers_linear(struct sway_output *output,
int corner_radius = config->smart_corner_radius &&
output->current.active_workspace->current_gaps.top == 0
? 0 : child->corner_radius;
+
struct decoration_data deco_data = {
.alpha = child->alpha,
.dim_color = view_is_urgent(view)
? config->dim_inactive_colors.urgent
: config->dim_inactive_colors.unfocused,
- .dim = child->current.focused || parent->focused ? 0.0f: config->dim_inactive,
+ .dim = child->current.focused || parent->focused ? 0.0f : child->dim,
// no corner radius if no gaps (allows smart_gaps to work as expected)
.corner_radius = corner_radius,
.saturation = child->saturation,
@@ -1112,7 +1113,7 @@ static void render_containers_tabbed(struct sway_output *output,
.dim_color = view_is_urgent(current->view)
? config->dim_inactive_colors.urgent
: config->dim_inactive_colors.unfocused,
- .dim = current->current.focused || parent->focused ? 0.0f: config->dim_inactive,
+ .dim = current->current.focused || parent->focused ? 0.0f : current->dim,
.corner_radius = current->corner_radius,
.saturation = current->saturation,
.has_titlebar = true,
@@ -1186,7 +1187,7 @@ static void render_containers_stacked(struct sway_output *output,
.dim_color = view_is_urgent(current->view)
? config->dim_inactive_colors.urgent
: config->dim_inactive_colors.unfocused,
- .dim = current->current.focused || parent->focused ? 0.0f: config->dim_inactive,
+ .dim = current->current.focused || parent->focused ? 0.0f : current->dim,
.saturation = current->saturation,
.corner_radius = current->corner_radius,
.has_titlebar = true,
@@ -1286,7 +1287,7 @@ static void render_floating_container(struct sway_output *soutput,
.dim_color = view_is_urgent(view)
? config->dim_inactive_colors.urgent
: config->dim_inactive_colors.unfocused,
- .dim = con->current.focused ? 0.0f: config->dim_inactive,
+ .dim = con->current.focused ? 0.0f : con->dim,
.saturation = con->saturation,
.corner_radius = con->corner_radius,
.has_titlebar = has_titlebar,
@@ -1512,7 +1513,7 @@ void output_render(struct sway_output *output, struct timespec *when,
.dim_color = view_is_urgent(focus->view)
? config->dim_inactive_colors.urgent
: config->dim_inactive_colors.unfocused,
- .dim = focus->current.focused ? 0.0f: config->dim_inactive,
+ .dim = focus->current.focused ? 0.0f : focus->dim,
.corner_radius = 0,
.saturation = focus->saturation,
.has_titlebar = false,
diff --git a/sway/meson.build b/sway/meson.build
index c3688e92..4191a9b9 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -53,6 +53,7 @@ sway_sources = files(
'commands/smart_corner_radius.c',
'commands/create_output.c',
'commands/default_border.c',
+ 'commands/default_dim_inactive.c',
'commands/default_floating_border.c',
'commands/default_orientation.c',
'commands/dim_inactive.c',
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index d25330db..e3e62ed7 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -652,10 +652,15 @@ The default colors are:
*smart_corner_radius* on|off
Set corner radius only if there are gaps around the window.
-*dim_inactive* <value>
+*default_dim_inactive* <value>
Adjusts the dimming of inactive windows between 0.0 (no dimming) and 1.0
(fully dimmed) while 0.0 is the default value.
+*dim_inactive* <value>
+ This can only be used with a *for_window* rule.
+ Adjusts the dimming of a window, matching the rule, between 0.0 (no dimming)
+ and 1.0 (fully dimmed). Default value: *default_dim_inactive*
+
*dim_inactive_colors.unfocused* <hex color>
The color to dim inactive windows with. Example color: #000000FF
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 9de6c551..d22dadd5 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -42,6 +42,7 @@ struct sway_container *container_create(struct sway_view *view) {
c->view = view;
c->alpha = 1.0f;
c->saturation = 1.0f;
+ c->dim = config->default_dim_inactive;
c->shadow_enabled = config->shadow_enabled;
c->corner_radius = config->corner_radius;