I have a snippet that I use to determine what font size to set based on the resolution of the display, for when my laptop has an external monitor set or not:
(defconst prefs/font-size 14) (defconst prefs/font-size/display-laptop 12) (defconst prefs/font-size/display-external 18) (defun prefs/use-font-size () (let ((px (display-pixel-width))) (cond ((eq px 7040) prefs/font-size/display-external) ((eq px 3200) prefs/font-size/display-laptop) (t prefs/font-size))))
This works great when emacs is started normally; however I'm trying to daemon-ify my configuration. Based on that, I now have a function to set UI-related things on
default-frame-alist parameters in a
before-make-frame as well as
initial-frame-alist at startup:
(defun jl/set-frame-params (frame-alist) (add-to-list frame-alist `(font . ,(concat (prefs/use-font) "-" (number-to-string (prefs/use-font-size))))) ; ... more frame parameters ) (jl/set-frame-params 'initial-frame-alist) (add-hook 'before-make-frame-hook ; configure new frames #'(lambda () (jl/set-frame-params 'default-frame-alist)))
However, here's the behavior I'm seeing:
- initial daemon load:
(display-pixel-width)returns nonsense (10) and the initial emacsclient frame has the font size set incorrectly
- creating a new frame after that via
(display-pixel-width)returns the correct value, but the font size is still incorrect.
- creating a second new frame with
make-frame, the font size is finally correct.
What am I doing wrong here, and how can I get my font size set correctly both for the first frame created on a server, and subsequent frames?