diff --git a/app/wm/abstractwindowinterface.cpp b/app/wm/abstractwindowinterface.cpp index 2b08cfcf..39bd5fef 100644 --- a/app/wm/abstractwindowinterface.cpp +++ b/app/wm/abstractwindowinterface.cpp @@ -1,107 +1,126 @@ /* * Copyright 2016 Smith AR * Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Latte-Dock is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "abstractwindowinterface.h" // local #include "tracker/schemes.h" #include "tracker/trackerwindows.h" #include "../lattecorona.h" namespace Latte { namespace WindowSystem { AbstractWindowInterface::AbstractWindowInterface(QObject *parent) : QObject(parent) { + m_activities = new KActivities::Consumer(this); + m_currentActivity = m_activities->currentActivity(); + m_corona = qobject_cast(parent); m_windowsTracker = new Tracker::Windows(this); m_schemesTracker = new Tracker::Schemes(this); rulesConfig = KSharedConfig::openConfig(QStringLiteral("taskmanagerrulesrc")); m_windowWaitingTimer.setInterval(150); m_windowWaitingTimer.setSingleShot(true); connect(&m_windowWaitingTimer, &QTimer::timeout, this, [&]() { WindowId wid = m_windowChangedWaiting; m_windowChangedWaiting = QVariant(); emit windowChanged(wid); }); connect(this, &AbstractWindowInterface::windowChanged, this, [&](WindowId wid) { qDebug() << "WINDOW CHANGED ::: " << wid; }); + + connect(m_activities.data(), &KActivities::Consumer::currentActivityChanged, this, [&](const QString &id) { + m_currentActivity = id; + emit currentActivityChanged(); + }); + } AbstractWindowInterface::~AbstractWindowInterface() { m_windowWaitingTimer.stop(); m_schemesTracker->deleteLater(); m_windowsTracker->deleteLater(); } +QString AbstractWindowInterface::currentDesktop() const +{ + return m_currentDesktop; +} + +QString AbstractWindowInterface::currentActivity() const +{ + return m_currentActivity; +} + Latte::Corona *AbstractWindowInterface::corona() { return m_corona; } Tracker::Schemes *AbstractWindowInterface::schemesTracker() { return m_schemesTracker; } Tracker::Windows *AbstractWindowInterface::windowsTracker() const { return m_windowsTracker; } void AbstractWindowInterface::considerWindowChanged(WindowId wid) { //! Consider if the windowChanged signal should be sent DIRECTLY or WAIT if (m_windowChangedWaiting == wid && m_windowWaitingTimer.isActive()) { //! window should be sent later m_windowWaitingTimer.start(); return; } if (m_windowChangedWaiting != wid && !m_windowWaitingTimer.isActive()) { //! window should be sent later m_windowChangedWaiting = wid; m_windowWaitingTimer.start(); } if (m_windowChangedWaiting != wid && m_windowWaitingTimer.isActive()) { m_windowWaitingTimer.stop(); //! sent previous waiting window emit (m_windowChangedWaiting); //! retrigger waiting for the upcoming window m_windowChangedWaiting = wid; m_windowWaitingTimer.start(); } } } } diff --git a/app/wm/abstractwindowinterface.h b/app/wm/abstractwindowinterface.h index 803c0288..fbd4bb04 100644 --- a/app/wm/abstractwindowinterface.h +++ b/app/wm/abstractwindowinterface.h @@ -1,154 +1,158 @@ /* * Copyright 2016 Smith AR * Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Latte-Dock is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef ABSTRACTWINDOWINTERFACE_H #define ABSTRACTWINDOWINTERFACE_H // local #include "schemecolors.h" #include "tasktools.h" #include "windowinfowrap.h" #include "tracker/trackerwindows.h" #include "../liblatte2/types.h" #include "../liblatte2/extras.h" // C++ #include #include // Qt #include #include #include #include #include #include #include #include #include // KDE #include #include // Plasma #include namespace Latte { class Corona; namespace WindowSystem { namespace Tracker { class Schemes; class Windows; } } } namespace Latte { namespace WindowSystem { class AbstractWindowInterface : public QObject { Q_OBJECT public: enum class Slide { None, Top, Left, Bottom, Right, }; explicit AbstractWindowInterface(QObject *parent = nullptr); virtual ~AbstractWindowInterface(); virtual void setViewExtraFlags(QWindow &view) = 0; virtual void setViewStruts(QWindow &view, const QRect &rect , Plasma::Types::Location location) = 0; virtual void setWindowOnActivities(QWindow &window, const QStringList &activities) = 0; virtual void removeViewStruts(QWindow &view) const = 0; virtual WindowId activeWindow() const = 0; virtual WindowInfoWrap requestInfo(WindowId wid) const = 0; virtual WindowInfoWrap requestInfoActive() const = 0; - virtual bool isOnCurrentDesktop(WindowId wid) const = 0; - virtual bool isOnCurrentActivity(WindowId wid) const = 0; virtual void setKeepAbove(const QDialog &dialog, bool above = true) const = 0; virtual void skipTaskBar(const QDialog &dialog) const = 0; virtual void slideWindow(QWindow &view, Slide location) const = 0; virtual void enableBlurBehind(QWindow &view) const = 0; virtual void setEdgeStateFor(QWindow *view, bool active) const = 0; virtual void releaseMouseEventFor(WindowId wid) const = 0; virtual void requestActivate(WindowId wid) const = 0; virtual void requestClose(WindowId wid) const = 0; virtual void requestMoveWindow(WindowId wid, QPoint from) const = 0; virtual void requestToggleIsOnAllDesktops(WindowId wid) const = 0; virtual void requestToggleKeepAbove(WindowId wid) const = 0; virtual void requestToggleMinimized(WindowId wid) const = 0; virtual void requestToggleMaximized(WindowId wid) const = 0; virtual bool windowCanBeDragged(WindowId wid) const = 0; virtual QIcon iconFor(WindowId wid) const = 0; virtual WindowId winIdFor(QString appId, QRect geometry) const = 0; virtual AppData appDataFor(WindowId wid) const = 0; + QString currentDesktop() const; + QString currentActivity() const; + Latte::Corona *corona(); Tracker::Schemes *schemesTracker(); Tracker::Windows *windowsTracker() const; signals: void activeWindowChanged(WindowId wid); void windowChanged(WindowId winfo); void windowAdded(WindowId wid); void windowRemoved(WindowId wid); void currentDesktopChanged(); void currentActivityChanged(); protected: + QString m_currentDesktop; + QString m_currentActivity; + QPointer m_activities; //! Sending too fast plenty of signals for the same window //! has no reason and can create HIGH CPU usage. This Timer //! can delay the batch sending of signals for the same window WindowId m_windowChangedWaiting; QTimer m_windowWaitingTimer; //! Plasma taskmanager rules ile KSharedConfig::Ptr rulesConfig; void considerWindowChanged(WindowId wid); private: Latte::Corona *m_corona; Tracker::Schemes *m_schemesTracker; Tracker::Windows *m_windowsTracker; }; } } #endif // ABSTRACTWINDOWINTERFACE_H diff --git a/app/wm/tracker/trackerwindows.cpp b/app/wm/tracker/trackerwindows.cpp index b120c522..f7797f1b 100644 --- a/app/wm/tracker/trackerwindows.cpp +++ b/app/wm/tracker/trackerwindows.cpp @@ -1,624 +1,624 @@ /* * Copyright 2019 Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Latte-Dock is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "trackerwindows.h" // local #include "lastactivewindow.h" #include "schemes.h" #include "trackedviewinfo.h" #include "../abstractwindowinterface.h" #include "../schemecolors.h" #include "../../lattecorona.h" #include "../../layouts/manager.h" #include "../../view/view.h" #include "../../view/positioner.h" #include "../../../liblatte2/types.h" namespace Latte { namespace WindowSystem { namespace Tracker { Windows::Windows(AbstractWindowInterface *parent) : QObject(parent) { m_wm = parent; init(); } Windows::~Windows() { //! clear all the m_views tracking information for (QHash::iterator i=m_views.begin(); i!=m_views.end(); ++i) { i.value()->deleteLater(); m_views[i.key()] = nullptr; } m_views.clear(); } void Windows::init() { connect(m_wm->corona(), &Plasma::Corona::availableScreenRectChanged, this, &Windows::updateAvailableScreenGeometries); connect(m_wm, &AbstractWindowInterface::windowChanged, this, [&](WindowId wid) { m_windows[wid] = m_wm->requestInfo(wid); updateViewsHints(); emit windowChanged(wid); }); connect(m_wm, &AbstractWindowInterface::windowRemoved, this, [&](WindowId wid) { m_windows.remove(wid); updateViewsHints(); emit windowRemoved(wid); }); connect(m_wm, &AbstractWindowInterface::windowAdded, this, [&](WindowId wid) { if (!m_windows.contains(wid)) { m_windows.insert(wid, m_wm->requestInfo(wid)); } updateViewsHints(); }); connect(m_wm, &AbstractWindowInterface::activeWindowChanged, this, [&](WindowId wid) { //! for some reason this is needed in order to update properly activeness values //! when the active window changes the previous active windows should be also updated for (const auto view : m_views.keys()) { WindowId lastWinId = m_views[view]->lastActiveWindow()->winId(); if ((lastWinId) != wid && m_windows.contains(lastWinId)) { m_windows[lastWinId] = m_wm->requestInfo(lastWinId); } } m_windows[wid] = m_wm->requestInfo(wid); updateViewsHints(); emit activeWindowChanged(wid); }); connect(m_wm, &AbstractWindowInterface::currentDesktopChanged, this, [&] { updateViewsHints(); }); connect(m_wm, &AbstractWindowInterface::currentActivityChanged, this, [&] { if (m_wm->corona()->layoutsManager()->memoryUsage() == Types::MultipleLayouts) { //! this is needed in MultipleLayouts because there is a chance that multiple //! layouts are providing different available screen geometries in different Activities updateAvailableScreenGeometries(); } updateViewsHints(); }); } void Windows::initViewHints(Latte::View *view) { if (!m_views.contains(view)) { return; } setActiveWindowMaximized(view, false); setActiveWindowTouching(view, false); setExistsWindowActive(view, false); setExistsWindowTouching(view, false); setExistsWindowMaximized(view, false); setActiveWindowScheme(view, nullptr); setTouchingWindowScheme(view, nullptr); } AbstractWindowInterface *Windows::wm() { return m_wm; } void Windows::addView(Latte::View *view) { if (m_views.contains(view)) { return; } m_views[view] = new TrackedViewInfo(this, view); updateAvailableScreenGeometries(); updateHints(view); } void Windows::removeView(Latte::View *view) { if (!m_views.contains(view)) { return; } m_views[view]->deleteLater(); m_views.remove(view); } //! Views Properties And Hints bool Windows::enabled(Latte::View *view) { if (!m_views.contains(view)) { return false; } return m_views[view]->enabled(); } void Windows::setEnabled(Latte::View *view, const bool enabled) { if (!m_views.contains(view) || m_views[view]->enabled() == enabled) { return; } m_views[view]->setEnabled(enabled); if (enabled) { updateHints(view); } else { initViewHints(view); } emit enabledChanged(view); } bool Windows::activeWindowMaximized(Latte::View *view) const { if (!m_views.contains(view)) { return false; } return m_views[view]->activeWindowMaximized(); } void Windows::setActiveWindowMaximized(Latte::View *view, bool activeMaximized) { if (!m_views.contains(view) || m_views[view]->activeWindowMaximized() == activeMaximized) { return; } m_views[view]->setActiveWindowMaximized(activeMaximized); emit activeWindowMaximizedChanged(view); } bool Windows::activeWindowTouching(Latte::View *view) const { if (!m_views.contains(view)) { return false; } return m_views[view]->activeWindowTouching(); } void Windows::setActiveWindowTouching(Latte::View *view, bool activeTouching) { if (!m_views.contains(view) || m_views[view]->activeWindowTouching() == activeTouching) { return; } m_views[view]->setActiveWindowTouching(activeTouching); emit activeWindowTouchingChanged(view); } bool Windows::existsWindowActive(Latte::View *view) const { if (!m_views.contains(view)) { return false; } return m_views[view]->existsWindowActive(); } void Windows::setExistsWindowActive(Latte::View *view, bool windowActive) { if (!m_views.contains(view) || m_views[view]->existsWindowActive() == windowActive) { return; } m_views[view]->setExistsWindowActive(windowActive); emit existsWindowActiveChanged(view); } bool Windows::existsWindowMaximized(Latte::View *view) const { if (!m_views.contains(view)) { return false; } return m_views[view]->existsWindowMaximized(); } void Windows::setExistsWindowMaximized(Latte::View *view, bool windowMaximized) { if (!m_views.contains(view) || m_views[view]->existsWindowMaximized() == windowMaximized) { return; } m_views[view]->setExistsWindowMaximized(windowMaximized); emit existsWindowMaximizedChanged(view); } bool Windows::existsWindowTouching(Latte::View *view) const { if (!m_views.contains(view)) { return false; } return m_views[view]->existsWindowTouching(); } void Windows::setExistsWindowTouching(Latte::View *view, bool windowTouching) { if (!m_views.contains(view) || m_views[view]->existsWindowTouching() == windowTouching) { return; } m_views[view]->setExistsWindowTouching(windowTouching); emit existsWindowTouchingChanged(view); } SchemeColors *Windows::activeWindowScheme(Latte::View *view) const { if (!m_views.contains(view)) { return nullptr; } return m_views[view]->activeWindowScheme(); } void Windows::setActiveWindowScheme(Latte::View *view, WindowSystem::SchemeColors *scheme) { if (!m_views.contains(view) || m_views[view]->activeWindowScheme() == scheme) { return; } m_views[view]->setActiveWindowScheme(scheme); emit activeWindowSchemeChanged(view); } SchemeColors *Windows::touchingWindowScheme(Latte::View *view) const { if (!m_views.contains(view)) { return nullptr; } return m_views[view]->touchingWindowScheme(); } void Windows::setTouchingWindowScheme(Latte::View *view, WindowSystem::SchemeColors *scheme) { if (!m_views.contains(view) || m_views[view]->touchingWindowScheme() == scheme) { return; } m_views[view]->setTouchingWindowScheme(scheme); emit touchingWindowSchemeChanged(view); } LastActiveWindow *Windows::lastActiveWindow(Latte::View *view) { if (!m_views.contains(view)) { return nullptr; } return m_views[view]->lastActiveWindow(); } bool Windows::isValidFor(const WindowId &wid) const { if (!m_windows.contains(wid)) { return false; } return m_windows[wid].isValid() && !m_windows[wid].isPlasmaDesktop(); } QIcon Windows::iconFor(const WindowId &wid) { if (!m_windows.contains(wid)) { return QIcon(); } if (m_windows[wid].icon().isNull()) { AppData data = m_wm->appDataFor(wid); QIcon icon = data.icon; if (icon.isNull()) { icon = m_wm->iconFor(wid); } m_windows[wid].setIcon(icon); return icon; } return m_windows[wid].icon(); } QString Windows::appNameFor(const WindowId &wid) { if (!m_windows.contains(wid)) { return QString(); } if (m_windows[wid].appName().isEmpty()) { AppData data = m_wm->appDataFor(wid); m_windows[wid].setAppName(data.name); return data.name; } return m_windows[wid].appName(); } WindowInfoWrap Windows::infoFor(const WindowId &wid) const { if (!m_windows.contains(wid)) { return WindowInfoWrap(); } return m_windows[wid]; } //! Windows Criteria Functions bool Windows::inCurrentDesktopActivity(const WindowInfoWrap &winfo) { - return (winfo.isValid() && m_wm->isOnCurrentDesktop(winfo.wid()) && m_wm->isOnCurrentActivity(winfo.wid())); + return (winfo.isValid() && winfo.isOnDesktop(m_wm->currentDesktop()) && winfo.isOnActivity(m_wm->currentActivity())); } bool Windows::intersects(Latte::View *view, const WindowInfoWrap &winfo) { return (!winfo.isMinimized() && !winfo.isShaded() && winfo.geometry().intersects(view->absoluteGeometry())); } bool Windows::isActive(const WindowInfoWrap &winfo) { return (winfo.isValid() && winfo.isActive() && !winfo.isPlasmaDesktop() && !winfo.isMinimized()); } bool Windows::isActiveInViewScreen(Latte::View *view, const WindowInfoWrap &winfo) { return (winfo.isValid() && winfo.isActive() && !winfo.isPlasmaDesktop() && !winfo.isMinimized() && m_views[view]->availableScreenGeometry().contains(winfo.geometry().center())); } bool Windows::isMaximizedInViewScreen(Latte::View *view, const WindowInfoWrap &winfo) { auto viewIntersectsMaxVert = [&]() noexcept -> bool { return ((winfo.isMaxVert() || (view->screen() && view->screen()->availableSize().height() <= winfo.geometry().height())) && intersects(view, winfo)); }; auto viewIntersectsMaxHoriz = [&]() noexcept -> bool { return ((winfo.isMaxHoriz() || (view->screen() && view->screen()->availableSize().width() <= winfo.geometry().width())) && intersects(view, winfo)); }; //! updated implementation to identify the screen that the maximized window is present //! in order to avoid: https://bugs.kde.org/show_bug.cgi?id=397700 return (winfo.isValid() && !winfo.isPlasmaDesktop() && !winfo.isMinimized() && (winfo.isMaximized() || viewIntersectsMaxVert() || viewIntersectsMaxHoriz()) && m_views[view]->availableScreenGeometry().contains(winfo.geometry().center())); } bool Windows::isTouchingView(Latte::View *view, const WindowSystem::WindowInfoWrap &winfo) { return (winfo.isValid() && !winfo.isPlasmaDesktop() && intersects(view, winfo)); } bool Windows::isTouchingViewEdge(Latte::View *view, const WindowInfoWrap &winfo) { if (winfo.isValid() && !winfo.isPlasmaDesktop() && !winfo.isMinimized()) { bool touchingViewEdge{false}; QRect screenGeometry = view->screenGeometry(); QRect availableScreenGeometry = m_views[view]->availableScreenGeometry(); bool inCurrentScreen{screenGeometry.contains(winfo.geometry().topLeft()) || screenGeometry.contains(winfo.geometry().bottomRight())}; if (inCurrentScreen) { if (view->location() == Plasma::Types::TopEdge) { touchingViewEdge = (winfo.geometry().y() == availableScreenGeometry.y()); } else if (view->location() == Plasma::Types::BottomEdge) { touchingViewEdge = (winfo.geometry().bottom() == availableScreenGeometry.bottom()); } else if (view->location() == Plasma::Types::LeftEdge) { touchingViewEdge = (winfo.geometry().x() == availableScreenGeometry.x()); } else if (view->location() == Plasma::Types::RightEdge) { touchingViewEdge = (winfo.geometry().right() == availableScreenGeometry.right()); } } return touchingViewEdge; } return false; } void Windows::cleanupFaultyWindows() { for (const auto &key : m_windows.keys()) { auto winfo = m_windows[key]; //! garbage windows removing if (winfo.geometry() == QRect(0, 0, 0, 0)) { //qDebug() << "Faulty Geometry ::: " << winfo.wid(); m_windows.remove(key); } } } void Windows::updateAvailableScreenGeometries() { for (const auto view : m_views.keys()) { if (m_views[view]->enabled()) { int currentScrId = view->positioner()->currentScreenId(); QRect tempAvailableScreenGeometry = m_wm->corona()->availableScreenRectWithCriteria(currentScrId, {Types::AlwaysVisible}, {}); if (tempAvailableScreenGeometry != m_views[view]->availableScreenGeometry()) { m_views[view]->setAvailableScreenGeometry(tempAvailableScreenGeometry); updateHints(view); } } } } void Windows::setPlasmaDesktop(WindowId wid) { if (!m_windows.contains(wid)) { return; } if (!m_windows[wid].isPlasmaDesktop()) { m_windows[wid].setIsPlasmaDesktop(true); qDebug() << " plasmashell updated..."; updateViewsHints(); } } void Windows::updateViewsHints() { for (const auto view : m_views.keys()) { if (m_views[view]->enabled()) { updateHints(view); } } } void Windows::updateHints(Latte::View *view) { if (!m_views.contains(view)) { return; } bool foundActive{false}; bool foundActiveInCurScreen{false}; bool foundActiveTouchInCurScreen{false}; bool foundTouchInCurScreen{false}; bool foundMaximizedInCurScreen{false}; //! the notification window is not sending a remove signal and creates windows of geometry (0x0 0,0), //! maybe a garbage collector here is a good idea!!! bool existsFaultyWindow{false}; WindowId maxWinId; WindowId activeWinId; WindowId touchWinId; WindowId activeTouchWinId; for (const auto &winfo : m_windows) { if (winfo.isPlasmaDesktop() || !inCurrentDesktopActivity(winfo)) { continue; } if (isActive(winfo)) { foundActive = true; } if (isActiveInViewScreen(view, winfo)) { foundActiveInCurScreen = true; activeWinId = winfo.wid(); } if (isTouchingViewEdge(view, winfo) || isTouchingView(view, winfo)) { if (winfo.isActive()) { foundActiveTouchInCurScreen = true; activeTouchWinId = winfo.wid(); if (isMaximizedInViewScreen(view, winfo)) { //! active maximized windows have higher priority than the rest maximized windows foundMaximizedInCurScreen = true; maxWinId = winfo.wid(); } } else { foundTouchInCurScreen = true; touchWinId = winfo.wid(); } if (!foundMaximizedInCurScreen && isMaximizedInViewScreen(view, winfo)) { foundMaximizedInCurScreen = true; maxWinId = winfo.wid(); } } if (!existsFaultyWindow && winfo.geometry() == QRect(0, 0, 0, 0)) { existsFaultyWindow = true; } //qDebug() << "window geometry ::: " << winfo.geometry(); } if (existsFaultyWindow) { cleanupFaultyWindows(); } //! HACK: KWin Effects such as ShowDesktop have no way to be identified and as such //! create issues with identifying properly touching and maximized windows. BUT when //! they are enabled then NO ACTIVE window is found. This is a way to identify these //! effects trigerring and disable the touch flags. //! BUG: 404483 //! Disabled because it has fault identifications, e.g. when a window is maximized and //! Latte or Plasma are showing their View settings //foundMaximizedInCurScreen = foundMaximizedInCurScreen && foundActive; //foundTouchInCurScreen = foundTouchInCurScreen && foundActive; //! assign flags setExistsWindowActive(view, foundActiveInCurScreen); setActiveWindowTouching(view, foundActiveTouchInCurScreen); setActiveWindowMaximized(view, (maxWinId.toInt()>0 && (maxWinId == activeTouchWinId))); setExistsWindowMaximized(view, foundMaximizedInCurScreen); setExistsWindowTouching(view, (foundTouchInCurScreen || foundActiveTouchInCurScreen)); //! update color schemes for active and touching windows setActiveWindowScheme(view, (foundActiveInCurScreen ? m_wm->schemesTracker()->schemeForWindow(activeWinId) : nullptr)); if (foundActiveTouchInCurScreen) { setTouchingWindowScheme(view, m_wm->schemesTracker()->schemeForWindow(activeTouchWinId)); } else if (foundMaximizedInCurScreen) { setTouchingWindowScheme(view, m_wm->schemesTracker()->schemeForWindow(maxWinId)); } else if (foundTouchInCurScreen) { setTouchingWindowScheme(view, m_wm->schemesTracker()->schemeForWindow(touchWinId)); } else { setTouchingWindowScheme(view, nullptr); } //! update LastActiveWindow if (foundActiveInCurScreen) { m_views[view]->setActiveWindow(activeWinId); } //! Debug //qDebug() << "TRACKING | SCREEN: " << view->positioner()->currentScreenId() << " , EDGE:" << view->location() << " , ENABLED:" << enabled(view); //qDebug() << "TRACKING | activeWindowTouching: " << foundActiveTouchInCurScreen << " ,activeWindowMaximized: " << activeWindowMaximized(view); //qDebug() << "TRACKING | existsWindowActive: " << foundActiveInCurScreen << " , existsWindowMaximized:" << existsWindowMaximized(view) // << " , existsWindowTouching:"< * Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Latte-Dock is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "waylandinterface.h" // local #include "view/screenedgeghostwindow.h" #include "view/view.h" #include "../lattecorona.h" #include "../liblatte2/extras.h" // Qt #include #include #include #include #include #include // KDE #include #include #include #if KF5_VERSION_MINOR >= 52 #include #endif // X11 #include using namespace KWayland::Client; namespace Latte { class Private::GhostWindow : public QRasterWindow { Q_OBJECT public: GhostWindow(WindowSystem::WaylandInterface *waylandInterface) : m_waylandInterface(waylandInterface) { setFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::NoDropShadowWindowHint | Qt::WindowDoesNotAcceptFocus); setupWaylandIntegration(); show(); } ~GhostWindow() { delete m_shellSurface; } void setGeometry(const QRect &rect) { QWindow::setGeometry(rect); setMaximumSize(rect.size()); m_shellSurface->setPosition(rect.topLeft()); } void setupWaylandIntegration() { using namespace KWayland::Client; if (m_shellSurface) return; Surface *s{Surface::fromWindow(this)}; if (!s) return; m_shellSurface = m_waylandInterface->waylandCoronaInterface()->createSurface(s, this); qDebug() << "wayland ghost window surface was created..."; m_shellSurface->setSkipTaskbar(true); m_shellSurface->setPanelTakesFocus(false); m_shellSurface->setRole(PlasmaShellSurface::Role::Panel); m_shellSurface->setPanelBehavior(PlasmaShellSurface::PanelBehavior::AlwaysVisible); } KWayland::Client::PlasmaShellSurface *m_shellSurface{nullptr}; WindowSystem::WaylandInterface *m_waylandInterface{nullptr}; }; namespace WindowSystem { WaylandInterface::WaylandInterface(QObject *parent) : AbstractWindowInterface(parent) { m_corona = qobject_cast(parent); - - m_activities = new KActivities::Consumer(this); - - - connect(m_activities.data(), &KActivities::Consumer::currentActivityChanged - , this, &WaylandInterface::currentActivityChanged); } WaylandInterface::~WaylandInterface() { } void WaylandInterface::init() { } void WaylandInterface::initWindowManagement(KWayland::Client::PlasmaWindowManagement *windowManagement) { if (m_windowManagement == windowManagement) { return; } m_windowManagement = windowManagement; connect(m_windowManagement, &PlasmaWindowManagement::windowCreated, this, &WaylandInterface::windowCreatedProxy); connect(m_windowManagement, &PlasmaWindowManagement::activeWindowChanged, this, [&]() noexcept { auto w = m_windowManagement->activeWindow(); if (!w || (w && (!isPlasmaDesktop(w) && w->appId() != QLatin1String("latte-dock")))) { emit activeWindowChanged(w ? w->internalId() : 0); } }, Qt::QueuedConnection); } #if KF5_VERSION_MINOR >= 52 void WaylandInterface::initVirtualDesktopManagement(KWayland::Client::PlasmaVirtualDesktopManagement *virtualDesktopManagement) { if (m_virtualDesktopManagement == virtualDesktopManagement) { return; } m_virtualDesktopManagement = virtualDesktopManagement; connect(m_virtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopCreated, this, [this](const QString &id, quint32 position) { addDesktop(id, position); }); connect(m_virtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopRemoved, this, [this](const QString &id) { m_desktops.removeAll(id); if (m_currentDesktop == id) { setCurrentDesktop(QString()); } }); } void WaylandInterface::addDesktop(const QString &id, quint32 position) { if (m_desktops.contains(id)) { return; } m_desktops.append(id); const KWayland::Client::PlasmaVirtualDesktop *desktop = m_virtualDesktopManagement->getVirtualDesktop(id); QObject::connect(desktop, &KWayland::Client::PlasmaVirtualDesktop::activated, this, [desktop, this]() { setCurrentDesktop(desktop->id()); } ); if (desktop->isActive()) { setCurrentDesktop(id); } } void WaylandInterface::setCurrentDesktop(QString desktop) { if (m_currentDesktop == desktop) { return; } m_currentDesktop = desktop; emit currentDesktopChanged(); } #endif KWayland::Client::PlasmaShell *WaylandInterface::waylandCoronaInterface() const { return m_corona->waylandCoronaInterface(); } void WaylandInterface::setViewExtraFlags(QWindow &view) { Q_UNUSED(view) } void WaylandInterface::setViewStruts(QWindow &view, const QRect &rect, Plasma::Types::Location location) { if (!m_ghostWindows.contains(view.winId())) m_ghostWindows[view.winId()] = new Private::GhostWindow(this); auto w = m_ghostWindows[view.winId()]; switch (location) { case Plasma::Types::TopEdge: case Plasma::Types::BottomEdge: w->setGeometry({rect.x() + rect.width() / 2, rect.y(), 1, rect.height()}); break; case Plasma::Types::LeftEdge: case Plasma::Types::RightEdge: w->setGeometry({rect.x(), rect.y() + rect.height() / 2, rect.width(), 1}); break; default: break; } } void WaylandInterface::setWindowOnActivities(QWindow &window, const QStringList &activities) { //! needs to updated to wayland case // KWindowSystem::setOnActivities(view.winId(), activities); } void WaylandInterface::removeViewStruts(QWindow &view) const { delete m_ghostWindows.take(view.winId()); } WindowId WaylandInterface::activeWindow() const { if (!m_windowManagement) { return 0; } auto wid = m_windowManagement->activeWindow(); return wid ? wid->internalId() : 0; } void WaylandInterface::setKeepAbove(const QDialog &dialog, bool above) const { if (above) { KWindowSystem::setState(dialog.winId(), NET::KeepAbove); } else { KWindowSystem::clearState(dialog.winId(), NET::KeepAbove); } } void WaylandInterface::skipTaskBar(const QDialog &dialog) const { KWindowSystem::setState(dialog.winId(), NET::SkipTaskbar); } void WaylandInterface::slideWindow(QWindow &view, AbstractWindowInterface::Slide location) const { auto slideLocation = KWindowEffects::NoEdge; switch (location) { case Slide::Top: slideLocation = KWindowEffects::TopEdge; break; case Slide::Bottom: slideLocation = KWindowEffects::BottomEdge; break; case Slide::Left: slideLocation = KWindowEffects::LeftEdge; break; case Slide::Right: slideLocation = KWindowEffects::RightEdge; break; default: break; } KWindowEffects::slideWindow(view.winId(), slideLocation, -1); } void WaylandInterface::enableBlurBehind(QWindow &view) const { KWindowEffects::enableBlurBehind(view.winId()); } void WaylandInterface::setEdgeStateFor(QWindow *view, bool active) const { ViewPart::ScreenEdgeGhostWindow *window = qobject_cast(view); if (!window) { return; } if (window->parentView()->surface() && window->parentView()->visibility() && (window->parentView()->visibility()->mode() == Types::DodgeActive || window->parentView()->visibility()->mode() == Types::DodgeMaximized || window->parentView()->visibility()->mode() == Types::DodgeAllWindows || window->parentView()->visibility()->mode() == Types::AutoHide)) { if (active) { window->showWithMask(); window->surface()->requestHideAutoHidingPanel(); } else { window->hideWithMask(); window->surface()->requestShowAutoHidingPanel(); } } } WindowInfoWrap WaylandInterface::requestInfoActive() const { if (!m_windowManagement) { return {}; } auto w = m_windowManagement->activeWindow(); if (!w) return {}; return requestInfo(w->internalId()); } -bool WaylandInterface::isOnCurrentDesktop(WindowId wid) const -{ - if (!m_windowManagement) { - return true; - } - -#if KF5_VERSION_MINOR >= 52 - auto window = windowFor(wid); - if (window) { - QStringList wvds = window->plasmaVirtualDesktops(); - return (wvds.isEmpty() || (!wvds.isEmpty() && wvds.contains(m_currentDesktop))); - } -#endif - - return true; -} - -bool WaylandInterface::isOnCurrentActivity(WindowId wid) const -{ - return true; -} - WindowInfoWrap WaylandInterface::requestInfo(WindowId wid) const { WindowInfoWrap winfoWrap; auto w = windowFor(wid); if (w) { if (isPlasmaDesktop(w)) { winfoWrap.setIsValid(true); winfoWrap.setIsPlasmaDesktop(true); winfoWrap.setWid(wid); } else 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.setIsOnAllDesktops(w->isOnAllDesktops()); + winfoWrap.setIsOnAllActivities(true); winfoWrap.setGeometry(w->geometry()); winfoWrap.setHasSkipTaskbar(w->skipTaskbar()); winfoWrap.setDisplay(w->title()); +#if KF5_VERSION_MINOR >= 52 + winfoWrap.setDesktops(w->plasmaVirtualDesktops()); +#endif + winfoWrap.setActivities(QStringList()); } } else { return {}; } return winfoWrap; } AppData WaylandInterface::appDataFor(WindowId wid) const { auto window = windowFor(wid); const AppData &data = appDataFromUrl(windowUrlFromMetadata(window->appId(), window->pid(), rulesConfig)); return data; } KWayland::Client::PlasmaWindow *WaylandInterface::windowFor(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 nullptr; } return *it; } QIcon WaylandInterface::iconFor(WindowId wid) const { auto window = windowFor(wid); if (window) { return window->icon(); } return QIcon(); } WindowId WaylandInterface::winIdFor(QString appId, QRect geometry) const { auto it = std::find_if(m_windowManagement->windows().constBegin(), m_windowManagement->windows().constEnd(), [&appId, &geometry](PlasmaWindow * w) noexcept { return w->isValid() && w->appId() == appId && w->geometry() == geometry; }); if (it == m_windowManagement->windows().constEnd()) { return 0; } return (*it)->internalId(); } bool WaylandInterface::windowCanBeDragged(WindowId wid) const { WindowInfoWrap winfo = requestInfo(wid); return (winfo.isValid() && !winfo.isMinimized() && !winfo.isPlasmaDesktop()); } void WaylandInterface::releaseMouseEventFor(WindowId wid) const { // this isnt really needed under wayland } void WaylandInterface::requestActivate(WindowId wid) const { auto w = windowFor(wid); if (w) { w->requestActivate(); } } void WaylandInterface::requestClose(WindowId wid) const { auto w = windowFor(wid); if (w) { w->requestClose(); } } void WaylandInterface::requestMoveWindow(WindowId wid, QPoint from) const { if (windowCanBeDragged(wid)) { auto w = windowFor(wid); if (w && isValidWindow(w)) { w->requestMove(); } } } void WaylandInterface::requestToggleIsOnAllDesktops(WindowId wid) const { #if KF5_VERSION_MINOR >= 52 auto w = windowFor(wid); if (w && isValidWindow(w) && m_desktops.count() > 1) { if (w->isOnAllDesktops()) { w->requestEnterVirtualDesktop(m_currentDesktop); } else { const QStringList &now = w->plasmaVirtualDesktops(); foreach (const QString &desktop, now) { w->requestLeaveVirtualDesktop(desktop); } } } #endif } void WaylandInterface::requestToggleKeepAbove(WindowId wid) const { auto w = windowFor(wid); if (w) { w->requestToggleKeepAbove(); } } void WaylandInterface::requestToggleMinimized(WindowId wid) const { auto w = windowFor(wid); if (w && isValidWindow(w)) { #if KF5_VERSION_MINOR >= 52 if (!m_currentDesktop.isEmpty()) { w->requestEnterVirtualDesktop(m_currentDesktop); } #endif w->requestToggleMinimized(); } } void WaylandInterface::requestToggleMaximized(WindowId wid) const { auto w = windowFor(wid); if (w && isValidWindow(w)) { #if KF5_VERSION_MINOR >= 52 if (!m_currentDesktop.isEmpty()) { w->requestEnterVirtualDesktop(m_currentDesktop); } #endif w->requestToggleMaximized(); } } bool WaylandInterface::isPlasmaDesktop(const KWayland::Client::PlasmaWindow *w) const { if (!w || (w->appId() != QLatin1String("org.kde.plasmashell"))) { return false; } bool hasScreenGeometry{false}; for (const auto scr : qGuiApp->screens()) { if (!w->geometry().isEmpty() && w->geometry() == scr->geometry()) { hasScreenGeometry = true; break; } } return hasScreenGeometry; } bool WaylandInterface::isValidWindow(const KWayland::Client::PlasmaWindow *w) const { //! DEPRECATED comment is case we must reenable this //! because wayland does not have any way yet to identify the window type //! a trick is to just consider windows as valid when they can be shown in the //! taskbar. Of course that creates issues with plasma native dialogs //! e.g. widgets explorer, Activities etc. that are not used to hide //! the dodge views appropriately return w->isValid() && !isPlasmaDesktop(w) && w->appId()!=QLatin1String("latte-dock");// && !w->skipTaskbar(); } void WaylandInterface::windowCreatedProxy(KWayland::Client::PlasmaWindow *w) { if (!isValidWindow(w)) return; if (!mapper) mapper = new QSignalMapper(this); mapper->setMapping(w, w); connect(w, &PlasmaWindow::unmapped, this, [ &, win = w]() noexcept { mapper->removeMappings(win); emit windowRemoved(win->internalId()); }); connect(w, SIGNAL(activeChanged()), mapper, SLOT(map()) ); connect(w, SIGNAL(titleChanged()), mapper, SLOT(map()) ); connect(w, SIGNAL(fullscreenChanged()), mapper, SLOT(map()) ); connect(w, SIGNAL(geometryChanged()), mapper, SLOT(map()) ); connect(w, SIGNAL(maximizedChanged()), mapper, SLOT(map()) ); connect(w, SIGNAL(minimizedChanged()), mapper, SLOT(map()) ); connect(w, SIGNAL(shadedChanged()), mapper, SLOT(map()) ); connect(w, SIGNAL(skipTaskbarChanged()), mapper, SLOT(map()) ); connect(w, SIGNAL(onAllDesktopsChanged()), mapper, SLOT(map()) ); connect(w, SIGNAL(virtualDesktopChanged()), mapper, SLOT(map()) ); #if KF5_VERSION_MINOR >= 52 connect(w, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopEntered, this, [w, this] { mapper->map(w); }); connect(w, &KWayland::Client::PlasmaWindow::plasmaVirtualDesktopLeft, this, [w, this] { mapper->map(w); }); #endif connect(mapper, static_cast(&QSignalMapper::mapped) , this, [&](QObject * w) noexcept { //qDebug() << "window changed:" << qobject_cast(w)->appId(); PlasmaWindow *pW = qobject_cast(w); if (pW && !isPlasmaDesktop(pW) && pW->appId() != QLatin1String("latte-dock")) { considerWindowChanged(pW->internalId()); } }); emit windowAdded(w->internalId()); } } } #include "waylandinterface.moc" diff --git a/app/wm/waylandinterface.h b/app/wm/waylandinterface.h index 3cec9d1d..bea8e5e5 100644 --- a/app/wm/waylandinterface.h +++ b/app/wm/waylandinterface.h @@ -1,143 +1,140 @@ /* * Copyright 2016 Smith AR * Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Latte-Dock is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef WAYLANDINTERFACE_H #define WAYLANDINTERFACE_H // local #include #include "abstractwindowinterface.h" #include "windowinfowrap.h" // Qt #include #include #include // KDE #include #include #include #include #include #include #include namespace Latte { class Corona; namespace Private { //! this class is used to create the struts inside wayland class GhostWindow; } } namespace Latte { namespace WindowSystem { class WaylandInterface : public AbstractWindowInterface { Q_OBJECT public: explicit WaylandInterface(QObject *parent = nullptr); ~WaylandInterface() override; void setViewExtraFlags(QWindow &view) override; void setViewStruts(QWindow &view, const QRect &rect , Plasma::Types::Location location) override; void setWindowOnActivities(QWindow &view, const QStringList &activities) override; void removeViewStruts(QWindow &view) const override; WindowId activeWindow() const override; WindowInfoWrap requestInfo(WindowId wid) const override; WindowInfoWrap requestInfoActive() const override; - bool isOnCurrentDesktop(WindowId wid) const override; - bool isOnCurrentActivity(WindowId wid) const override; void setKeepAbove(const QDialog &dialog, bool above = true) const override; void skipTaskBar(const QDialog &dialog) const override; void slideWindow(QWindow &view, Slide location) const override; void enableBlurBehind(QWindow &view) const override; void releaseMouseEventFor(WindowId wid) const override; void requestActivate(WindowId wid) const override; void requestClose(WindowId wid) const override; void requestMoveWindow(WindowId wid, QPoint from) const override; void requestToggleIsOnAllDesktops(WindowId wid) const override; void requestToggleKeepAbove(WindowId wid) const override; void requestToggleMinimized(WindowId wid) const override; void requestToggleMaximized(WindowId wid) const override; bool windowCanBeDragged(WindowId wid) const; QIcon iconFor(WindowId wid) const; WindowId winIdFor(QString appId, QRect geometry) const override; AppData appDataFor(WindowId wid) const override; void setEdgeStateFor(QWindow *view, bool active) const override; void initWindowManagement(KWayland::Client::PlasmaWindowManagement *windowManagement); #if KF5_VERSION_MINOR >= 52 //! VirtualDesktopsSupport void initVirtualDesktopManagement(KWayland::Client::PlasmaVirtualDesktopManagement *virtualDesktopManagement); #endif private: void init(); bool isValidWindow(const KWayland::Client::PlasmaWindow *w) const; bool isPlasmaDesktop(const KWayland::Client::PlasmaWindow *w) const; void windowCreatedProxy(KWayland::Client::PlasmaWindow *w); KWayland::Client::PlasmaWindow *windowFor(WindowId wid) const; KWayland::Client::PlasmaShell *waylandCoronaInterface() const; #if KF5_VERSION_MINOR >= 52 //! VirtualDesktopsSupport void setCurrentDesktop(QString desktop); void addDesktop(const QString &id, quint32 position); #endif private: QSignalMapper *mapper{nullptr}; friend class Private::GhostWindow; mutable QMap m_ghostWindows; KWayland::Client::PlasmaWindowManagement *m_windowManagement{nullptr}; #if KF5_VERSION_MINOR >= 52 //! VirtualDesktopsSupport KWayland::Client::PlasmaVirtualDesktopManagement *m_virtualDesktopManagement{nullptr}; - QString m_currentDesktop; QStringList m_desktops; #endif Latte::Corona *m_corona{nullptr}; }; } } #endif // WAYLANDINTERFACE_H diff --git a/app/wm/windowinfowrap.h b/app/wm/windowinfowrap.h index 0215200e..f836f1d8 100644 --- a/app/wm/windowinfowrap.h +++ b/app/wm/windowinfowrap.h @@ -1,458 +1,458 @@ /* * Copyright 2016 Smith AR * Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Latte-Dock is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef WINDOWINFOWRAP_H #define WINDOWINFOWRAP_H // Qt #include #include #include #include namespace Latte { namespace WindowSystem { using WindowId = QVariant; class WindowInfoWrap { public: WindowInfoWrap() noexcept : m_isValid(false) , m_isActive(false) , m_isMinimized(false) , m_isMaxVert(false) , m_isMaxHoriz(false) , m_isFullscreen(false) , m_isShaded(false) , m_isPlasmaDesktop(false) , m_isKeepAbove(false) , m_hasSkipTaskbar(false) , m_isOnAllDesktops(false) , m_isOnAllActivities(false) { } WindowInfoWrap(const WindowInfoWrap &o) noexcept : m_wid(o.m_wid) , m_geometry(o.m_geometry) , m_isValid(o.m_isValid) , m_isActive(o.m_isActive) , m_isMinimized(o.m_isMinimized) , m_isMaxVert(o.m_isMaxVert) , m_isMaxHoriz(o.m_isMaxHoriz) , m_isFullscreen(o.m_isFullscreen) , m_isShaded(o.m_isShaded) , m_isPlasmaDesktop(o.m_isPlasmaDesktop) , m_isKeepAbove(o.m_isKeepAbove) , m_hasSkipTaskbar(o.m_hasSkipTaskbar) , m_isOnAllDesktops(o.m_isOnAllDesktops) , m_isOnAllActivities(o.m_isOnAllActivities) , m_desktops(o.m_desktops) , m_activities(o.m_activities) , m_display(o.m_display) { } WindowInfoWrap(WindowInfoWrap &&o) noexcept : m_wid(o.m_wid) , m_geometry(o.m_geometry) , m_isValid(o.m_isValid) , m_isActive(o.m_isActive) , m_isMinimized(o.m_isMinimized) , m_isMaxVert(o.m_isMaxVert) , m_isMaxHoriz(o.m_isMaxHoriz) , m_isFullscreen(o.m_isFullscreen) , m_isShaded(o.m_isShaded) , m_isPlasmaDesktop(o.m_isPlasmaDesktop) , m_isKeepAbove(o.m_isKeepAbove) , m_hasSkipTaskbar(o.m_hasSkipTaskbar) , m_isOnAllDesktops(o.m_isOnAllDesktops) , m_isOnAllActivities(o.m_isOnAllActivities) , m_desktops(o.m_desktops) , m_activities(o.m_activities) , m_display(o.m_display) { } inline WindowInfoWrap &operator=(WindowInfoWrap &&rhs) noexcept; inline WindowInfoWrap &operator=(const WindowInfoWrap &rhs) noexcept; inline bool operator==(const WindowInfoWrap &rhs) const noexcept; inline bool operator<(const WindowInfoWrap &rhs) const noexcept; inline bool operator>(const WindowInfoWrap &rhs) const noexcept; inline bool isValid() const noexcept; inline void setIsValid(bool isValid) noexcept; inline bool isActive() const noexcept; inline void setIsActive(bool isActive) noexcept; inline bool isMinimized() const noexcept; inline void setIsMinimized(bool isMinimized) noexcept; inline bool isMaximized() const noexcept; inline bool isMaxVert() const noexcept; inline void setIsMaxVert(bool isMaxVert) noexcept; inline bool isMaxHoriz() const noexcept; inline void setIsMaxHoriz(bool isMaxHoriz) noexcept; inline bool isFullscreen() const noexcept; inline void setIsFullscreen(bool isFullscreen) noexcept; inline bool isShaded() const noexcept; inline void setIsShaded(bool isShaded) noexcept; inline bool isPlasmaDesktop() const noexcept; inline void setIsPlasmaDesktop(bool isPlasmaDesktop) noexcept; inline bool isKeepAbove() const noexcept; inline void setIsKeepAbove(bool isKeepAbove) noexcept; inline bool hasSkipTaskbar() const noexcept; inline void setHasSkipTaskbar(bool skipTaskbar) noexcept; inline bool isOnAllDesktops() const noexcept; inline void setIsOnAllDesktops(bool alldesktops) noexcept; inline bool isOnAllActivities() const noexcept; inline void setIsOnAllActivities(bool allactivities) noexcept; inline QRect geometry() const noexcept; inline void setGeometry(const QRect &geometry) noexcept; inline QString appName() const noexcept; inline void setAppName(const QString &appName) noexcept; inline QString display() const noexcept; inline void setDisplay(const QString &display) noexcept; inline QIcon icon() const noexcept; inline void setIcon(const QIcon &icon) noexcept; inline WindowId wid() const noexcept; inline void setWid(const WindowId &wid) noexcept; - inline QVariantList desktops() const noexcept; - inline void setDesktops(const QVariantList &desktops) noexcept; + inline QStringList desktops() const noexcept; + inline void setDesktops(const QStringList &desktops) noexcept; inline QStringList activities() const noexcept; inline void setActivities(const QStringList &activities) noexcept; - inline bool isOnDesktop(const QVariant &desktop) const noexcept; + inline bool isOnDesktop(const QString &desktop) const noexcept; inline bool isOnActivity(const QString &activity) const noexcept; private: WindowId m_wid{0}; QRect m_geometry; bool m_isValid : 1; bool m_isActive : 1; bool m_isMinimized : 1; bool m_isMaxVert : 1; bool m_isMaxHoriz : 1; bool m_isFullscreen : 1; bool m_isShaded : 1; bool m_isPlasmaDesktop : 1; bool m_isKeepAbove: 1; bool m_hasSkipTaskbar: 1; bool m_isOnAllDesktops: 1; bool m_isOnAllActivities: 1; QString m_appName; QString m_display; QIcon m_icon; - QVariantList m_desktops; + QStringList m_desktops; QStringList m_activities; }; // BEGIN: definitions inline WindowInfoWrap &WindowInfoWrap::operator=(WindowInfoWrap &&rhs) noexcept { m_wid = rhs.m_wid; m_geometry = rhs.m_geometry; m_isValid = rhs.m_isValid; m_isActive = rhs.m_isActive; m_isMinimized = rhs.m_isMinimized; m_isMaxVert = rhs.m_isMaxVert; m_isMaxHoriz = rhs.m_isMaxHoriz; m_isFullscreen = rhs.m_isFullscreen; m_isShaded = rhs.m_isShaded; m_isPlasmaDesktop = rhs.m_isPlasmaDesktop; m_isKeepAbove = rhs.m_isKeepAbove; m_hasSkipTaskbar = rhs.m_hasSkipTaskbar; m_isOnAllDesktops = rhs.m_isOnAllDesktops; m_isOnAllActivities = rhs.m_isOnAllActivities; m_display = rhs.m_display; m_desktops = rhs.m_desktops; m_activities = rhs.m_activities; return *this; } inline WindowInfoWrap &WindowInfoWrap::operator=(const WindowInfoWrap &rhs) noexcept { m_wid = rhs.m_wid; m_geometry = std::move(rhs.m_geometry); m_isValid = rhs.m_isValid; m_isActive = rhs.m_isActive; m_isMinimized = rhs.m_isMinimized; m_isMaxVert = rhs.m_isMaxVert; m_isMaxHoriz = rhs.m_isMaxHoriz; m_isFullscreen = rhs.m_isFullscreen; m_isShaded = rhs.m_isShaded; m_isPlasmaDesktop = rhs.m_isPlasmaDesktop; m_isKeepAbove = rhs.m_isKeepAbove; m_hasSkipTaskbar = rhs.m_hasSkipTaskbar; m_isOnAllDesktops = rhs.m_isOnAllDesktops; m_isOnAllActivities = rhs.m_isOnAllActivities; m_display = rhs.m_display; m_desktops = rhs.m_desktops; m_activities = rhs.m_activities; return *this; } inline bool WindowInfoWrap::operator==(const WindowInfoWrap &rhs) const noexcept { return m_wid == rhs.m_wid; } inline bool WindowInfoWrap::operator<(const WindowInfoWrap &rhs) const noexcept { return m_wid < rhs.m_wid; } inline bool WindowInfoWrap::operator>(const WindowInfoWrap &rhs) const noexcept { return m_wid > rhs.m_wid; } inline bool WindowInfoWrap::isValid() const noexcept { return m_isValid; } inline void WindowInfoWrap::setIsValid(bool isValid) noexcept { m_isValid = isValid; } inline bool WindowInfoWrap::isActive() const noexcept { return m_isActive; } inline void WindowInfoWrap::setIsActive(bool isActive) noexcept { m_isActive = isActive; } inline bool WindowInfoWrap::isMinimized() const noexcept { return m_isMinimized; } inline void WindowInfoWrap::setIsMinimized(bool isMinimized) noexcept { m_isMinimized = isMinimized; } inline bool WindowInfoWrap::isMaximized() const noexcept { return m_isMaxVert || m_isMaxHoriz; } inline bool WindowInfoWrap::isMaxVert() const noexcept { return m_isMaxVert; } inline void WindowInfoWrap::setIsMaxVert(bool isMaxVert) noexcept { m_isMaxVert = isMaxVert; } inline bool WindowInfoWrap::isMaxHoriz() const noexcept { return m_isMaxHoriz; } inline void WindowInfoWrap::setIsMaxHoriz(bool isMaxHoriz) noexcept { m_isMaxHoriz = isMaxHoriz; } inline bool WindowInfoWrap::isFullscreen() const noexcept { return m_isFullscreen; } inline void WindowInfoWrap::setIsFullscreen(bool isFullscreen) noexcept { m_isFullscreen = isFullscreen; } inline bool WindowInfoWrap::isShaded() const noexcept { return m_isShaded; } inline void WindowInfoWrap::setIsShaded(bool isShaded) noexcept { m_isShaded = isShaded; } inline bool WindowInfoWrap::isPlasmaDesktop() const noexcept { return m_isPlasmaDesktop; } inline void WindowInfoWrap::setIsPlasmaDesktop(bool isPlasmaDesktop) noexcept { m_isPlasmaDesktop = isPlasmaDesktop; } inline bool WindowInfoWrap::isKeepAbove() const noexcept { return m_isKeepAbove; } inline void WindowInfoWrap::setIsKeepAbove(bool isKeepAbove) noexcept { m_isKeepAbove = isKeepAbove; } inline bool WindowInfoWrap::hasSkipTaskbar() const noexcept { return m_hasSkipTaskbar; } inline void WindowInfoWrap::setHasSkipTaskbar(bool skipTaskbar) noexcept { m_hasSkipTaskbar = skipTaskbar; } inline bool WindowInfoWrap::isOnAllDesktops() const noexcept { return m_isOnAllDesktops; } inline void WindowInfoWrap::setIsOnAllDesktops(bool alldesktops) noexcept { m_isOnAllDesktops = alldesktops; } inline bool WindowInfoWrap::isOnAllActivities() const noexcept { return m_isOnAllActivities; } inline void WindowInfoWrap::setIsOnAllActivities(bool allactivities) noexcept { m_isOnAllActivities = allactivities; } inline QString WindowInfoWrap::appName() const noexcept { return m_appName; } inline void WindowInfoWrap::setAppName(const QString &appName) noexcept { m_appName = appName; } inline QString WindowInfoWrap::display() const noexcept { return m_display; } inline void WindowInfoWrap::setDisplay(const QString &display) noexcept { m_display = display; } inline QIcon WindowInfoWrap::icon() const noexcept { return m_icon; } inline void WindowInfoWrap::setIcon(const QIcon &icon) noexcept { m_icon = icon; } inline QRect WindowInfoWrap::geometry() const noexcept { return m_geometry; } inline void WindowInfoWrap::setGeometry(const QRect &geometry) noexcept { m_geometry = geometry; } inline WindowId WindowInfoWrap::wid() const noexcept { return m_wid; } inline void WindowInfoWrap::setWid(const WindowId &wid) noexcept { m_wid = wid; } -inline QVariantList WindowInfoWrap::desktops() const noexcept +inline QStringList WindowInfoWrap::desktops() const noexcept { return m_desktops; } -inline void WindowInfoWrap::setDesktops(const QVariantList &desktops) noexcept +inline void WindowInfoWrap::setDesktops(const QStringList &desktops) noexcept { m_desktops = desktops; } inline QStringList WindowInfoWrap::activities() const noexcept { return m_activities; } inline void WindowInfoWrap::setActivities(const QStringList &activities) noexcept { m_activities = activities; } // END: definitions -inline bool WindowInfoWrap::isOnDesktop(const QVariant &desktop) const noexcept +inline bool WindowInfoWrap::isOnDesktop(const QString &desktop) const noexcept { return m_isOnAllDesktops || m_desktops.contains(desktop); } inline bool WindowInfoWrap::isOnActivity(const QString &activity) const noexcept { return m_isOnAllActivities || m_activities.contains(activity); } } } #endif // WINDOWINFOWRAP_H diff --git a/app/wm/xwindowinterface.cpp b/app/wm/xwindowinterface.cpp index 121d763c..2497b6d1 100644 --- a/app/wm/xwindowinterface.cpp +++ b/app/wm/xwindowinterface.cpp @@ -1,645 +1,639 @@ /* * Copyright 2016 Smith AR * Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Latte-Dock is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "xwindowinterface.h" // local #include "tasktools.h" #include "view/screenedgeghostwindow.h" #include "view/view.h" #include "../liblatte2/extras.h" // Qt #include #include #include // KDE #include #include #include #include // X11 #include #include namespace Latte { namespace WindowSystem { XWindowInterface::XWindowInterface(QObject *parent) : AbstractWindowInterface(parent) { - m_activities = new KActivities::Consumer(this); + m_currentDesktop = QString(KWindowSystem::self()->currentDesktop()); connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &AbstractWindowInterface::activeWindowChanged); connect(KWindowSystem::self(), &KWindowSystem::windowAdded, this, &AbstractWindowInterface::windowAdded); connect(KWindowSystem::self(), &KWindowSystem::windowRemoved, this, &AbstractWindowInterface::windowRemoved); - connect(KWindowSystem::self(), &KWindowSystem::currentDesktopChanged, this, &XWindowInterface::currentDesktopChanged); + + connect(KWindowSystem::self(), &KWindowSystem::currentDesktopChanged, this, [&](int desktop) { + m_currentDesktop = QString(desktop); + emit currentDesktopChanged(); + }); connect(KWindowSystem::self() , static_cast (&KWindowSystem::windowChanged) , this, &XWindowInterface::windowChangedProxy); - - connect(m_activities.data(), &KActivities::Consumer::currentActivityChanged, this, &XWindowInterface::currentActivityChanged); } XWindowInterface::~XWindowInterface() { } void XWindowInterface::setViewExtraFlags(QWindow &view) { NETWinInfo winfo(QX11Info::connection() , static_cast(view.winId()) , static_cast(view.winId()) , 0, 0); winfo.setAllowedActions(NET::ActionChangeDesktop); KWindowSystem::setType(view.winId(), NET::Dock); KWindowSystem::setState(view.winId(), NET::SkipTaskbar | NET::SkipPager); KWindowSystem::setOnAllDesktops(view.winId(), true); } void XWindowInterface::setViewStruts(QWindow &view, const QRect &rect , Plasma::Types::Location location) { NETExtendedStrut strut; const auto screen = view.screen(); const QRect currentScreen {screen->geometry()}; const QRect wholeScreen {{0, 0}, screen->virtualSize()}; //! WORKAROUND in order to fix KWin faulty behavior concerning struts //! under !compositing mode. Under !compositing mode, kwin removes 1px. //! from the struts const int strutsGap = KWindowSystem::compositingActive ? 1 : 2; switch (location) { case Plasma::Types::TopEdge: { const int topOffset {screen->geometry().top()}; strut.top_width = rect.height() + topOffset; strut.top_start = rect.x(); strut.top_end = rect.x() + rect.width() - strutsGap; break; } case Plasma::Types::BottomEdge: { const int bottomOffset {wholeScreen.bottom() - currentScreen.bottom()}; strut.bottom_width = rect.height() + bottomOffset; strut.bottom_start = rect.x(); strut.bottom_end = rect.x() + rect.width() - strutsGap; break; } case Plasma::Types::LeftEdge: { const int leftOffset = {screen->geometry().left()}; strut.left_width = rect.width() + leftOffset; strut.left_start = rect.y(); strut.left_end = rect.y() + rect.height() - strutsGap; break; } case Plasma::Types::RightEdge: { const int rightOffset = {wholeScreen.right() - currentScreen.right()}; strut.right_width = rect.width() + rightOffset; strut.right_start = rect.y(); strut.right_end = rect.y() + rect.height() - strutsGap; break; } default: qWarning() << "wrong location:" << qEnumToStr(location); return; } KWindowSystem::setExtendedStrut(view.winId(), strut.left_width, strut.left_start, strut.left_end, strut.right_width, strut.right_start, strut.right_end, strut.top_width, strut.top_start, strut.top_end, strut.bottom_width, strut.bottom_start, strut.bottom_end ); } void XWindowInterface::setWindowOnActivities(QWindow &window, const QStringList &activities) { KWindowSystem::setOnActivities(window.winId(), activities); } void XWindowInterface::removeViewStruts(QWindow &view) const { KWindowSystem::setStrut(view.winId(), 0, 0, 0, 0); } WindowId XWindowInterface::activeWindow() const { return KWindowSystem::self()->activeWindow(); } void XWindowInterface::setKeepAbove(const QDialog &dialog, bool above) const { if (above) { KWindowSystem::setState(dialog.winId(), NET::KeepAbove); } else { KWindowSystem::clearState(dialog.winId(), NET::KeepAbove); } } void XWindowInterface::skipTaskBar(const QDialog &dialog) const { KWindowSystem::setState(dialog.winId(), NET::SkipTaskbar); } void XWindowInterface::slideWindow(QWindow &view, AbstractWindowInterface::Slide location) const { auto slideLocation = KWindowEffects::NoEdge; switch (location) { case Slide::Top: slideLocation = KWindowEffects::TopEdge; break; case Slide::Bottom: slideLocation = KWindowEffects::BottomEdge; break; case Slide::Left: slideLocation = KWindowEffects::LeftEdge; break; case Slide::Right: slideLocation = KWindowEffects::RightEdge; break; default: break; } KWindowEffects::slideWindow(view.winId(), slideLocation, -1); } void XWindowInterface::enableBlurBehind(QWindow &view) const { KWindowEffects::enableBlurBehind(view.winId()); } void XWindowInterface::setEdgeStateFor(QWindow *view, bool active) const { ViewPart::ScreenEdgeGhostWindow *window = qobject_cast(view); if (!window) { return; } xcb_connection_t *c = QX11Info::connection(); const QByteArray effectName = QByteArrayLiteral("_KDE_NET_WM_SCREEN_EDGE_SHOW"); xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c, false, effectName.length(), effectName.constData()); QScopedPointer atom(xcb_intern_atom_reply(c, atomCookie, nullptr)); if (!atom) { return; } if (!active) { xcb_delete_property(c, window->winId(), atom->atom); window->hideWithMask(); return; } window->showWithMask(); uint32_t value = 0; switch (window->location()) { case Plasma::Types::TopEdge: value = 0; break; case Plasma::Types::RightEdge: value = 1; break; case Plasma::Types::BottomEdge: value = 2; break; case Plasma::Types::LeftEdge: value = 3; break; case Plasma::Types::Floating: default: value = 4; break; } int hideType = 0; value |= hideType << 8; xcb_change_property(c, XCB_PROP_MODE_REPLACE, window->winId(), atom->atom, XCB_ATOM_CARDINAL, 32, 1, &value); } WindowInfoWrap XWindowInterface::requestInfoActive() const { return requestInfo(KWindowSystem::activeWindow()); } -bool XWindowInterface::isOnCurrentDesktop(WindowId wid) const -{ - KWindowInfo winfo(wid.value(), NET::WMDesktop); - return winfo.valid() && winfo.isOnCurrentDesktop(); -} - -bool XWindowInterface::isOnCurrentActivity(WindowId wid) const -{ - KWindowInfo winfo(wid.value(), 0, NET::WM2Activities); - - return winfo.valid() - && (winfo.activities().contains(m_activities->currentActivity()) || winfo.activities().empty()); -} - WindowInfoWrap XWindowInterface::requestInfo(WindowId wid) const { const KWindowInfo winfo{wid.value(), NET::WMFrameExtents | NET::WMWindowType | NET::WMGeometry | NET::WMDesktop | NET::WMState | NET::WMName | NET::WMVisibleName, - NET::WM2WindowClass}; + NET::WM2WindowClass + | NET::WM2Activities}; //! update desktop id bool isPlasmaDesktop{false}; if (winfo.windowClassName() == "plasmashell" && hasScreenGeometry(winfo)) { isPlasmaDesktop = true; windowsTracker()->setPlasmaDesktop(wid); } WindowInfoWrap winfoWrap; if (isValidWindow(winfo) && !isPlasmaDesktop) { winfoWrap.setIsValid(true); winfoWrap.setWid(wid); winfoWrap.setIsActive(KWindowSystem::activeWindow() == wid.value()); winfoWrap.setIsMinimized(winfo.hasState(NET::Hidden)); winfoWrap.setIsMaxVert(winfo.hasState(NET::MaxVert)); winfoWrap.setIsMaxHoriz(winfo.hasState(NET::MaxHoriz)); winfoWrap.setIsFullscreen(winfo.hasState(NET::FullScreen)); winfoWrap.setIsShaded(winfo.hasState(NET::Shaded)); winfoWrap.setIsOnAllDesktops(winfo.onAllDesktops()); + winfoWrap.setIsOnAllActivities(winfo.activities().empty()); winfoWrap.setGeometry(winfo.frameGeometry()); winfoWrap.setIsKeepAbove(winfo.hasState(NET::KeepAbove)); winfoWrap.setHasSkipTaskbar(winfo.hasState(NET::SkipTaskbar)); winfoWrap.setDisplay(winfo.visibleName()); + + winfoWrap.setDesktops({QString(winfo.desktop())}); + winfoWrap.setActivities(winfo.activities()); } else if (m_desktopId == wid) { winfoWrap.setIsValid(true); winfoWrap.setIsPlasmaDesktop(true); winfoWrap.setWid(wid); winfoWrap.setHasSkipTaskbar(true); } return winfoWrap; } AppData XWindowInterface::appDataFor(WindowId wid) const { return appDataFromUrl(windowUrl(wid)); } QUrl XWindowInterface::windowUrl(WindowId wid) const { const KWindowInfo info(wid.value(), 0, NET::WM2WindowClass | NET::WM2DesktopFileName); QString desktopFile = QString::fromUtf8(info.desktopFileName()); if (!desktopFile.isEmpty()) { KService::Ptr service = KService::serviceByStorageId(desktopFile); if (service) { const QString &menuId = service->menuId(); // applications: URLs are used to refer to applications by their KService::menuId // (i.e. .desktop file name) rather than the absolute path to a .desktop file. if (!menuId.isEmpty()) { return QUrl(QStringLiteral("applications:") + menuId); } return QUrl::fromLocalFile(service->entryPath()); } if (!desktopFile.endsWith(QLatin1String(".desktop"))) { desktopFile.append(QLatin1String(".desktop")); } if (KDesktopFile::isDesktopFile(desktopFile) && QFile::exists(desktopFile)) { return QUrl::fromLocalFile(desktopFile); } } return windowUrlFromMetadata(info.windowClassClass(), NETWinInfo(QX11Info::connection(), wid.value(), QX11Info::appRootWindow(), NET::WMPid, NET::Properties2()).pid(), rulesConfig, info.windowClassName()); } bool XWindowInterface::windowCanBeDragged(WindowId wid) const { WindowInfoWrap winfo = requestInfo(wid); return (winfo.isValid() && !winfo.isMinimized() && !winfo.isPlasmaDesktop()); } void XWindowInterface::releaseMouseEventFor(WindowId wid) const { auto connection = QX11Info::connection(); xcb_button_release_event_t releaseEvent; memset(&releaseEvent, 0, sizeof(releaseEvent)); releaseEvent.response_type = XCB_BUTTON_RELEASE; releaseEvent.event = wid.toInt(); releaseEvent.child = XCB_WINDOW_NONE; releaseEvent.root = QX11Info::appRootWindow(); releaseEvent.event_x = -1; releaseEvent.event_y = -1; releaseEvent.root_x = -1; releaseEvent.root_y = -1; releaseEvent.detail = XCB_BUTTON_INDEX_1; releaseEvent.state = XCB_BUTTON_MASK_1; releaseEvent.time = XCB_CURRENT_TIME; releaseEvent.same_screen = true; xcb_send_event( connection, false, wid.toInt(), XCB_EVENT_MASK_BUTTON_RELEASE, reinterpret_cast(&releaseEvent)); } void XWindowInterface::requestActivate(WindowId wid) const { KWindowSystem::activateWindow(wid.toInt()); } QIcon XWindowInterface::iconFor(WindowId wid) const { QIcon icon; icon.addPixmap(KWindowSystem::icon(wid.value(), KIconLoader::SizeSmall, KIconLoader::SizeSmall, false)); icon.addPixmap(KWindowSystem::icon(wid.value(), KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium, false)); icon.addPixmap(KWindowSystem::icon(wid.value(), KIconLoader::SizeMedium, KIconLoader::SizeMedium, false)); icon.addPixmap(KWindowSystem::icon(wid.value(), KIconLoader::SizeLarge, KIconLoader::SizeLarge, false)); return icon; } WindowId XWindowInterface::winIdFor(QString appId, QRect geometry) const { return activeWindow(); } void XWindowInterface::requestClose(WindowId wid) const { WindowInfoWrap wInfo = requestInfo(wid); if (!wInfo.isValid() || wInfo.isPlasmaDesktop()) { return; } NETRootInfo ri(QX11Info::connection(), NET::CloseWindow); ri.closeWindowRequest(wInfo.wid().toUInt()); } void XWindowInterface::requestMoveWindow(WindowId wid, QPoint from) const { WindowInfoWrap wInfo = requestInfo(wid); if (!wInfo.isValid() || wInfo.isPlasmaDesktop()) { return; } 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 = 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 int validX = qBound(minX, from.x(), maxX); int validY = qBound(minY, from.y(), maxY); NETRootInfo ri(QX11Info::connection(), NET::WMMoveResize); ri.moveResizeRequest(wInfo.wid().toUInt(), validX, validY, NET::Move); } void XWindowInterface::requestToggleIsOnAllDesktops(WindowId wid) const { WindowInfoWrap wInfo = requestInfo(wid); if (!wInfo.isValid() || wInfo.isPlasmaDesktop()) { return; } if (KWindowSystem::numberOfDesktops() <= 1) { return; } if (wInfo.isOnAllDesktops()) { KWindowSystem::setOnDesktop(wid.toUInt(), KWindowSystem::currentDesktop()); KWindowSystem::forceActiveWindow(wid.toUInt()); } else { KWindowSystem::setOnAllDesktops(wid.toUInt(), true); } } void XWindowInterface::requestToggleKeepAbove(WindowId wid) const { WindowInfoWrap wInfo = requestInfo(wid); if (!wInfo.isValid() || wInfo.isPlasmaDesktop()) { return; } NETWinInfo ni(QX11Info::connection(), wid.toUInt(), QX11Info::appRootWindow(), NET::WMState, NET::Properties2()); if (wInfo.isKeepAbove()) { ni.setState(NET::States(), NET::StaysOnTop); } else { ni.setState(NET::StaysOnTop, NET::StaysOnTop); } } void XWindowInterface::requestToggleMinimized(WindowId wid) const { WindowInfoWrap wInfo = requestInfo(wid); if (!wInfo.isValid() || wInfo.isPlasmaDesktop()) { return; } if (wInfo.isMinimized()) { - bool onCurrent = isOnCurrentDesktop(wid); + bool onCurrent = wInfo.isOnDesktop(m_currentDesktop); KWindowSystem::unminimizeWindow(wid.toUInt()); if (onCurrent) { KWindowSystem::forceActiveWindow(wid.toUInt()); } } else { KWindowSystem::minimizeWindow(wid.toUInt()); } } void XWindowInterface::requestToggleMaximized(WindowId wid) const { WindowInfoWrap wInfo = requestInfo(wid); bool restore = wInfo.isMaxHoriz() && wInfo.isMaxVert(); if (wInfo.isMinimized()) { KWindowSystem::unminimizeWindow(wid.toUInt()); } 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(WindowId wid) const { if (windowsTracker()->isValidFor(wid)) { return true; } const KWindowInfo winfo{wid.value(), NET::WMWindowType}; return isValidWindow(winfo); } bool XWindowInterface::isValidWindow(const KWindowInfo &winfo) const { if (windowsTracker()->isValidFor(winfo.win())) { return true; } constexpr auto types = NET::DockMask | NET::MenuMask | NET::SplashMask | NET::PopupMenuMask | NET::NormalMask | NET::DialogMask; NET::WindowType winType = winfo.windowType(types); const auto winClass = KWindowInfo(winfo.win(), 0, NET::WM2WindowClass).windowClassName(); //! ignore latte related windows from tracking if (winClass == "latte-dock") { return false; } if (m_desktopId == winfo.win()) { return false; } if (winType == -1) { // Trying to get more types for verify if the window have any other type winType = winfo.windowType(~types & NET::AllTypesMask); if (winType == -1) { qWarning() << KWindowInfo(winfo.win(), 0, NET::WM2WindowClass).windowClassName() << "doesn't have any WindowType, assuming as NET::Normal"; return true; } } bool isMenu = ((winType & NET::Menu) == true); bool isDock = ((winType & NET::Dock) == true); bool isPopup = ((winType & NET::PopupMenu) == true); bool isSplash = ((winType & NET::Splash) == true); //! GTK2+ dialogs case e.g. inkscape, gimp2, etc... //! are both Popups and Splash types, this is why //! we can not black list them here return !(isMenu || isDock); } bool XWindowInterface::hasScreenGeometry(const KWindowInfo &winfo) const { bool hasScreenGeometry{false}; for (const auto scr : qGuiApp->screens()) { if (!winfo.geometry().isEmpty() && winfo.geometry() == scr->geometry()) { hasScreenGeometry = true; break; } } return hasScreenGeometry; } void XWindowInterface::windowChangedProxy(WId wid, NET::Properties prop1, NET::Properties2 prop2) { const KWindowInfo info(wid, NET::WMGeometry, NET::WM2WindowClass); const auto winClass = info.windowClassName(); //! ignore latte related windows from tracking if (winClass == "latte-dock") { return; } //! update desktop id if (winClass == "plasmashell" && hasScreenGeometry(info)) { m_desktopId = wid; windowsTracker()->setPlasmaDesktop(wid); considerWindowChanged(wid); return; } //! accept only NET::Properties events, //! ignore when the user presses a key, or a window is sending X events etc. //! without needing to (e.g. Firefox, https://bugzilla.mozilla.org/show_bug.cgi?id=1389953) //! NET::WM2UserTime, NET::WM2IconPixmap etc.... - if (prop1 == 0) { + if (prop1 == 0 && !(prop2 & NET::WM2Activities)) { return; } //! accept only the following NET:Properties changed signals //! NET::WMState, NET::WMGeometry, NET::ActiveWindow if ( !(prop1 & NET::WMState) && !(prop1 & NET::WMGeometry) && !(prop1 & NET::ActiveWindow) && !(prop1 & NET::WMDesktop) - && !(prop1 & (NET::WMName | NET::WMVisibleName)) ) { + && !(prop1 & (NET::WMName | NET::WMVisibleName) + && !(prop2 & NET::WM2Activities)) ) { return; } //! ignore windows that do not respect normal windows types if (!isValidWindow(wid)) { return; } considerWindowChanged(wid); } } } diff --git a/app/wm/xwindowinterface.h b/app/wm/xwindowinterface.h index fe2471fa..02339943 100644 --- a/app/wm/xwindowinterface.h +++ b/app/wm/xwindowinterface.h @@ -1,101 +1,99 @@ /* * Copyright 2016 Smith AR * Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Latte-Dock is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef XWINDOWINTERFACE_H #define XWINDOWINTERFACE_H // local #include "abstractwindowinterface.h" #include "windowinfowrap.h" // Qt #include // KDE #include #include namespace Latte { namespace WindowSystem { class XWindowInterface : public AbstractWindowInterface { Q_OBJECT public: explicit XWindowInterface(QObject *parent = nullptr); ~XWindowInterface() override; void setViewExtraFlags(QWindow &view) override; void setViewStruts(QWindow &view, const QRect &rect , Plasma::Types::Location location) override; void setWindowOnActivities(QWindow &window, const QStringList &activities) override; void removeViewStruts(QWindow &view) const override; WindowId activeWindow() const override; WindowInfoWrap requestInfo(WindowId wid) const override; WindowInfoWrap requestInfoActive() const override; - bool isOnCurrentDesktop(WindowId wid) const override; - bool isOnCurrentActivity(WindowId wid) const override; void setKeepAbove(const QDialog &dialog, bool above = true) const override; void skipTaskBar(const QDialog &dialog) const override; void slideWindow(QWindow &view, Slide location) const override; void enableBlurBehind(QWindow &view) const override; void releaseMouseEventFor(WindowId wid) const override; void requestActivate(WindowId wid) const override; void requestClose(WindowId wid) const override; void requestMoveWindow(WindowId wid, QPoint from) const override; void requestToggleIsOnAllDesktops(WindowId wid) const override; void requestToggleKeepAbove(WindowId wid) const override; void requestToggleMinimized(WindowId wid) const override; void requestToggleMaximized(WindowId wid) const override; bool windowCanBeDragged(WindowId wid) const override; QIcon iconFor(WindowId wid) const override; WindowId winIdFor(QString appId, QRect geometry) const override; AppData appDataFor(WindowId wid) const override; void setEdgeStateFor(QWindow *view, bool active) const override; private: bool hasScreenGeometry(const KWindowInfo &winfo) const; bool isValidWindow(WindowId wid) const; bool isValidWindow(const KWindowInfo &winfo) const; void windowChangedProxy(WId wid, NET::Properties prop1, NET::Properties2 prop2); QUrl windowUrl(WindowId wid) const; private: WindowId m_desktopId{-1}; }; } } #endif // XWINDOWINTERFACE_H