Skip to content

Commit

Permalink
Add function to load a user config file
Browse files Browse the repository at this point in the history
This loads a config file first checking $XDG_CONFIG_HOME and if that
does not exist falls back to .config/mahogany/init.lisp.

It is adapted from the function in stumpwm.
  • Loading branch information
tpine committed Jan 16, 2024
1 parent 353e94c commit d84c33c
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 deletions lisp/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,57 @@
(new-view handle-new-view-event)
(view-destroyed handle-view-destroyed-event)))

(defun load-config-file (&optional (catch-errors t))
"Load the user's config file. Returns a values list: whether the file loaded (t if no
rc files exist), the error if it didn't, and the config file that was
loaded. When CATCH-ERRORS is nil, errors are left to be handled
further up. "
(let* ((xdg-config
(probe-file (merge-pathnames #p"mahogany/init.lisp" (uiop:xdg-config-home))))
(fallback-config
(probe-file (merge-pathnames #p".config/mahogany/init.lisp" (user-homedir-pathname))))
(config-file (or xdg-config fallback-config)))
(if config-file
(if catch-errors
(handler-case (load config-file)
(error (c) (values nil (format nil "~a" c) config-file))
(:no-error (&rest args) (declare (ignore args)) (values t nil config-file)))
(progn
(log-string :debug (format nil "Found config file at ~a" config-file))
(load config-file)
(values t nil config-file)))
(progn
(log-string :debug "Did not find config file")
(values t nil nil)))))

(defun run-server ()
(disable-fpu-exceptions)
(hrt:load-foreign-libraries)
(log-init :level :trace)
(sb-ext:enable-debugger)
(load-config-file)
(cffi:with-foreign-objects ((output-callbacks '(:struct hrt-output-callbacks))
(seat-callbacks '(:struct hrt-seat-callbacks))
(view-callbacks '(:struct hrt-view-callbacks))
(server '(:struct hrt-server)))
(init-callback-struct output-callbacks (:struct hrt-output-callbacks)
(output-added handle-new-output)
(output-removed handle-output-removed)
(output-mode-changed output-mode-change-callback))
(init-callback-struct seat-callbacks (:struct hrt-seat-callbacks)
(button-event cursor-callback)
(wheel-event cursor-callback)
(keyboard-keypress-event keyboard-callback))
(init-view-callbacks view-callbacks)
(init-callback-struct output-callbacks (:struct hrt-output-callbacks)
(output-added handle-new-output)
(output-removed handle-output-removed)
(output-mode-changed output-mode-change-callback))
(init-callback-struct seat-callbacks (:struct hrt-seat-callbacks)
(button-event cursor-callback)
(wheel-event cursor-callback)
(keyboard-keypress-event keyboard-callback))
(init-view-callbacks view-callbacks)

(setf (mahogany-state-server *compositor-state*) server)
(log-string :debug "Initialized mahogany state")
(hrt-server-init server output-callbacks seat-callbacks view-callbacks 3)
(log-string :debug "Initialized heart state")
(unwind-protect
(hrt-server-start server)
(log-string :debug "Cleaning up...")
(server-stop *compositor-state*)
(hrt-server-finish server)
(server-state-reset *compositor-state*)
(log-string :debug "Shutdown reached."))))
(setf (mahogany-state-server *compositor-state*) server)
(log-string :debug "Initialized mahogany state")
(hrt-server-init server output-callbacks seat-callbacks view-callbacks 3)
(log-string :debug "Initialized heart state")
(unwind-protect
(hrt-server-start server)
(log-string :debug "Cleaning up...")
(server-stop *compositor-state*)
(hrt-server-finish server)
(server-state-reset *compositor-state*)
(log-string :debug "Shutdown reached."))))

0 comments on commit d84c33c

Please sign in to comment.