Skip to content

Commit

Permalink
Move theme update logic to (setf theme) :after.
Browse files Browse the repository at this point in the history
  • Loading branch information
hgluka committed Sep 5, 2023
1 parent 8ea9b05 commit aa3aa23
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
30 changes: 30 additions & 0 deletions source/browser.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,36 @@ prevents otherwise.")
(declare (ignore ignored))
(make-instance 'theme:theme))

(defmethod (setf theme) :after (theme (browser browser))
(declare (ignorable theme))
(flet ((apply-initfunction (class slot)
(apply (closer-mop:slot-definition-initfunction (mopu:get-slot-definition class slot))
nil)))
(mapc (lambda (window)
(mapc (lambda (panel)
(setf (style panel)
(apply-initfunction 'panel-buffer 'style))
(reload-buffer panel))
(panel-buffers window))
(mapc (lambda (prompt-buffer)
(setf (style prompt-buffer)
(apply-initfunction 'prompt-buffer 'style))
(show-prompt-buffer prompt-buffer))
(active-prompt-buffers window))
(setf (style (status-buffer window))
(apply-initfunction 'status-buffer 'style))
(setf (message-buffer-style window)
(apply-initfunction 'window 'message-buffer-style)))
(alex:hash-table-values (windows browser)))
(mapc (lambda (buffer)
(when (internal-url-p (url buffer))
(setf (style buffer)
(apply-initfunction 'web-buffer 'style))
(reload-buffer buffer)))
(alex:hash-table-values (buffers browser)))
(print-status)
(echo "Theme changed.")))

(defmethod get-containing-window-for-buffer ((buffer buffer) (browser browser))
"Get the window containing a buffer."
(find buffer (alex:hash-table-values (windows browser)) :key #'active-buffer))
Expand Down
27 changes: 1 addition & 26 deletions source/help.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,7 @@ Note that some settings may require restarting Nyxt to take effect.")
:style (format nil "background-color: ~a; color: ~a"
(theme:accent-color (symbol-value theme-symbol))
(theme:on-accent-color (symbol-value theme-symbol)))
`(nyxt/setting::apply-generic-setting 'nyxt/setting::browser-generic-setting
(lambda (browser)
(setf (theme browser) ,theme-symbol)
(mapc (lambda (window)
(mapc (lambda (panel)
(setf (style panel)
(apply (closer-mop:slot-definition-initfunction (mopu:get-slot-definition 'panel-buffer 'style))
nil))
(reload-buffer panel))
(panel-buffers window))
(setf (style (status-buffer window))
(apply (closer-mop:slot-definition-initfunction (mopu:get-slot-definition 'status-buffer 'style))
nil))
(setf (message-buffer-style window)
(apply (closer-mop:slot-definition-initfunction (mopu:get-slot-definition 'window 'message-buffer-style))
nil)))
(alex:hash-table-values (windows browser)))
(mapc (lambda (buffer)
(when (internal-url-p (url buffer))
(setf (style buffer)
(apply (closer-mop:slot-definition-initfunction (mopu:get-slot-definition 'web-buffer 'style))
nil))
(reload-buffer buffer)))
(alex:hash-table-values (buffers browser)))
(print-status)
(echo "Theme changed."))))
`(nyxt/setting::apply-slot-setting 'theme 'nyxt/setting::browser-slot-setting ,theme-symbol))
(:p "Colors:")
(:dl
(loop for (name color text-color) in '(("Background" theme:background-color theme:on-background-color)
Expand Down

0 comments on commit aa3aa23

Please sign in to comment.