emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114102: Use XGetMotionEvents to ask the last mouse


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r114102: Use XGetMotionEvents to ask the last mouse motion time from X server.
Date: Mon, 02 Sep 2013 08:46:05 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114102
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Mon 2013-09-02 12:45:32 +0400
message:
  Use XGetMotionEvents to ask the last mouse motion time from X server.
  * xterm.c (X_MOTION_HISTORY): Default to 1.
  (x_last_mouse_movement_time) [X_MOTION_HISTORY]: New function.
  (x_last_mouse_movement_time) [!X_MOTION_HISTORY]: Legacy version.
  (note_mouse_movement, x_scroll_bar_note_movement) [!X_MOTION_HISTORY]:
  Ifdef away legacy code.
  (XTmouse_position, x_scroll_bar_report_motion):
  Use x_last_mouse_movement_time.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/xterm.c                    xterm.c-20091113204419-o5vbwnq5f7feedwu-244
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-09-02 06:45:04 +0000
+++ b/src/ChangeLog     2013-09-02 08:45:32 +0000
@@ -1,5 +1,16 @@
 2013-09-02  Dmitry Antipov  <address@hidden>
 
+       Use XGetMotionEvents to ask the last mouse motion time from X server.
+       * xterm.c (X_MOTION_HISTORY): Default to 1.
+       (x_last_mouse_movement_time) [X_MOTION_HISTORY]: New function.
+       (x_last_mouse_movement_time) [!X_MOTION_HISTORY]: Legacy version.
+       (note_mouse_movement, x_scroll_bar_note_movement) [!X_MOTION_HISTORY]:
+       Ifdef away legacy code.
+       (XTmouse_position, x_scroll_bar_report_motion):
+       Use x_last_mouse_movement_time.
+
+2013-09-02  Dmitry Antipov  <address@hidden>
+
        * msdos.c (last_mouse_window): Move to...
        (dos_rawgetc): ...this function and adjust comment.
        * nsterm.m (last_window): Rename to last_mouse_window, move to...

=== modified file 'src/xterm.c'
--- a/src/xterm.c       2013-09-02 06:45:04 +0000
+++ b/src/xterm.c       2013-09-02 08:45:32 +0000
@@ -133,6 +133,9 @@
 #include <X11/XKBlib.h>
 #endif
 
+/* Default to using XGetMotionEvents.  */
+#define X_MOTION_HISTORY 1
+
 /* Default to using XIM if available.  */
 #ifdef USE_XIM
 int use_xim = 1;
@@ -221,15 +224,6 @@
 
 static Lisp_Object last_mouse_scroll_bar;
 
-/* This is a hack.  We would really prefer that XTmouse_position would
-   return the time associated with the position it returns, but there
-   doesn't seem to be any way to wrest the time-stamp from the server
-   along with the position query.  So, we just keep track of the time
-   of the last movement we received, and return that in hopes that
-   it's somewhat accurate.  */
-
-static Time last_mouse_movement_time;
-
 /* Time for last user interaction as returned in X events.  */
 
 static Time last_user_time;
@@ -3722,7 +3716,44 @@
   return Qnil;
 }
 
-
+#ifdef X_MOTION_HISTORY
+
+/* Here we assume that X server supports XGetMotionEvents.  If you hit
+   eassert in the function below, most probably your X server is too
+   old and/or buggy.  Undef X_MOTION_HISTORY to enable legacy code.  */
+
+static Time
+x_last_mouse_movement_time (struct frame *f)
+{
+  Time t;
+  int nevents;
+  XTimeCoord *xtc = XGetMotionEvents (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
+                                     1, last_user_time, &nevents);
+  eassert (xtc && nevents > 0);
+  t = xtc[nevents - 1].time;
+  XFree (xtc);
+  return t;
+}
+
+#else /* no X_MOTION_HISTORY */
+
+/* This is a hack.  We would really prefer that XTmouse_position would
+   return the time associated with the position it returns, but there
+   doesn't seem to be any way to wrest the time-stamp from the server
+   along with the position query.  So, we just keep track of the time
+   of the last movement we received, and return that in hopes that
+   it's somewhat accurate.  */
+
+static Time last_mouse_movement_time;
+
+static Time
+x_last_mouse_movement_time (struct frame *f)
+{
+  return last_mouse_movement_time;
+}
+
+#endif /* X_MOTION_HISTORY */
+
 /* Function to report a mouse movement to the mainstream Emacs code.
    The input handler calls this.
 
@@ -3737,7 +3768,9 @@
 static int
 note_mouse_movement (struct frame *frame, XMotionEvent *event)
 {
+#ifndef X_MOTION_HISTORY
   last_mouse_movement_time = event->time;
+#endif /* legacy */
   last_mouse_motion_event = *event;
   XSETFRAME (last_mouse_motion_frame, frame);
 
@@ -3993,7 +4026,7 @@
            *fp = f1;
            XSETINT (*x, win_x);
            XSETINT (*y, win_y);
-           *timestamp = last_mouse_movement_time;
+           *timestamp = x_last_mouse_movement_time (f1);
          }
       }
     }
@@ -5499,9 +5532,9 @@
 x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event)
 {
   struct frame *f = XFRAME (XWINDOW (bar->window)->frame);
-
+#ifndef X_MOTION_HISTORY
   last_mouse_movement_time = event->xmotion.time;
-
+#endif /* legacy */
   f->mouse_moved = 1;
   XSETVECTOR (last_mouse_scroll_bar, bar);
 
@@ -5586,10 +5619,9 @@
 
       f->mouse_moved = 0;
       last_mouse_scroll_bar = Qnil;
+      *timestamp = x_last_mouse_movement_time (f);
     }
 
-  *timestamp = last_mouse_movement_time;
-
   unblock_input ();
 }
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]