From 24806d89099a99832b232abda0f58485e58cf71a Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 28 Oct 2018 21:10:08 +0200 Subject: [PATCH] drop TaskManager for drag/double click panel --use the visibilitymanager in order to drag and maximize/restore an active window. Update also the wayland functions for these features. --- app/abstractwindowinterface.h | 5 +- app/dock/visibilitymanager.cpp | 33 +++++++- app/dock/visibilitymanager.h | 1 + app/dock/visibilitymanager_p.h | 1 + app/waylandinterface.cpp | 80 ++++++++++++------- app/waylandinterface.h | 6 +- app/xwindowinterface.cpp | 37 ++++++--- app/xwindowinterface.h | 5 +- .../package/contents/ui/RootMouseArea.qml | 28 +------ 9 files changed, 122 insertions(+), 74 deletions(-) diff --git a/app/abstractwindowinterface.h b/app/abstractwindowinterface.h index b6ab91132..98485fc1f 100644 --- a/app/abstractwindowinterface.h +++ b/app/abstractwindowinterface.h @@ -83,8 +83,9 @@ public: virtual void enableBlurBehind(QWindow &view) const = 0; virtual void setEdgeStateFor(QWindow *view, bool active) const = 0; - virtual void requestMoveActiveWindow(QPoint from) const = 0; - virtual bool activeWindowCanBeDragged() const = 0; + virtual void requestToggleMaximized(WindowId wid) const = 0; + virtual void requestMoveWindow(WindowId wid, QPoint from) const = 0; + virtual bool windowCanBeDragged(WindowId wid) const = 0; void addDock(WindowId wid); void removeDock(WindowId wid); diff --git a/app/dock/visibilitymanager.cpp b/app/dock/visibilitymanager.cpp index da0d3e1be..569ab2a72 100644 --- a/app/dock/visibilitymanager.cpp +++ b/app/dock/visibilitymanager.cpp @@ -1042,15 +1042,37 @@ void VisibilityManagerPrivate::deleteEdgeGhostWindow() } //! Window Functions +void VisibilityManagerPrivate::requestToggleMaximizeForActiveWindow() +{ + WindowInfoWrap actInfo = wm->requestInfoActive(); + + //active window can be toggled only when it is in the same screen + if (actInfo.isValid() && !actInfo.geometry().isNull() && dockView->screenGeometry().contains(actInfo.geometry().center())) { + wm->requestToggleMaximized(actInfo.wid()); + } +} + void VisibilityManagerPrivate::requestMoveActiveWindow(int localX, int localY) { - QPoint globalPoint{dockView->x() + localX, dockView->y() + localY}; - wm->requestMoveActiveWindow(globalPoint); + WindowInfoWrap actInfo = wm->requestInfoActive(); + + //active window can be dragged only when it is in the same screen + if (actInfo.isValid() && !actInfo.geometry().isNull() && dockView->screenGeometry().contains(actInfo.geometry().center())) { + QPoint globalPoint{dockView->x() + localX, dockView->y() + localY}; + wm->requestMoveWindow(actInfo.wid(), globalPoint); + } } bool VisibilityManagerPrivate::activeWindowCanBeDragged() { - return wm->activeWindowCanBeDragged(); + WindowInfoWrap actInfo = wm->requestInfoActive(); + + //active window can be dragged only when it is in the same screen + if (actInfo.isValid() && !actInfo.geometry().isNull() && dockView->screenGeometry().contains(actInfo.geometry().center())) { + return wm->windowCanBeDragged(actInfo.wid()); + } + + return false; } //! END: VisibilityManagerPrivate implementation @@ -1201,6 +1223,11 @@ bool VisibilityManager::supportsKWinEdges() const } //! Window Functions +void VisibilityManager::requestToggleMaximizeForActiveWindow() +{ + d->requestToggleMaximizeForActiveWindow(); +} + void VisibilityManager::requestMoveActiveWindow(int localX, int localY) { d->requestMoveActiveWindow(localX, localY); diff --git a/app/dock/visibilitymanager.h b/app/dock/visibilitymanager.h index 62aae83d9..0911df3d1 100644 --- a/app/dock/visibilitymanager.h +++ b/app/dock/visibilitymanager.h @@ -105,6 +105,7 @@ public: bool supportsKWinEdges() const; public slots: + Q_INVOKABLE void requestToggleMaximizeForActiveWindow(); Q_INVOKABLE void requestMoveActiveWindow(int localX, int localY); Q_INVOKABLE bool activeWindowCanBeDragged(); diff --git a/app/dock/visibilitymanager_p.h b/app/dock/visibilitymanager_p.h index 3383e82da..6bf48031d 100644 --- a/app/dock/visibilitymanager_p.h +++ b/app/dock/visibilitymanager_p.h @@ -82,6 +82,7 @@ public: void updateStrutsBasedOnLayoutsAndActivities(); + void requestToggleMaximizeForActiveWindow(); void requestMoveActiveWindow(int localX, int localY); bool activeWindowCanBeDragged(); diff --git a/app/waylandinterface.cpp b/app/waylandinterface.cpp index 8bbc4b457..2964e69b1 100644 --- a/app/waylandinterface.cpp +++ b/app/waylandinterface.cpp @@ -318,45 +318,71 @@ bool WaylandInterface::isOnCurrentActivity(WindowId wid) const WindowInfoWrap WaylandInterface::requestInfo(WindowId wid) const { - auto it = std::find_if(m_windowManagement->windows().constBegin(), m_windowManagement->windows().constEnd(), [&wid](PlasmaWindow * w) noexcept { - return w->isValid() && w->internalId() == wid; - }); - - if (it == m_windowManagement->windows().constEnd()) - return {}; - WindowInfoWrap winfoWrap; - auto w = *it; + auto w = windowFor(wid); - if (isValidWindow(w)) { - winfoWrap.setIsValid(true); - winfoWrap.setWid(wid); - winfoWrap.setIsActive(w->isActive()); - winfoWrap.setIsMinimized(w->isMinimized()); - winfoWrap.setIsMaxVert(w->isMaximized()); - winfoWrap.setIsMaxHoriz(w->isMaximized()); - winfoWrap.setIsFullscreen(w->isFullscreen()); - winfoWrap.setIsShaded(w->isShaded()); - winfoWrap.setGeometry(w->geometry()); - } else if (w->appId() == QLatin1String("org.kde.plasmashell")) { - winfoWrap.setIsValid(true); - winfoWrap.setIsPlasmaDesktop(true); - winfoWrap.setWid(wid); + if (w) { + if (isValidWindow(w)) { + winfoWrap.setIsValid(true); + winfoWrap.setWid(wid); + winfoWrap.setIsActive(w->isActive()); + winfoWrap.setIsMinimized(w->isMinimized()); + winfoWrap.setIsMaxVert(w->isMaximized()); + winfoWrap.setIsMaxHoriz(w->isMaximized()); + winfoWrap.setIsFullscreen(w->isFullscreen()); + winfoWrap.setIsShaded(w->isShaded()); + winfoWrap.setGeometry(w->geometry()); + winfoWrap.setHasSkipTaskbar(w->skipTaskbar()); + } else if (w->appId() == QLatin1String("org.kde.plasmashell")) { + winfoWrap.setIsValid(true); + winfoWrap.setIsPlasmaDesktop(true); + winfoWrap.setWid(wid); + } + } else { + return {}; } return winfoWrap; } -bool WaylandInterface::activeWindowCanBeDragged() const +KWayland::Client::PlasmaWindow *WaylandInterface::windowFor(WindowId wid) const { - WindowInfoWrap activeInfo = requestInfoActive(); - return (activeInfo.isValid() && !activeInfo.isPlasmaDesktop() && !activeInfo.hasSkipTaskbar()); + auto it = std::find_if(m_windowManagement->windows().constBegin(), m_windowManagement->windows().constEnd(), [&wid](PlasmaWindow * w) noexcept { + return w->isValid() && w->internalId() == wid; + }); + + if (it == m_windowManagement->windows().constEnd()) { + return nullptr; + } + + return *it; } -void WaylandInterface::requestMoveActiveWindow(QPoint from) const +bool WaylandInterface::windowCanBeDragged(WindowId wid) const { - //to be supported + WindowInfoWrap winfo = requestInfo(wid); + return (winfo.isValid() && !winfo.isPlasmaDesktop() && !winfo.hasSkipTaskbar()); +} + +void WaylandInterface::requestMoveWindow(WindowId wid, QPoint from) const +{ + if (windowCanBeDragged(wid)) { + auto w = windowFor(wid); + + if (w && isValidWindow(w)) { + w->requestMove(); + } + } +} + +void WaylandInterface::requestToggleMaximized(WindowId wid) const +{ + auto w = windowFor(wid); + + if (w && isValidWindow(w)) { + w->requestToggleMaximized(); + } } inline bool WaylandInterface::isValidWindow(const KWayland::Client::PlasmaWindow *w) const diff --git a/app/waylandinterface.h b/app/waylandinterface.h index b751f1fa3..1aa05a658 100644 --- a/app/waylandinterface.h +++ b/app/waylandinterface.h @@ -75,8 +75,9 @@ public: void slideWindow(QWindow &view, Slide location) const override; void enableBlurBehind(QWindow &view) const override; - void requestMoveActiveWindow(QPoint from) const override; - bool activeWindowCanBeDragged() const; + void requestToggleMaximized(WindowId wid) const override; + void requestMoveWindow(WindowId wid, QPoint from) const override; + bool windowCanBeDragged(WindowId wid) const; void setEdgeStateFor(QWindow *view, bool active) const override; @@ -86,6 +87,7 @@ private: void init(); inline bool isValidWindow(const KWayland::Client::PlasmaWindow *w) const; void windowCreatedProxy(KWayland::Client::PlasmaWindow *w); + KWayland::Client::PlasmaWindow *windowFor(WindowId wid) const; KWayland::Client::PlasmaShell *waylandDockCoronaInterface() const; QSignalMapper *mapper{nullptr}; diff --git a/app/xwindowinterface.cpp b/app/xwindowinterface.cpp index 25ca4c893..85e5e8ab0 100644 --- a/app/xwindowinterface.cpp +++ b/app/xwindowinterface.cpp @@ -322,28 +322,28 @@ WindowInfoWrap XWindowInterface::requestInfo(WindowId wid) const return winfoWrap; } -bool XWindowInterface::activeWindowCanBeDragged() const +bool XWindowInterface::windowCanBeDragged(WindowId wid) const { - WindowInfoWrap activeInfo = requestInfoActive(); - return (activeInfo.isValid() && !activeInfo.isPlasmaDesktop() && !activeInfo.hasSkipTaskbar()); + WindowInfoWrap winfo = requestInfo(wid); + return (winfo.isValid() && !winfo.isPlasmaDesktop() && !winfo.hasSkipTaskbar()); } -void XWindowInterface::requestMoveActiveWindow(QPoint from) const +void XWindowInterface::requestMoveWindow(WindowId wid, QPoint from) const { - WindowInfoWrap activeInfo = requestInfoActive(); + WindowInfoWrap wInfo = requestInfo(wid); - if (!activeInfo.isValid() || activeInfo.isPlasmaDesktop()) { + if (!wInfo.isValid() || wInfo.isPlasmaDesktop()) { return; } - int borderX{activeInfo.geometry().width() > 120 ? 60 : 10}; + int borderX{wInfo.geometry().width() > 120 ? 60 : 10}; int borderY{10}; //! find min/max values for x,y based on active window geometry - int minX = activeInfo.geometry().x() + borderX; - int maxX = activeInfo.geometry().x() + activeInfo.geometry().width() - borderX; - int minY = activeInfo.geometry().y() + borderY; - int maxY = activeInfo.geometry().y() + activeInfo.geometry().height() - borderY; + int minX = wInfo.geometry().x() + borderX; + int maxX = wInfo.geometry().x() + wInfo.geometry().width() - borderX; + int minY = wInfo.geometry().y() + borderY; + int maxY = wInfo.geometry().y() + wInfo.geometry().height() - borderY; //! set the point from which this window will be moved, //! make sure that it is in window boundaries @@ -351,9 +351,22 @@ void XWindowInterface::requestMoveActiveWindow(QPoint from) const int validY = qBound(minY, from.y(), maxY); NETRootInfo ri(QX11Info::connection(), NET::WMMoveResize); - ri.moveResizeRequest(activeInfo.wid().toUInt(), validX, validY, NET::Move); + ri.moveResizeRequest(wInfo.wid().toUInt(), validX, validY, NET::Move); } +void XWindowInterface::requestToggleMaximized(WindowId wid) const +{ + WindowInfoWrap wInfo = requestInfo(wid); + bool restore = wInfo.isMaxHoriz() && wInfo.isMaxVert(); + + NETWinInfo ni(QX11Info::connection(), wid.toInt(), QX11Info::appRootWindow(), NET::WMState, NET::Properties2()); + + if (restore) { + ni.setState(NET::States(), NET::Max); + } else { + ni.setState(NET::Max, NET::Max); + } +} bool XWindowInterface::isValidWindow(const KWindowInfo &winfo) const { diff --git a/app/xwindowinterface.h b/app/xwindowinterface.h index 0af55e0fa..a17dbd4fe 100644 --- a/app/xwindowinterface.h +++ b/app/xwindowinterface.h @@ -58,8 +58,9 @@ public: void slideWindow(QWindow &view, Slide location) const override; void enableBlurBehind(QWindow &view) const override; - void requestMoveActiveWindow(QPoint from) const override; - bool activeWindowCanBeDragged() const override; + void requestToggleMaximized(WindowId wid) const override; + void requestMoveWindow(WindowId wid, QPoint from) const override; + bool windowCanBeDragged(WindowId wid) const override; void setEdgeStateFor(QWindow *view, bool active) const override; diff --git a/containment/package/contents/ui/RootMouseArea.qml b/containment/package/contents/ui/RootMouseArea.qml index 3bbae06e3..6435bcd6d 100644 --- a/containment/package/contents/ui/RootMouseArea.qml +++ b/containment/package/contents/ui/RootMouseArea.qml @@ -22,8 +22,6 @@ import QtQuick 2.7 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.plasmoid 2.0 -import org.kde.taskmanager 0.1 as TaskManager - MouseArea{ id: mainArea @@ -71,7 +69,8 @@ MouseArea{ onDoubleClicked: { drawWindowTimer.stop(); restoreGrabberTimer.stop(); - tasksModel.requestToggleMaximized(tasksModel.activeTask); + dock.visibility.requestToggleMaximizeForActiveWindow(); + //tasksModel.requestToggleMaximized(tasksModel.activeTask); } function activateDragging(){ @@ -99,27 +98,4 @@ MouseArea{ mainArea.lastPressY = -1; } } - - ////////// Dragging windows etc.... - TaskManager.TasksModel { - id: tasksModel - sortMode: TaskManager.TasksModel.SortVirtualDesktop - groupMode: TaskManager.TasksModel.GroupDisabled - - virtualDesktop: virtualDesktopInfo.currentDesktop - activity: activityInfo.currentActivity - screenGeometry: plasmoid.screenGeometry - - filterByVirtualDesktop: true - filterByScreen: true - filterByActivity: true - } - TaskManager.VirtualDesktopInfo { - id: virtualDesktopInfo - } - - TaskManager.ActivityInfo { - id: activityInfo - } - ////////// Dragging windows etc.... }