aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMoritz Maxeiner2023-07-22 16:55:07 +0200
committerEli Zaretskii2023-07-22 18:39:24 +0300
commit191aef4f618408c1be9f57459eaaa91b955fec18 (patch)
treefa8eb8087b6142555354181bdff2a9f7010e509f /src
parentaf547c4bbe806bf011363d6a04d93aef27d94df9 (diff)
downloademacs-191aef4f618408c1be9f57459eaaa91b955fec18.tar.gz
emacs-191aef4f618408c1be9f57459eaaa91b955fec18.zip
Implement new option 'mouse-prefer-closest-glyph'
* src/dispnew.c (mouse_prefer_closest_glyph): New global variable. (buffer_posn_from_coords): * src/xdisp.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 (Accessing Mouse): Update documentation to say what the new option does when enabled. * lisp/cus-start.el (standard): New user option 'mouse-prefer-closest-glyph'.
Diffstat (limited to 'src')
-rw-r--r--src/dispnew.c18
-rw-r--r--src/xdisp.c17
2 files changed, 34 insertions, 1 deletions
diff --git a/src/dispnew.c b/src/dispnew.c
index 82524d8cb8d..821357c51c1 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5636,6 +5636,15 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p
5636 argument is ZV to prevent move_it_in_display_line from matching 5636 argument is ZV to prevent move_it_in_display_line from matching
5637 based on buffer positions. */ 5637 based on buffer positions. */
5638 move_it_in_display_line (&it, ZV, to_x, MOVE_TO_X); 5638 move_it_in_display_line (&it, ZV, to_x, MOVE_TO_X);
5639 if (mouse_prefer_closest_glyph)
5640 {
5641 int next_x = it.current_x + it.pixel_width;
5642 int before_dx = to_x - it.current_x;
5643 int after_dx = next_x - to_x;
5644 if (before_dx > after_dx)
5645 move_it_in_display_line (&it, ZV, next_x, MOVE_TO_X);
5646 }
5647
5639 bidi_unshelve_cache (itdata, 0); 5648 bidi_unshelve_cache (itdata, 0);
5640 5649
5641 Fset_buffer (old_current_buffer); 5650 Fset_buffer (old_current_buffer);
@@ -6813,6 +6822,15 @@ predicates which report frame's specific UI-related capabilities. */);
6813 DEFVAR_BOOL ("cursor-in-echo-area", cursor_in_echo_area, 6822 DEFVAR_BOOL ("cursor-in-echo-area", cursor_in_echo_area,
6814 doc: /* Non-nil means put cursor in minibuffer, at end of any message there. */); 6823 doc: /* Non-nil means put cursor in minibuffer, at end of any message there. */);
6815 6824
6825 DEFVAR_BOOL ("mouse-prefer-closest-glyph", mouse_prefer_closest_glyph,
6826 doc: /* Non-nil means mouse position lists are reported relative
6827to the glyph closest to their coordinates.
6828
6829 When non-nil, mouse position lists will be reported with their
6830`posn-point' set to the position of the glyph closest to the mouse
6831pointer, instead of the glyph immediately under. */);
6832 mouse_prefer_closest_glyph = false;
6833
6816 DEFVAR_LISP ("glyph-table", Vglyph_table, 6834 DEFVAR_LISP ("glyph-table", Vglyph_table,
6817 doc: /* Table defining how to output a glyph code to the frame. 6835 doc: /* Table defining how to output a glyph code to the frame.
6818If not nil, this is a vector indexed by glyph code to define the glyph. 6836If 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 2eba42e3d90..1de6fcfd172 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -2759,6 +2759,7 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
2759 enum window_part part; 2759 enum window_part part;
2760 enum glyph_row_area area; 2760 enum glyph_row_area area;
2761 int x, y, width, height; 2761 int x, y, width, height;
2762 int original_gx;
2762 2763
2763 if (mouse_fine_grained_tracking) 2764 if (mouse_fine_grained_tracking)
2764 { 2765 {
@@ -2769,6 +2770,8 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
2769 /* Try to determine frame pixel position and size of the glyph under 2770 /* Try to determine frame pixel position and size of the glyph under
2770 frame pixel coordinates X/Y on frame F. */ 2771 frame pixel coordinates X/Y on frame F. */
2771 2772
2773 original_gx = gx;
2774
2772 if (window_resize_pixelwise) 2775 if (window_resize_pixelwise)
2773 { 2776 {
2774 width = height = 1; 2777 width = height = 1;
@@ -2984,6 +2987,15 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
2984 gy += WINDOW_TOP_EDGE_Y (w); 2987 gy += WINDOW_TOP_EDGE_Y (w);
2985 2988
2986 store_rect: 2989 store_rect:
2990 if (mouse_prefer_closest_glyph)
2991 {
2992 int half_width = width / 2;
2993 width = half_width;
2994
2995 int bisection = gx + half_width;
2996 if (original_gx > bisection)
2997 gx = bisection;
2998 }
2987 STORE_NATIVE_RECT (*rect, gx, gy, width, height); 2999 STORE_NATIVE_RECT (*rect, gx, gy, width, height);
2988 3000
2989 /* Visible feedback for debugging. */ 3001 /* Visible feedback for debugging. */
@@ -37503,7 +37515,10 @@ may be more familiar to users. */);
37503 DEFVAR_BOOL ("mouse-fine-grained-tracking", mouse_fine_grained_tracking, 37515 DEFVAR_BOOL ("mouse-fine-grained-tracking", mouse_fine_grained_tracking,
37504 doc: /* Non-nil for pixel-wise mouse-movement. 37516 doc: /* Non-nil for pixel-wise mouse-movement.
37505When nil, mouse-movement events will not be generated as long as the 37517When nil, mouse-movement events will not be generated as long as the
37506mouse stays within the extent of a single glyph (except for images). */); 37518mouse stays within the extent of a single glyph (except for images).
37519When nil and mouse-prefer-closest-glyph is non-nil, mouse-movement
37520events will instead not be generated as long as the mouse stays within
37521the extent of a single left/right half glyph (except for images). */);
37507 mouse_fine_grained_tracking = false; 37522 mouse_fine_grained_tracking = false;
37508 37523
37509 DEFVAR_BOOL ("tab-bar--dragging-in-progress", tab_bar__dragging_in_progress, 37524 DEFVAR_BOOL ("tab-bar--dragging-in-progress", tab_bar__dragging_in_progress,