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
This commit is contained in:
parent
e78fc3364b
commit
9f20a52638
|
@ -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`
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 },
|
||||
|
|
30
sway/commands/default_dim_inactive.c
Normal file
30
sway/commands/default_dim_inactive.c
Normal file
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue