This is pretty nice: "Multi-Monitor Compatible Code to Center Emacs Frames on Screen • Christian Tietze"

I made it into a single function:

;; Adapted from:

(defun gk-frame-recenter (&optional frame)
"Center a frame on the screen."
(unless (eq 'maximised (frame-parameter nil 'fullscreen))
(let* ((w (frame-pixel-width frame))
(h (frame-pixel-height frame))
(cw (caddr (frame-monitor-workarea frame)))
(ch (cadddr (frame-monitor-workarea frame)))
(center (list (/ (- cw w) 2) (/ (- ch h) 2))))
(apply 'set-frame-position (flatten-list (list frame center))))))

(add-hook 'after-init-hook #'gk-frame-recenter)
(add-hook 'after-make-frame-functions #'gk-frame-recenter)
Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!