aboutsummaryrefslogtreecommitdiff
path: root/src/menu.lisp
diff options
context:
space:
mode:
authorChristopher R. Nelson <christopher.nelson@languidnights.com>2026-11-01 00:27:57 -0400
committerChristopher R. Nelson <christopher.nelson@languidnights.com>2026-11-01 00:27:57 -0400
commitf1933ef4b012de715e637f489bbcb89d944496f8 (patch)
tree8a00179529584f6376dfa1a40d3713c30795bd41 /src/menu.lisp
parent7fb53e418a48b8baa7bcab89967a0755f2230162 (diff)
Save the chosen wallpaper and restore it at loginHEADmain
Menu items now call the program back with --set FILE, which runs the configured command and, if it exits 0, saves the path to $XDG_STATE_HOME/wallpaper-switcher/current. --restore sets the saved wallpaper again, for use in labwc/openbox autostart. Items use the binary's absolute path so the menu works when it is not on PATH. Paths from the command line are parsed as native namestrings so file names containing * or [ are not treated as wildcards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'src/menu.lisp')
-rw-r--r--src/menu.lisp37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/menu.lisp b/src/menu.lisp
index da99ab0..b65a8c6 100644
--- a/src/menu.lisp
+++ b/src/menu.lisp
@@ -90,24 +90,43 @@ directory's last component."
(t (write-char c out) (incf i))))
(progn (write-char c out) (incf i)))))))
-(defun build-command (template pathname)
- "The command line for one menu item. Openbox splits Execute commands
-like a shell does but does not run them through one, so the expanded
-template is passed to `sh -c` as a single quoted argument."
- (format nil "sh -c ~A"
- (shell-quote (expand-template template (uiop:native-namestring pathname)))))
+(defvar *self-command* '("wallpaper-switcher")
+ "How a menu item calls this program back: the executable followed by any
+options (--config, --command) that should carry over to --set. MAIN sets
+it to the executable's absolute path, so the menu still works when the
+program is not on PATH.")
+
+(defun build-command (pathname)
+ "The Execute command for one menu item: call this program back with
+--set, which sets the wallpaper and saves it for --restore. Openbox
+splits the command into words like a shell would, so each word is
+shell-quoted."
+ (format nil "~{~A~^ ~}"
+ (mapcar #'shell-quote
+ (append *self-command*
+ (list "--set" (uiop:native-namestring pathname))))))
+
+(defun run-wallpaper-command (template file)
+ "Run TEMPLATE for FILE under `sh -c` and return its exit code. This waits
+for the shell, which is why the default command ends with &: swaybg keeps
+running, so it has to go in the background."
+ (nth-value 2 (uiop:run-program (list "/bin/sh" "-c" (expand-template template file))
+ :input nil
+ :output :interactive
+ :error-output :interactive
+ :ignore-error-status t)))
;;; Rendering
(defun indent (stream depth)
(loop repeat (* 2 depth) do (write-char #\Space stream)))
-(defun render-item (stream depth pathname command)
+(defun render-item (stream depth pathname)
(indent stream depth)
(format stream "<item label=\"~A\">~%" (xml-escape (menu-label pathname)))
(indent stream (1+ depth))
(format stream "<action name=\"Execute\"><command>~A</command></action>~%"
- (xml-escape (build-command command pathname)))
+ (xml-escape (build-command pathname)))
(indent stream depth)
(format stream "</item>~%"))
@@ -141,7 +160,7 @@ rather than recursed into forever."
(indent stream depth)
(format stream "</menu>~%"))
(dolist (f files)
- (render-item stream depth f (config-command config)))))
+ (render-item stream depth f))))
(defun render-menu (config &optional (stream *standard-output*))
"Write the Openbox pipe menu XML for CONFIG to STREAM."