From: Moritz Maxeiner <mm@ucw.sh>
To: Eli Zaretskii <eliz@gnu.org>
Cc: luangruo@yahoo.com, emacs-devel@gnu.org
Subject: Re: Moving point after character when clicking latter half of it
Date: Sat, 22 Jul 2023 17:28:34 +0200 [thread overview]
Message-ID: <5699684.DvuYhMxLoT@anduin> (raw)
In-Reply-To: <83mszo85yv.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1433 bytes --]
On Saturday 22 July 2023 14:51:20 CEST Eli Zaretskii wrote:
> > From: Moritz Maxeiner <mm@ucw.sh>
> > Cc: emacs-devel@gnu.org
> > Date: Sat, 22 Jul 2023 12:07:27 +0200
> >
> > On Saturday 22 July 2023 07:41:53 CEST Eli Zaretskii wrote:
> > > > From: Po Lu <luangruo@yahoo.com>
> > > > Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
> > > > Date: Sat, 22 Jul 2023 07:57:53 +0800
> > > >
> > > > Moritz Maxeiner <mm@ucw.sh> writes:
> > > > > +This new option defaults to off.
> > > >
> > > > I think this sentence is redundant.
> > >
> > > It isn't. But a better wording would be
> > >
> > > By default this is disabled.
> >
> > Done. Though I am concerned that capitalizing "x coordinate" to "X
> > coordinate" will lead to confusion, as capitalized X seems to usually
> > refer to the X window system within NEWS. In this instance, it's not
> > supposed to be referring to that, instead it's referring to the x of the
> > (x,y) coordinate pair.
>
> Thanks. So now, to make it ready to go, please produce the patch in
> the "git format-patch" format, or at least add to the patch a
> ChangeLog-style commit log message describing the changes with their
> file names and function names. You can find the instructions for that
> in CONTRIBUTE, and a lot of examples in "git log".
Sure, I hope the attached patch meets the requirements. I wasn't 100% on
some of the rules so I tried emulating what I saw in git log.
[-- Attachment #2: 0001-Implement-new-option-mouse-prefer-closest-glyph.patch --]
[-- Type: text/x-patch, Size: 6802 bytes --]
From f4efae2e7a089a784cd074080fcd211e0ca9ddb5 Mon Sep 17 00:00:00 2001
From: Moritz Maxeiner <mm@ucw.sh>
Date: Sat, 22 Jul 2023 16:55:07 +0200
Subject: [PATCH] Implement new option mouse-prefer-closest-glyph
* doc/lispref/commands.texi (Accessing Mouse): Update documentation to
say what the new option does when enabled.
* etc/NEWS: Announce the new option.
* lisp/cus-start.el (standard): New user custom
`mouse-prefer-closest-glyph'.
* src/dispnew.c (mouse_prefer_closest_glyph): New global variable.
(buffer_posn_from_coords):
* src/xdispc.c (remember_mouse_glyph):
Respect `mouse_prefer_closest_glyph'.
(mouse_fine_grained_tracking): Update documentation to include
`mouse_prefer_closest_glyph' effects.
---
doc/lispref/commands.texi | 10 ++++++++++
etc/NEWS | 11 +++++++++++
lisp/cus-start.el | 1 +
src/dispnew.c | 18 ++++++++++++++++++
src/xdisp.c | 17 ++++++++++++++++-
5 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi
index cd1745614eb..d1b8f9c494c 100644
--- a/doc/lispref/commands.texi
+++ b/doc/lispref/commands.texi
@@ -2751,6 +2751,16 @@ If @var{whole} is non-@code{nil}, the @var{x} coordinate is relative
to the entire window area including scroll bars, margins and fringes.
@end defun
+@defopt mouse-prefer-closest-glyph
+If this variable is non-@code{nil}, the @code{posn-point} of a mouse
+position list will be set to the position of the glyph whose left most
+position is closest to the mouse pointer, as opposed to the position of
+the glyph underneath the mouse pointer itself. For example, if
+@code{posn-at-x-y} is called with @var{x} set to @code{9}, which is
+contained within a character of width 10 positioned at column 0, the
+point saved within the mouse position list will be after that character.
+@end defopt
+
@node Accessing Scroll
@subsection Accessing Scroll Bar Events
@cindex scroll bar events, data in
diff --git a/etc/NEWS b/etc/NEWS
index 9e6f0c16bcd..3c127aa9bd7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -952,6 +952,17 @@ wheel reports. Unlike 'pixel-scroll-mode', this mode scrolls the
display pixel-by-pixel, as opposed to only animating line-by-line
scrolls.
++++
+** New user option 'mouse-prefer-closest-glyph'.
+When enabled, clicking or dragging with the mouse will put the point
+in front of the buffer position corresponding to the glyph with the
+closest X coordinate to the click or start of the drag.
+In other words, if the mouse pointer is in the right half of a glyph,
+point will be put after the buffer position corresponding to that glyph,
+whereas if the mouse pointer is in the left half of a glyph, point
+will be put in front the buffer position corresponding to that glyph.
+By default this is disabled.
+
** Terminal Emacs
---
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index 054683d7cf6..2ed904f178f 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -231,6 +231,7 @@ Leaving \"Default\" unchecked is equivalent with specifying a default of
(inverse-video display boolean)
(visible-bell display boolean)
(no-redraw-on-reenter display boolean)
+ (mouse-prefer-closest-glyph display boolean)
;; doc.c
(text-quoting-style display
diff --git a/src/dispnew.c b/src/dispnew.c
index 65d9cf9b4e1..143dda412e9 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5611,6 +5611,15 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p
argument is ZV to prevent move_it_in_display_line from matching
based on buffer positions. */
move_it_in_display_line (&it, ZV, to_x, MOVE_TO_X);
+ if (mouse_prefer_closest_glyph)
+ {
+ int next_x = it.current_x + it.pixel_width;
+ int before_dx = to_x - it.current_x;
+ int after_dx = next_x - to_x;
+ if (before_dx > after_dx)
+ move_it_in_display_line (&it, ZV, next_x, MOVE_TO_X);
+ }
+
bidi_unshelve_cache (itdata, 0);
Fset_buffer (old_current_buffer);
@@ -6788,6 +6797,15 @@ predicates which report frame's specific UI-related capabilities. */);
DEFVAR_BOOL ("cursor-in-echo-area", cursor_in_echo_area,
doc: /* Non-nil means put cursor in minibuffer, at end of any message there. */);
+ DEFVAR_BOOL ("mouse-prefer-closest-glyph", mouse_prefer_closest_glyph,
+ doc: /* Non-nil means mouse position lists are reported relative
+to the glyph closest to their coordinates.
+
+ When non-nil, mouse position lists will be reported with their
+`posn-point' set to the position of the glyph closest to the mouse
+pointer, instead of the glyph immediately under. */);
+ mouse_prefer_closest_glyph = false;
+
DEFVAR_LISP ("glyph-table", Vglyph_table,
doc: /* Table defining how to output a glyph code to the frame.
If not nil, this is a vector indexed by glyph code to define the glyph.
diff --git a/src/xdisp.c b/src/xdisp.c
index 763af7d3bc8..1d71bb02641 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -2723,6 +2723,7 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
enum window_part part;
enum glyph_row_area area;
int x, y, width, height;
+ int original_gx;
if (mouse_fine_grained_tracking)
{
@@ -2733,6 +2734,8 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
/* Try to determine frame pixel position and size of the glyph under
frame pixel coordinates X/Y on frame F. */
+ original_gx = gx;
+
if (window_resize_pixelwise)
{
width = height = 1;
@@ -2948,6 +2951,15 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
gy += WINDOW_TOP_EDGE_Y (w);
store_rect:
+ if (mouse_prefer_closest_glyph)
+ {
+ int half_width = width / 2;
+ width = half_width;
+
+ int bisection = gx + half_width;
+ if (original_gx > bisection)
+ gx = bisection;
+ }
STORE_NATIVE_RECT (*rect, gx, gy, width, height);
/* Visible feedback for debugging. */
@@ -37345,7 +37357,10 @@ may be more familiar to users. */);
DEFVAR_BOOL ("mouse-fine-grained-tracking", mouse_fine_grained_tracking,
doc: /* Non-nil for pixel-wise mouse-movement.
When nil, mouse-movement events will not be generated as long as the
-mouse stays within the extent of a single glyph (except for images). */);
+mouse stays within the extent of a single glyph (except for images).
+When nil and mouse-prefer-closest-glyph is non-nil, mouse-movement
+events will instead not be generated as long as the mouse stays within
+the extent of a single left/right half glyph (except for images). */);
mouse_fine_grained_tracking = false;
DEFVAR_BOOL ("tab-bar--dragging-in-progress", tab_bar__dragging_in_progress,
--
2.41.0
next prev parent reply other threads:[~2023-07-22 15:28 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-08 21:01 Moving point after character when clicking latter half of it Moritz Maxeiner
2023-07-09 6:35 ` Eli Zaretskii
2023-07-09 12:44 ` Moritz Maxeiner
2023-07-09 13:23 ` Eli Zaretskii
2023-07-09 13:51 ` Moritz Maxeiner
2023-07-09 14:14 ` Eli Zaretskii
2023-07-09 21:47 ` Moritz Maxeiner
2023-07-10 12:46 ` Eli Zaretskii
2023-07-10 14:43 ` [External] : " Drew Adams
2023-07-10 20:02 ` Moritz Maxeiner
2023-07-11 12:29 ` Eli Zaretskii
2023-07-11 13:10 ` Po Lu
2023-07-11 18:01 ` Moritz Maxeiner
2023-07-12 0:52 ` Po Lu
2023-07-12 19:58 ` Moritz Maxeiner
2023-07-12 21:17 ` Yuan Fu
2023-07-12 21:36 ` Moritz Maxeiner
2023-07-12 22:08 ` Yuan Fu
2023-07-13 5:27 ` Eli Zaretskii
2023-07-13 23:25 ` Yuan Fu
2023-07-13 0:31 ` Po Lu
2023-07-13 8:47 ` Eli Zaretskii
2023-07-21 19:04 ` Moritz Maxeiner
2023-07-21 23:57 ` Po Lu
2023-07-22 5:41 ` Eli Zaretskii
2023-07-22 10:07 ` Moritz Maxeiner
2023-07-22 11:31 ` Po Lu
2023-07-22 12:51 ` Eli Zaretskii
2023-07-22 15:28 ` Moritz Maxeiner [this message]
2023-07-22 15:51 ` Eli Zaretskii
2023-07-22 15:59 ` Moritz Maxeiner
2023-07-22 16:34 ` Eli Zaretskii
2023-07-22 19:10 ` Yuan Fu
2023-07-09 13:58 ` Yuri Khan
2023-07-09 12:40 ` Benjamin Riefenstahl
2023-07-09 12:47 ` Moritz Maxeiner
2023-07-09 13:37 ` Benjamin Riefenstahl
2023-07-09 15:15 ` [External] : " Drew Adams
2023-07-09 15:33 ` Moritz Maxeiner
2023-07-09 16:06 ` Drew Adams
2023-07-09 16:21 ` Brian Cully via Emacs development discussions.
2023-07-09 18:01 ` Jens Schmidt
2023-07-09 16:43 ` [External] : " Eli Zaretskii
2023-07-12 18:21 ` Benjamin Riefenstahl
2023-07-12 18:32 ` Eli Zaretskii
[not found] ` <12248204.O9o76ZdvQC@anduin>
[not found] ` <87ilac2kla.fsf@yahoo.com>
2023-07-22 14:48 ` Moritz Maxeiner
2023-07-22 15:26 ` Eli Zaretskii
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=5699684.DvuYhMxLoT@anduin \
--to=mm@ucw.sh \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=luangruo@yahoo.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).