From b99e1c0a6b5586976f7d979c988e16b4e4749be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 26 Feb 2013 08:45:44 +0100 Subject: [PATCH] Reduce usage of QCursor::pos() and ::setPos() Where possible it is changed to Cursor::pos(), where we cannot use the Cursor class (e.g. Aurorae) we can at least try to limit the usage to prevent roundtrips to the X server. REVIEW: 109178 --- activation.cpp | 3 ++- client.cpp | 2 +- clients/aurorae/src/aurorae.cpp | 15 +++++++++------ effects/magiclamp/magiclamp.cpp | 2 +- events.cpp | 9 +++++---- geometry.cpp | 6 +++--- killwindow.cpp | 3 ++- useractions.cpp | 5 +++-- workspace.cpp | 2 +- 9 files changed, 27 insertions(+), 20 deletions(-) diff --git a/activation.cpp b/activation.cpp index 4f23bea4c2..2b4b355d11 100644 --- a/activation.cpp +++ b/activation.cpp @@ -27,6 +27,7 @@ along with this program. If not, see . */ #include "client.h" +#include "cursor.h" #include "focuschain.h" #include "workspace.h" @@ -417,7 +418,7 @@ Client *Workspace::clientUnderMouse(int screen) const client->isOnCurrentActivity() && client->isOnScreen(screen))) continue; - if (client->geometry().contains(QCursor::pos())) { + if (client->geometry().contains(Cursor::pos())) { return client; } } diff --git a/client.cpp b/client.cpp index b30191fca0..32b27924d7 100644 --- a/client.cpp +++ b/client.cpp @@ -1892,7 +1892,7 @@ bool Client::untab(const QRect &toGeometry, bool clientRemoved) } if (keepSize && changedSize) { geom_restore = geometry(); // checkWorkspacePosition() invokes it - QPoint cpoint = QCursor::pos(); + QPoint cpoint = Cursor::pos(); QPoint point = cpoint; point.setX((point.x() - toGeometry.x()) * geom_restore.width() / toGeometry.width()); point.setY((point.y() - toGeometry.y()) * geom_restore.height() / toGeometry.height()); diff --git a/clients/aurorae/src/aurorae.cpp b/clients/aurorae/src/aurorae.cpp index 682ae12533..413a80446c 100644 --- a/clients/aurorae/src/aurorae.cpp +++ b/clients/aurorae/src/aurorae.cpp @@ -490,8 +490,9 @@ void AuroraeClient::titleMouseMoved(int button, int buttons) void AuroraeClient::titlePressed(Qt::MouseButton button, Qt::MouseButtons buttons) { - QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, widget()->mapFromGlobal(QCursor::pos()), - QCursor::pos(), button, buttons, Qt::NoModifier); + const QPoint cursor = QCursor::pos(); + QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonPress, widget()->mapFromGlobal(cursor), + cursor, button, buttons, Qt::NoModifier); processMousePressEvent(event); delete event; event = 0; @@ -499,8 +500,9 @@ void AuroraeClient::titlePressed(Qt::MouseButton button, Qt::MouseButtons button void AuroraeClient::titleReleased(Qt::MouseButton button, Qt::MouseButtons buttons) { - QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonRelease, widget()->mapFromGlobal(QCursor::pos()), - QCursor::pos(), button, buttons, Qt::NoModifier); + const QPoint cursor = QCursor::pos(); + QMouseEvent *event = new QMouseEvent(QEvent::MouseButtonRelease, widget()->mapFromGlobal(cursor), + cursor, button, buttons, Qt::NoModifier); QApplication::sendEvent(widget(), event); delete event; event = 0; @@ -508,8 +510,9 @@ void AuroraeClient::titleReleased(Qt::MouseButton button, Qt::MouseButtons butto void AuroraeClient::titleMouseMoved(Qt::MouseButton button, Qt::MouseButtons buttons) { - QMouseEvent *event = new QMouseEvent(QEvent::MouseMove, widget()->mapFromGlobal(QCursor::pos()), - QCursor::pos(), button, buttons, Qt::NoModifier); + const QPoint cursor = QCursor::pos(); + QMouseEvent *event = new QMouseEvent(QEvent::MouseMove, widget()->mapFromGlobal(cursor), + cursor, button, buttons, Qt::NoModifier); QApplication::sendEvent(widget(), event); delete event; event = 0; diff --git a/effects/magiclamp/magiclamp.cpp b/effects/magiclamp/magiclamp.cpp index ca8ee49646..21b7253335 100644 --- a/effects/magiclamp/magiclamp.cpp +++ b/effects/magiclamp/magiclamp.cpp @@ -125,7 +125,7 @@ void MagicLampEffect::paintWindow(EffectWindow* w, int mask, QRegion region, Win // If there's no icon geometry, minimize to the center of the screen if (!icon.isValid()) { QRect extG = geo.adjusted(mShadowOffset[0], mShadowOffset[1], mShadowOffset[2], mShadowOffset[3]); - QPoint pt = QCursor::pos(); + QPoint pt = cursorPos(); // focussing inside the window is no good, leads to ugly artefacts, find nearest border if (extG.contains(pt)) { const int d[2][2] = { {pt.x() - extG.x(), extG.right() - pt.x()}, diff --git a/events.cpp b/events.cpp index c960a0ccc1..ec84914090 100644 --- a/events.cpp +++ b/events.cpp @@ -28,6 +28,7 @@ along with this program. If not, see . #include #include "client.h" +#include "cursor.h" #include "focuschain.h" #include "workspace.h" #include "atoms.h" @@ -1524,11 +1525,11 @@ void Client::NETMoveResize(int x_root, int y_root, NET::Direction direction) updateCursor(); } else if (direction == NET::KeyboardMove) { // ignore mouse coordinates given in the message, mouse position is used by the moving algorithm - QCursor::setPos(geometry().center()); + Cursor::setPos(geometry().center()); performMouseCommand(Options::MouseUnrestrictedMove, geometry().center()); } else if (direction == NET::KeyboardSize) { // ignore mouse coordinates given in the message, mouse position is used by the resizing algorithm - QCursor::setPos(geometry().bottomRight()); + Cursor::setPos(geometry().bottomRight()); performMouseCommand(Options::MouseUnrestrictedResize, geometry().bottomRight()); } } @@ -1571,7 +1572,7 @@ void Client::keyPressEvent(uint key_code) default: return; } - QCursor::setPos(pos); + Cursor::setPos(pos); } #ifdef HAVE_XSYNC @@ -1609,7 +1610,7 @@ bool Unmanaged::windowEvent(XEvent* e) } switch(e->type) { case UnmapNotify: - workspace()->updateFocusMousePosition(QCursor::pos()); + workspace()->updateFocusMousePosition(Cursor::pos()); unmapNotifyEvent(&e->xunmap); break; case MapNotify: diff --git a/geometry.cpp b/geometry.cpp index cc048ac6ca..03085db449 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -2302,7 +2302,7 @@ void Client::changeMaximize(bool vertical, bool horizontal, bool adjust) r.setSize(adjustedSize(r.size(), SizemodeMax)); if (r.size() != clientArea.size()) { // to avoid off-by-one errors... if (isElectricBorderMaximizing() && r.width() < clientArea.width()) - r.moveLeft(QCursor::pos().x() - r.width()/2); + r.moveLeft(Cursor::pos().x() - r.width()/2); else r.moveCenter(clientArea.center()); r.moveTopLeft(rules()->checkPosition(r.topLeft())); @@ -2362,7 +2362,7 @@ void Client::setFullScreen(bool set, bool user) setShade(ShadeNone); bool was_fs = isFullScreen(); if (was_fs) - workspace()->updateFocusMousePosition(QCursor::pos()); + workspace()->updateFocusMousePosition(Cursor::pos()); else geom_fs_restore = geometry(); fullscreen_mode = set ? FullScreenNormal : FullScreenNone; @@ -2588,7 +2588,7 @@ bool Client::startMoveResize() ScreenEdges::self()->reserveDesktopSwitching(true, Qt::Vertical|Qt::Horizontal); #endif if (fakeMove) // fix geom_restore position - it HAS to happen at the end, ie. when all moving is set up. inline call will lock focus!! - handleMoveResize(QCursor::pos().x(), QCursor::pos().y(), QCursor::pos().x(), QCursor::pos().y()); + handleMoveResize(Cursor::pos().x(), Cursor::pos().y(), Cursor::pos().x(), Cursor::pos().y()); return true; } diff --git a/killwindow.cpp b/killwindow.cpp index 8aec222594..c20bc288e9 100644 --- a/killwindow.cpp +++ b/killwindow.cpp @@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "killwindow.h" +#include "cursor.h" #include "workspace.h" // Qt #include @@ -164,7 +165,7 @@ void KillWindow::handleKeyPress(xcb_keycode_t keycode, uint16_t state) mx /= 10; my /= 10; } - QCursor::setPos(cursorPos() + QPoint(mx, my)); + Cursor::setPos(Cursor::pos() + QPoint(mx, my)); if (returnPressed) { performKill(); } diff --git a/useractions.cpp b/useractions.cpp index 394be8f7f7..6ada8138c1 100755 --- a/useractions.cpp +++ b/useractions.cpp @@ -32,6 +32,7 @@ along with this program. If not, see . ////////////////////////////////////////////////////////////////////////////// #include "useractions.h" +#include "cursor.h" #include "client.h" #include "workspace.h" #include "effects.h" @@ -932,9 +933,9 @@ void Workspace::performWindowOperation(Client* c, Options::WindowOperation op) if (!c) return; if (op == Options::MoveOp || op == Options::UnrestrictedMoveOp) - QCursor::setPos(c->geometry().center()); + Cursor::setPos(c->geometry().center()); if (op == Options::ResizeOp || op == Options::UnrestrictedResizeOp) - QCursor::setPos(c->geometry().bottomRight()); + Cursor::setPos(c->geometry().bottomRight()); switch(op) { case Options::MoveOp: c->performMouseCommand(Options::MouseMove, cursorPos()); diff --git a/workspace.cpp b/workspace.cpp index 464fd00167..2f23d43364 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -1193,7 +1193,7 @@ Client *Workspace::findClientToActivateOnDesktop(uint desktop) client->isOnCurrentActivity() && client->isOnScreen(activeScreen()))) continue; - if (client->geometry().contains(QCursor::pos())) { + if (client->geometry().contains(Cursor::pos())) { if (!client->isDesktop()) return client; break; // unconditional break - we do not pass the focus to some client below an unusable one