changeset 54650:9dc8330eda34

(x_mouse_click_focus_ignore_position): New var. (syms_of_xterm): DEFVAR_BOOL it. (ignore_next_mouse_click_timeout): New var. (handle_one_xevent): Clear it on KeyPress, set it on EnterNotify. Use it to filter mouse clicks following focus event.
author Kim F. Storm <storm@cua.dk>
date Mon, 29 Mar 2004 22:49:15 +0000
parents d6816d5766d3
children ee25175db902
files src/xterm.c
diffstat 1 files changed, 48 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/xterm.c	Mon Mar 29 22:37:09 2004 +0000
+++ b/src/xterm.c	Mon Mar 29 22:49:15 2004 +0000
@@ -217,6 +217,17 @@
 
 static int toolkit_scroll_bar_interaction;
 
+/* Non-zero means to not move point as a result of clicking on a
+   frame to focus it (when focus-follows-mouse is nil).  */
+
+int x_mouse_click_focus_ignore_position;
+
+/* Non-zero timeout value means ignore next mouse click if it arrives
+   before that timeout elapses (i.e. as part of the same sequence of
+   events resulting from clicking on a frame to select it).  */
+
+static unsigned long ignore_next_mouse_click_timeout;
+
 /* Mouse movement.
 
    Formerly, we used PointerMotionHintMask (in standard_event_mask)
@@ -747,13 +758,13 @@
 
       if (p->overlay_p)
 	{
-	  clipmask = XCreatePixmapFromBitmapData (display, 
+	  clipmask = XCreatePixmapFromBitmapData (display,
 						  FRAME_X_DISPLAY_INFO (f)->root_window,
-						  bits, p->wd, p->h, 
+						  bits, p->wd, p->h,
 						  1, 0, 1);
 	  gcv.clip_mask = clipmask;
 	  gcv.clip_x_origin = p->x;
-	  gcv.clip_y_origin = p->y; 
+	  gcv.clip_y_origin = p->y;
 	  XChangeGC (display, gc, GCClipMask | GCClipXOrigin | GCClipYOrigin, &gcv);
 	}
 
@@ -5725,7 +5736,7 @@
       else
 	{
 	  current_count +=
-	    handle_one_xevent (dpyinfo, xev, &current_finish, 
+	    handle_one_xevent (dpyinfo, xev, &current_finish,
 			       current_hold_quit);
 	}
     }
@@ -6167,6 +6178,8 @@
 
     case KeyPress:
 
+      ignore_next_mouse_click_timeout = 0;
+
 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
       /* Dispatch KeyPress events when in menu.  */
       if (popup_activated ())
@@ -6526,6 +6539,9 @@
 
       f = x_any_window_to_frame (dpyinfo, event.xcrossing.window);
 
+      if (f && x_mouse_click_focus_ignore_position)
+	ignore_next_mouse_click_timeout = event.xmotion.time + 200;
+
 #if 0
       if (event.xcrossing.focus)
 	{
@@ -6769,7 +6785,21 @@
 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
                   if (! popup_activated ())
 #endif
-                    construct_mouse_click (&inev, &event, f);
+		    {
+		      if (ignore_next_mouse_click_timeout)
+			{
+			  if (event.type == ButtonPress
+			      && (int)(event.xbutton.time - ignore_next_mouse_click_timeout) > 0)
+			    {
+			      ignore_next_mouse_click_timeout = 0;
+			      construct_mouse_click (&inev, &event, f);
+			    }
+			  if (event.type == ButtonRelease)
+			    ignore_next_mouse_click_timeout = 0;
+			}
+		      else
+			construct_mouse_click (&inev, &event, f);
+		    }
                 }
           }
         else
@@ -6917,7 +6947,7 @@
 	  any_help_event_p = 1;
 	  gen_help_event (help_echo_string, frame, help_echo_window,
 			  help_echo_object, help_echo_pos);
-	} 
+	}
       else
 	{
 	  help_echo_string = Qnil;
@@ -8229,7 +8259,7 @@
       f->win_gravity = NorthWestGravity;
     }
   x_calc_absolute_position (f);
- 
+
   BLOCK_INPUT;
   x_wm_set_size_hint (f, (long) 0, 0);
 
@@ -10350,7 +10380,7 @@
       get_bits_and_offset (dpyinfo->visual->green_mask,
                            &dpyinfo->green_bits, &dpyinfo->green_offset);
     }
-      
+
   /* See if a private colormap is requested.  */
   if (dpyinfo->visual == DefaultVisualOfScreen (dpyinfo->screen))
     {
@@ -10824,6 +10854,16 @@
 to 4.1, set this to nil.  */);
   x_use_underline_position_properties = 1;
 
+  DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
+	       &x_mouse_click_focus_ignore_position,
+    doc: /* Non-nil means that a mouse click to focus a frame does not move point.
+This variable is only used when the window manager requires that you
+click on a frame to select it (give it focus).  In that case, a value
+of nil, means that the selected window and cursor position changes to
+reflect the mouse click position, while a non-nil value means that the
+selected window or cursor position is preserved.  */);
+  x_mouse_click_focus_ignore_position = 0;
+
   DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
     doc: /* What X toolkit scroll bars Emacs uses.
 A value of nil means Emacs doesn't use X toolkit scroll bars.