casouri / eldoc-box

childframe doc for eglot and anything that uses eldoc
361 stars 26 forks source link

Ugly in-between frames when resizing the box #110

Open poniponiponiponiponiponiponiponiponi opened 3 months ago

poniponiponiponiponiponiponiponiponi commented 3 months ago

Hey, first thank you for this package! I've noticed there are some ugly in-between frames when resizing the box. image 1

I'm on Fedora 40 with Emacs 31, the same behavior persists between i3 and Sway. Personally I fixed this by overwriting a function in my config like this:

(setq prev-size '(0 . 0))
(defun eldoc-box--update-childframe-geometry (frame window)
  "Update the size and the position of childframe.
FRAME is the childframe, WINDOW is the primary window."
  (setcdr eldoc-box--markdown-separator-display-props nil)

  (let* ((size
          (window-text-pixel-size
           window nil nil
           (if (functionp eldoc-box-max-pixel-width) (funcall eldoc-box-max-pixel-width) eldoc-box-max-pixel-width)
           (if (functionp eldoc-box-max-pixel-height) (funcall eldoc-box-max-pixel-height) eldoc-box-max-pixel-height)
           t))
         (width (car size))
         (height (cdr size))
         (width (+ width (frame-char-width frame))) ; add margin
         (frame-resize-pixelwise t)
         (pos (funcall eldoc-box-position-function width height)))
    (if (not (equal prev-size size))
        (eldoc-box--maybe-cleanup))
    (setq prev-size size)
    (set-frame-size frame width height t)

    ;; Set the display property back.
    (setcdr eldoc-box--markdown-separator-display-props
            '(:width text))

    ;; move position
    (set-frame-position frame (car pos) (cdr pos))))

It's not perfect, because now sometimes there's a "flicking effect" (the box disappears for one frame) but I prefer it this way. The check (if (not (equal prev-size size)) is there so there isn't any flicking when the box isn't resized.