aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog32
-rw-r--r--src/dispnew.c2
-rw-r--r--src/keyboard.c220
-rw-r--r--src/msdos.c2
-rw-r--r--src/w32term.c4
-rw-r--r--src/window.c224
-rw-r--r--src/window.h4
-rw-r--r--src/xdisp.c7
-rw-r--r--src/xterm.c4
9 files changed, 244 insertions, 255 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index ca673be0074..401a93bbfb3 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,35 @@
12010-11-16 Chong Yidong <cyd@stupidchicken.com>
2
3 * keyboard.c (make_lispy_position): For text area clicks, record Y
4 pixel position relative to the text area, excluding header line.
5 Also change X and Y to Lisp_Objects, not pointers; don't return
6 coordinate values via pointers. Pass ON_TEXT_AREA coordinate to
7 buffer_posn_from_coords counting from the start of the text area.
8 (Fposn_at_x_y, make_lispy_event): Callers changed.
9
10 * window.c (coordinates_in_window): Change X and Y to ints rather
11 than pointers; don't return coordinates via pointers.
12 (struct check_window_data): Change X and Y from pointers to ints.
13 (window_from_coordinates): Remove args WX and WY; don't return
14 coordinates via pointers.
15 (Fcoordinates_in_window_p, window_from_coordinates):
16 (check_window_containing, Fwindow_at): Callers changed.
17 (window_relative_x_coord): New function.
18
19 * window.h (window_from_coordinates, window_relative_x_coord):
20 Update prototypes.
21
22 * dispnew.c (buffer_posn_from_coords): Assume that X counts from
23 the start of the text area.
24
25 * xdisp.c (remember_mouse_glyph): Change window_from_coordinates
26 call. Use window_relative_x_coord.
27 (note_mouse_highlight): Change window_from_coordinates call.
28
29 * w32term.c (w32_read_socket):
30 * msdos.c (dos_rawgetc):
31 * xterm.c (handle_one_xevent): Likewise.
32
12010-11-16 Dan Nicolaescu <dann@ics.uci.edu> 332010-11-16 Dan Nicolaescu <dann@ics.uci.edu>
2 34
3 * strftime.c (LOCALE_PARAM_DECL): Update for standard C. 35 * strftime.c (LOCALE_PARAM_DECL): Update for standard C.
diff --git a/src/dispnew.c b/src/dispnew.c
index 116d9972ba5..8835b458fd6 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5393,7 +5393,7 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p
5393 BYTEPOS (startp) = min (ZV_BYTE, max (BEGV_BYTE, BYTEPOS (startp))); 5393 BYTEPOS (startp) = min (ZV_BYTE, max (BEGV_BYTE, BYTEPOS (startp)));
5394 start_display (&it, w, startp); 5394 start_display (&it, w, startp);
5395 5395
5396 x0 = *x - WINDOW_LEFT_MARGIN_WIDTH (w); 5396 x0 = *x;
5397 5397
5398 /* First, move to the beginning of the row corresponding to *Y. We 5398 /* First, move to the beginning of the row corresponding to *Y. We
5399 need to be in that row to get the correct value of base paragraph 5399 need to be in that row to get the correct value of base paragraph
diff --git a/src/keyboard.c b/src/keyboard.c
index 017a4981b98..d048404e856 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -5243,24 +5243,22 @@ EMACS_INT double_click_fuzz;
5243 5243
5244int double_click_count; 5244int double_click_count;
5245 5245
5246/* Return position of a mouse click or wheel event */ 5246/* X and Y are frame-relative coordinates for a click or wheel event.
5247 Return a Lisp-style event list. */
5247 5248
5248static Lisp_Object 5249static Lisp_Object
5249make_lispy_position (struct frame *f, Lisp_Object *x, Lisp_Object *y, 5250make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
5250 unsigned long time) 5251 unsigned long time)
5251{ 5252{
5252 Lisp_Object window;
5253 enum window_part part; 5253 enum window_part part;
5254 Lisp_Object posn = Qnil; 5254 Lisp_Object posn = Qnil;
5255 Lisp_Object extra_info = Qnil; 5255 Lisp_Object extra_info = Qnil;
5256 int wx, wy; 5256 /* Coordinate pixel positions to return. */
5257 5257 int xret = 0, yret = 0;
5258 /* Set `window' to the window under frame pixel coordinates (x,y) */ 5258 /* The window under frame pixel coordinates (x,y) */
5259 if (f) 5259 Lisp_Object window = f
5260 window = window_from_coordinates (f, XINT (*x), XINT (*y), 5260 ? window_from_coordinates (f, XINT (x), XINT (y), &part, 0)
5261 &part, &wx, &wy, 0); 5261 : Qnil;
5262 else
5263 window = Qnil;
5264 5262
5265 if (WINDOWP (window)) 5263 if (WINDOWP (window))
5266 { 5264 {
@@ -5268,102 +5266,113 @@ make_lispy_position (struct frame *f, Lisp_Object *x, Lisp_Object *y,
5268 struct window *w = XWINDOW (window); 5266 struct window *w = XWINDOW (window);
5269 Lisp_Object string_info = Qnil; 5267 Lisp_Object string_info = Qnil;
5270 EMACS_INT textpos = -1; 5268 EMACS_INT textpos = -1;
5271 int rx = -1, ry = -1; 5269 int col = -1, row = -1;
5272 int dx = -1, dy = -1; 5270 int dx = -1, dy = -1;
5273 int width = -1, height = -1; 5271 int width = -1, height = -1;
5274 Lisp_Object object = Qnil; 5272 Lisp_Object object = Qnil;
5275 5273
5276 /* Set event coordinates to window-relative coordinates 5274 /* Pixel coordinates relative to the window corner. */
5277 for constructing the Lisp event below. */ 5275 int wx = XINT (x) - WINDOW_LEFT_EDGE_X (w);
5278 XSETINT (*x, wx); 5276 int wy = XINT (y) - WINDOW_TOP_EDGE_Y (w);
5279 XSETINT (*y, wy);
5280 5277
5278 /* For text area clicks, return X, Y relative to the corner of
5279 this text area. Note that dX, dY etc are set below, by
5280 buffer_posn_from_coords. */
5281 if (part == ON_TEXT) 5281 if (part == ON_TEXT)
5282 { 5282 {
5283 wx += WINDOW_LEFT_MARGIN_WIDTH (w); 5283 xret = XINT (x) - window_box_left (w, TEXT_AREA);
5284 yret = wy - WINDOW_HEADER_LINE_HEIGHT (w);
5284 } 5285 }
5286 /* For mode line and header line clicks, return X relative to
5287 the left window edge; ignore Y. Use mode_line_string to look
5288 for a string on the click position. */
5285 else if (part == ON_MODE_LINE || part == ON_HEADER_LINE) 5289 else if (part == ON_MODE_LINE || part == ON_HEADER_LINE)
5286 { 5290 {
5287 /* Mode line or header line. Look for a string under
5288 the mouse that may have a `local-map' property. */
5289 Lisp_Object string; 5291 Lisp_Object string;
5290 EMACS_INT charpos; 5292 EMACS_INT charpos;
5291 5293
5292 posn = part == ON_MODE_LINE ? Qmode_line : Qheader_line; 5294 posn = (part == ON_MODE_LINE) ? Qmode_line : Qheader_line;
5293 rx = wx, ry = wy; 5295 /* Note that mode_line_string takes COL, ROW as pixels and
5294 string = mode_line_string (w, part, &rx, &ry, &charpos, 5296 converts them to characters. */
5297 col = wx;
5298 row = wy;
5299 string = mode_line_string (w, part, &col, &row, &charpos,
5295 &object, &dx, &dy, &width, &height); 5300 &object, &dx, &dy, &width, &height);
5296 if (STRINGP (string)) 5301 if (STRINGP (string))
5297 string_info = Fcons (string, make_number (charpos)); 5302 string_info = Fcons (string, make_number (charpos));
5298 if (w == XWINDOW (selected_window) 5303 textpos = (w == XWINDOW (selected_window)
5299 && current_buffer == XBUFFER (w->buffer)) 5304 && current_buffer == XBUFFER (w->buffer))
5300 textpos = PT; 5305 ? PT : XMARKER (w->pointm)->charpos;
5301 else 5306
5302 textpos = XMARKER (w->pointm)->charpos; 5307 xret = wx;
5303 }
5304 else if (part == ON_VERTICAL_BORDER)
5305 {
5306 posn = Qvertical_line;
5307 wx = -1;
5308 dx = 0;
5309 width = 1;
5310 } 5308 }
5309 /* For fringes and margins, Y is relative to the area's (and the
5310 window's) top edge, while X is meaningless. */
5311 else if (part == ON_LEFT_MARGIN || part == ON_RIGHT_MARGIN) 5311 else if (part == ON_LEFT_MARGIN || part == ON_RIGHT_MARGIN)
5312 { 5312 {
5313 Lisp_Object string; 5313 Lisp_Object string;
5314 EMACS_INT charpos; 5314 EMACS_INT charpos;
5315 5315
5316 posn = (part == ON_LEFT_MARGIN) ? Qleft_margin : Qright_margin; 5316 posn = (part == ON_LEFT_MARGIN) ? Qleft_margin : Qright_margin;
5317 rx = wx, ry = wy; 5317 col = wx;
5318 string = marginal_area_string (w, part, &rx, &ry, &charpos, 5318 row = wy;
5319 string = marginal_area_string (w, part, &col, &row, &charpos,
5319 &object, &dx, &dy, &width, &height); 5320 &object, &dx, &dy, &width, &height);
5320 if (STRINGP (string)) 5321 if (STRINGP (string))
5321 string_info = Fcons (string, make_number (charpos)); 5322 string_info = Fcons (string, make_number (charpos));
5322 if (part == ON_LEFT_MARGIN) 5323 yret = wy - WINDOW_HEADER_LINE_HEIGHT (w);
5323 wx = 0;
5324 else
5325 wx = window_box_right_offset (w, TEXT_AREA) - 1;
5326 } 5324 }
5327 else if (part == ON_LEFT_FRINGE) 5325 else if (part == ON_LEFT_FRINGE)
5328 { 5326 {
5329 posn = Qleft_fringe; 5327 posn = Qleft_fringe;
5330 rx = 0; 5328 col = 0;
5331 dx = wx; 5329 dx = wx
5332 wx = (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) 5330 - (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
5333 ? 0 5331 ? 0 : window_box_width (w, LEFT_MARGIN_AREA));
5334 : window_box_width (w, LEFT_MARGIN_AREA)); 5332 dy = yret = wy - WINDOW_HEADER_LINE_HEIGHT (w);
5335 dx -= wx;
5336 } 5333 }
5337 else if (part == ON_RIGHT_FRINGE) 5334 else if (part == ON_RIGHT_FRINGE)
5338 { 5335 {
5339 posn = Qright_fringe; 5336 posn = Qright_fringe;
5340 rx = 0; 5337 col = 0;
5341 dx = wx; 5338 dx = wx
5342 wx = (window_box_width (w, LEFT_MARGIN_AREA) 5339 - window_box_width (w, LEFT_MARGIN_AREA)
5343 + window_box_width (w, TEXT_AREA) 5340 - window_box_width (w, TEXT_AREA)
5344 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) 5341 - (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
5345 ? window_box_width (w, RIGHT_MARGIN_AREA) 5342 ? window_box_width (w, RIGHT_MARGIN_AREA)
5346 : 0)); 5343 : 0);
5347 dx -= wx; 5344 dy = yret = wy - WINDOW_HEADER_LINE_HEIGHT (w);
5348 } 5345 }
5349 else 5346 else if (part == ON_VERTICAL_BORDER)
5350 { 5347 {
5351 /* Note: We have no special posn for part == ON_SCROLL_BAR. */ 5348 posn = Qvertical_line;
5352 wx = max (WINDOW_LEFT_MARGIN_WIDTH (w), wx); 5349 width = 1;
5350 dx = 0;
5351 dy = yret = wy;
5353 } 5352 }
5353 /* Nothing special for part == ON_SCROLL_BAR. */
5354 5354
5355 /* For clicks in the text area, fringes, or margins, call
5356 buffer_posn_from_coords to extract TEXTPOS, the buffer
5357 position nearest to the click. */
5355 if (textpos < 0) 5358 if (textpos < 0)
5356 { 5359 {
5357 Lisp_Object string2, object2 = Qnil; 5360 Lisp_Object string2, object2 = Qnil;
5358 struct display_pos p; 5361 struct display_pos p;
5359 int dx2, dy2; 5362 int dx2, dy2;
5360 int width2, height2; 5363 int width2, height2;
5361 string2 = buffer_posn_from_coords (w, &wx, &wy, &p, 5364 /* The pixel X coordinate passed to buffer_posn_from_coords
5365 is the X coordinate relative to the text area for
5366 text-area clicks, zero otherwise. */
5367 int x2 = (part == ON_TEXT) ? xret : 0;
5368 int y2 = wy;
5369
5370 string2 = buffer_posn_from_coords (w, &x2, &y2, &p,
5362 &object2, &dx2, &dy2, 5371 &object2, &dx2, &dy2,
5363 &width2, &height2); 5372 &width2, &height2);
5364 textpos = CHARPOS (p.pos); 5373 textpos = CHARPOS (p.pos);
5365 if (rx < 0) rx = wx; 5374 if (col < 0) col = x2;
5366 if (ry < 0) ry = wy; 5375 if (row < 0) row = y2;
5367 if (dx < 0) dx = dx2; 5376 if (dx < 0) dx = dx2;
5368 if (dy < 0) dy = dy2; 5377 if (dy < 0) dy = dy2;
5369 if (width < 0) width = width2; 5378 if (width < 0) width = width2;
@@ -5394,34 +5403,27 @@ make_lispy_position (struct frame *f, Lisp_Object *x, Lisp_Object *y,
5394#endif 5403#endif
5395 5404
5396 /* Object info */ 5405 /* Object info */
5397 extra_info = Fcons (object, 5406 extra_info
5398 Fcons (Fcons (make_number (dx), 5407 = list3 (object,
5399 make_number (dy)), 5408 Fcons (make_number (dx), make_number (dy)),
5400 Fcons (Fcons (make_number (width), 5409 Fcons (make_number (width), make_number (height)));
5401 make_number (height)),
5402 Qnil)));
5403 5410
5404 /* String info */ 5411 /* String info */
5405 extra_info = Fcons (string_info, 5412 extra_info = Fcons (string_info,
5406 Fcons (make_number (textpos), 5413 Fcons (make_number (textpos),
5407 Fcons (Fcons (make_number (rx), 5414 Fcons (Fcons (make_number (col),
5408 make_number (ry)), 5415 make_number (row)),
5409 extra_info))); 5416 extra_info)));
5410 } 5417 }
5411 else if (f != 0) 5418 else if (f != 0)
5412 { 5419 XSETFRAME (window, f);
5413 XSETFRAME (window, f);
5414 }
5415 else 5420 else
5416 { 5421 window = Qnil;
5417 window = Qnil;
5418 XSETFASTINT (*x, 0);
5419 XSETFASTINT (*y, 0);
5420 }
5421 5422
5422 return Fcons (window, 5423 return Fcons (window,
5423 Fcons (posn, 5424 Fcons (posn,
5424 Fcons (Fcons (*x, *y), 5425 Fcons (Fcons (make_number (xret),
5426 make_number (yret)),
5425 Fcons (make_number (time), 5427 Fcons (make_number (time),
5426 extra_info)))); 5428 extra_info))));
5427} 5429}
@@ -5610,14 +5612,6 @@ make_lispy_event (struct input_event *event)
5610 int hpos; 5612 int hpos;
5611 int i; 5613 int i;
5612 5614
5613#if 0
5614 /* Activate the menu bar on the down event. If the
5615 up event comes in before the menu code can deal with it,
5616 just ignore it. */
5617 if (! (event->modifiers & down_modifier))
5618 return Qnil;
5619#endif
5620
5621 /* Find the menu bar item under `column'. */ 5615 /* Find the menu bar item under `column'. */
5622 item = Qnil; 5616 item = Qnil;
5623 items = FRAME_MENU_BAR_ITEMS (f); 5617 items = FRAME_MENU_BAR_ITEMS (f);
@@ -5649,7 +5643,7 @@ make_lispy_event (struct input_event *event)
5649 } 5643 }
5650#endif /* not USE_X_TOOLKIT && not USE_GTK && not HAVE_NS */ 5644#endif /* not USE_X_TOOLKIT && not USE_GTK && not HAVE_NS */
5651 5645
5652 position = make_lispy_position (f, &event->x, &event->y, 5646 position = make_lispy_position (f, event->x, event->y,
5653 event->timestamp); 5647 event->timestamp);
5654 } 5648 }
5655#ifndef USE_TOOLKIT_SCROLL_BARS 5649#ifndef USE_TOOLKIT_SCROLL_BARS
@@ -5749,23 +5743,21 @@ make_lispy_event (struct input_event *event)
5749 return Qnil; 5743 return Qnil;
5750 5744
5751 event->modifiers &= ~up_modifier; 5745 event->modifiers &= ~up_modifier;
5752#if 0 /* Formerly we treated an up with no down as a click event. */ 5746
5753 if (!CONSP (start_pos))
5754 event->modifiers |= click_modifier;
5755 else
5756#endif
5757 { 5747 {
5758 Lisp_Object down; 5748 Lisp_Object new_down, down;
5759 EMACS_INT xdiff = double_click_fuzz, ydiff = double_click_fuzz; 5749 EMACS_INT xdiff = double_click_fuzz, ydiff = double_click_fuzz;
5760 5750
5761 /* The third element of every position 5751 /* The third element of every position
5762 should be the (x,y) pair. */ 5752 should be the (x,y) pair. */
5763 down = Fcar (Fcdr (Fcdr (start_pos))); 5753 down = Fcar (Fcdr (Fcdr (start_pos)));
5754 new_down = Fcar (Fcdr (Fcdr (position)));
5755
5764 if (CONSP (down) 5756 if (CONSP (down)
5765 && INTEGERP (XCAR (down)) && INTEGERP (XCDR (down))) 5757 && INTEGERP (XCAR (down)) && INTEGERP (XCDR (down)))
5766 { 5758 {
5767 xdiff = XINT (event->x) - XINT (XCAR (down)); 5759 xdiff = XINT (XCAR (new_down)) - XINT (XCAR (down));
5768 ydiff = XINT (event->y) - XINT (XCDR (down)); 5760 ydiff = XINT (XCDR (new_down)) - XINT (XCDR (down));
5769 } 5761 }
5770 5762
5771 if (ignore_mouse_drag_p) 5763 if (ignore_mouse_drag_p)
@@ -5848,7 +5840,7 @@ make_lispy_event (struct input_event *event)
5848 if (! FRAME_LIVE_P (f)) 5840 if (! FRAME_LIVE_P (f))
5849 return Qnil; 5841 return Qnil;
5850 5842
5851 position = make_lispy_position (f, &event->x, &event->y, 5843 position = make_lispy_position (f, event->x, event->y,
5852 event->timestamp); 5844 event->timestamp);
5853 5845
5854 /* Set double or triple modifiers to indicate the wheel speed. */ 5846 /* Set double or triple modifiers to indicate the wheel speed. */
@@ -5868,10 +5860,8 @@ make_lispy_event (struct input_event *event)
5868 else 5860 else
5869 abort (); 5861 abort ();
5870 5862
5871 if (FRAME_WINDOW_P (f)) 5863 fuzz = FRAME_WINDOW_P (f)
5872 fuzz = double_click_fuzz; 5864 ? double_click_fuzz : double_click_fuzz / 8;
5873 else
5874 fuzz = double_click_fuzz / 8;
5875 5865
5876 if (event->modifiers & up_modifier) 5866 if (event->modifiers & up_modifier)
5877 { 5867 {
@@ -6009,7 +5999,7 @@ make_lispy_event (struct input_event *event)
6009 if (! FRAME_LIVE_P (f)) 5999 if (! FRAME_LIVE_P (f))
6010 return Qnil; 6000 return Qnil;
6011 6001
6012 position = make_lispy_position (f, &event->x, &event->y, 6002 position = make_lispy_position (f, event->x, event->y,
6013 event->timestamp); 6003 event->timestamp);
6014 6004
6015 head = modify_event_symbol (0, event->modifiers, 6005 head = modify_event_symbol (0, event->modifiers,
@@ -6092,8 +6082,8 @@ make_lispy_event (struct input_event *event)
6092 start_pos_ptr = &AREF (button_down_location, button); 6082 start_pos_ptr = &AREF (button_down_location, button);
6093 start_pos = *start_pos_ptr; 6083 start_pos = *start_pos_ptr;
6094 6084
6095 position = make_lispy_position (f, &event->x, &event->y, 6085 position = make_lispy_position (f, event->x, event->y,
6096 event->timestamp); 6086 event->timestamp);
6097 6087
6098 if (event->modifiers & down_modifier) 6088 if (event->modifiers & down_modifier)
6099 *start_pos_ptr = Fcopy_alist (position); 6089 *start_pos_ptr = Fcopy_alist (position);
@@ -6152,25 +6142,19 @@ make_lispy_movement (FRAME_PTR frame, Lisp_Object bar_window, enum scroll_bar_pa
6152 6142
6153 part_sym = *scroll_bar_parts[(int) part]; 6143 part_sym = *scroll_bar_parts[(int) part];
6154 return Fcons (Qscroll_bar_movement, 6144 return Fcons (Qscroll_bar_movement,
6155 (Fcons (Fcons (bar_window, 6145 Fcons (list5 (bar_window,
6156 Fcons (Qvertical_scroll_bar, 6146 Qvertical_scroll_bar,
6157 Fcons (Fcons (x, y), 6147 Fcons (x, y),
6158 Fcons (make_number (time), 6148 make_number (time),
6159 Fcons (part_sym, 6149 part_sym),
6160 Qnil))))), 6150 Qnil));
6161 Qnil)));
6162 } 6151 }
6163
6164 /* Or is it an ordinary mouse movement? */ 6152 /* Or is it an ordinary mouse movement? */
6165 else 6153 else
6166 { 6154 {
6167 Lisp_Object position; 6155 Lisp_Object position;
6168 6156 position = make_lispy_position (frame, x, y, time);
6169 position = make_lispy_position (frame, &x, &y, time); 6157 return list2 (Qmouse_movement, position);
6170
6171 return Fcons (Qmouse_movement,
6172 Fcons (position,
6173 Qnil));
6174 } 6158 }
6175} 6159}
6176 6160
@@ -11327,7 +11311,7 @@ The `posn-' functions access elements of such lists. */)
11327 11311
11328 CHECK_LIVE_FRAME (frame_or_window); 11312 CHECK_LIVE_FRAME (frame_or_window);
11329 11313
11330 return make_lispy_position (XFRAME (frame_or_window), &x, &y, 0); 11314 return make_lispy_position (XFRAME (frame_or_window), x, y, 0);
11331} 11315}
11332 11316
11333DEFUN ("posn-at-point", Fposn_at_point, Sposn_at_point, 0, 2, 0, 11317DEFUN ("posn-at-point", Fposn_at_point, Sposn_at_point, 0, 2, 0,
diff --git a/src/msdos.c b/src/msdos.c
index 6593714ba1f..964fde0cbf5 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -2698,7 +2698,7 @@ dos_rawgetc (void)
2698 mouse_window = window_from_coordinates (SELECTED_FRAME(), 2698 mouse_window = window_from_coordinates (SELECTED_FRAME(),
2699 mouse_last_x, 2699 mouse_last_x,
2700 mouse_last_y, 2700 mouse_last_y,
2701 0, 0, 0, 0); 2701 0, 0);
2702 /* A window will be selected only when it is not 2702 /* A window will be selected only when it is not
2703 selected now, and the last mouse movement event was 2703 selected now, and the last mouse movement event was
2704 not in it. A minibuffer window will be selected iff 2704 not in it. A minibuffer window will be selected iff
diff --git a/src/w32term.c b/src/w32term.c
index 33b60c568c0..7145efbc604 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -4317,7 +4317,7 @@ w32_read_socket (struct terminal *terminal, int expected,
4317 int x = LOWORD (msg.msg.lParam); 4317 int x = LOWORD (msg.msg.lParam);
4318 int y = HIWORD (msg.msg.lParam); 4318 int y = HIWORD (msg.msg.lParam);
4319 4319
4320 window = window_from_coordinates (f, x, y, 0, 0, 0, 0); 4320 window = window_from_coordinates (f, x, y, 0, 0);
4321 4321
4322 /* Window will be selected only when it is not 4322 /* Window will be selected only when it is not
4323 selected now and last mouse movement event was 4323 selected now and last mouse movement event was
@@ -4396,7 +4396,7 @@ w32_read_socket (struct terminal *terminal, int expected,
4396 int x = XFASTINT (inev.x); 4396 int x = XFASTINT (inev.x);
4397 int y = XFASTINT (inev.y); 4397 int y = XFASTINT (inev.y);
4398 4398
4399 window = window_from_coordinates (f, x, y, 0, 0, 0, 1); 4399 window = window_from_coordinates (f, x, y, 0, 1);
4400 4400
4401 if (EQ (window, f->tool_bar_window)) 4401 if (EQ (window, f->tool_bar_window))
4402 { 4402 {
diff --git a/src/window.c b/src/window.c
index 086cd858c2e..a2a0c793111 100644
--- a/src/window.c
+++ b/src/window.c
@@ -755,32 +755,26 @@ display margins, fringes, header line, and/or mode line. */)
755 - WINDOW_MODE_LINE_HEIGHT (w) + add_y)); 755 - WINDOW_MODE_LINE_HEIGHT (w) + add_y));
756} 756}
757 757
758/* Test if the character at column *X, row *Y is within window W. 758/* Test if the character at column X, row Y is within window W.
759 If it is not, return ON_NOTHING; 759 If it is not, return ON_NOTHING;
760 if it is in the window's text area, 760 if it is in the window's text area, return ON_TEXT;
761 set *x and *y to its location relative to the upper left corner
762 of the window, and
763 return ON_TEXT;
764 if it is on the window's modeline, return ON_MODE_LINE; 761 if it is on the window's modeline, return ON_MODE_LINE;
765 if it is on the border between the window and its right sibling, 762 if it is on the border between the window and its right sibling,
766 return ON_VERTICAL_BORDER. 763 return ON_VERTICAL_BORDER.
767 if it is on a scroll bar, 764 if it is on a scroll bar, return ON_SCROLL_BAR.
768 return ON_SCROLL_BAR.
769 if it is on the window's top line, return ON_HEADER_LINE; 765 if it is on the window's top line, return ON_HEADER_LINE;
770 if it is in left or right fringe of the window, 766 if it is in left or right fringe of the window,
771 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y 767 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
772 to window-relative coordinates;
773 if it is in the marginal area to the left/right of the window, 768 if it is in the marginal area to the left/right of the window,
774 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y 769 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
775 to window-relative coordinates.
776 770
777 X and Y are frame relative pixel coordinates. */ 771 X and Y are frame relative pixel coordinates. */
778 772
779static enum window_part 773static enum window_part
780coordinates_in_window (register struct window *w, register int *x, register int *y) 774coordinates_in_window (register struct window *w, int x, int y)
781{ 775{
782 struct frame *f = XFRAME (WINDOW_FRAME (w)); 776 struct frame *f = XFRAME (WINDOW_FRAME (w));
783 int left_x, right_x, top_y, bottom_y; 777 int left_x, right_x;
784 enum window_part part; 778 enum window_part part;
785 int ux = FRAME_COLUMN_WIDTH (f); 779 int ux = FRAME_COLUMN_WIDTH (f);
786 int x0 = WINDOW_LEFT_EDGE_X (w); 780 int x0 = WINDOW_LEFT_EDGE_X (w);
@@ -789,6 +783,12 @@ coordinates_in_window (register struct window *w, register int *x, register int
789 (Between mode lines for instance. */ 783 (Between mode lines for instance. */
790 int grabbable_width = ux; 784 int grabbable_width = ux;
791 int lmargin_width, rmargin_width, text_left, text_right; 785 int lmargin_width, rmargin_width, text_left, text_right;
786 int top_y = WINDOW_TOP_EDGE_Y (w);
787 int bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
788
789 /* Outside any interesting row? */
790 if (y < top_y || y >= bottom_y)
791 return ON_NOTHING;
792 792
793 /* In what's below, we subtract 1 when computing right_x because we 793 /* In what's below, we subtract 1 when computing right_x because we
794 want the rightmost pixel, which is given by left_pixel+width-1. */ 794 want the rightmost pixel, which is given by left_pixel+width-1. */
@@ -796,21 +796,13 @@ coordinates_in_window (register struct window *w, register int *x, register int
796 { 796 {
797 left_x = 0; 797 left_x = 0;
798 right_x = WINDOW_TOTAL_WIDTH (w) - 1; 798 right_x = WINDOW_TOTAL_WIDTH (w) - 1;
799 top_y = WINDOW_TOP_EDGE_Y (w);
800 bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
801 } 799 }
802 else 800 else
803 { 801 {
804 left_x = WINDOW_BOX_LEFT_EDGE_X (w); 802 left_x = WINDOW_BOX_LEFT_EDGE_X (w);
805 right_x = WINDOW_BOX_RIGHT_EDGE_X (w) - 1; 803 right_x = WINDOW_BOX_RIGHT_EDGE_X (w) - 1;
806 top_y = WINDOW_TOP_EDGE_Y (w);
807 bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
808 } 804 }
809 805
810 /* Outside any interesting row? */
811 if (*y < top_y || *y >= bottom_y)
812 return ON_NOTHING;
813
814 /* On the mode line or header line? If it's near the start of 806 /* On the mode line or header line? If it's near the start of
815 the mode or header line of window that's has a horizontal 807 the mode or header line of window that's has a horizontal
816 sibling, say it's on the vertical line. That's to be able 808 sibling, say it's on the vertical line. That's to be able
@@ -818,7 +810,7 @@ coordinates_in_window (register struct window *w, register int *x, register int
818 scroll bars. */ 810 scroll bars. */
819 811
820 if (WINDOW_WANTS_MODELINE_P (w) 812 if (WINDOW_WANTS_MODELINE_P (w)
821 && *y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w)) 813 && y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w))
822 { 814 {
823 part = ON_MODE_LINE; 815 part = ON_MODE_LINE;
824 816
@@ -827,60 +819,37 @@ coordinates_in_window (register struct window *w, register int *x, register int
827 between mode lines of horizontally adjacent mode lines 819 between mode lines of horizontally adjacent mode lines
828 as the vertical border. If scroll bars on the left, 820 as the vertical border. If scroll bars on the left,
829 return the right window. */ 821 return the right window. */
830 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) 822 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
831 || WINDOW_RIGHTMOST_P (w)) 823 || WINDOW_RIGHTMOST_P (w))
832 { 824 && !WINDOW_LEFTMOST_P (w)
833 if (!WINDOW_LEFTMOST_P (w) && eabs (*x - x0) < grabbable_width) 825 && eabs (x - x0) < grabbable_width)
834 { 826 return ON_VERTICAL_BORDER;
835 /* Convert X and Y to window relative coordinates. 827
836 Vertical border is at the left edge of window. */ 828 /* Make sure we're not at the rightmost position of a
837 *x = max (0, *x - x0); 829 mode-/header-line and there's yet another window on the
838 *y -= top_y; 830 right. (Bug#1372) */
839 return ON_VERTICAL_BORDER; 831 else if ((WINDOW_RIGHTMOST_P (w) || x < x1)
840 } 832 && eabs (x - x1) < grabbable_width)
841 } 833 return ON_VERTICAL_BORDER;
842 else 834
843 { 835 if (x < x0 || x >= x1)
844 /* Make sure we're not at the rightmost position of a
845 mode-/header-line and there's yet another window on
846 the right. (Bug#1372) */
847 if ((WINDOW_RIGHTMOST_P (w) || *x < x1)
848 && eabs (*x - x1) < grabbable_width)
849 {
850 /* Convert X and Y to window relative coordinates.
851 Vertical border is at the right edge of window. */
852 *x = min (x1, *x) - x0;
853 *y -= top_y;
854 return ON_VERTICAL_BORDER;
855 }
856 }
857
858 if (*x < x0 || *x >= x1)
859 return ON_NOTHING; 836 return ON_NOTHING;
860 837
861 /* Convert X and Y to window relative coordinates.
862 Mode line starts at left edge of window. */
863 *x -= x0;
864 *y -= top_y;
865 return part; 838 return part;
866 } 839 }
867 840
868 if (WINDOW_WANTS_HEADER_LINE_P (w) 841 if (WINDOW_WANTS_HEADER_LINE_P (w)
869 && *y < top_y + CURRENT_HEADER_LINE_HEIGHT (w)) 842 && y < top_y + CURRENT_HEADER_LINE_HEIGHT (w))
870 { 843 {
871 part = ON_HEADER_LINE; 844 part = ON_HEADER_LINE;
872 goto header_vertical_border_check; 845 goto header_vertical_border_check;
873 } 846 }
874 847
875 if (*x < x0 || *x >= x1) 848 if (x < x0 || x >= x1) return ON_NOTHING;
876 return ON_NOTHING;
877 849
878 /* Outside any interesting column? */ 850 /* Outside any interesting column? */
879 if (*x < left_x || *x > right_x) 851 if (x < left_x || x > right_x)
880 { 852 return ON_SCROLL_BAR;
881 *y -= top_y;
882 return ON_SCROLL_BAR;
883 }
884 853
885 lmargin_width = window_box_width (w, LEFT_MARGIN_AREA); 854 lmargin_width = window_box_width (w, LEFT_MARGIN_AREA);
886 rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA); 855 rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA);
@@ -893,77 +862,79 @@ coordinates_in_window (register struct window *w, register int *x, register int
893 if (!w->pseudo_window_p 862 if (!w->pseudo_window_p
894 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w) 863 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w)
895 && !WINDOW_RIGHTMOST_P (w) 864 && !WINDOW_RIGHTMOST_P (w)
896 && (eabs (*x - right_x) < grabbable_width)) 865 && (eabs (x - right_x) < grabbable_width))
897 { 866 return ON_VERTICAL_BORDER;
898 /* Convert X and Y to window relative coordinates.
899 Vertical border is at the right edge of window. */
900 *x = min (right_x, *x) - left_x;
901 *y -= top_y;
902 return ON_VERTICAL_BORDER;
903 }
904 }
905 else
906 {
907 /* Need to say "*x > right_x" rather than >=, since on character
908 terminals, the vertical line's x coordinate is right_x. */
909 if (!w->pseudo_window_p
910 && !WINDOW_RIGHTMOST_P (w)
911 && *x > right_x - ux)
912 {
913 /* On the border on the right side of the window? Assume that
914 this area begins at RIGHT_X minus a canonical char width. */
915 *x = min (right_x, *x) - left_x;
916 *y -= top_y;
917 return ON_VERTICAL_BORDER;
918 }
919 } 867 }
868 /* Need to say "x > right_x" rather than >=, since on character
869 terminals, the vertical line's x coordinate is right_x. */
870 else if (!w->pseudo_window_p
871 && !WINDOW_RIGHTMOST_P (w)
872 && x > right_x - ux)
873 return ON_VERTICAL_BORDER;
920 874
921 if (*x < text_left) 875 if (x < text_left)
922 { 876 {
923 if (lmargin_width > 0 877 if (lmargin_width > 0
924 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) 878 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
925 ? (*x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w)) 879 ? (x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w))
926 : (*x < left_x + lmargin_width))) 880 : (x < left_x + lmargin_width)))
927 { 881 return ON_LEFT_MARGIN;
928 *x -= left_x;
929 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
930 *x -= WINDOW_LEFT_FRINGE_WIDTH (w);
931 *y -= top_y;
932 return ON_LEFT_MARGIN;
933 }
934 882
935 /* Convert X and Y to window-relative pixel coordinates. */
936 *x -= left_x;
937 *y -= top_y;
938 return ON_LEFT_FRINGE; 883 return ON_LEFT_FRINGE;
939 } 884 }
940 885
941 if (*x >= text_right) 886 if (x >= text_right)
942 { 887 {
943 if (rmargin_width > 0 888 if (rmargin_width > 0
944 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) 889 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
945 ? (*x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w)) 890 ? (x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w))
946 : (*x >= right_x - rmargin_width))) 891 : (x >= right_x - rmargin_width)))
947 { 892 return ON_RIGHT_MARGIN;
948 *x -= right_x - rmargin_width;
949 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
950 *x += WINDOW_RIGHT_FRINGE_WIDTH (w);
951 *y -= top_y;
952 return ON_RIGHT_MARGIN;
953 }
954 893
955 /* Convert X and Y to window-relative pixel coordinates. */
956 *x -= left_x + WINDOW_LEFT_FRINGE_WIDTH (w);
957 *y -= top_y;
958 return ON_RIGHT_FRINGE; 894 return ON_RIGHT_FRINGE;
959 } 895 }
960 896
961 /* Everything special ruled out - must be on text area */ 897 /* Everything special ruled out - must be on text area */
962 *x -= text_left;
963 *y -= top_y;
964 return ON_TEXT; 898 return ON_TEXT;
965} 899}
966 900
901/* Take X is the frame-relative pixel x-coordinate, and return the
902 x-coordinate relative to part PART of window W. */
903int
904window_relative_x_coord (struct window *w, enum window_part part, int x)
905{
906 int left_x = (w->pseudo_window_p) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w);
907
908 switch (part)
909 {
910 case ON_TEXT:
911 return x - window_box_left (w, TEXT_AREA);
912
913 case ON_LEFT_FRINGE:
914 return x - left_x;
915
916 case ON_RIGHT_FRINGE:
917 return x - left_x - WINDOW_LEFT_FRINGE_WIDTH (w);
918
919 case ON_LEFT_MARGIN:
920 return (x - left_x
921 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
922 ? WINDOW_LEFT_FRINGE_WIDTH (w) : 0));
923
924 case ON_RIGHT_MARGIN:
925 return (x + 1
926 - ((w->pseudo_window_p)
927 ? WINDOW_TOTAL_WIDTH (w)
928 : WINDOW_BOX_RIGHT_EDGE_X (w))
929 + window_box_width (w, RIGHT_MARGIN_AREA)
930 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w))
931 ? WINDOW_RIGHT_FRINGE_WIDTH (w) : 0));
932 }
933
934 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
935 return 0;
936}
937
967 938
968DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p, 939DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
969 Scoordinates_in_window_p, 2, 2, 0, 940 Scoordinates_in_window_p, 2, 2, 0,
@@ -1000,14 +971,16 @@ If they are in the windows's left or right marginal areas, `left-margin'\n\
1000 x = FRAME_PIXEL_X_FROM_CANON_X (f, lx) + FRAME_INTERNAL_BORDER_WIDTH (f); 971 x = FRAME_PIXEL_X_FROM_CANON_X (f, lx) + FRAME_INTERNAL_BORDER_WIDTH (f);
1001 y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly) + FRAME_INTERNAL_BORDER_WIDTH (f); 972 y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly) + FRAME_INTERNAL_BORDER_WIDTH (f);
1002 973
1003 switch (coordinates_in_window (w, &x, &y)) 974 switch (coordinates_in_window (w, x, y))
1004 { 975 {
1005 case ON_NOTHING: 976 case ON_NOTHING:
1006 return Qnil; 977 return Qnil;
1007 978
1008 case ON_TEXT: 979 case ON_TEXT:
1009 /* X and Y are now window relative pixel coordinates. Convert 980 /* Convert X and Y to window relative pixel coordinates, and
1010 them to canonical char units before returning them. */ 981 return the canonical char units. */
982 x -= window_box_left (w, TEXT_AREA);
983 y -= WINDOW_TOP_EDGE_Y (w);
1011 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f, x), 984 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f, x),
1012 FRAME_CANON_Y_FROM_PIXEL_Y (f, y)); 985 FRAME_CANON_Y_FROM_PIXEL_Y (f, y));
1013 986
@@ -1054,7 +1027,7 @@ If they are in the windows's left or right marginal areas, `left-margin'\n\
1054struct check_window_data 1027struct check_window_data
1055{ 1028{
1056 Lisp_Object *window; 1029 Lisp_Object *window;
1057 int *x, *y; 1030 int x, y;
1058 enum window_part *part; 1031 enum window_part *part;
1059}; 1032};
1060 1033
@@ -1081,8 +1054,7 @@ check_window_containing (struct window *w, void *user_data)
1081 return it as a Lisp_Object. 1054 return it as a Lisp_Object.
1082 1055
1083 If X, Y is on one of the window's special `window_part' elements, 1056 If X, Y is on one of the window's special `window_part' elements,
1084 set *PART to the id of that element, and return X and Y converted 1057 set *PART to the id of that element.
1085 to window relative coordinates in WX and WY.
1086 1058
1087 If there is no window under X, Y return nil and leave *PART 1059 If there is no window under X, Y return nil and leave *PART
1088 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows. 1060 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
@@ -1097,7 +1069,8 @@ check_window_containing (struct window *w, void *user_data)
1097 case. */ 1069 case. */
1098 1070
1099Lisp_Object 1071Lisp_Object
1100window_from_coordinates (struct frame *f, int x, int y, enum window_part *part, int *wx, int *wy, int tool_bar_p) 1072window_from_coordinates (struct frame *f, int x, int y,
1073 enum window_part *part, int tool_bar_p)
1101{ 1074{
1102 Lisp_Object window; 1075 Lisp_Object window;
1103 struct check_window_data cw; 1076 struct check_window_data cw;
@@ -1107,7 +1080,7 @@ window_from_coordinates (struct frame *f, int x, int y, enum window_part *part,
1107 part = &dummy; 1080 part = &dummy;
1108 1081
1109 window = Qnil; 1082 window = Qnil;
1110 cw.window = &window, cw.x = &x, cw.y = &y; cw.part = part; 1083 cw.window = &window, cw.x = x, cw.y = y; cw.part = part;
1111 foreach_window (f, check_window_containing, &cw); 1084 foreach_window (f, check_window_containing, &cw);
1112 1085
1113 /* If not found above, see if it's in the tool bar window, if a tool 1086 /* If not found above, see if it's in the tool bar window, if a tool
@@ -1116,16 +1089,13 @@ window_from_coordinates (struct frame *f, int x, int y, enum window_part *part,
1116 && tool_bar_p 1089 && tool_bar_p
1117 && WINDOWP (f->tool_bar_window) 1090 && WINDOWP (f->tool_bar_window)
1118 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0 1091 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0
1119 && (coordinates_in_window (XWINDOW (f->tool_bar_window), &x, &y) 1092 && (coordinates_in_window (XWINDOW (f->tool_bar_window), x, y)
1120 != ON_NOTHING)) 1093 != ON_NOTHING))
1121 { 1094 {
1122 *part = ON_TEXT; 1095 *part = ON_TEXT;
1123 window = f->tool_bar_window; 1096 window = f->tool_bar_window;
1124 } 1097 }
1125 1098
1126 if (wx) *wx = x;
1127 if (wy) *wy = y;
1128
1129 return window; 1099 return window;
1130} 1100}
1131 1101
@@ -1152,7 +1122,7 @@ column 0. */)
1152 + FRAME_INTERNAL_BORDER_WIDTH (f)), 1122 + FRAME_INTERNAL_BORDER_WIDTH (f)),
1153 (FRAME_PIXEL_Y_FROM_CANON_Y (f, y) 1123 (FRAME_PIXEL_Y_FROM_CANON_Y (f, y)
1154 + FRAME_INTERNAL_BORDER_WIDTH (f)), 1124 + FRAME_INTERNAL_BORDER_WIDTH (f)),
1155 0, 0, 0, 0); 1125 0, 0);
1156} 1126}
1157 1127
1158DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0, 1128DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
diff --git a/src/window.h b/src/window.h
index e9529487b14..c1148836d79 100644
--- a/src/window.h
+++ b/src/window.h
@@ -788,8 +788,7 @@ EXFUN (Fset_window_point, 2);
788extern Lisp_Object make_window (void); 788extern Lisp_Object make_window (void);
789extern void delete_window (Lisp_Object); 789extern void delete_window (Lisp_Object);
790extern Lisp_Object window_from_coordinates (struct frame *, int, int, 790extern Lisp_Object window_from_coordinates (struct frame *, int, int,
791 enum window_part *, 791 enum window_part *, int);
792 int *, int*, int);
793EXFUN (Fwindow_dedicated_p, 1); 792EXFUN (Fwindow_dedicated_p, 1);
794extern int window_height (Lisp_Object); 793extern int window_height (Lisp_Object);
795extern int window_width (Lisp_Object); 794extern int window_width (Lisp_Object);
@@ -804,6 +803,7 @@ extern void foreach_window (struct frame *,
804 void *); 803 void *);
805extern void grow_mini_window (struct window *, int); 804extern void grow_mini_window (struct window *, int);
806extern void shrink_mini_window (struct window *); 805extern void shrink_mini_window (struct window *);
806extern int window_relative_x_coord (struct window *, enum window_part, int);
807 807
808void run_window_configuration_change_hook (struct frame *f); 808void run_window_configuration_change_hook (struct frame *f);
809 809
diff --git a/src/xdisp.c b/src/xdisp.c
index 21c89088383..d3ebc1a4a8a 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -2218,7 +2218,7 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
2218 frame pixel coordinates X/Y on frame F. */ 2218 frame pixel coordinates X/Y on frame F. */
2219 2219
2220 if (!f->glyphs_initialized_p 2220 if (!f->glyphs_initialized_p
2221 || (window = window_from_coordinates (f, gx, gy, &part, &x, &y, 0), 2221 || (window = window_from_coordinates (f, gx, gy, &part, 0),
2222 NILP (window))) 2222 NILP (window)))
2223 { 2223 {
2224 width = FRAME_SMALLEST_CHAR_WIDTH (f); 2224 width = FRAME_SMALLEST_CHAR_WIDTH (f);
@@ -2230,6 +2230,9 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
2230 width = WINDOW_FRAME_COLUMN_WIDTH (w); 2230 width = WINDOW_FRAME_COLUMN_WIDTH (w);
2231 height = WINDOW_FRAME_LINE_HEIGHT (w); 2231 height = WINDOW_FRAME_LINE_HEIGHT (w);
2232 2232
2233 x = window_relative_x_coord (w, part, gx);
2234 y = gy - WINDOW_TOP_EDGE_Y (w);
2235
2233 r = MATRIX_FIRST_TEXT_ROW (w->current_matrix); 2236 r = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
2234 end_row = MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w); 2237 end_row = MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w);
2235 2238
@@ -25383,7 +25386,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
25383 } 25386 }
25384 25387
25385 /* Which window is that in? */ 25388 /* Which window is that in? */
25386 window = window_from_coordinates (f, x, y, &part, 0, 0, 1); 25389 window = window_from_coordinates (f, x, y, &part, 1);
25387 25390
25388 /* If we were displaying active text in another window, clear that. 25391 /* If we were displaying active text in another window, clear that.
25389 Also clear if we move out of text area in same window. */ 25392 Also clear if we move out of text area in same window. */
diff --git a/src/xterm.c b/src/xterm.c
index 331ff9ab4a9..eaa19523970 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -6658,7 +6658,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventp, int *finish,
6658 6658
6659 window = window_from_coordinates (f, 6659 window = window_from_coordinates (f,
6660 event.xmotion.x, event.xmotion.y, 6660 event.xmotion.x, event.xmotion.y,
6661 0, 0, 0, 0); 6661 0, 0);
6662 6662
6663 /* Window will be selected only when it is not selected now and 6663 /* Window will be selected only when it is not selected now and
6664 last mouse movement event was not in it. Minibuffer window 6664 last mouse movement event was not in it. Minibuffer window
@@ -6797,7 +6797,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventp, int *finish,
6797 int x = event.xbutton.x; 6797 int x = event.xbutton.x;
6798 int y = event.xbutton.y; 6798 int y = event.xbutton.y;
6799 6799
6800 window = window_from_coordinates (f, x, y, 0, 0, 0, 1); 6800 window = window_from_coordinates (f, x, y, 0, 1);
6801 tool_bar_p = EQ (window, f->tool_bar_window); 6801 tool_bar_p = EQ (window, f->tool_bar_window);
6802 6802
6803 if (tool_bar_p && event.xbutton.button < 4) 6803 if (tool_bar_p && event.xbutton.button < 4)