aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2013-09-02 12:45:32 +0400
committerDmitry Antipov2013-09-02 12:45:32 +0400
commit84e70bbae4e86a7832ead64c3f2f7240967ca4b7 (patch)
treecfc1b6388ddd34ac3c8ca5d4f03859ac5aea03df /src
parentf167c27b1973c9f2f7a8755c07f23ea671ba1bf1 (diff)
downloademacs-84e70bbae4e86a7832ead64c3f2f7240967ca4b7.tar.gz
emacs-84e70bbae4e86a7832ead64c3f2f7240967ca4b7.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog11
-rw-r--r--src/xterm.c62
2 files changed, 58 insertions, 15 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 1806e642c71..85f3abb98b3 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,16 @@
12013-09-02 Dmitry Antipov <dmantipov@yandex.ru> 12013-09-02 Dmitry Antipov <dmantipov@yandex.ru>
2 2
3 Use XGetMotionEvents to ask the last mouse motion time from X server.
4 * xterm.c (X_MOTION_HISTORY): Default to 1.
5 (x_last_mouse_movement_time) [X_MOTION_HISTORY]: New function.
6 (x_last_mouse_movement_time) [!X_MOTION_HISTORY]: Legacy version.
7 (note_mouse_movement, x_scroll_bar_note_movement) [!X_MOTION_HISTORY]:
8 Ifdef away legacy code.
9 (XTmouse_position, x_scroll_bar_report_motion):
10 Use x_last_mouse_movement_time.
11
122013-09-02 Dmitry Antipov <dmantipov@yandex.ru>
13
3 * msdos.c (last_mouse_window): Move to... 14 * msdos.c (last_mouse_window): Move to...
4 (dos_rawgetc): ...this function and adjust comment. 15 (dos_rawgetc): ...this function and adjust comment.
5 * nsterm.m (last_window): Rename to last_mouse_window, move to... 16 * nsterm.m (last_window): Rename to last_mouse_window, move to...
diff --git a/src/xterm.c b/src/xterm.c
index 4355e9d6b83..bc7dd639c6b 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -133,6 +133,9 @@ extern void _XEditResCheckMessages (Widget, XtPointer, XEvent *, Boolean *);
133#include <X11/XKBlib.h> 133#include <X11/XKBlib.h>
134#endif 134#endif
135 135
136/* Default to using XGetMotionEvents. */
137#define X_MOTION_HISTORY 1
138
136/* Default to using XIM if available. */ 139/* Default to using XIM if available. */
137#ifdef USE_XIM 140#ifdef USE_XIM
138int use_xim = 1; 141int use_xim = 1;
@@ -221,15 +224,6 @@ static struct frame *last_mouse_glyph_frame;
221 224
222static Lisp_Object last_mouse_scroll_bar; 225static Lisp_Object last_mouse_scroll_bar;
223 226
224/* This is a hack. We would really prefer that XTmouse_position would
225 return the time associated with the position it returns, but there
226 doesn't seem to be any way to wrest the time-stamp from the server
227 along with the position query. So, we just keep track of the time
228 of the last movement we received, and return that in hopes that
229 it's somewhat accurate. */
230
231static Time last_mouse_movement_time;
232
233/* Time for last user interaction as returned in X events. */ 227/* Time for last user interaction as returned in X events. */
234 228
235static Time last_user_time; 229static Time last_user_time;
@@ -3722,7 +3716,44 @@ construct_mouse_click (struct input_event *result, XButtonEvent *event, struct f
3722 return Qnil; 3716 return Qnil;
3723} 3717}
3724 3718
3725 3719#ifdef X_MOTION_HISTORY
3720
3721/* Here we assume that X server supports XGetMotionEvents. If you hit
3722 eassert in the function below, most probably your X server is too
3723 old and/or buggy. Undef X_MOTION_HISTORY to enable legacy code. */
3724
3725static Time
3726x_last_mouse_movement_time (struct frame *f)
3727{
3728 Time t;
3729 int nevents;
3730 XTimeCoord *xtc = XGetMotionEvents (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
3731 1, last_user_time, &nevents);
3732 eassert (xtc && nevents > 0);
3733 t = xtc[nevents - 1].time;
3734 XFree (xtc);
3735 return t;
3736}
3737
3738#else /* no X_MOTION_HISTORY */
3739
3740/* This is a hack. We would really prefer that XTmouse_position would
3741 return the time associated with the position it returns, but there
3742 doesn't seem to be any way to wrest the time-stamp from the server
3743 along with the position query. So, we just keep track of the time
3744 of the last movement we received, and return that in hopes that
3745 it's somewhat accurate. */
3746
3747static Time last_mouse_movement_time;
3748
3749static Time
3750x_last_mouse_movement_time (struct frame *f)
3751{
3752 return last_mouse_movement_time;
3753}
3754
3755#endif /* X_MOTION_HISTORY */
3756
3726/* Function to report a mouse movement to the mainstream Emacs code. 3757/* Function to report a mouse movement to the mainstream Emacs code.
3727 The input handler calls this. 3758 The input handler calls this.
3728 3759
@@ -3737,7 +3768,9 @@ static Lisp_Object last_mouse_motion_frame;
3737static int 3768static int
3738note_mouse_movement (struct frame *frame, XMotionEvent *event) 3769note_mouse_movement (struct frame *frame, XMotionEvent *event)
3739{ 3770{
3771#ifndef X_MOTION_HISTORY
3740 last_mouse_movement_time = event->time; 3772 last_mouse_movement_time = event->time;
3773#endif /* legacy */
3741 last_mouse_motion_event = *event; 3774 last_mouse_motion_event = *event;
3742 XSETFRAME (last_mouse_motion_frame, frame); 3775 XSETFRAME (last_mouse_motion_frame, frame);
3743 3776
@@ -3993,7 +4026,7 @@ XTmouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
3993 *fp = f1; 4026 *fp = f1;
3994 XSETINT (*x, win_x); 4027 XSETINT (*x, win_x);
3995 XSETINT (*y, win_y); 4028 XSETINT (*y, win_y);
3996 *timestamp = last_mouse_movement_time; 4029 *timestamp = x_last_mouse_movement_time (f1);
3997 } 4030 }
3998 } 4031 }
3999 } 4032 }
@@ -5499,9 +5532,9 @@ static void
5499x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event) 5532x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event)
5500{ 5533{
5501 struct frame *f = XFRAME (XWINDOW (bar->window)->frame); 5534 struct frame *f = XFRAME (XWINDOW (bar->window)->frame);
5502 5535#ifndef X_MOTION_HISTORY
5503 last_mouse_movement_time = event->xmotion.time; 5536 last_mouse_movement_time = event->xmotion.time;
5504 5537#endif /* legacy */
5505 f->mouse_moved = 1; 5538 f->mouse_moved = 1;
5506 XSETVECTOR (last_mouse_scroll_bar, bar); 5539 XSETVECTOR (last_mouse_scroll_bar, bar);
5507 5540
@@ -5586,10 +5619,9 @@ x_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_window,
5586 5619
5587 f->mouse_moved = 0; 5620 f->mouse_moved = 0;
5588 last_mouse_scroll_bar = Qnil; 5621 last_mouse_scroll_bar = Qnil;
5622 *timestamp = x_last_mouse_movement_time (f);
5589 } 5623 }
5590 5624
5591 *timestamp = last_mouse_movement_time;
5592
5593 unblock_input (); 5625 unblock_input ();
5594} 5626}
5595 5627