Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorMartin Poirier <theeth@yahoo.com>2009-11-24 22:47:57 +0300
committerMartin Poirier <theeth@yahoo.com>2009-11-24 22:47:57 +0300
commit1aebd524a222a084d96d07c1a3d41f0d5de6ad3a (patch)
treea8f4587194f2aa4be9b34deecaa213ccdb0fb02b /intern
parentdcd1642121a14ddc3191399fb7120fe0a15437ce (diff)
Fix for continuous grab on X11.
Need to stop accumulating warp coordinates after the first cursor warp (store time of new generated event and skip warp for events time smaller). There's some interesting X11 code in there, if people are curious.
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.cpp75
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.h9
2 files changed, 79 insertions, 5 deletions
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index ff4a5956a12..3f5f52aa2ed 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -23,6 +23,9 @@
*
* Contributor(s): none yet.
*
+ * Part of this code has been taken from Qt, under LGPL license
+ * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ *
* ***** END GPL LICENSE BLOCK *****
*/
@@ -126,6 +129,8 @@ GHOST_SystemX11(
m_xclip_out= XInternAtom(m_display, "XCLIP_OUT", False);
m_incr= XInternAtom(m_display, "INCR", False);
m_utf8_string= XInternAtom(m_display, "UTF8_STRING", False);
+ m_last_warp = 0;
+
// compute the initial time
timeval tv;
@@ -310,6 +315,61 @@ static void SleepTillEvent(Display *display, GHOST_TInt64 maxSleep) {
}
}
+/* This function borrowed from Qt's X11 support
+ * qclipboard_x11.cpp
+ * */
+struct init_timestamp_data
+{
+ Time timestamp;
+};
+
+static Bool init_timestamp_scanner(Display*, XEvent *event, XPointer arg)
+{
+ init_timestamp_data *data =
+ reinterpret_cast<init_timestamp_data*>(arg);
+ switch(event->type)
+ {
+ case ButtonPress:
+ case ButtonRelease:
+ data->timestamp = event->xbutton.time;
+ break;
+ case MotionNotify:
+ data->timestamp = event->xmotion.time;
+ break;
+ case KeyPress:
+ case KeyRelease:
+ data->timestamp = event->xkey.time;
+ break;
+ case PropertyNotify:
+ data->timestamp = event->xproperty.time;
+ break;
+ case EnterNotify:
+ case LeaveNotify:
+ data->timestamp = event->xcrossing.time;
+ break;
+ case SelectionClear:
+ data->timestamp = event->xselectionclear.time;
+ break;
+ default:
+ break;
+ }
+
+ return false;
+}
+
+Time
+GHOST_SystemX11::
+lastEventTime(Time default_time) {
+ init_timestamp_data data;
+ data.timestamp = default_time;
+ XEvent ev;
+ XCheckIfEvent(m_display, &ev, &init_timestamp_scanner, (XPointer)&data);
+
+ return data.timestamp;
+}
+
+
+
bool
GHOST_SystemX11::
processEvents(
@@ -405,10 +465,15 @@ GHOST_SystemX11::processEvent(XEvent *xe)
window->getCursorGrabAccum(x_accum, y_accum);
if(x_new != xme.x_root || y_new != xme.y_root) {
- /* when wrapping we don't need to add an event because the
- * setCursorPosition call will cause a new event after */
- setCursorPosition(x_new, y_new); /* wrap */
- window->setCursorGrabAccum(x_accum + (xme.x_root - x_new), y_accum + (xme.y_root - y_new));
+ if (xme.time > m_last_warp) {
+ /* when wrapping we don't need to add an event because the
+ * setCursorPosition call will cause a new event after */
+ setCursorPosition(x_new, y_new); /* wrap */
+ window->setCursorGrabAccum(x_accum + (xme.x_root - x_new), y_accum + (xme.y_root - y_new));
+ m_last_warp = lastEventTime(xme.time);
+ } else {
+ setCursorPosition(x_new, y_new); /* wrap but don't accumulate */
+ }
}
else {
g_event = new
@@ -907,7 +972,7 @@ setCursorPosition(
int rely = y-cy;
XWarpPointer(m_display,None,None,0,0,0,0,relx,rely);
- XFlush(m_display);
+ XSync(m_display, 0); /* Sync to process all requests */
return GHOST_kSuccess;
}
diff --git a/intern/ghost/intern/GHOST_SystemX11.h b/intern/ghost/intern/GHOST_SystemX11.h
index 782f08f6737..d76c3991beb 100644
--- a/intern/ghost/intern/GHOST_SystemX11.h
+++ b/intern/ghost/intern/GHOST_SystemX11.h
@@ -266,6 +266,10 @@ private :
/// A vector of keyboard key masks
char m_keyboard_vector[32];
+ /* to prevent multiple warp, we store the time of the last warp event
+ * and stop accumulating all events generated before that */
+ Time m_last_warp;
+
/**
* Return the ghost window associated with the
* X11 window xwind
@@ -281,6 +285,11 @@ private :
XEvent *xe
);
+ Time
+ lastEventTime(
+ Time default_time
+ );
+
bool
generateWindowExposeEvents(
);