* How to create a small child-frame which only show two lines
@ 2017-12-07 0:04 tumashu
2017-12-07 2:35 ` jun
2017-12-07 9:27 ` How " martin rudalics
0 siblings, 2 replies; 23+ messages in thread
From: tumashu @ 2017-12-07 0:04 UTC (permalink / raw)
To: emacs-devel@gnu.org, tumashu@163.com
[-- Attachment #1.1: Type: text/plain, Size: 1403 bytes --]
Hello,
Emacs26's child-frame feature is very useful. I have created a candadite menu of
chinese input method with its help, and find that it is much fast than popup-el's menu
and comparable with minibuffer.
the only problem I faced it that: I only need show 2 lines with child-frame while its mini
size is show 4 lines, anyone suggest how to deal with this problem?
---------------
(setq my-child-frame
(let ((after-make-frame-functions nil))
(make-frame
`((parent-frame . ,(window-frame))
(no-accept-focus . t)
(min-width . t)
(min-height . t)
(border-width . 0)
(internal-border-width . 0)
(vertical-scroll-bars . nil)
(horizontal-scroll-bars . nil)
(left-fringe . 10)
(right-fringe . 0)
(menu-bar-lines . 0)
(tool-bar-lines . 0)
(line-spacing . 0)
(unsplittable . t)
(no-other-frame . t)
;;(undecorated . t)
(undecorated . nil)
(visibility . t)
(cursor-type . nil)
(minibuffer . nil)
(width . 50)
(height . 1)
(no-special-glyphs . t)))))
(let ((window (frame-root-window my-child-frame)))
(set-window-parameter window 'mode-line-format 'none)
(set-window-parameter window 'header-line-format 'none))
--------------
[-- Attachment #1.2: Type: text/html, Size: 2949 bytes --]
[-- Attachment #2: child-frame-usage.png --]
[-- Type: image/png, Size: 9282 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re:How to create a small child-frame which only show two lines
2017-12-07 0:04 How to create a small child-frame which only show two lines tumashu
@ 2017-12-07 2:35 ` jun
2017-12-07 2:45 ` tumashu
2017-12-07 9:27 ` How " martin rudalics
1 sibling, 1 reply; 23+ messages in thread
From: jun @ 2017-12-07 2:35 UTC (permalink / raw)
To: tumashu; +Cc: emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1524 bytes --]
Maybe you can bind the variable window-min-height to 2.
At 2017-12-07 08:04:12, "tumashu" <tumashu@163.com> wrote:
Hello,
Emacs26's child-frame feature is very useful. I have created a candadite menu of
chinese input method with its help, and find that it is much fast than popup-el's menu
and comparable with minibuffer.
the only problem I faced it that: I only need show 2 lines with child-frame while its mini
size is show 4 lines, anyone suggest how to deal with this problem?
---------------
(setq my-child-frame
(let ((after-make-frame-functions nil))
(make-frame
`((parent-frame . ,(window-frame))
(no-accept-focus . t)
(min-width . t)
(min-height . t)
(border-width . 0)
(internal-border-width . 0)
(vertical-scroll-bars . nil)
(horizontal-scroll-bars . nil)
(left-fringe . 10)
(right-fringe . 0)
(menu-bar-lines . 0)
(tool-bar-lines . 0)
(line-spacing . 0)
(unsplittable . t)
(no-other-frame . t)
;;(undecorated . t)
(undecorated . nil)
(visibility . t)
(cursor-type . nil)
(minibuffer . nil)
(width . 50)
(height . 1)
(no-special-glyphs . t)))))
(let ((window (frame-root-window my-child-frame)))
(set-window-parameter window 'mode-line-format 'none)
(set-window-parameter window 'header-line-format 'none))
--------------
[-- Attachment #2: Type: text/html, Size: 3836 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re:Re:How to create a small child-frame which only show two lines
2017-12-07 2:35 ` jun
@ 2017-12-07 2:45 ` tumashu
0 siblings, 0 replies; 23+ messages in thread
From: tumashu @ 2017-12-07 2:45 UTC (permalink / raw)
To: jun; +Cc: emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1977 bytes --]
I have try this variable, It can make a smaller frame, but when I use this frame to show a buffer
and use fit-frame-to-buffer to adjust frame's size. the adjusted frame will show two blank line's space.
I have try set mini-height to 2, but no effect, can mode-line's space not be removed?
在 2017-12-07 10:35:50,"jun" <netjune@163.com> 写道:
Maybe you can bind the variable window-min-height to 2.
At 2017-12-07 08:04:12, "tumashu" <tumashu@163.com> wrote:
Hello,
Emacs26's child-frame feature is very useful. I have created a candadite menu of
chinese input method with its help, and find that it is much fast than popup-el's menu
and comparable with minibuffer.
the only problem I faced it that: I only need show 2 lines with child-frame while its mini
size is show 4 lines, anyone suggest how to deal with this problem?
---------------
(setq my-child-frame
(let ((after-make-frame-functions nil))
(make-frame
`((parent-frame . ,(window-frame))
(no-accept-focus . t)
(min-width . t)
(min-height . t)
(border-width . 0)
(internal-border-width . 0)
(vertical-scroll-bars . nil)
(horizontal-scroll-bars . nil)
(left-fringe . 10)
(right-fringe . 0)
(menu-bar-lines . 0)
(tool-bar-lines . 0)
(line-spacing . 0)
(unsplittable . t)
(no-other-frame . t)
;;(undecorated . t)
(undecorated . nil)
(visibility . t)
(cursor-type . nil)
(minibuffer . nil)
(width . 50)
(height . 1)
(no-special-glyphs . t)))))
(let ((window (frame-root-window my-child-frame)))
(set-window-parameter window 'mode-line-format 'none)
(set-window-parameter window 'header-line-format 'none))
--------------
【网易自营|30天无忧退货】仅售同款价1/4!MUJI制造商“冬季舒适家居拖鞋系列”限时仅39元>>
[-- Attachment #2: Type: text/html, Size: 4555 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-07 0:04 How to create a small child-frame which only show two lines tumashu
2017-12-07 2:35 ` jun
@ 2017-12-07 9:27 ` martin rudalics
2017-12-08 10:12 ` martin rudalics
1 sibling, 1 reply; 23+ messages in thread
From: martin rudalics @ 2017-12-07 9:27 UTC (permalink / raw)
To: tumashu, emacs-devel@gnu.org
> I only need show 2 lines with child-frame while its mini
> size is show 4 lines, anyone suggest how to deal with this problem?
[...]
> (let ((window (frame-root-window my-child-frame)))
> (set-window-parameter window 'mode-line-format 'none)
> (set-window-parameter window 'header-line-format 'none))
Looks like a stupid bug in the implementation of these parameters. I'll
hopefully come up with a fix soon.
Thank you very much for reporting this, martin
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-07 9:27 ` How " martin rudalics
@ 2017-12-08 10:12 ` martin rudalics
2017-12-08 12:05 ` tumashu
0 siblings, 1 reply; 23+ messages in thread
From: martin rudalics @ 2017-12-08 10:12 UTC (permalink / raw)
To: tumashu, emacs-devel@gnu.org
> > I only need show 2 lines with child-frame while its mini
> > size is show 4 lines, anyone suggest how to deal with this problem?
> [...]
> > (let ((window (frame-root-window my-child-frame)))
> > (set-window-parameter window 'mode-line-format 'none)
> > (set-window-parameter window 'header-line-format 'none))
>
> Looks like a stupid bug in the implementation of these parameters. I'll
> hopefully come up with a fix soon.
Sorry. Trying again with the current release version the following form
makes a frame with a two lines root window. What does it make for you?
(let ((window-min-height 1)
(window-min-width 1))
(setq my-child-frame
(let ((after-make-frame-functions nil))
(make-frame
`((parent-frame . ,(window-frame))
(no-accept-focus . t)
(min-width . t)
(min-height . t)
(border-width . 0)
(internal-border-width . 0)
(vertical-scroll-bars . nil)
(horizontal-scroll-bars . nil)
(left-fringe . 10)
(right-fringe . 0)
(menu-bar-lines . 0)
(tool-bar-lines . 0)
(line-spacing . 0)
(unsplittable . t)
(no-other-frame . t)
;;(undecorated . t)
(undecorated . nil)
(visibility . t)
(cursor-type . nil)
(minibuffer . nil)
(width . 50)
(height . 1)
(no-special-glyphs . t)))))
(let ((window (frame-root-window my-child-frame)))
(set-window-parameter window 'mode-line-format 'none)
(set-window-parameter window 'header-line-format 'none))
(set-window-buffer
(frame-root-window my-child-frame) (get-buffer-create "*foo*"))
(with-current-buffer "*foo*" (insert "line 1\nline 2\n"))
(fit-frame-to-buffer my-child-frame))
If it gives you more than two lines, then please tell me what the
following two forms evaluate to.
(window-mode-line-height (frame-root-window my-child-frame))
(window-header-line-height (frame-root-window my-child-frame))
Thank you, martin
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re:Re: How to create a small child-frame which only show two lines
2017-12-08 10:12 ` martin rudalics
@ 2017-12-08 12:05 ` tumashu
2017-12-09 10:35 ` martin rudalics
0 siblings, 1 reply; 23+ messages in thread
From: tumashu @ 2017-12-08 12:05 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]
Thank your for your help, I have solved the problem: I add (window-min-height 1) and (window-min-width 1))
to my code and let my English main font is taller than my Chinese fonts.
At 2017-12-08 18:12:02, "martin rudalics" <rudalics@gmx.at> wrote:
> > > I only need show 2 lines with child-frame while its mini
> > > size is show 4 lines, anyone suggest how to deal with this problem?
> > [...]
> > > (let ((window (frame-root-window my-child-frame)))
> > > (set-window-parameter window 'mode-line-format 'none)
> > > (set-window-parameter window 'header-line-format 'none))
> >
> > Looks like a stupid bug in the implementation of these parameters. I'll
> > hopefully come up with a fix soon.
>
>Sorry. Trying again with the current release version the following form
>makes a frame with a two lines root window. What does it make for you?
>
>(let ((window-min-height 1)
> (window-min-width 1))
> (setq my-child-frame
> (let ((after-make-frame-functions nil))
> (make-frame
> `((parent-frame . ,(window-frame))
> (no-accept-focus . t)
> (min-width . t)
> (min-height . t)
> (border-width . 0)
> (internal-border-width . 0)
> (vertical-scroll-bars . nil)
> (horizontal-scroll-bars . nil)
> (left-fringe . 10)
> (right-fringe . 0)
> (menu-bar-lines . 0)
> (tool-bar-lines . 0)
> (line-spacing . 0)
> (unsplittable . t)
> (no-other-frame . t)
> ;;(undecorated . t)
> (undecorated . nil)
> (visibility . t)
> (cursor-type . nil)
> (minibuffer . nil)
> (width . 50)
> (height . 1)
> (no-special-glyphs . t)))))
>
> (let ((window (frame-root-window my-child-frame)))
> (set-window-parameter window 'mode-line-format 'none)
> (set-window-parameter window 'header-line-format 'none))
>
> (set-window-buffer
> (frame-root-window my-child-frame) (get-buffer-create "*foo*"))
>
> (with-current-buffer "*foo*" (insert "line 1\nline 2\n"))
> (fit-frame-to-buffer my-child-frame))
>
>If it gives you more than two lines, then please tell me what the
>following two forms evaluate to.
>
>(window-mode-line-height (frame-root-window my-child-frame))
>(window-header-line-height (frame-root-window my-child-frame))
>
>Thank you, martin
[-- Attachment #2: Type: text/html, Size: 2915 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-08 12:05 ` tumashu
@ 2017-12-09 10:35 ` martin rudalics
2017-12-11 0:21 ` tumashu
0 siblings, 1 reply; 23+ messages in thread
From: martin rudalics @ 2017-12-09 10:35 UTC (permalink / raw)
To: tumashu; +Cc: emacs-devel@gnu.org
> Thank your for your help, I have solved the problem: I add (window-min-height 1) and (window-min-width 1))
> to my code and let my English main font is taller than my Chinese fonts.
Would setting `set-frame-font' for that child frame help then? Provided
you can say in advance which of your fonts should be the dominant one
for the frame in question.
BTW, note that setting these parameters
(set-window-parameter window 'mode-line-format 'none)
(set-window-parameter window 'header-line-format 'none))
is generally only needed when you show the corresponding buffer in a
"normal" window and in a child frame window. If you show the buffer in
a child frame only, setting the buffer-local values of
`mode-line-format' and `header-line-format' to nil usually suffices.
martin
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re:Re: How to create a small child-frame which only show two lines
2017-12-09 10:35 ` martin rudalics
@ 2017-12-11 0:21 ` tumashu
2017-12-11 6:42 ` martin rudalics
0 siblings, 1 reply; 23+ messages in thread
From: tumashu @ 2017-12-11 0:21 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 1179 bytes --]
Font's align problem is not a big problem :-), Chinese emacs user's fonts setup is complicate, so
it is not easily to use set-frame-font. so I decide just ignore this small problem :-)
I have use `mode-line-format' and `header-line-format' , they are more simple. thanks for this good tip.
At 2017-12-09 18:35:42, "martin rudalics" <rudalics@gmx.at> wrote:
> > Thank your for your help, I have solved the problem: I add (window-min-height 1) and (window-min-width 1))
> > to my code and let my English main font is taller than my Chinese fonts.
>
>Would setting `set-frame-font' for that child frame help then? Provided
>you can say in advance which of your fonts should be the dominant one
>for the frame in question.
>
>BTW, note that setting these parameters
>
> (set-window-parameter window 'mode-line-format 'none)
> (set-window-parameter window 'header-line-format 'none))
>
>is generally only needed when you show the corresponding buffer in a
>"normal" window and in a child frame window. If you show the buffer in
>a child frame only, setting the buffer-local values of
>`mode-line-format' and `header-line-format' to nil usually suffices.
>
>martin
[-- Attachment #2: Type: text/html, Size: 1489 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-11 0:21 ` tumashu
@ 2017-12-11 6:42 ` martin rudalics
2017-12-11 8:29 ` tumashu
0 siblings, 1 reply; 23+ messages in thread
From: martin rudalics @ 2017-12-11 6:42 UTC (permalink / raw)
To: tumashu; +Cc: emacs-devel@gnu.org
> Font's align problem is not a big problem :-), Chinese emacs user's fonts setup is complicate, so
> it is not easily to use set-frame-font. so I decide just ignore this small problem :-)
BTW, have you set `frame-resize-pixelwise' to non-nil? Because only in
that case the result of fitting a frame will be always exact.
martin
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re:Re: How to create a small child-frame which only show two lines
2017-12-11 6:42 ` martin rudalics
@ 2017-12-11 8:29 ` tumashu
2017-12-11 15:29 ` Eli Zaretskii
2017-12-12 8:56 ` martin rudalics
0 siblings, 2 replies; 23+ messages in thread
From: tumashu @ 2017-12-11 8:29 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 3699 bytes --]
Thanks for this infomation,
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?
The below is an example I current use:
-------------
(defun pyim-tooltip-compute-pixel-position
(&optional pos window pixel-width pixel-height dx dy)
"Return pixel position of POS in WINDOW, which indicates relative
coordinates of bottom left corner of the object, its returned value is
like (X . Y)
Omitting POS and WINDOW means use current position and selected window,
respectively.
If PIXEL-WIDTH and PIXEL-HEIGHT are given, this function regard these
values as the size of a small window located around the POS, for example:
tooltip. These values are used to adjust the small window's location and
let it not disappear by sticking out of the display.
DX specifies horizontal offset in pixel.
DY specifies vertical offset in pixel. This makes the calculations done
without considering the height of object at POS, so the object might be
hidden by the tooltip.
This function is shameless steal from pos-tip."
(let* ((frame (window-frame (or window (selected-window))))
(posn (posn-at-point (or pos (window-point window)) window))
(line (cdr (posn-actual-col-row posn)))
(line-height (and line
(or (window-line-height line window)
(and (redisplay t)
(window-line-height line window)))))
(x-y (or (posn-x-y posn)
(let ((geom (pos-visible-in-window-p
(or pos (window-point window)) window t)))
(and geom (cons (car geom) (cadr geom))))
'(0 . 0)))
(x (+ (car (window-inside-pixel-edges window))
(car x-y)
(or dx 0)))
(y0 (+ (cadr (window-pixel-edges window))
(or (nth 2 line-height) (cdr x-y))))
(y (+ y0
(or dy
(car line-height)
(with-current-buffer (window-buffer window)
(cond
;; `posn-object-width-height' returns an incorrect value
;; when the header line is displayed (Emacs bug #4426).
((and posn
(null header-line-format))
(cdr (posn-object-width-height posn)))
((and (bound-and-true-p text-scale-mode)
(not (zerop (with-no-warnings
text-scale-mode-amount))))
(round (* (frame-char-height frame)
(with-no-warnings
(expt text-scale-mode-step
text-scale-mode-amount)))))
(t (frame-char-height frame)))))))
(xmax (frame-pixel-width frame))
(ymax (frame-pixel-height frame))
(upperside-p (> (+ y (or pixel-height 0))
ymax)))
(cons (max 0 (min x (- xmax (or pixel-width 0))))
(max 0 (if upperside-p
(- (if dy ymax y0) (or pixel-height 0))
y)))))
-----------
At 2017-12-11 14:42:23, "martin rudalics" <rudalics@gmx.at> wrote:
> > Font's align problem is not a big problem :-), Chinese emacs user's fonts setup is complicate, so
> > it is not easily to use set-frame-font. so I decide just ignore this small problem :-)
>
>BTW, have you set `frame-resize-pixelwise' to non-nil? Because only in
>that case the result of fitting a frame will be always exact.
>
>martin
[-- Attachment #2: Type: text/html, Size: 7835 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-11 8:29 ` tumashu
@ 2017-12-11 15:29 ` Eli Zaretskii
2017-12-12 0:43 ` tumashu
2018-01-07 2:56 ` Feng Shu
2017-12-12 8:56 ` martin rudalics
1 sibling, 2 replies; 23+ messages in thread
From: Eli Zaretskii @ 2017-12-11 15:29 UTC (permalink / raw)
To: tumashu; +Cc: rudalics, emacs-devel
> Date: Mon, 11 Dec 2017 16:29:16 +0800 (CST)
> From: tumashu <tumashu@163.com>
> Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
>
> 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?
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re:Re: How to create a small child-frame which only show two lines
2017-12-11 15:29 ` Eli Zaretskii
@ 2017-12-12 0:43 ` tumashu
2017-12-12 3:22 ` Stefan Monnier
2017-12-12 16:26 ` Eli Zaretskii
2018-01-07 2:56 ` Feng Shu
1 sibling, 2 replies; 23+ messages in thread
From: tumashu @ 2017-12-12 0:43 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: martin rudalics, emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 573 bytes --]
I need this function to get the pixel position, so I can put a tooltip in this position to show
some information. vertical-motion seem to not have the feature.
At 2017-12-11 23:29:28, "Eli Zaretskii" <eliz@gnu.org> wrote:
>> Date: Mon, 11 Dec 2017 16:29:16 +0800 (CST)
>> From: tumashu <tumashu@163.com>
>> Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
>>
>> 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?
[-- Attachment #2: Type: text/html, Size: 848 bytes --]
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-12 0:43 ` tumashu
@ 2017-12-12 3:22 ` Stefan Monnier
2017-12-12 8:56 ` martin rudalics
2017-12-12 16:26 ` Eli Zaretskii
1 sibling, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2017-12-12 3:22 UTC (permalink / raw)
To: emacs-devel
> I need this function to get the pixel position, so I can put a tooltip
> in this position to show some information. vertical-motion seem to
> not have the feature.
Maybe you're looking for posn-at-point?
Stefan
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-11 8:29 ` tumashu
2017-12-11 15:29 ` Eli Zaretskii
@ 2017-12-12 8:56 ` martin rudalics
2017-12-12 12:19 ` Feng Shu
` (2 more replies)
1 sibling, 3 replies; 23+ messages in thread
From: martin rudalics @ 2017-12-12 8:56 UTC (permalink / raw)
To: tumashu; +Cc: emacs-devel@gnu.org
> (defun pyim-tooltip-compute-pixel-position
> (&optional pos window pixel-width pixel-height dx dy)
> "Return pixel position of POS in WINDOW, which indicates relative
> coordinates of bottom left corner of the object, its returned value is
> like (X . Y)
For mouse positions we return the upper left corner and in addition the
width and height of the object at point (where the height value would
inherently use the height of the entire line the object is part of). I
think we should do the same here. If the object is on top of the window
and partially off-screen, we'd probably have to return a negative
vertical position value.
> If PIXEL-WIDTH and PIXEL-HEIGHT are given, this function regard these
> values as the size of a small window located around the POS, for example:
> tooltip. These values are used to adjust the small window's location and
> let it not disappear by sticking out of the display.
IIUC your code avoids tooltips "sticking out of the frame". Right? In
either case you'd narrow the semantics and maybe something more general
should be used.
> DX specifies horizontal offset in pixel.
>
> DY specifies vertical offset in pixel. This makes the calculations done
> without considering the height of object at POS, so the object might be
> hidden by the tooltip.
IIUC these are needed for the "sticking out of the frame" avoidance.
Right? Because otherwise they should not be part of such a function.
A more general solution would allow to position the tooltip at either of
the four corners of the object at POS (for example, I'd prefer to put
them on an empty line that might happen to be above or below the glyph
at POS).
> (and (redisplay t)
> (window-line-height line window)))))
I'm never sure whether this is sufficient or `force-window-update' would
be needed too. These days, `redisplay' has a quite confusing doc-string
wrt `redisplay-dont-pause' which makes me doubt even more.
> ;; `posn-object-width-height' returns an incorrect value
> ;; when the header line is displayed (Emacs bug #4426).
FWIW this bug should have been fixed more than six years ago.
martin
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-12 3:22 ` Stefan Monnier
@ 2017-12-12 8:56 ` martin rudalics
0 siblings, 0 replies; 23+ messages in thread
From: martin rudalics @ 2017-12-12 8:56 UTC (permalink / raw)
To: Stefan Monnier, emacs-devel
> Maybe you're looking for posn-at-point?
His code is using that already.
martin
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-12 8:56 ` martin rudalics
@ 2017-12-12 12:19 ` Feng Shu
2017-12-12 17:05 ` Eli Zaretskii
2018-01-06 10:42 ` Feng Shu
2 siblings, 0 replies; 23+ messages in thread
From: Feng Shu @ 2017-12-12 12:19 UTC (permalink / raw)
To: martin rudalics; +Cc: Feng Shu, emacs-devel
martin rudalics <rudalics@gmx.at> writes:
>> (defun pyim-tooltip-compute-pixel-position
>> (&optional pos window pixel-width pixel-height dx dy)
>> "Return pixel position of POS in WINDOW, which indicates relative
>> coordinates of bottom left corner of the object, its returned value is
>> like (X . Y)
>
> For mouse positions we return the upper left corner and in addition the
> width and height of the object at point (where the height value would
> inherently use the height of the entire line the object is part of). I
> think we should do the same here. If the object is on top of the window
> and partially off-screen, we'd probably have to return a negative
> vertical position value.
>
>> If PIXEL-WIDTH and PIXEL-HEIGHT are given, this function regard these
>> values as the size of a small window located around the POS, for example:
>> tooltip. These values are used to adjust the small window's location and
>> let it not disappear by sticking out of the display.
>
> IIUC your code avoids tooltips "sticking out of the frame". Right? In
> either case you'd narrow the semantics and maybe something more general
> should be used.
>
>> DX specifies horizontal offset in pixel.
>>
>> DY specifies vertical offset in pixel. This makes the calculations done
>> without considering the height of object at POS, so the object might be
>> hidden by the tooltip.
>
> IIUC these are needed for the "sticking out of the frame" avoidance.
> Right? Because otherwise they should not be part of such a function.
>
> A more general solution would allow to position the tooltip at either of
> the four corners of the object at POS (for example, I'd prefer to put
> them on an empty line that might happen to be above or below the glyph
> at POS).
>
>> (and (redisplay t)
>> (window-line-height line window)))))
>
> I'm never sure whether this is sufficient or `force-window-update' would
> be needed too. These days, `redisplay' has a quite confusing doc-string
> wrt `redisplay-dont-pause' which makes me doubt even more.
>
>> ;; `posn-object-width-height' returns an incorrect value
>> ;; when the header line is displayed (Emacs bug #4426).
>
> FWIW this bug should have been fixed more than six years ago.
>
To be honest, I do not understand the function very much, I only know it
just work :-), for this function is copied from pos-tip.el five years
ago's version, maybe many code of it just dead code.
pos-tip is a package which has similar job with popup-el, the different
is that pos-tip use tooltip while popup-el use overlay. popup-el is
very popular but it does not run well with No-English language,
pos-tip has not this problem but it run too slow and unmaintaned
five years ago.
I find we can use child-frame to create a popup-el like package, which
is fast, easy understand and works well with No-English language.
> martin
>
--
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-12 0:43 ` tumashu
2017-12-12 3:22 ` Stefan Monnier
@ 2017-12-12 16:26 ` Eli Zaretskii
2017-12-12 16:48 ` Stefan Monnier
1 sibling, 1 reply; 23+ messages in thread
From: Eli Zaretskii @ 2017-12-12 16:26 UTC (permalink / raw)
To: tumashu; +Cc: rudalics, emacs-devel
> Date: Tue, 12 Dec 2017 08:43:34 +0800 (CST)
> From: tumashu <tumashu@163.com>
> Cc: "martin rudalics" <rudalics@gmx.at>,
> "emacs-devel@gnu.org" <emacs-devel@gnu.org>
>
> I need this function to get the pixel position, so I can put a tooltip in this position to show
> some information. vertical-motion seem to not have the feature.
Perhaps there is a misunderstanding. AFAIU, you can determine the
left-top pixel position at point, but you wanted the left-bottom
position instead, is that right? If so, my suggestion was to call
vertical-motion to move down one line, then take the left-top position
at that place. Doesn't that give you what you want?
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-12 16:26 ` Eli Zaretskii
@ 2017-12-12 16:48 ` Stefan Monnier
2017-12-12 17:19 ` Eli Zaretskii
0 siblings, 1 reply; 23+ messages in thread
From: Stefan Monnier @ 2017-12-12 16:48 UTC (permalink / raw)
To: emacs-devel
> Perhaps there is a misunderstanding. AFAIU, you can determine the
> left-top pixel position at point, but you wanted the left-bottom
> position instead, is that right? If so, my suggestion was to call
> vertical-motion to move down one line, then take the left-top position
> at that place.
What if there's no position "down one line" (e.g. the next line is too
short or there's no next line)?
Stefan
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-12 8:56 ` martin rudalics
2017-12-12 12:19 ` Feng Shu
@ 2017-12-12 17:05 ` Eli Zaretskii
2017-12-13 8:50 ` martin rudalics
2018-01-06 10:42 ` Feng Shu
2 siblings, 1 reply; 23+ messages in thread
From: Eli Zaretskii @ 2017-12-12 17:05 UTC (permalink / raw)
To: martin rudalics; +Cc: tumashu, emacs-devel
> Date: Tue, 12 Dec 2017 09:56:19 +0100
> From: martin rudalics <rudalics@gmx.at>
> Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
>
> > ;; `posn-object-width-height' returns an incorrect value
> > ;; when the header line is displayed (Emacs bug #4426).
>
> FWIW this bug should have been fixed more than six years ago.
AFAIU you are saying that it _is_ fixed, so you wonder why the OP
seems to see it. If so, I concur. E.g., I couldn't reproduce the
original problem in an Info buffer (which does have a header-line).
Or am I missing something?
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-12 16:48 ` Stefan Monnier
@ 2017-12-12 17:19 ` Eli Zaretskii
0 siblings, 0 replies; 23+ messages in thread
From: Eli Zaretskii @ 2017-12-12 17:19 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Tue, 12 Dec 2017 11:48:17 -0500
>
> > Perhaps there is a misunderstanding. AFAIU, you can determine the
> > left-top pixel position at point, but you wanted the left-bottom
> > position instead, is that right? If so, my suggestion was to call
> > vertical-motion to move down one line, then take the left-top position
> > at that place.
>
> What if there's no position "down one line" (e.g. the next line is too
> short or there's no next line)?
Does this mean that my suggestion works in all the other cases? If
so, the above is easy. But I'm not yet sure I understand the problem,
because the presented solution was so complex I'm probably missing
something much more important than the situation you describe.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-12 17:05 ` Eli Zaretskii
@ 2017-12-13 8:50 ` martin rudalics
0 siblings, 0 replies; 23+ messages in thread
From: martin rudalics @ 2017-12-13 8:50 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: tumashu, emacs-devel
>> FWIW this bug should have been fixed more than six years ago.
>
> AFAIU you are saying that it _is_ fixed, so you wonder why the OP
> seems to see it. If so, I concur. E.g., I couldn't reproduce the
> original problem in an Info buffer (which does have a header-line).
>
> Or am I missing something?
I didn't want to exclude the possibility that the OP found a scenario
how to resurrect that bug.
martin
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-12 8:56 ` martin rudalics
2017-12-12 12:19 ` Feng Shu
2017-12-12 17:05 ` Eli Zaretskii
@ 2018-01-06 10:42 ` Feng Shu
2 siblings, 0 replies; 23+ messages in thread
From: Feng Shu @ 2018-01-06 10:42 UTC (permalink / raw)
To: martin rudalics; +Cc: Feng Shu, emacs-devel
martin rudalics <rudalics@gmx.at> writes:
The below is a simple version, and it works well for pyim and is easy
understand.
---------------------------------------------------------------------------
(defun pyim-tooltip-compute-pixel-position (pos pixel-width pixel-height)
"Return pixel position of POS in WINDOW, which indicates relative
coordinates of bottom left corner of the object, its returned value is
like (X . Y)
If PIXEL-WIDTH and PIXEL-HEIGHT are given, this function regard these
values as the size of a small window located around the POS, for example:
tooltip. These values are used to adjust the small window's location and
let it not disappear by sticking out of the display.
This function is shameless steal from pos-tip."
(let* ((window (selected-window))
(frame (window-frame window))
(xmax (frame-pixel-width frame))
(ymax (frame-pixel-height frame))
(posn (posn-at-point pos window))
(line (cdr (posn-actual-col-row posn)))
(line-height
(or (window-line-height line window)
(and (redisplay t)
(window-line-height line window))))
(x-y (or (posn-x-y posn) '(0 . 0)))
(x (+ (car (window-inside-pixel-edges window))
(car x-y)))
(y0 (+ (cadr (window-pixel-edges window))
(or (nth 2 line-height) (cdr x-y))))
(y (+ y0 (car line-height))))
(cons (max 0 (min x (- xmax (or pixel-width 0))))
(max 0 (if (> (+ y (or pixel-height 0)) ymax)
(- y0 (or pixel-height 0))
y)))))
-------------------------------------------------------------------
--
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: How to create a small child-frame which only show two lines
2017-12-11 15:29 ` Eli Zaretskii
2017-12-12 0:43 ` tumashu
@ 2018-01-07 2:56 ` Feng Shu
1 sibling, 0 replies; 23+ messages in thread
From: Feng Shu @ 2018-01-07 2:56 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Feng Shu, emacs-devel
Eli Zaretskii <eliz@gnu.org> writes:
>> Date: Mon, 11 Dec 2017 16:29:16 +0800 (CST)
>> From: tumashu <tumashu@163.com>
>> Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
>>
>> 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)))))
--
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2018-01-07 2:56 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-07 0:04 How to create a small child-frame which only show two lines tumashu
2017-12-07 2:35 ` jun
2017-12-07 2:45 ` tumashu
2017-12-07 9:27 ` How " martin rudalics
2017-12-08 10:12 ` martin rudalics
2017-12-08 12:05 ` tumashu
2017-12-09 10:35 ` martin rudalics
2017-12-11 0:21 ` tumashu
2017-12-11 6:42 ` martin rudalics
2017-12-11 8:29 ` tumashu
2017-12-11 15:29 ` Eli Zaretskii
2017-12-12 0:43 ` tumashu
2017-12-12 3:22 ` Stefan Monnier
2017-12-12 8:56 ` martin rudalics
2017-12-12 16:26 ` Eli Zaretskii
2017-12-12 16:48 ` Stefan Monnier
2017-12-12 17:19 ` Eli Zaretskii
2018-01-07 2:56 ` Feng Shu
2017-12-12 8:56 ` martin rudalics
2017-12-12 12:19 ` Feng Shu
2017-12-12 17:05 ` Eli Zaretskii
2017-12-13 8:50 ` martin rudalics
2018-01-06 10:42 ` Feng Shu
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).