1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
From 4be515802326e8e829d0df47295cd5fd05de21e8 Mon Sep 17 00:00:00 2001
From: Rouven Czerwinski <rouven@czerwinskis.de>
Date: Mon, 19 May 2025 13:18:11 +0200
Subject: [PATCH] Support to explicitly set layer shell namespace
This is useful for compositors such as niri, which can match on the
layer shell namespace to put the background either behind the overview
or set it as the normal desktop backdrop.
---
main.c | 15 +++++++++++----
swaybg.1.scd | 3 +++
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/main.c b/main.c
index 181adb4..a3d2fa5 100644
--- a/main.c
+++ b/main.c
@@ -64,6 +64,7 @@ struct swaybg_image {
struct swaybg_output_config {
char *output;
const char *image_path;
+ char *namespace;
struct swaybg_image *image;
enum background_mode mode;
uint32_t color;
@@ -279,7 +280,7 @@ static void output_mode(void *data, struct wl_output *output, uint32_t flags,
// Who cares
}
-static void create_layer_surface(struct swaybg_output *output) {
+static void create_layer_surface(struct swaybg_output *output, char *namespace) {
output->surface = wl_compositor_create_surface(output->state->compositor);
assert(output->surface);
@@ -307,7 +308,7 @@ static void create_layer_surface(struct swaybg_output *output) {
output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
output->state->layer_shell, output->surface, output->wl_output,
- ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "wallpaper");
+ ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, namespace);
assert(output->layer_surface);
zwlr_layer_surface_v1_set_size(output->layer_surface, 0, 0);
@@ -331,7 +332,7 @@ static void output_done(void *data, struct wl_output *wl_output) {
} else if (!output->layer_surface) {
swaybg_log(LOG_DEBUG, "Found config %s for output %s (%s)",
output->config->output, output->name, output->identifier);
- create_layer_surface(output);
+ create_layer_surface(output, output->config->namespace);
}
}
@@ -480,6 +481,7 @@ static void parse_command_line(int argc, char **argv,
{"help", no_argument, NULL, 'h'},
{"image", required_argument, NULL, 'i'},
{"mode", required_argument, NULL, 'm'},
+ {"namespace", required_argument, NULL, 'n'},
{"output", required_argument, NULL, 'o'},
{"version", no_argument, NULL, 'v'},
{0, 0, 0, 0}
@@ -492,6 +494,7 @@ static void parse_command_line(int argc, char **argv,
" -h, --help Show help message and quit.\n"
" -i, --image <path> Set the image to display.\n"
" -m, --mode <mode> Set the mode to use for the image.\n"
+ " -n, --namespace <name> Set the namespace to use for the layer shell surface.\n"
" -o, --output <name> Set the output to operate on or * for all.\n"
" -v, --version Show the version number and quit.\n"
"\n"
@@ -501,12 +504,13 @@ static void parse_command_line(int argc, char **argv,
struct swaybg_output_config *config = calloc(1, sizeof(struct swaybg_output_config));
config->output = strdup("*");
config->mode = BACKGROUND_MODE_INVALID;
+ config->namespace = "wallpaper";
wl_list_init(&config->link); // init for safe removal
int c;
while (1) {
int option_index = 0;
- c = getopt_long(argc, argv, "c:hi:m:o:v", long_options, &option_index);
+ c = getopt_long(argc, argv, "c:hi:m:n:o:v", long_options, &option_index);
if (c == -1) {
break;
}
@@ -527,6 +531,9 @@ static void parse_command_line(int argc, char **argv,
swaybg_log(LOG_ERROR, "Invalid mode: %s", optarg);
}
break;
+ case 'n': // mode
+ config->namespace = optarg;
+ break;
case 'o': // output
if (config && !store_swaybg_output_config(state, config)) {
// Empty config or merged on top of an existing one
diff --git a/swaybg.1.scd b/swaybg.1.scd
index d1a79bc..e81da99 100644
--- a/swaybg.1.scd
+++ b/swaybg.1.scd
@@ -30,6 +30,9 @@ these options.
Default is _stretch_. Use the additional mode _solid\_color_ to display
only the background color, even if a background image is specified.
+*-n, --namespace* <name>
+ Namespace to use for the layer shell surface. Defaults to "wallpaper".
+
*-o, --output* <name>
Select an output to configure. Subsequent appearance options will only
apply to this output. The special value _\*_ selects all outputs.
--
2.54.0
|