tumashu / posframe

Pop a posframe (just a child-frame) at point, posframe is a **GNU ELPA** package!
453 stars 58 forks source link

posframe-poshandler-point-bottom-center feature? #131

Open rickalex21 opened 1 year ago

rickalex21 commented 1 year ago

Hello, thanks for this awesome package.

I was having problems centering the hydras with hints so I decided to go this route.

For small hydras it's not an issue to use the posframe-poshandler-point-bottom-left-corner but for bigger ones I would like to center on the cursor above or below. If I'm on the edge of the screen default to left or right of the cursor.

Is there a way to place the center of the frame above or below the cursor like this?

Thanks

tumashu commented 1 year ago

Try below poshandler or write your own poshandler.

  1. `posframe-poshandler-point-window-center'
  2. `posframe-poshandler-point-frame-center'
rickalex21 commented 1 year ago

I was looking at posframe-poshandler-point-1 and I noticed that a few functions call it with no arguments other than info? How does it change positions with no arguments...

For example:

(defun posframe-poshandler-point-bottom-left-corner (info)
  "Posframe's position handler.

This poshandler function let top left corner of posframe align to
bottom left corner of point.

The structure of INFO can be found in docstring of
`posframe-show'."
  (posframe-poshandler-point-1 info))

This is what I came up with, not perfect, needs some work. It does not work on my laptop, only on my hdmi monitor. By any chance is there any way I can use your code to simply the function?

(defun my-posframe-poshandler (info)
  "Custom poshandler function for Posframe."
  (let* ((window (plist-get info :parent-window))
         (pos (plist-get info :position))
         (pos (if (integerp pos) (posn-at-point pos window) pos))
         (pwidth (plist-get info :posframe-width))
         (pheight (plist-get info :posframe-height))
         (fheight (plist-get info :parent-frame-height))
         (fonth (plist-get info :font-height))
         (bottom (+ (nth 2 (window-pixel-edges window)) 10))
         (x (- (car (posn-x-y pos)) (/ pwidth 2)))
         (x (or (and (< x 0) 0) x))
         (y (+ (cdr (posn-x-y pos)) (* fonth 3)))
         (y (or (and (> (+ y pheight ) bottom) (- y (* 2 pheight))) y)))
    (cons x  y)))

(let ((hydra-posframe-show-params
         '(:internal-border-width 1
          :internal-border-color "black"
          :poshandler my-posframe-poshandler))
       (hydra-hint-display-type 'posframe))

(hydra-org-agenda/body))