summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorJeremy Katz <jeremy.katz@nokia.com>2009-12-18 12:21:51 (GMT)
committerJeremy Katz <jeremy.katz@nokia.com>2009-12-18 12:21:51 (GMT)
commit2c64beebfe265a140263ec156a0c41f93005ba73 (patch)
tree0fc200b3cbd60b68c699922a92a303887edec713 /src/plugins
parent0e5b1ab9bce08a1c0927e13efdc6d24873d920ec (diff)
downloadQt-2c64beebfe265a140263ec156a0c41f93005ba73.zip
Qt-2c64beebfe265a140263ec156a0c41f93005ba73.tar.gz
Qt-2c64beebfe265a140263ec156a0c41f93005ba73.tar.bz2
queued dispatch of keyboard and mouse events
Mouse and Key events can't be handed off directly to QApplicationPrivate:: andleMouseEvent() and QApplicationPrivate::handleKeyEvent() from methods that are called as the slot for a QAbstractSocket::readyRead() signal. Doing so can result in event starvation in the case of things like QMenu::exec() that have their own event loop.
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/graphicssystems/vnc/qvncserver.cpp46
-rw-r--r--src/plugins/graphicssystems/vnc/qvncserver.h6
2 files changed, 48 insertions, 4 deletions
diff --git a/src/plugins/graphicssystems/vnc/qvncserver.cpp b/src/plugins/graphicssystems/vnc/qvncserver.cpp
index fcff255..c2fb676 100644
--- a/src/plugins/graphicssystems/vnc/qvncserver.cpp
+++ b/src/plugins/graphicssystems/vnc/qvncserver.cpp
@@ -389,6 +389,10 @@ void QVNCServer::init(uint port)
qvnc_cursor = 0;
#endif
encoder = 0;
+
+ eventTimer.setInterval(0);
+ eventTimer.setSingleShot(true);
+ connect(&eventTimer, SIGNAL(timeout()), this, SLOT(sendInputEvents()));
}
QVNCServer::~QVNCServer()
@@ -819,6 +823,30 @@ static bool buttonChange(Qt::MouseButtons before, Qt::MouseButtons after, Qt::Mo
return false;
}
+void QVNCServer::sendInputEvents()
+{
+ EventPair pair;
+ for (int i = 0 ; i < eventList.count(); i++) {
+ pair = eventList[i];
+ switch(pair.first) {
+ case MouseEvent: {
+ QMouseEvent *me = static_cast<QMouseEvent *>(pair.second);
+ QApplicationPrivate::handleMouseEvent(0, *me);
+ delete me;
+ break;
+ }
+ case KeyboardEvent: {
+ QKeyEvent *ke = static_cast<QKeyEvent *>(pair.second);
+ QApplicationPrivate::handleKeyEvent(0, ke);
+ delete ke;
+ break;
+ }
+ }
+ }
+ eventList.clear();
+ Q_ASSERT(eventList.count() == 0);
+}
+
void QVNCServer::pointerEvent()
{
QRfbPointerEvent ev;
@@ -834,8 +862,13 @@ void QVNCServer::pointerEvent()
bool isPress;
if (buttonChange(buttons, ev.buttons, &button, &isPress))
type = isPress ? QEvent::MouseButtonPress : QEvent::MouseButtonRelease;
- QMouseEvent me(type, QPoint(ev.x, ev.y), QPoint(ev.x, ev.y), button, ev.buttons, keymod);
- QApplicationPrivate::handleMouseEvent(0, me);
+ QMouseEvent * me = new QMouseEvent(type, QPoint(ev.x, ev.y), QPoint(ev.x, ev.y), button, ev.buttons, keymod);
+ EventPair pair;
+ pair.first = MouseEvent;
+ pair.second = me;
+ eventList.append(pair);
+ if (!eventTimer.isActive())
+ eventTimer.start();
buttons = ev.buttons;
handleMsg = false;
}
@@ -861,8 +894,13 @@ void QVNCServer::keyEvent()
QString str;
if (ev.unicode && ev.unicode != 0xffff)
str = QString(ev.unicode);
- QKeyEvent keyEvent(type, ev.keycode, keymod, str);
- QApplicationPrivate::handleKeyEvent(0, &keyEvent);
+ QKeyEvent *keyEvent = new QKeyEvent(type, ev.keycode, keymod, str);
+ EventPair pair;
+ pair.first = KeyboardEvent;
+ pair.second = keyEvent;
+ eventList.append(pair);
+ if (!eventTimer.isActive())
+ eventTimer.start();
}
handleMsg = false;
}
diff --git a/src/plugins/graphicssystems/vnc/qvncserver.h b/src/plugins/graphicssystems/vnc/qvncserver.h
index 79b2098..be84c3c 100644
--- a/src/plugins/graphicssystems/vnc/qvncserver.h
+++ b/src/plugins/graphicssystems/vnc/qvncserver.h
@@ -482,6 +482,7 @@ private slots:
void readClient();
void checkUpdate();
void discardClient();
+ void sendInputEvents();
private:
void init(uint port);
@@ -519,6 +520,11 @@ private:
QRfbEncoder *encoder;
QVNCCursor *cursor;
+
+ enum EventType { MouseEvent, KeyboardEvent };
+ QTimer eventTimer;
+ typedef QPair<EventType, QInputEvent *> EventPair;
+ QList<EventPair> eventList;
};