From: Dmitry Antipov Date: Wed, 18 Sep 2013 06:48:11 +0000 (+0400) Subject: * frame.c (x_mouse_grabbed): New function. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1535 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7a0c745ad134aff0bb8f4258ea607137a819b58d;p=emacs.git * frame.c (x_mouse_grabbed): New function. * dispextern.h (x_mouse_grabbed): Add prototype. (last_mouse_frame): Remove declaration. * xterm.h (struct x_display_info): * w32term.h (struct w32_display_info): * nsterm.h (struct ns_display_info): New member last_mouse_frame, going to replace... * xdisp.c (last_mouse_frame): ...global variable. (note_tool_bar_highlight): * w32term.c (w32_mouse_position, w32_read_socket): * xterm.c (XTmouse_position, handle_one_xevent): Use x_mouse_grabbed. * nsterm.m (ns_mouse_position, mouseDown): Adjust user. --- diff --git a/src/ChangeLog b/src/ChangeLog index 4223573a6ff..b5bdf1dca70 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +2013-09-18 Dmitry Antipov + + * frame.c (x_mouse_grabbed): New function. + * dispextern.h (x_mouse_grabbed): Add prototype. + (last_mouse_frame): Remove declaration. + * xterm.h (struct x_display_info): + * w32term.h (struct w32_display_info): + * nsterm.h (struct ns_display_info): New member + last_mouse_frame, going to replace... + * xdisp.c (last_mouse_frame): ...global variable. + (note_tool_bar_highlight): + * w32term.c (w32_mouse_position, w32_read_socket): + * xterm.c (XTmouse_position, handle_one_xevent): + Use x_mouse_grabbed. + * nsterm.m (ns_mouse_position, mouseDown): Adjust user. + 2013-09-17 Dmitry Antipov * w32term.c (w32_read_socket): Avoid temporary diff --git a/src/dispextern.h b/src/dispextern.h index e91403bce68..c8af00ad915 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3194,7 +3194,6 @@ extern int help_echo_showing_p; extern Lisp_Object help_echo_string, help_echo_window; extern Lisp_Object help_echo_object, previous_help_echo_string; extern ptrdiff_t help_echo_pos; -extern struct frame *last_mouse_frame; extern int last_tool_bar_item; extern void reseat_at_previous_visible_line_start (struct it *); extern Lisp_Object lookup_glyphless_char_display (int, struct it *); @@ -3531,6 +3530,7 @@ enum resource_types RES_TYPE_BOOLEAN_NUMBER }; +extern bool x_mouse_grabbed (Display_Info *); extern Display_Info *check_x_display_info (Lisp_Object); extern Lisp_Object x_get_arg (Display_Info *, Lisp_Object, Lisp_Object, const char *, const char *class, diff --git a/src/frame.c b/src/frame.c index 365629d0f48..a31bf35aa6b 100644 --- a/src/frame.c +++ b/src/frame.c @@ -3432,7 +3432,16 @@ x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval) return; } - +/* Non-zero if mouse is grabbed on DPYINFO + and we know the frame where it is. */ + +bool x_mouse_grabbed (Display_Info *dpyinfo) +{ + return (dpyinfo->grabbed + && dpyinfo->last_mouse_frame + && FRAME_LIVE_P (dpyinfo->last_mouse_frame)); +} + /* Subroutines of creating an X frame. */ /* Make sure that Vx_resource_name is set to a reasonable value. diff --git a/src/nsterm.h b/src/nsterm.h index 30ae871da83..373e06cefd2 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -597,6 +597,9 @@ struct ns_display_info struct frame *x_highlight_frame; struct frame *x_focus_frame; + + /* The frame where the mouse was last time we reported a mouse event. */ + struct frame *last_mouse_frame; }; /* This is a chain of structures for all the NS displays currently in use. */ diff --git a/src/nsterm.m b/src/nsterm.m index 6c5f5f54cb9..d41bd856b0c 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1812,8 +1812,9 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, XFRAME (frame)->mouse_moved = 0; last_mouse_scroll_bar = nil; - if (last_mouse_frame && FRAME_LIVE_P (last_mouse_frame)) - f = last_mouse_frame; + if (dpyinfo->last_mouse_frame + && FRAME_LIVE_P (dpyinfo->last_mouse_frame)) + f = dpyinfo->last_mouse_frame; else f = dpyinfo->x_focus_frame ? dpyinfo->x_focus_frame : SELECTED_FRAME (); @@ -5362,6 +5363,7 @@ not_in_argv (NSString *arg) /* This is what happens when the user presses a mouse button. */ - (void)mouseDown: (NSEvent *)theEvent { + struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe); NSPoint p = [self convertPoint: [theEvent locationInWindow] fromView: nil]; NSTRACE (mouseDown); @@ -5371,10 +5373,10 @@ not_in_argv (NSString *arg) if (!emacs_event) return; - last_mouse_frame = emacsframe; + dpyinfo->last_mouse_frame = emacsframe; /* appears to be needed to prevent spurious movement events generated on button clicks */ - last_mouse_frame->mouse_moved = 0; + emacsframe->mouse_moved = 0; if ([theEvent type] == NSScrollWheel) { diff --git a/src/w32term.c b/src/w32term.c index 331a86ef7d7..97dda0e8c55 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -3404,6 +3404,7 @@ w32_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, unsigned long *time) { struct frame *f1; + struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (*fp); block_input (); @@ -3426,19 +3427,11 @@ w32_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, /* Now we have a position on the root; find the innermost window containing the pointer. */ { - if (FRAME_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame - && FRAME_LIVE_P (last_mouse_frame)) - { - /* If mouse was grabbed on a frame, give coords for that frame - even if the mouse is now outside it. */ - f1 = last_mouse_frame; - } - else - { - /* Is window under mouse one of our frames? */ - f1 = x_any_window_to_frame (FRAME_DISPLAY_INFO (*fp), - WindowFromPoint (pt)); - } + /* If mouse was grabbed on a frame, give coords for that + frame even if the mouse is now outside it. Otherwise + check for window under mouse on one of our frames. */ + f1 = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame + : x_any_window_to_frame (dpyinfo, WindowFromPoint (pt))); /* If not, is it one of our scroll bars? */ if (! f1) @@ -4479,11 +4472,8 @@ w32_read_socket (struct terminal *terminal, previous_help_echo_string = help_echo_string; help_echo_string = Qnil; - if (dpyinfo->grabbed && last_mouse_frame - && FRAME_LIVE_P (last_mouse_frame)) - f = last_mouse_frame; - else - f = x_window_to_frame (dpyinfo, msg.msg.hwnd); + f = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame + : x_window_to_frame (dpyinfo, msg.msg.hwnd)); if (hlinfo->mouse_face_hidden) { @@ -4559,11 +4549,8 @@ w32_read_socket (struct terminal *terminal, int button; int up; - if (dpyinfo->grabbed && last_mouse_frame - && FRAME_LIVE_P (last_mouse_frame)) - f = last_mouse_frame; - else - f = x_window_to_frame (dpyinfo, msg.msg.hwnd); + f = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame + : x_window_to_frame (dpyinfo, msg.msg.hwnd)); if (f) { @@ -4602,7 +4589,7 @@ w32_read_socket (struct terminal *terminal, else { dpyinfo->grabbed |= (1 << button); - last_mouse_frame = f; + dpyinfo->last_mouse_frame = f; /* Ignore any mouse motion that happened before this event; any subsequent mouse-movement Emacs events should reflect only motion after @@ -4619,11 +4606,8 @@ w32_read_socket (struct terminal *terminal, case WM_MOUSEWHEEL: case WM_MOUSEHWHEEL: { - if (dpyinfo->grabbed && last_mouse_frame - && FRAME_LIVE_P (last_mouse_frame)) - f = last_mouse_frame; - else - f = x_window_to_frame (dpyinfo, msg.msg.hwnd); + f = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame + : x_window_to_frame (dpyinfo, msg.msg.hwnd)); if (f) { @@ -4640,7 +4624,7 @@ w32_read_socket (struct terminal *terminal, ButtonPress. */ f->mouse_moved = 0; } - last_mouse_frame = f; + dpyinfo->last_mouse_frame = f; last_tool_bar_item = -1; } break; diff --git a/src/w32term.h b/src/w32term.h index 99253627e64..d29cab35ded 100644 --- a/src/w32term.h +++ b/src/w32term.h @@ -182,6 +182,9 @@ struct w32_display_info /* The frame waiting to be auto-raised in w32_read_socket. */ struct frame *w32_pending_autoraise_frame; + + /* The frame where the mouse was last time we reported a mouse event. */ + struct frame *last_mouse_frame; }; /* This is a chain of structures for all the displays currently in use. */ diff --git a/src/xdisp.c b/src/xdisp.c index b07aad51bc9..c4f7b205119 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -11454,10 +11454,6 @@ update_menu_bar (struct frame *f, int save_match_data, int hooks_run) #ifdef HAVE_WINDOW_SYSTEM -/* Where the mouse was last time we reported a mouse event. */ - -struct frame *last_mouse_frame; - /* Tool-bar item index of the item on which a mouse button was pressed or -1. */ @@ -12320,9 +12316,9 @@ note_tool_bar_highlight (struct frame *f, int x, int y) clear_mouse_face (hlinfo); /* Mouse is down, but on different tool-bar item? */ - mouse_down_p = (dpyinfo->grabbed - && f == last_mouse_frame - && FRAME_LIVE_P (f)); + mouse_down_p = (x_mouse_grabbed (dpyinfo) + && f == dpyinfo->last_mouse_frame); + if (mouse_down_p && last_tool_bar_item != prop_idx) return; diff --git a/src/xterm.c b/src/xterm.c index 08a360fd52c..7d8c40b8cf0 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -3945,6 +3945,7 @@ XTmouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, Time *timestamp) { struct frame *f1; + struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (*fp); block_input (); @@ -4004,22 +4005,24 @@ XTmouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, x_catch_errors (FRAME_X_DISPLAY (*fp)); - if (FRAME_DISPLAY_INFO (*fp)->grabbed && last_mouse_frame - && FRAME_LIVE_P (last_mouse_frame)) + if (x_mouse_grabbed (dpyinfo)) { /* If mouse was grabbed on a frame, give coords for that frame even if the mouse is now outside it. */ XTranslateCoordinates (FRAME_X_DISPLAY (*fp), - /* From-window, to-window. */ - root, FRAME_X_WINDOW (last_mouse_frame), + /* From-window. */ + root, + + /* To-window. */ + FRAME_X_WINDOW (dpyinfo->last_mouse_frame), /* From-position, to-position. */ root_x, root_y, &win_x, &win_y, /* Child of win. */ &child); - f1 = last_mouse_frame; + f1 = dpyinfo->last_mouse_frame; } else { @@ -4043,7 +4046,7 @@ XTmouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, want the edit window. For non-Gtk+ the innermost window is the edit window. For Gtk+ it might not be. It might be the tool bar for example. */ - if (x_window_to_frame (FRAME_DISPLAY_INFO (*fp), win)) + if (x_window_to_frame (dpyinfo, win)) break; #endif win = child; @@ -4065,10 +4068,10 @@ XTmouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, #ifdef USE_GTK /* We don't wan't to know the innermost window. We want the edit window. */ - f1 = x_window_to_frame (FRAME_DISPLAY_INFO (*fp), win); + f1 = x_window_to_frame (dpyinfo, win); #else /* Is win one of our frames? */ - f1 = x_any_window_to_frame (FRAME_DISPLAY_INFO (*fp), win); + f1 = x_any_window_to_frame (dpyinfo, win); #endif #ifdef USE_X_TOOLKIT @@ -6704,11 +6707,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, previous_help_echo_string = help_echo_string; help_echo_string = Qnil; - if (dpyinfo->grabbed && last_mouse_frame - && FRAME_LIVE_P (last_mouse_frame)) - f = last_mouse_frame; - else - f = x_window_to_frame (dpyinfo, event->xmotion.window); + f = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame + : x_window_to_frame (dpyinfo, event->xmotion.window)); if (hlinfo->mouse_face_hidden) { @@ -6845,12 +6845,8 @@ handle_one_xevent (struct x_display_info *dpyinfo, last_mouse_glyph_frame = 0; dpyinfo->last_user_time = event->xbutton.time; - if (dpyinfo->grabbed - && last_mouse_frame - && FRAME_LIVE_P (last_mouse_frame)) - f = last_mouse_frame; - else - f = x_window_to_frame (dpyinfo, event->xbutton.window); + f = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame + : x_window_to_frame (dpyinfo, event->xbutton.window)); #ifdef USE_GTK if (f && xg_event_is_for_scrollbar (f, event)) @@ -6923,7 +6919,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (event->type == ButtonPress) { dpyinfo->grabbed |= (1 << event->xbutton.button); - last_mouse_frame = f; + dpyinfo->last_mouse_frame = f; if (!tool_bar_p) last_tool_bar_item = -1; diff --git a/src/xterm.h b/src/xterm.h index e1556de36b9..f1bfc883a64 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -305,6 +305,9 @@ struct x_display_info /* The frame waiting to be auto-raised in XTread_socket. */ struct frame *x_pending_autoraise_frame; + /* The frame where the mouse was last time we reported a mouse event. */ + struct frame *last_mouse_frame; + /* Time of last user interaction as returned in X events on this display. */ Time last_user_time;