Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to load a user config file #82

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lisp/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,36 @@
(hrt:new-view handle-new-view-event)
(hrt:view-destroyed handle-view-destroyed-event)))

(defun load-config-file (&optional (catch-errors nil))
"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
(progn
(log-string :debug "Found config file at ~a" 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
(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)
(enable-debugger)
(load-config-file)
(cffi:with-foreign-objects ((output-callbacks '(:struct hrt:hrt-output-callbacks))
(seat-callbacks '(:struct hrt:hrt-seat-callbacks))
(view-callbacks '(:struct hrt:hrt-view-callbacks))
Expand Down
Loading