From 18da0d8ad4e5036185acbad3238cbfe2aaf3ca66 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 18 Sep 2013 13:23:10 +0400 Subject: [PATCH] * frame.c (x_redo_mouse_highlight): New function to factor out common code used in W32 and X ports. * dispextern.h (x_redo_mouse_highlight): Add prototype. * xterm.h (struct x_display_info): * w32term.h (struct w32_display_info): * nsterm.h (struct ns_display_info): New members last_mouse_motion_frame, last_mouse_motion_x and last_mouse_motion_y, going to replace static variables below. * xterm.c (last_mouse_motion_event, last_mouse_motion_frame) (redo_mouse_highlight): Remove. (note_mouse_movement, syms_of_xterm): Adjust user. (handle_one_xevent): Likewise. Use x_redo_mouse_highlight. * w32term.c (last_mouse_motion_event, last_mouse_motion_frame) (redo_mouse_highlight): Remove. (note_mouse_movement, syms_of_w32term): Adjust user. (w32_read_socket): Likewise. Use x_redo_mouse_highlight. * nsterm.m (last_mouse_motion_position, last_mouse_motion_frame): Remove. (note_mouse_movement, mouseMoved, syms_of_nsterm): * nsfns.m (compute_tip_xy): Adjust user. --- src/ChangeLog | 23 +++++++++++++++++++++++ src/dispextern.h | 1 + src/frame.c | 13 +++++++++++++ src/nsfns.m | 4 +++- src/nsterm.h | 9 ++++++++- src/nsterm.m | 22 +++++++++------------- src/w32term.c | 31 +++++++++---------------------- src/w32term.h | 8 ++++++++ src/xterm.c | 35 ++++++++--------------------------- src/xterm.h | 8 ++++++++ 10 files changed, 90 insertions(+), 64 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b5bdf1dca70..55345027811 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,26 @@ +2013-09-18 Dmitry Antipov + + * frame.c (x_redo_mouse_highlight): New function + to factor out common code used in W32 and X ports. + * dispextern.h (x_redo_mouse_highlight): Add prototype. + * xterm.h (struct x_display_info): + * w32term.h (struct w32_display_info): + * nsterm.h (struct ns_display_info): New members + last_mouse_motion_frame, last_mouse_motion_x and + last_mouse_motion_y, going to replace static variables below. + * xterm.c (last_mouse_motion_event, last_mouse_motion_frame) + (redo_mouse_highlight): Remove. + (note_mouse_movement, syms_of_xterm): Adjust user. + (handle_one_xevent): Likewise. Use x_redo_mouse_highlight. + * w32term.c (last_mouse_motion_event, last_mouse_motion_frame) + (redo_mouse_highlight): Remove. + (note_mouse_movement, syms_of_w32term): Adjust user. + (w32_read_socket): Likewise. Use x_redo_mouse_highlight. + * nsterm.m (last_mouse_motion_position, last_mouse_motion_frame): + Remove. + (note_mouse_movement, mouseMoved, syms_of_nsterm): + * nsfns.m (compute_tip_xy): Adjust user. + 2013-09-18 Dmitry Antipov * frame.c (x_mouse_grabbed): New function. diff --git a/src/dispextern.h b/src/dispextern.h index c8af00ad915..7244c84893d 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3545,6 +3545,7 @@ extern Lisp_Object x_default_parameter (struct frame *, Lisp_Object, enum resource_types); extern char *x_get_string_resource (XrmDatabase, const char *, const char *); +extern void x_redo_mouse_highlight (Display_Info *); #endif /* HAVE_WINDOW_SYSTEM */ diff --git a/src/frame.c b/src/frame.c index a31bf35aa6b..997cc9c73ae 100644 --- a/src/frame.c +++ b/src/frame.c @@ -3442,6 +3442,19 @@ bool x_mouse_grabbed (Display_Info *dpyinfo) && FRAME_LIVE_P (dpyinfo->last_mouse_frame)); } +/* Re-highlight something with mouse-face properties + on DPYINFO using saved frame and mouse position. */ + +void +x_redo_mouse_highlight (Display_Info *dpyinfo) +{ + if (dpyinfo->last_mouse_motion_frame + && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame)) + note_mouse_highlight (dpyinfo->last_mouse_motion_frame, + dpyinfo->last_mouse_motion_x, + dpyinfo->last_mouse_motion_y); +} + /* Subroutines of creating an X frame. */ /* Make sure that Vx_resource_name is set to a reasonable value. diff --git a/src/nsfns.m b/src/nsfns.m index 408e6d2176e..93b7d12becb 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -2564,6 +2564,7 @@ compute_tip_xy (struct frame *f, { Lisp_Object left, top; EmacsView *view = FRAME_NS_VIEW (f); + struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); NSPoint pt; /* Start with user-specified or mouse position. */ @@ -2572,7 +2573,8 @@ compute_tip_xy (struct frame *f, if (!INTEGERP (left) || !INTEGERP (top)) { - pt = last_mouse_motion_position; + pt.x = dpyinfo->last_mouse_motion_x; + pt.y = dpyinfo->last_mouse_motion_y; /* Convert to screen coordinates */ pt = [view convertPoint: pt toView: nil]; pt = [[view window] convertBaseToScreen: pt]; diff --git a/src/nsterm.h b/src/nsterm.h index 373e06cefd2..7a626c75fe6 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -600,6 +600,14 @@ struct ns_display_info /* The frame where the mouse was last time we reported a mouse event. */ struct frame *last_mouse_frame; + + /* The frame where the mouse was last time we reported a mouse motion. */ + struct frame *last_mouse_motion_frame; + + /* Position where the mouse was last time we reported a motion. + This is a position on last_mouse_motion_frame. */ + int last_mouse_motion_x; + int last_mouse_motion_y; }; /* This is a chain of structures for all the NS displays currently in use. */ @@ -869,7 +877,6 @@ extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds, sigset_t const *sigmask); extern unsigned long ns_get_rgb_color (struct frame *f, float r, float g, float b, float a); -extern NSPoint last_mouse_motion_position; /* From nsterm.m, needed in nsfont.m. */ #ifdef __OBJC__ diff --git a/src/nsterm.m b/src/nsterm.m index d41bd856b0c..dc27fd09e30 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -191,10 +191,8 @@ Lisp_Object ns_display_name_list; long context_menu_value = 0; /* display update */ -NSPoint last_mouse_motion_position; static NSRect last_mouse_glyph; static Time last_mouse_movement_time = 0; -static Lisp_Object last_mouse_motion_frame; static EmacsScroller *last_mouse_scroll_bar = nil; static struct frame *ns_updating_frame; static NSView *focus_view = NULL; @@ -1742,7 +1740,7 @@ note_mouse_movement (struct frame *frame, CGFloat x, CGFloat y) { // NSTRACE (note_mouse_movement); - XSETFRAME (last_mouse_motion_frame, frame); + FRAME_DISPLAY_INFO (frame)->last_mouse_motion_frame = frame; /* Note, this doesn't get called for enter/leave, since we don't have a position. Those are taken care of in the corresponding NSView methods. */ @@ -5448,13 +5446,16 @@ not_in_argv (NSString *arg) - (void)mouseMoved: (NSEvent *)e { Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (emacsframe); + struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe); Lisp_Object frame; + NSPoint pt; // NSTRACE (mouseMoved); last_mouse_movement_time = EV_TIMESTAMP (e); - last_mouse_motion_position - = [self convertPoint: [e locationInWindow] fromView: nil]; + pt = [self convertPoint: [e locationInWindow] fromView: nil]; + dpyinfo->last_mouse_motion_x = pt.x; + dpyinfo->last_mouse_motion_y = pt.y; /* update any mouse face */ if (hlinfo->mouse_face_hidden) @@ -5471,9 +5472,8 @@ not_in_argv (NSString *arg) { NSTRACE (mouse_autoselect_window); static Lisp_Object last_mouse_window; - Lisp_Object window = window_from_coordinates - (emacsframe, last_mouse_motion_position.x, - last_mouse_motion_position.y, 0, 0); + Lisp_Object window + = window_from_coordinates (emacsframe, pt.x, pt.y, 0, 0); if (WINDOWP (window) && !EQ (window, last_mouse_window) @@ -5491,8 +5491,7 @@ not_in_argv (NSString *arg) last_mouse_window = window; } - if (!note_mouse_movement (emacsframe, last_mouse_motion_position.x, - last_mouse_motion_position.y)) + if (!note_mouse_movement (emacsframe, pt.x, pt.y)) help_echo_string = previous_help_echo_string; XSETFRAME (frame, emacsframe); @@ -7416,9 +7415,6 @@ allowing it to be used at a lower level for accented character entry."); staticpro (&ns_display_name_list); ns_display_name_list = Qnil; - staticpro (&last_mouse_motion_frame); - last_mouse_motion_frame = Qnil; - DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar, doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near. Only works on OSX 10.6 or later. */); diff --git a/src/w32term.c b/src/w32term.c index 97dda0e8c55..7c0a3987d1e 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -3304,22 +3304,22 @@ queue_notifications (struct input_event *event, W32Msg *msg, struct frame *f, the mainstream emacs code by setting mouse_moved. If not, ask for another motion event, so we can check again the next time it moves. */ -static MSG last_mouse_motion_event; -static Lisp_Object last_mouse_motion_frame; - static int note_mouse_movement (struct frame *frame, MSG *msg) { + struct w32_display_info *dpyinfo; int mouse_x = LOWORD (msg->lParam); int mouse_y = HIWORD (msg->lParam); - last_mouse_movement_time = msg->time; - memcpy (&last_mouse_motion_event, msg, sizeof (last_mouse_motion_event)); - XSETFRAME (last_mouse_motion_frame, frame); - - if (!FRAME_X_OUTPUT (frame)) + if (!FRAME_W32_OUTPUT (frame)) return 0; + dpyinfo = FRAME_DISPLAY_INFO (frame); + last_mouse_movement_time = msg->time; + dpyinfo->last_mouse_motion_frame = frame; + dpyinfo->last_mouse_motion_x = mouse_x; + dpyinfo->last_mouse_motion_y = mouse_y; + if (msg->hwnd != FRAME_W32_WINDOW (frame)) { frame->mouse_moved = 1; @@ -3363,16 +3363,6 @@ static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *, unsigned long *); static void x_check_fullscreen (struct frame *); -static void -redo_mouse_highlight (void) -{ - if (!NILP (last_mouse_motion_frame) - && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame))) - note_mouse_highlight (XFRAME (last_mouse_motion_frame), - LOWORD (last_mouse_motion_event.lParam), - HIWORD (last_mouse_motion_event.lParam)); -} - static void w32_define_cursor (Window window, Cursor cursor) { @@ -4683,7 +4673,7 @@ w32_read_socket (struct terminal *terminal, if (!msg.msg.wParam && msg.msg.hwnd == tip_window) { tip_window = NULL; - redo_mouse_highlight (); + x_redo_mouse_highlight (dpyinfo); } /* If window has been obscured or exposed by another window @@ -6649,9 +6639,6 @@ X toolkit. Possible values are: gtk, motif, xaw, or xaw3d. With MS Windows or Nextstep, the value is t. */); Vx_toolkit_scroll_bars = Qt; - staticpro (&last_mouse_motion_frame); - last_mouse_motion_frame = Qnil; - /* Tell Emacs about this window system. */ Fprovide (Qw32, Qnil); } diff --git a/src/w32term.h b/src/w32term.h index d29cab35ded..ef7f0842680 100644 --- a/src/w32term.h +++ b/src/w32term.h @@ -185,6 +185,14 @@ struct w32_display_info /* The frame where the mouse was last time we reported a mouse event. */ struct frame *last_mouse_frame; + + /* The frame where the mouse was last time we reported a mouse motion. */ + struct frame *last_mouse_motion_frame; + + /* Position where the mouse was last time we reported a motion. + This is a position on last_mouse_motion_frame. */ + int last_mouse_motion_x; + int last_mouse_motion_y; }; /* This is a chain of structures for all the displays currently in use. */ diff --git a/src/xterm.c b/src/xterm.c index 7d8c40b8cf0..9e10037685b 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -3860,19 +3860,20 @@ construct_mouse_click (struct input_event *result, the mainstream emacs code by setting mouse_moved. If not, ask for another motion event, so we can check again the next time it moves. */ -static XMotionEvent last_mouse_motion_event; -static Lisp_Object last_mouse_motion_frame; - static int note_mouse_movement (struct frame *frame, const XMotionEvent *event) { - last_mouse_movement_time = event->time; - last_mouse_motion_event = *event; - XSETFRAME (last_mouse_motion_frame, frame); + struct x_display_info *dpyinfo; if (!FRAME_X_OUTPUT (frame)) return 0; + dpyinfo = FRAME_DISPLAY_INFO (frame); + last_mouse_movement_time = event->time; + dpyinfo->last_mouse_motion_frame = frame; + dpyinfo->last_mouse_motion_x = event->x; + dpyinfo->last_mouse_motion_y = event->y; + if (event->window != FRAME_X_WINDOW (frame)) { frame->mouse_moved = 1; @@ -3902,23 +3903,6 @@ note_mouse_movement (struct frame *frame, const XMotionEvent *event) return 0; } - -/************************************************************************ - Mouse Face - ************************************************************************/ - -static void -redo_mouse_highlight (void) -{ - if (!NILP (last_mouse_motion_frame) - && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame))) - note_mouse_highlight (XFRAME (last_mouse_motion_frame), - last_mouse_motion_event.x, - last_mouse_motion_event.y); -} - - - /* Return the current position of the mouse. *FP should be a frame which indicates which display to ask about. @@ -6223,7 +6207,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (event->xunmap.window == tip_window) { tip_window = 0; - redo_mouse_highlight (); + x_redo_mouse_highlight (dpyinfo); } f = x_top_window_to_frame (dpyinfo, event->xunmap.window); @@ -10705,9 +10689,6 @@ With MS Windows or Nextstep, the value is t. */); Vx_toolkit_scroll_bars = Qnil; #endif - staticpro (&last_mouse_motion_frame); - last_mouse_motion_frame = Qnil; - Qmodifier_value = intern_c_string ("modifier-value"); Qalt = intern_c_string ("alt"); Fput (Qalt, Qmodifier_value, make_number (alt_modifier)); diff --git a/src/xterm.h b/src/xterm.h index f1bfc883a64..9f01a840e53 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -308,9 +308,17 @@ struct x_display_info /* The frame where the mouse was last time we reported a mouse event. */ struct frame *last_mouse_frame; + /* The frame where the mouse was last time we reported a mouse motion. */ + struct frame *last_mouse_motion_frame; + /* Time of last user interaction as returned in X events on this display. */ Time last_user_time; + /* Position where the mouse was last time we reported a motion. + This is a position on last_mouse_motion_frame. */ + int last_mouse_motion_x; + int last_mouse_motion_y; + /* The gray pixmap. */ Pixmap gray; -- 2.39.2