From: Eli Zaretskii <eliz@gnu.org>
To: JD Smith <jdtsmith@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: xterm-mouse-mode gives incorrect posn-object-x-y with display space
Date: Fri, 25 Nov 2022 09:21:27 +0200 [thread overview]
Message-ID: <83tu2nv6rs.fsf@gnu.org> (raw)
In-Reply-To: <5BBC7E49-41C3-4693-95F6-26E8EAC7F7A4@gmail.com> (message from JD Smith on Thu, 24 Nov 2022 16:42:29 -0500)
> 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.
next prev parent reply other threads:[~2022-11-25 7:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-24 17:22 xterm-mouse-mode gives incorrect posn-object-x-y with display space JD Smith
2022-11-24 18:09 ` Stefan Monnier
2022-11-24 18:34 ` Eli Zaretskii
2022-11-24 21:42 ` JD Smith
2022-11-25 7:21 ` Eli Zaretskii [this message]
2022-11-25 15:15 ` JD Smith
2022-11-26 12:07 ` Eli Zaretskii
2022-11-26 18:56 ` Akib Azmain Turja
2022-11-26 19:14 ` Eli Zaretskii
2022-11-27 1:14 ` JD Smith
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83tu2nv6rs.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=jdtsmith@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).