exwm-xsettings: Use color-dark-p from Compat

This commit is contained in:
Daniel Mendler 2024-07-07 18:43:18 +02:00
parent 87c429561f
commit 841ead8141
No known key found for this signature in database
GPG key ID: D88ADB2A2693CA43

View file

@ -129,20 +129,6 @@ These settings take precedence over `exwm-xsettings-theme' and
:initialize #'custom-initialize-default
:set #'exwm-xsettings--custom-set)
(defalias 'exwm-xsettings--color-dark-p
(if (eval-when-compile (< emacs-major-version 29))
;; Borrowed from Emacs 29.
(lambda (rgb)
"Whether RGB is more readable against white than black."
(unless (<= 0 (apply #'min rgb) (apply #'max rgb) 1)
(error "RGB components %S not in [0,1]" rgb))
(let* ((r (expt (nth 0 rgb) 2.2))
(g (expt (nth 1 rgb) 2.2))
(b (expt (nth 2 rgb) 2.2))
(y (+ (* r 0.2126) (* g 0.7152) (* b 0.0722))))
(< y 0.325)))
'color-dark-p))
(defun exwm-xsettings--pick-theme (theme)
"Pick a light or dark theme from the given THEME.
If THEME is a string, it's returned directly.
@ -151,7 +137,7 @@ the default face's background color."
(pcase theme
((cl-type string) theme)
(`(,(cl-type string) . ,(cl-type string))
(if (exwm-xsettings--color-dark-p (color-name-to-rgb (face-background 'default)))
(if (color-dark-p (color-name-to-rgb (face-background 'default)))
(cdr theme) (car theme)))
(_ (error "Expected theme to be a string or a pair of strings"))))