From 873e2b032054b36c3912acd98d4c4dceff46602b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 23 Feb 2016 14:08:28 +0100 Subject: [PATCH] Add support for Move/Resize cursor mode --- pointer_input.cpp | 30 ++++++++++++++++++++++++++++++ pointer_input.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/pointer_input.cpp b/pointer_input.cpp index b4bfba8638..b5ea2d056d 100644 --- a/pointer_input.cpp +++ b/pointer_input.cpp @@ -508,6 +508,14 @@ CursorImage::CursorImage(PointerInputRedirection *parent) connect(waylandServer()->seat(), &KWayland::Server::SeatInterface::focusedPointerChanged, this, &CursorImage::update); connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged, this, &CursorImage::reevaluteSource); connect(m_pointer, &PointerInputRedirection::decorationChanged, this, &CursorImage::updateDecoration); + // connect the move resize of all window + auto setupMoveResizeConnection = [this] (AbstractClient *c) { + connect(c, &AbstractClient::moveResizedChanged, this, &CursorImage::updateMoveResize); + }; + const auto clients = workspace()->allClientList(); + std::for_each(clients.begin(), clients.end(), setupMoveResizeConnection); + connect(workspace(), &Workspace::clientAdded, this, setupMoveResizeConnection); + connect(waylandServer(), &WaylandServer::shellClientAdded, this, setupMoveResizeConnection); loadThemeCursor(Qt::ArrowCursor, &m_fallbackCursor); if (m_cursorTheme) { connect(m_cursorTheme, &WaylandCursorTheme::themeChanged, this, @@ -515,6 +523,7 @@ CursorImage::CursorImage(PointerInputRedirection *parent) m_cursors.clear(); loadThemeCursor(Qt::ArrowCursor, &m_fallbackCursor); updateDecorationCursor(); + updateMoveResize(); // TODO: update effects } ); @@ -585,6 +594,19 @@ void CursorImage::updateDecorationCursor() reevaluteSource(); } +void CursorImage::updateMoveResize() +{ + m_moveResizeCursor.image = QImage(); + m_moveResizeCursor.hotSpot = QPoint(); + if (AbstractClient *c = workspace()->getMovingClient()) { + loadThemeCursor(c->isMove() ? Qt::SizeAllCursor : Qt::SizeBDiagCursor, &m_moveResizeCursor); + if (m_currentSource == CursorSource::MoveResize) { + emit changed(); + } + } + reevaluteSource(); +} + void CursorImage::updateServerCursor() { m_serverCursor.image = QImage(); @@ -697,6 +719,10 @@ void CursorImage::reevaluteSource() setSource(CursorSource::EffectsOverride); return; } + if (workspace() && workspace()->getMovingClient()) { + setSource(CursorSource::MoveResize); + return; + } if (!m_pointer->decoration().isNull()) { setSource(CursorSource::Decoration); return; @@ -722,6 +748,8 @@ QImage CursorImage::image() const switch (m_currentSource) { case CursorSource::EffectsOverride: return m_effectsCursor.image; + case CursorSource::MoveResize: + return m_moveResizeCursor.image; case CursorSource::LockScreen: case CursorSource::PointerSurface: // lockscreen also uses server cursor image @@ -740,6 +768,8 @@ QPoint CursorImage::hotSpot() const switch (m_currentSource) { case CursorSource::EffectsOverride: return m_effectsCursor.hotSpot; + case CursorSource::MoveResize: + return m_moveResizeCursor.hotSpot; case CursorSource::LockScreen: case CursorSource::PointerSurface: // lockscreen also uses server cursor image diff --git a/pointer_input.h b/pointer_input.h index b66cb5a2e3..7247745a81 100644 --- a/pointer_input.h +++ b/pointer_input.h @@ -143,6 +143,7 @@ private: void updateServerCursor(); void updateDecoration(); void updateDecorationCursor(); + void updateMoveResize(); void loadTheme(); struct Image { QImage image; @@ -153,6 +154,7 @@ private: enum class CursorSource { LockScreen, EffectsOverride, + MoveResize, PointerSurface, Decoration, Fallback @@ -172,6 +174,7 @@ private: Image m_decorationCursor; QMetaObject::Connection m_decorationConnection; Image m_fallbackCursor; + Image m_moveResizeCursor; QHash m_cursors; QElapsedTimer m_surfaceRenderedTimer; };