emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xterm-mouse-mode gives incorrect posn-object-x-y with display space


From: Eli Zaretskii
Subject: Re: xterm-mouse-mode gives incorrect posn-object-x-y with display space
Date: Fri, 25 Nov 2022 09:21:27 +0200

> From: JD Smith <jdtsmith@gmail.com>
> Date: Thu, 24 Nov 2022 16:42:29 -0500
> Cc: emacs-devel@gnu.org
> 
> Thanks.  The documentation on posn-object-* provides no guidance that a 
> “string object” would not include a
> stretched string with specified space.  So it was not at all surprising to me 
> that it worked "as expected" in the
> GUI.  In further support of this impression (leaving aside specified space), 
> posn-object-x-y works perfectly
> well on normal width characters in the buffer, providing pixel level 
> information on where *within the
> character* you clicked.  In fact I cannot think what "pixel-based x and y 
> coordinates relative to the upper left
> corner” would mean other than this for a "string object".  Surely that is not 
> an accident of the
> implementation!

Yes, but on TTY frames the DX/DY _within_ the character glyph are always
zero, because each character is considered to be exactly one "pixel".  And
if I tell you that stretches of whitespace produced by 'space' display specs
are implemented on TTY as sequences of SPC characters (of course, what
else?), then I think you will understand why the DX/DY values, defined in
the ELisp manual as "the coordinates relative to the top left corner of the
character glyph clicked on", on a TTY are always zero: wherever the click
is, it is always on a glyph of some SPC character from those that represent
the stretch of whitespace.

> But it sounds like internal position X/Y offsets for specified spaces in GUI 
> vs. TTY are not reliable, so maybe
> I should stop using them.

On TTY, you will always get zero DX/DY, so if this is deemed "unreliable",
then yes, you should not use that for your needs, whatever those are.

> Is there a reliable way to determine where (in pixels [1]) the mouse was 
> clicked relative to a string displayed
> with specified space, which works equally in the GUI and TTYs?   Keep in mind 
> that the string may not be at
> a fixed column, but at an arbitrary pixel offset from the window (due to 
> prior specified space, variable width
> fonts, etc.).  

Please tell more about your use case.  I don't think I understand what you
mean by "string displayed with specified space"; AFAIU there were no display
or overlay strings in the recipe you posted, and no description of what you
are trying to do with the 'space' spec that the DX/DY offsets are so
important.

If I have to guess what you want, then my suggestion would be to use
something like this:

  (let* ((event-posn (posn-point (event-start ev)))
         (click-x-y (posn-x-y (event-start ev)))
         (obj-x-y (posn-x-y (posn-at-point event-posn))))
    (cons (- (car click-x-y) (car obj-x-y))
          (- (cdr click-x-y) (cdr obj-x-y))))

IOW, don't trust DX/DY, but calculate the offsets "by hand".

But that's a guess.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]