Add layer_effects command
This commit is contained in:
parent
d0244b0bf1
commit
fe2ab9c1da
11 changed files with 101 additions and 12 deletions
|
@ -31,6 +31,8 @@ Sway is an incredible window manager, and certainly one of the most well establi
|
||||||
- `blur_xray enable|disable`
|
- `blur_xray enable|disable`
|
||||||
- `blur_passes <integer value 0 - 10>`
|
- `blur_passes <integer value 0 - 10>`
|
||||||
- `blur_radius <integer value 0 - 10>`
|
- `blur_radius <integer value 0 - 10>`
|
||||||
|
+ LayerShell effects: *ONLY ON SWAYFX-GIT, NOT YET RELEASED*
|
||||||
|
- `layer_effects <layer namespace, eg: "waybar"> blur corner_radius`
|
||||||
+ Dim unfocused windows:
|
+ Dim unfocused windows:
|
||||||
- `default_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>`
|
- `for_window [CRITERIA_HERE] dim_inactive <float value 0.0 - 1.0>`
|
||||||
|
|
|
@ -157,6 +157,7 @@ sway_cmd cmd_input;
|
||||||
sway_cmd cmd_seat;
|
sway_cmd cmd_seat;
|
||||||
sway_cmd cmd_ipc;
|
sway_cmd cmd_ipc;
|
||||||
sway_cmd cmd_kill;
|
sway_cmd cmd_kill;
|
||||||
|
sway_cmd cmd_layer_effects;
|
||||||
sway_cmd cmd_layout;
|
sway_cmd cmd_layout;
|
||||||
sway_cmd cmd_log_colors;
|
sway_cmd cmd_log_colors;
|
||||||
sway_cmd cmd_mark;
|
sway_cmd cmd_mark;
|
||||||
|
|
|
@ -475,6 +475,12 @@ struct blur_parameters {
|
||||||
int radius;
|
int radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct layer_effects {
|
||||||
|
char *namespace;
|
||||||
|
bool blur;
|
||||||
|
bool corner_radius;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The configuration struct. The result of loading a config file.
|
* The configuration struct. The result of loading a config file.
|
||||||
*/
|
*/
|
||||||
|
@ -500,6 +506,8 @@ struct sway_config {
|
||||||
bool titlebar_separator;
|
bool titlebar_separator;
|
||||||
bool scratchpad_minimize;
|
bool scratchpad_minimize;
|
||||||
|
|
||||||
|
list_t *layer_effects;
|
||||||
|
|
||||||
char *swaynag_command;
|
char *swaynag_command;
|
||||||
struct swaynag_instance swaynag_config_errors;
|
struct swaynag_instance swaynag_config_errors;
|
||||||
list_t *symbols;
|
list_t *symbols;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <wlr/types/wlr_compositor.h>
|
#include <wlr/types/wlr_compositor.h>
|
||||||
#include <wlr/types/wlr_layer_shell_v1.h>
|
#include <wlr/types/wlr_layer_shell_v1.h>
|
||||||
|
#include "sway/config.h"
|
||||||
|
|
||||||
enum layer_parent {
|
enum layer_parent {
|
||||||
LAYER_PARENT_LAYER,
|
LAYER_PARENT_LAYER,
|
||||||
|
@ -28,9 +29,7 @@ struct sway_layer_surface {
|
||||||
|
|
||||||
struct wl_list subsurfaces;
|
struct wl_list subsurfaces;
|
||||||
|
|
||||||
bool should_blur;
|
struct layer_effects *effects;
|
||||||
bool should_corner_radius;
|
|
||||||
bool should_shadow;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sway_layer_popup {
|
struct sway_layer_popup {
|
||||||
|
|
|
@ -119,6 +119,7 @@ static const struct cmd_handler handlers[] = {
|
||||||
static const struct cmd_handler config_handlers[] = {
|
static const struct cmd_handler config_handlers[] = {
|
||||||
{ "default_orientation", cmd_default_orientation },
|
{ "default_orientation", cmd_default_orientation },
|
||||||
{ "include", cmd_include },
|
{ "include", cmd_include },
|
||||||
|
{ "layer_effects", cmd_layer_effects },
|
||||||
{ "scratchpad_minimize", cmd_scratchpad_minimize },
|
{ "scratchpad_minimize", cmd_scratchpad_minimize },
|
||||||
{ "swaybg_command", cmd_swaybg_command },
|
{ "swaybg_command", cmd_swaybg_command },
|
||||||
{ "swaynag_command", cmd_swaynag_command },
|
{ "swaynag_command", cmd_swaynag_command },
|
||||||
|
|
54
sway/commands/layer_effects.c
Normal file
54
sway/commands/layer_effects.c
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#include "sway/commands.h"
|
||||||
|
#include "sway/config.h"
|
||||||
|
#include "sway/output.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
struct cmd_results *cmd_layer_effects(int argc, char **argv) {
|
||||||
|
struct cmd_results *error = NULL;
|
||||||
|
if ((error = checkarg(argc, "layer_effects", EXPECTED_AT_LEAST, 2))) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct layer_effects *effect = malloc(sizeof(struct layer_effects));
|
||||||
|
size_t len = sizeof(argv[0]);
|
||||||
|
effect->namespace = malloc(len + 1);
|
||||||
|
memcpy(effect->namespace, argv[0], len);
|
||||||
|
effect->blur = false;
|
||||||
|
effect->corner_radius = false;
|
||||||
|
|
||||||
|
// Parse the commands
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
char *arg = argv[i];
|
||||||
|
if (strcmp(arg, "blur") == 0) {
|
||||||
|
effect->blur = true;
|
||||||
|
continue;
|
||||||
|
} else if (strcmp(arg, "corner_rounding") == 0) {
|
||||||
|
effect->corner_radius = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return cmd_results_new(CMD_INVALID, "Invalid layer_effects effect! Got \"%s\"", arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!effect->blur && !effect->corner_radius) {
|
||||||
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the rule already exists
|
||||||
|
list_t *effects = config->layer_effects;
|
||||||
|
for (int i = 0; i < effects->length; ++i) {
|
||||||
|
struct layer_effects *existing = effects->items[i];
|
||||||
|
// Replace the duplicate entry
|
||||||
|
if (strcmp(existing->namespace, effect->namespace) == 0) {
|
||||||
|
memcpy(existing, effect, sizeof(struct layer_effects));
|
||||||
|
free(effect);
|
||||||
|
effect = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (effect) {
|
||||||
|
list_add(config->layer_effects, effect);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||||
|
}
|
|
@ -157,6 +157,14 @@ void free_config(struct sway_config *config) {
|
||||||
}
|
}
|
||||||
list_free(config->criteria);
|
list_free(config->criteria);
|
||||||
}
|
}
|
||||||
|
if (config->layer_effects) {
|
||||||
|
for (int i = 0; i < config->layer_effects->length; ++i) {
|
||||||
|
struct layer_effects *effect = config->criteria->items[i];
|
||||||
|
free(effect->namespace);
|
||||||
|
free(effect);
|
||||||
|
}
|
||||||
|
list_free(config->layer_effects);
|
||||||
|
}
|
||||||
list_free(config->no_focus);
|
list_free(config->no_focus);
|
||||||
list_free(config->active_bar_modifiers);
|
list_free(config->active_bar_modifiers);
|
||||||
list_free_items_and_destroy(config->config_chain);
|
list_free_items_and_destroy(config->config_chain);
|
||||||
|
@ -354,6 +362,8 @@ static void config_defaults(struct sway_config *config) {
|
||||||
config->titlebar_separator = true;
|
config->titlebar_separator = true;
|
||||||
config->scratchpad_minimize = true;
|
config->scratchpad_minimize = true;
|
||||||
|
|
||||||
|
if (!(config->layer_effects = create_list())) goto cleanup;
|
||||||
|
|
||||||
// The keysym to keycode translation
|
// The keysym to keycode translation
|
||||||
struct xkb_rule_names rules = {0};
|
struct xkb_rule_names rules = {0};
|
||||||
config->keysym_translation_state =
|
config->keysym_translation_state =
|
||||||
|
|
|
@ -686,12 +686,14 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
|
||||||
layer_surface->data = sway_layer;
|
layer_surface->data = sway_layer;
|
||||||
|
|
||||||
enum zwlr_layer_shell_v1_layer layer = layer_surface->current.layer;
|
enum zwlr_layer_shell_v1_layer layer = layer_surface->current.layer;
|
||||||
// TODO: Effects bool in config?
|
|
||||||
if (layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM && layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) {
|
if (layer != ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM && layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) {
|
||||||
printf("Namespace: %s\n", layer_surface->namespace);
|
for (int i = 0; i < config->layer_effects->length; ++i) {
|
||||||
sway_layer->should_blur = true;
|
struct layer_effects *effect = config->layer_effects->items[i];
|
||||||
sway_layer->should_corner_radius = true;
|
if (strcmp(effect->namespace, layer_surface->namespace) == 0) {
|
||||||
sway_layer->should_shadow = true;
|
sway_layer->effects = effect;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sway_output *output = layer_surface->output->data;
|
struct sway_output *output = layer_surface->output->data;
|
||||||
|
|
|
@ -200,10 +200,13 @@ void output_layer_for_each_toplevel_surface(struct sway_output *output,
|
||||||
struct wlr_layer_surface_v1 *wlr_layer_surface_v1 =
|
struct wlr_layer_surface_v1 *wlr_layer_surface_v1 =
|
||||||
layer_surface->layer_surface;
|
layer_surface->layer_surface;
|
||||||
struct fx_render_data *data = user_data;
|
struct fx_render_data *data = user_data;
|
||||||
data->deco_data.blur = layer_surface->should_blur;
|
struct layer_effects *effects = layer_surface->effects;
|
||||||
|
if (effects) {
|
||||||
|
data->deco_data.blur = effects->blur;
|
||||||
data->deco_data.corner_radius =
|
data->deco_data.corner_radius =
|
||||||
layer_surface->should_corner_radius? config->corner_radius: 0;
|
effects->corner_radius? config->corner_radius: 0;
|
||||||
data->is_toplevel_surface = true;
|
data->is_toplevel_surface = true;
|
||||||
|
}
|
||||||
|
|
||||||
output_surface_for_each_surface(output, wlr_layer_surface_v1->surface,
|
output_surface_for_each_surface(output, wlr_layer_surface_v1->surface,
|
||||||
layer_surface->geo.x, layer_surface->geo.y, iterator,
|
layer_surface->geo.x, layer_surface->geo.y, iterator,
|
||||||
|
|
|
@ -91,6 +91,7 @@ sway_sources = files(
|
||||||
'commands/include.c',
|
'commands/include.c',
|
||||||
'commands/input.c',
|
'commands/input.c',
|
||||||
'commands/layout.c',
|
'commands/layout.c',
|
||||||
|
'commands/layer_effects.c',
|
||||||
'commands/mode.c',
|
'commands/mode.c',
|
||||||
'commands/mouse_warping.c',
|
'commands/mouse_warping.c',
|
||||||
'commands/move.c',
|
'commands/move.c',
|
||||||
|
|
|
@ -71,6 +71,14 @@ The following commands may only be used in the configuration file.
|
||||||
*wordexp*(3) for details). The same include file can only be included once;
|
*wordexp*(3) for details). The same include file can only be included once;
|
||||||
subsequent attempts will be ignored.
|
subsequent attempts will be ignored.
|
||||||
|
|
||||||
|
*layer_effects* <layer-namespace> <effects>
|
||||||
|
Apply effects on specific layer shell surfaces, eg waybar or rofi.
|
||||||
|
At least one effect needs to be provided.
|
||||||
|
|
||||||
|
Effects:
|
||||||
|
- *blur*
|
||||||
|
- *corner_rounding*
|
||||||
|
|
||||||
*scratchpad_minimize* enable|disable
|
*scratchpad_minimize* enable|disable
|
||||||
Adjusts if minimized windows should be moved into the scratchpad.
|
Adjusts if minimized windows should be moved into the scratchpad.
|
||||||
Must be set at config-time (when starting sway).
|
Must be set at config-time (when starting sway).
|
||||||
|
|
Loading…
Add table
Reference in a new issue