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
This commit is contained in:
Martin Gräßlin 2013-02-26 08:45:44 +01:00
parent 939fa12707
commit b99e1c0a6b
9 changed files with 27 additions and 20 deletions

View file

@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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;
}
}

View file

@ -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());

View file

@ -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;

View file

@ -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()},

View file

@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <config-X11.h>
#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:

View file

@ -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;
}

View file

@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "killwindow.h"
#include "cursor.h"
#include "workspace.h"
// Qt
#include <QCursor>
@ -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();
}

View file

@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////
#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());

View file

@ -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