Open the launchpad to keep the display
This commit is contained in:
parent
82a34b1742
commit
b5e3fa865e
5 changed files with 129 additions and 4 deletions
|
@ -29,6 +29,7 @@ set(SRCS
|
|||
src/utils.cpp
|
||||
src/xwindowinterface.cpp
|
||||
src/dockbackground.cpp
|
||||
src/activity.cpp
|
||||
|
||||
src/fakewindow.cpp
|
||||
)
|
||||
|
|
64
src/activity.cpp
Normal file
64
src/activity.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: Reion Wong <reionwong@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "activity.h"
|
||||
|
||||
#include <NETWM>
|
||||
#include <KWindowSystem>
|
||||
|
||||
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<void (KWindowSystem::*)(WId)>(&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();
|
||||
}
|
49
src/activity.h
Normal file
49
src/activity.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (C) 2021 CutefishOS Team.
|
||||
*
|
||||
* Author: Reion Wong <reionwong@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ACTIVITY_H
|
||||
#define ACTIVITY_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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
|
|
@ -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();
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QQuickView>
|
||||
#include <QTimer>
|
||||
|
||||
#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;
|
||||
|
|
Loading…
Reference in a new issue