Change frame position display logic

This commit is contained in:
Jessie Hildebrandt 2023-12-20 19:39:02 -05:00
parent 8075b5662e
commit 0f2ba661f8

View File

@ -331,28 +331,27 @@ All functions are run with the eldoc child frame selected."
;; Frame geometry
;; ---------------------------------- ;;
(defun eldoc-frame--selected-window-side ()
"Return which side of the frame the selected window is on.
Return left if the selected window is on the left, or right if the selected
window is on the right. Return left if there is only one window in the frame."
(let* ((window-left (nth 0 (window-absolute-pixel-edges)))
(window-right (nth 2 (window-absolute-pixel-edges)))
(frame-left (nth 0 (frame-edges)))
(frame-right (nth 2 (frame-edges)))
(distance-left (- window-left frame-left))
(distance-right (- frame-right window-right)))
(if (<= distance-left distance-right) 'left 'right)))
(defun eldoc-frame--calc-frame-x-position (frame)
"Calculate the appropriate X position (offset) for FRAME."
(pcase-let ((`(,offset-l ,offset-r) eldoc-frame-offset))
(pcase (eldoc-frame--selected-window-side)
;; Selected window is on the left, so child frame should be on the right:
('left (- (frame-pixel-width (selected-frame))
(frame-pixel-width frame)
offset-r))
;; Selected window is on the right, so child frame should be on the left:
('right offset-l))))
"Calculate the appropriate X position (offset) for FRAME.
If the selected window is on the right side of the selected frame and is too
small to overlay FRAME over, or if `point' is too close to the right edge of the
selected frame, return an X coordinate that will place FRAME on the left side of
the selected frame. Otherwise, return an X coordinate that will place FRAME on
the right side of the selected frame."
(let ((offset-l (nth 0 eldoc-frame-offset))
(offset-r (nth 2 eldoc-frame-offset))
(window-left (nth 0 (window-absolute-pixel-edges)))
(min-containing-width (* (eval eldoc-frame-max-pixel-width) 2))
(cursor-x-position (or (car (window-absolute-pixel-position)) 0)))
(if (or (and (< (window-pixel-width) min-containing-width)
(> window-left (* (frame-pixel-width) .40)))
(> cursor-x-position (* (frame-pixel-width) .70)))
;; FRAME should be displayed on the left:
offset-l
;; FRAME should be displayed on the right:
(- (frame-pixel-width (selected-frame))
(frame-pixel-width frame)
offset-r))))
(defun eldoc-frame--update-frame-geometry (frame)
"Update size and position of FRAME."