aboutsummaryrefslogtreecommitdiff
path: root/src/menu.lisp
diff options
context:
space:
mode:
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."