From b5e3fa865e63f76b1ffbb7bff66f2d291932bbd6 Mon Sep 17 00:00:00 2001 From: reionwong Date: Wed, 21 Jul 2021 16:49:49 +0800 Subject: [PATCH] Open the launchpad to keep the display --- CMakeLists.txt | 1 + src/activity.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++ src/activity.h | 49 +++++++++++++++++++++++++++++++++++ src/mainwindow.cpp | 17 +++++++++--- src/mainwindow.h | 2 ++ 5 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 src/activity.cpp create mode 100644 src/activity.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a0a7f6..db3ee9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ set(SRCS src/utils.cpp src/xwindowinterface.cpp src/dockbackground.cpp + src/activity.cpp src/fakewindow.cpp ) diff --git a/src/activity.cpp b/src/activity.cpp new file mode 100644 index 0000000..6420095 --- /dev/null +++ b/src/activity.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Reion Wong + * + * This program 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 3 of the License, or + * any later version. + * + * This program 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 "activity.h" + +#include +#include + +static Activity *SELF = nullptr; + +Activity *Activity::self() +{ + if (!SELF) + SELF = new Activity; + + return SELF; +} + +Activity::Activity(QObject *parent) + : QObject(parent) +{ + onActiveWindowChanged(); + + connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &Activity::onActiveWindowChanged); + connect(KWindowSystem::self(), static_cast(&KWindowSystem::windowChanged), + this, &Activity::onActiveWindowChanged); +} + +bool Activity::launchPad() const +{ + return m_launchPad; +} + +void Activity::onActiveWindowChanged() +{ + KWindowInfo info(KWindowSystem::activeWindow(), + NET::WMState | NET::WMVisibleName, + NET::WM2WindowClass); + + bool launchPad = info.windowClassClass() == "cutefish-launcher"; + if (m_launchPad != launchPad) { + m_launchPad = launchPad; + emit launchPadChanged(); + } + + m_pid = info.pid(); + m_windowClass = info.windowClassClass().toLower(); +} diff --git a/src/activity.h b/src/activity.h new file mode 100644 index 0000000..0da591d --- /dev/null +++ b/src/activity.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Reion Wong + * + * This program 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 3 of the License, or + * any later version. + * + * This program 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 ACTIVITY_H +#define ACTIVITY_H + +#include + +class Activity : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool launchPad READ launchPad NOTIFY launchPadChanged) + +public: + static Activity *self(); + explicit Activity(QObject *parent = nullptr); + + bool launchPad() const; + +private slots: + void onActiveWindowChanged(); + +signals: + void launchPadChanged(); + +private: + QString m_windowClass; + quint32 m_pid; + + bool m_launchPad; +}; + +#endif // ACTIVITY_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c646e71..d83bc8c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -35,6 +35,7 @@ MainWindow::MainWindow(QQuickView *parent) : QQuickView(parent) + , m_activity(Activity::self()) , m_settings(DockSettings::self()) , m_appModel(new ApplicationModel) , m_fakeWindow(nullptr) @@ -65,13 +66,17 @@ MainWindow::MainWindow(QQuickView *parent) onVisibilityChanged(); m_showTimer->setSingleShot(true); - m_showTimer->setInterval(300); + m_showTimer->setInterval(200); connect(m_showTimer, &QTimer::timeout, this, [=] { setVisible(true); }); m_hideTimer->setSingleShot(true); - m_hideTimer->setInterval(800); + m_hideTimer->setInterval(500); connect(m_hideTimer, &QTimer::timeout, this, [=] { setVisible(false); }); + // When the current window changes. + connect(m_activity, &Activity::launchPadChanged, this, &MainWindow::onVisibilityChanged); + + // Screen change. connect(qApp->primaryScreen(), &QScreen::virtualGeometryChanged, this, &MainWindow::resizeWindow); connect(qApp->primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::resizeWindow); @@ -156,7 +161,7 @@ void MainWindow::initSlideWindow() void MainWindow::updateViewStruts() { - if (m_settings->visibility() == DockSettings::AlwaysShow) { + if (m_settings->visibility() == DockSettings::AlwaysShow || m_activity->launchPad()) { XWindowInterface::instance()->setViewStruts(this, m_settings->direction(), geometry()); } else { clearViewStruts(); @@ -249,7 +254,8 @@ void MainWindow::onIconSizeChanged() void MainWindow::onVisibilityChanged() { // Always show - if (m_settings->visibility() == DockSettings::AlwaysShow) { + // Must remain displayed when launchpad is opened. + if (m_settings->visibility() == DockSettings::AlwaysShow || m_activity->launchPad()) { m_hideTimer->stop(); setGeometry(windowRect()); @@ -262,6 +268,9 @@ void MainWindow::onVisibilityChanged() } } + if (m_activity->launchPad()) + return; + // Always hide if (m_settings->visibility() == DockSettings::AlwaysHide) { clearViewStruts(); diff --git a/src/mainwindow.h b/src/mainwindow.h index ca51145..a35a8f5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -23,6 +23,7 @@ #include #include +#include "activity.h" #include "docksettings.h" #include "applicationmodel.h" #include "fakewindow.h" @@ -60,6 +61,7 @@ protected: bool eventFilter(QObject *obj, QEvent *e) override; private: + Activity *m_activity; DockSettings *m_settings; ApplicationModel *m_appModel; FakeWindow *m_fakeWindow;