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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371 | diff --git a/src/utils.rs b/src/utils.rs
index 657b06f..8d61b1e 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -94,7 +94,7 @@ pub fn get_cache(send: bool) -> PathBuf {
.unwrap_or_else(|| get_home(send).join(".cache"))
}
-fn get_absolute_path(path_str: &str) -> Option<String> {
+pub fn get_absolute_path(path_str: &str) -> Option<String> {
fs::canonicalize(Path::new(path_str))
.ok()?
.to_str()
diff --git a/src/wallpaper.rs b/src/wallpaper.rs
index b0a9541..12c3fd2 100644
--- a/src/wallpaper.rs
+++ b/src/wallpaper.rs
@@ -1,5 +1,5 @@
use crate::utils::run;
-use crate::utils::{info, warning};
+use crate::utils::{get_absolute_path, info, warning};
use std::env;
use std::path::Path;
use std::process::{exit, Command, Stdio};
@@ -9,12 +9,13 @@ fn run_with_output(command: &str) -> Option<String> {
.arg("-c")
.arg(command)
.stderr(Stdio::null())
- .stdout(Stdio::null())
- .output()
+ .output() // ✅ Remove stdout(Stdio::null()) to capture output
.ok()?;
if output.status.success() {
- String::from_utf8(output.stdout).ok()
+ String::from_utf8(output.stdout)
+ .ok()
+ .map(|s| s.trim().to_string())
} else {
None
}
@@ -30,19 +31,7 @@ fn spawn(command: &str) {
}
fn get_desktop_env() -> Option<String> {
- let keys = [
- "XDG_CURRENT_DESKTOP",
- "DESKTOP_SESSION",
- "GNOME_DESKTOP_SESSION_ID",
- "MATE_DESKTOP_SESSION_ID",
- "SWAYSOCK",
- "HYPRLAND_INSTANCE_SIGNATURE",
- "DESKTOP_STARTUP_ID",
- "I3SOCK",
- "WAYLAND_DISPLAY",
- ];
-
- // Check specifically for Sway
+ // Check specifically for Sway first
if env::var("SWAYSOCK").is_ok() || run("pgrep -x sway") {
return Some("SWAY".to_string());
}
@@ -67,21 +56,33 @@ fn get_desktop_env() -> Option<String> {
return Some("QTILE".to_string());
}
- // Check for other environment variables
+ // Check environment variables
+ let keys = [
+ "XDG_CURRENT_DESKTOP",
+ "DESKTOP_SESSION",
+ "GNOME_DESKTOP_SESSION_ID",
+ "MATE_DESKTOP_SESSION_ID",
+ "DESKTOP_STARTUP_ID",
+ "WAYLAND_DISPLAY",
+ ];
+
for key in keys.iter() {
if let Ok(val) = env::var(key) {
if !val.is_empty() {
if *key == "DESKTOP_STARTUP_ID" && val.contains("awesome") {
return Some("AWESOME".to_string());
}
- if *key == "WAYLAND_DISPLAY" && env::var("XDG_CURRENT_DESKTOP").is_err() {
- // Generic Wayland session without specific DE identifier
- return Some("WAYLAND".to_string());
- }
- // Don't return SWAYSOCK here, as we've already checked for it
- if *key != "SWAYSOCK" {
- return Some(val);
+
+ if *key == "WAYLAND_DISPLAY" {
+ // Try to identify specific Wayland compositor
+ if let Ok(desktop) = env::var("XDG_CURRENT_DESKTOP") {
+ return Some(desktop);
+ } else {
+ return Some("WAYLAND".to_string());
+ }
}
+
+ return Some(val);
}
}
}
@@ -93,7 +94,6 @@ fn set_wm_wallpaper(img: &str, send: bool) {
spawn(&format!("xwallpaper --zoom '{img}'"));
info("Wallpaper", "wallpaper set with xwallpaper", send);
} else if run("which feh") {
- // I thought there was a problem, but there isn't.
spawn(&format!("feh --no-fehbg --bg-fill '{img}'"));
info("Wallpaper", "wallpaper set with feh", send);
} else if run("which hsetroot") {
@@ -118,21 +118,40 @@ fn set_wm_wallpaper(img: &str, send: bool) {
fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
let d = desktop.to_lowercase();
-
- // Convert img to absolute path
- let abs_path = if Path::new(img).is_absolute() {
+ let abs_path = get_absolute_path(&d).unwrap_or_else(|| {
+ warning("Wallpaper", "failed to get absolute path", send);
img.to_string()
- } else {
- match std::fs::canonicalize(img) {
- Ok(p) => p.to_string_lossy().to_string(),
- Err(_) => {
- warning("Wallpaper", "failed to get absolute path", send);
- img.to_string()
+ });
+ if d.contains("hyprland") {
+ // Hyprland-specific wallpaper handling
+ if run("which swww") {
+ if !run("pgrep -x swww-daemon") {
+ spawn("swww-daemon &");
+ // Give daemon time to start
+ std::thread::sleep(std::time::Duration::from_millis(500));
}
+ spawn(&format!(
+ "swww img '{abs_path}' --transition-type fade --transition-fps 60"
+ ));
+ info("Wallpaper", "wallpaper set with swww for Hyprland", send);
+ } else if run("which hyprpaper") {
+ spawn(&format!("hyprpaper '{abs_path}'"));
+ info("Wallpaper", "wallpaper set with hyprpaper", send);
+ } else if run("which swaybg") {
+ spawn(&format!("pkill swaybg; swaybg -i '{abs_path}' -m fill &"));
+ info("Wallpaper", "wallpaper set with swaybg for Hyprland", send);
+ } else if run("which wbg") {
+ spawn(&format!("pkill wbg; wbg '{abs_path}' &"));
+ info("Wallpaper", "wallpaper set with wbg for Hyprland", send);
+ } else {
+ warning(
+ "Wallpaper",
+ "no suitable wallpaper tool found for Hyprland (try installing swww, hyprpaper, swaybg, or wbg)",
+ send,
+ );
+ exit(1);
}
- };
-
- if d.contains("xfce") || d.contains("xubuntu") {
+ } else if d.contains("xfce") || d.contains("xubuntu") {
// Try to find the active monitor
let monitors = run_with_output("xfconf-query -c xfce4-desktop -l | grep last-image")
.unwrap_or_default();
@@ -178,10 +197,11 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
"gsettings set org.cinnamon.desktop.background picture-uri 'file://{abs_path}'"
));
info("Wallpaper", "wallpaper set with Cinnamon settings", send);
- } else if d == "sway" {
+ } else if d.contains("sway") {
if run("which swww") {
if !run("pgrep -x swww-daemon") {
- spawn("swww init");
+ spawn("swww-daemon &");
+ std::thread::sleep(std::time::Duration::from_millis(500));
}
spawn(&format!(
"swww img '{abs_path}' --transition-type fade --transition-fps 60"
@@ -193,7 +213,7 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
} else {
warning(
"Wallpaper",
- "no suitable wallpaper tool found for Sway",
+ "no suitable wallpaper tool found for Sway (try installing swww or swaybg)",
send,
);
exit(1)
@@ -212,51 +232,98 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
));
info("Wallpaper", "wallpaper set with KDE Plasma settings", send);
} else if d.contains("i3") {
- // i3 support
- if run("which feh") {
- spawn(&format!("feh --no-fehbg --bg-fill '{abs_path}'"));
- info("Wallpaper", "wallpaper set with feh for i3", send);
- } else {
- set_wm_wallpaper(&abs_path, send);
- }
+ set_wm_wallpaper(&abs_path, send);
} else if d.contains("bspwm") {
- // bspwm support
- if run("which feh") {
- spawn(&format!("feh --no-fehbg --bg-fill '{abs_path}'"));
- info("Wallpaper", "wallpaper set with feh for bspwm", send);
- } else {
- set_wm_wallpaper(&abs_path, send);
- }
+ set_wm_wallpaper(&abs_path, send);
} else if d.contains("qtile") {
- // qtile support - uses typical WM wallpaper setters
set_wm_wallpaper(&abs_path, send);
} else if d.contains("wayland") {
// Generic Wayland - try multiple approaches
- if run("which swaybg") {
+ if run("which swww") {
+ if !run("pgrep -x swww-daemon") {
+ spawn("swww-daemon &");
+ std::thread::sleep(std::time::Duration::from_millis(500));
+ }
+ spawn(&format!("swww img '{abs_path}'"));
+ info("Wallpaper", "wallpaper set with swww", send);
+ } else if run("which swaybg") {
spawn(&format!("pkill swaybg; swaybg -i '{abs_path}' -m fill &"));
info("Wallpaper", "wallpaper set with swaybg", send);
} else if run("which wbg") {
- spawn(&format!("wbg '{abs_path}'"));
+ spawn(&format!("pkill wbg; wbg '{abs_path}' &"));
info("Wallpaper", "wallpaper set with wbg", send);
- } else if run("which swww") {
- spawn(&format!("swww img '{abs_path}'"));
- info("Wallpaper", "wallpaper set with swww", send);
} else {
warning(
"Wallpaper",
- "no suitable Wayland wallpaper tool found",
+ "no suitable Wayland wallpaper tool found (try installing swww, swaybg, or wbg)",
send,
);
exit(1);
}
} else if d.contains("wayfire") {
- // Wayfire compositor
if run("which wbg") {
- spawn(&format!("wbg '{abs_path}'"));
+ spawn(&format!("pkill wbg; wbg '{abs_path}' &"));
info("Wallpaper", "wallpaper set with wbg for Wayfire", send);
- } else {
+ } else if run("which swaybg") {
spawn(&format!("pkill swaybg; swaybg -i '{abs_path}' -m fill &"));
info("Wallpaper", "wallpaper set with swaybg for Wayfire", send);
+ } else {
+ warning(
+ "Wallpaper",
+ "no suitable wallpaper tool found for Wayfire (try installing wbg or swaybg)",
+ send,
+ );
+ exit(1);
+ }
+ } else if d.contains("river") {
+ if run("which wbg") {
+ spawn(&format!("pkill wbg; wbg '{abs_path}' &"));
+ info("Wallpaper", "wallpaper set with wbg for River", send);
+ } else if run("which swaybg") {
+ spawn(&format!("pkill swaybg; swaybg -i '{abs_path}' -m fill &"));
+ info("Wallpaper", "wallpaper set with swaybg for River", send);
+ } else {
+ warning(
+ "Wallpaper",
+ "no suitable wallpaper tool found for River (try installing wbg or swaybg)",
+ send,
+ );
+ exit(1);
+ }
+ } else if d.contains("fht") || d.contains("fht-compositor") {
+ // fht-compositor support - it's a Wayland compositor
+ if run("which swaybg") {
+ spawn(&format!("pkill swaybg; swaybg -i '{abs_path}' -m fill &"));
+ info(
+ "Wallpaper",
+ "wallpaper set with swaybg for fht-compositor",
+ send,
+ );
+ } else if run("which wbg") {
+ spawn(&format!("pkill wbg; wbg '{abs_path}' &"));
+ info(
+ "Wallpaper",
+ "wallpaper set with wbg for fht-compositor",
+ send,
+ );
+ } else if run("which swww") {
+ if !run("pgrep -x swww-daemon") {
+ spawn("swww-daemon &");
+ std::thread::sleep(std::time::Duration::from_millis(500));
+ }
+ spawn(&format!("swww img '{abs_path}'"));
+ info(
+ "Wallpaper",
+ "wallpaper set with swww for fht-compositor",
+ send,
+ );
+ } else {
+ warning(
+ "Wallpaper",
+ "no suitable wallpaper tool found for fht-compositor (try installing swaybg, wbg, or swww)",
+ send,
+ );
+ exit(1);
}
} else if d.contains("deepin") {
spawn(&format!(
@@ -264,15 +331,12 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
));
info("Wallpaper", "wallpaper set with Deepin settings", send);
} else if d.contains("lxqt") {
- // LXQt uses pcmanfm-qt for desktop management
spawn(&format!("pcmanfm-qt --set-wallpaper='{abs_path}'"));
info("Wallpaper", "wallpaper set with LXQt settings", send);
} else if d.contains("lxde") {
- // LXDE uses pcmanfm for desktop management
spawn(&format!("pcmanfm --set-wallpaper='{abs_path}'"));
info("Wallpaper", "wallpaper set with LXDE settings", send);
} else if d.contains("budgie") {
- // Budgie uses GNOME settings
spawn(&format!(
"gsettings set org.gnome.desktop.background picture-uri 'file://{abs_path}'"
));
@@ -282,7 +346,6 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
send,
);
} else if d.contains("enlightenment") || d.contains("e17") || d.contains("e16") {
- // Enlightenment WM - try using enlightenment_remote
if run("which enlightenment_remote") {
spawn(&format!(
"enlightenment_remote -desktop-bg-add 0 0 0 0 '{abs_path}'"
@@ -293,6 +356,11 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
}
} else {
// Default to the generic wallpaper setters
+ info(
+ "Wallpaper",
+ &format!("Unknown desktop environment: {}, trying generic tools", d),
+ send,
+ );
set_wm_wallpaper(&abs_path, send);
}
}
@@ -305,9 +373,23 @@ pub fn change_wallpaper(img: &str, send: bool) {
match get_desktop_env() {
Some(d) => {
+ if send {
+ info(
+ "Desktop",
+ &format!("Detected desktop environment: {}", d),
+ send,
+ );
+ }
set_desktop_wallpaper(&d, img, send);
}
None => {
+ if send {
+ warning(
+ "Desktop",
+ "Could not detect desktop environment, using generic tools",
+ send,
+ );
+ }
set_wm_wallpaper(img, send);
}
}
|