Closed chubbymomo closed 6 months ago
Got it fixed using the below:
(defun advise-vertico-posframe-show-with-monitor-awareness (orig-fun buffer window-point &rest args)
"Advise `vertico-posframe--show` to position the posframe according to the focused monitor."
;; Extract the focused monitor's geometry
(let* ((monitor-geometry (get-focused-monitor-geometry))
(monitor-x (nth 0 monitor-geometry))
(monitor-y (nth 1 monitor-geometry)))
;; Override poshandler buffer-local variable to use monitor-aware positioning
(let ((vertico-posframe-poshandler
(lambda (info)
(let* ((parent-frame-width (plist-get info :parent-frame-width))
(parent-frame-height (plist-get info :parent-frame-height))
(posframe-width (plist-get info :posframe-width))
(posframe-height (plist-get info :posframe-height))
;; Calculate center position on the focused monitor
(x (+ monitor-x (/ (- parent-frame-width posframe-width) 2)))
(y (+ monitor-y (/ (- parent-frame-height posframe-height) 2))))
(cons x y)))))
;; Call the original function with potentially adjusted poshandler
(apply orig-fun buffer window-point args))))
(advice-add 'vertico-posframe--show :around #'advise-vertico-posframe-show-with-monitor-awareness)
I think we should improve the below function:
(defun vertico-posframe-refposhandler-default (&optional frame)
"The default posframe refposhandler used by vertico-posframe.
Optional argument FRAME ."
(cond
;; EXWM environment
((bound-and-true-p exwm--connection)
(or (ignore-errors
(let ((info (elt exwm-workspace--workareas
exwm-workspace-current-index)))
(cons (elt info 0)
(elt info 1))))
;; Need user install xwininfo.
(ignore-errors
(posframe-refposhandler-xwininfo frame))
;; Fallback, this value will incorrect sometime, for example: user
;; have panel.
(cons 0 0)))
(t nil)))
vertico-posframe-refposhandler-default will return top left (x, y ) of emacs
Okay, sounds good! Thanks for the response! I think we've got this covered.
Title pretty much explains it all, below is my config:
Vertico + Vertico posframe config: