the down mouse event. */
static Lisp_Object frame_relative_event_pos;
+/* The line-number display width, in columns, at the time of most
+ recent down mouse event. */
+static int down_mouse_line_number_width;
+
/* Information about the most recent up-going button event: Which
button, what location, and what time. */
#endif /* HAVE_WINDOW_SYSTEM */
+static void
+save_line_number_display_width (struct input_event *event)
+{
+ struct window *w;
+ int pixel_width;
+
+ if (WINDOWP (event->frame_or_window))
+ w = XWINDOW (event->frame_or_window);
+ else if (FRAMEP (event->frame_or_window))
+ w = XWINDOW (XFRAME (event->frame_or_window)->selected_window);
+ line_number_display_width (w, &down_mouse_line_number_width, &pixel_width);
+}
+
+/* Return non-zero if the change of position from START_POS to END_POS
+ is likely to be the effect of horizontal scrolling due to a change
+ in line-number width produced by redisplay between two mouse
+ events, like mouse-down followed by mouse-up, at those positions.
+ This is used to decide whether to converts mouse-down followed by
+ mouse-up event into a mouse-drag event. */
+static bool
+line_number_mode_hscroll (Lisp_Object start_pos, Lisp_Object end_pos)
+{
+ if (!EQ (Fcar (start_pos), Fcar (end_pos)) /* different window */
+ || list_length (start_pos) < 7 /* no COL/ROW info */
+ || list_length (end_pos) < 7)
+ return false;
+
+ Lisp_Object start_col_row = Fnth (make_fixnum (6), start_pos);
+ Lisp_Object end_col_row = Fnth (make_fixnum (6), end_pos);
+ Lisp_Object window = Fcar (end_pos);
+ int col_width, pixel_width, start_col, end_col;
+ struct window *w;
+ if (!WINDOW_VALID_P (window))
+ {
+ if (WINDOW_LIVE_P (window))
+ window = XFRAME (window)->selected_window;
+ else
+ window = selected_window;
+ }
+ w = XWINDOW (window);
+ line_number_display_width (w, &col_width, &pixel_width);
+ start_col = Fcar (start_col_row);
+ end_col = Fcar (end_col_row);
+ return start_col == end_col
+ && down_mouse_line_number_width >= 0
+ && col_width != down_mouse_line_number_width;
+}
+
/* Given a struct input_event, build the lisp event which represents
it. If EVENT is 0, build a mouse movement event from the mouse
movement buffer, which should have a movement event in it.
*start_pos_ptr = Fcopy_alist (position);
frame_relative_event_pos = Fcons (event->x, event->y);
ignore_mouse_drag_p = false;
+ /* Squirrel away the line-number width, if any. */
+ save_line_number_display_width (event);
}
/* Now we're releasing a button - check the coordinates to
it's probably OK to ignore it as well. */
&& (EQ (Fcar (Fcdr (start_pos)),
Fcar (Fcdr (position))) /* Same buffer pos */
+ /* Redisplay hscrolled text between down- and
+ up-events due to display-line-numbers-mode. */
+ || line_number_mode_hscroll (start_pos, position)
|| !EQ (Fcar (start_pos),
Fcar (position))))) /* Different window */
+
{
/* Mouse has moved enough. */
button_down_time = 0;
click_or_drag_modifier = drag_modifier;
+ /* Reset the value for future clicks. */
+ down_mouse_line_number_width = -1;
}
else if (((!EQ (Fcar (start_pos), Fcar (position)))
|| (!EQ (Fcar (Fcdr (start_pos)),