[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to create a small child-frame which only show two lines
From: |
Feng Shu |
Subject: |
Re: How to create a small child-frame which only show two lines |
Date: |
Sun, 07 Jan 2018 10:56:20 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) |
Eli Zaretskii <address@hidden> writes:
>> Date: Mon, 11 Dec 2017 16:29:16 +0800 (CST)
>> From: tumashu <address@hidden>
>> Cc: "address@hidden" <address@hidden>
>>
>> by the way, does emacs has a function, which can get the point's left-bottom
>> pixel position, if not,
>> is it possible to add it to emacs?
>
> Doesn't vertical-motion fit the bill? If not, why not?
I code the below function with your suggestion, seem to work :-)
(defun my-tooltip-compute-pixel-position (pos tooltip-width tooltip-height)
"Return bottom-left-corner pixel position of POS in WINDOW.
its returned value is like (X . Y)
If TOOLTIP-WIDTH and TOOLTIP-HEIGHT are given, this function will use
two values to adjust its output position, make sure the *tooltip* at
position not disappear by sticking out of the display."
(let* ((window (selected-window))
(frame (window-frame window))
(xmax (frame-pixel-width frame))
(ymax (frame-pixel-height frame))
(posn-top-left (posn-at-point pos window))
(x (+ (car (window-inside-pixel-edges window))
(or (car (posn-x-y posn-top-left)) 0)))
(y-top (+ (cadr (window-pixel-edges window))
(or (cdr (posn-x-y posn-top-left)) 0)))
(posn-next-line-beginning
(posn-at-point (save-excursion
(goto-char pos)
(vertical-motion 1)
(point))
window))
(y-buttom
(let ((value (or (cdr (posn-x-y posn-next-line-beginning)) 0)))
(if (= value y-top)
;; FIXME: If at the end line of buffer, we can not use the
above
;; method to get y-buttom, we just use y-top +
default-line-height instead.
(+ y-top (default-line-height))
value))))
(cons (max 0 (min x (- xmax (or tooltip-width 0))))
(max 0 (if (> (+ y-buttom (or tooltip-height 0)) ymax)
(- y-top (or tooltip-height 0))
y-buttom)))))
--