Support always hidden

This commit is contained in:
reionwong 2021-06-21 02:52:26 +08:00
parent e592c10e99
commit 333fbc8d2f
7 changed files with 125 additions and 21 deletions

View file

@ -42,7 +42,7 @@ DockSettings::DockSettings(QObject *parent)
, m_edgeMargins(10)
, m_roundedWindowEnabled(true)
, m_direction(Left)
, m_visibility(AlwaysVisible)
, m_visibility(AlwaysShow)
, m_settings(new QSettings(QSettings::UserScope, "cutefishos", "dock"))
, m_fileWatcher(new QFileSystemWatcher(this))
{
@ -51,7 +51,7 @@ DockSettings::DockSettings(QObject *parent)
if (!m_settings->contains("Direction"))
m_settings->setValue("Direction", Bottom);
if (!m_settings->contains("Visibility"))
m_settings->setValue("Visibility", AlwaysVisible);
m_settings->setValue("Visibility", AlwaysShow);
if (!m_settings->contains("RoundedWindow"))
m_settings->setValue("RoundedWindow", true);
@ -59,6 +59,7 @@ DockSettings::DockSettings(QObject *parent)
m_iconSize = m_settings->value("IconSize").toInt();
m_direction = static_cast<Direction>(m_settings->value("Direction").toInt());
m_visibility = static_cast<Visibility>(m_settings->value("Visibility").toInt());
m_roundedWindowEnabled = m_settings->value("RoundedWindow").toBool();
m_fileWatcher->addPath(m_settings->fileName());

View file

@ -41,7 +41,7 @@ public:
Q_ENUMS(Direction)
enum Visibility {
AlwaysVisible = 0,
AlwaysShow = 0,
AutoHide,
AlwaysHide
};

View file

@ -38,7 +38,7 @@ FakeWindow::FakeWindow(QQuickView *parent)
, m_delayedContainsMouse(false)
, m_containsMouse(false)
{
setColor(Qt::red);
setColor(Qt::transparent);
setDefaultAlphaBuffer(true);
setFlags(Qt::FramelessWindowHint |
Qt::WindowStaysOnTopHint |
@ -100,7 +100,7 @@ void FakeWindow::setContainsMouse(bool contains)
void FakeWindow::updateGeometry()
{
int length = 10;
int length = 5;
const QRect screenRect = qApp->primaryScreen()->geometry();
QRect newRect;

View file

@ -1,7 +1,7 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: rekols <revenmartin@gmail.com>
* 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
@ -39,6 +39,8 @@ MainWindow::MainWindow(QQuickView *parent)
, m_appModel(new ApplicationModel)
, m_fakeWindow(nullptr)
, m_trashManager(new TrashManager)
, m_showTimer(new QTimer(this))
, m_hideTimer(new QTimer(this))
{
setDefaultAlphaBuffer(false);
setColor(Qt::transparent);
@ -56,7 +58,6 @@ MainWindow::MainWindow(QQuickView *parent)
setSource(QUrl(QStringLiteral("qrc:/qml/main.qml")));
setResizeMode(QQuickView::SizeRootObjectToView);
setScreen(qApp->primaryScreen());
setVisible(true);
initSlideWindow();
resizeWindow();
@ -64,13 +65,28 @@ MainWindow::MainWindow(QQuickView *parent)
connect(qApp->primaryScreen(), &QScreen::virtualGeometryChanged, this, &MainWindow::resizeWindow);
connect(qApp->primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::resizeWindow);
connect(qApp->primaryScreen(), &QScreen::orientationChanged, this, [=] (Qt::ScreenOrientation orientation) {
Q_UNUSED(orientation)
m_showTimer->setSingleShot(true);
m_showTimer->setInterval(300);
connect(m_showTimer, &QTimer::timeout, this, [=] {
setVisible(true);
if (m_fakeWindow) {
m_fakeWindow->setVisible(false);
}
});
m_hideTimer->setSingleShot(true);
m_hideTimer->setInterval(1000);
connect(m_hideTimer, &QTimer::timeout, this, [=] {
setVisible(false);
if (m_fakeWindow) {
m_fakeWindow->setVisible(true);
}
});
connect(m_appModel, &ApplicationModel::countChanged, this, &MainWindow::resizeWindow);
connect(m_settings, &DockSettings::directionChanged, this, &MainWindow::onPositionChanged);
connect(m_settings, &DockSettings::iconSizeChanged, this, &MainWindow::onIconSizeChanged);
connect(m_settings, &DockSettings::visibilityChanged, this, &MainWindow::onVisibilityChanged);
@ -130,7 +146,9 @@ QRect MainWindow::windowRect() const
void MainWindow::resizeWindow()
{
setGeometry(windowRect());
updateViewStruts();
if (m_settings->visibility() == DockSettings::AlwaysShow)
updateViewStruts();
emit resizingFished();
}
@ -154,23 +172,45 @@ void MainWindow::updateViewStruts()
XWindowInterface::instance()->setViewStruts(this, m_settings->direction(), geometry());
}
void MainWindow::clearViewStruts()
{
XWindowInterface::instance()->clearViewStruts(this);
}
void MainWindow::createFakeWindow()
{
if (!m_fakeWindow) {
installEventFilter(this);
m_fakeWindow = new FakeWindow;
connect(m_fakeWindow, &FakeWindow::containsMouseChanged, this, [=](bool contains) {
switch (m_settings->visibility()) {
case DockSettings::AlwaysHide: {
m_showTimer->stop();
if (contains) {
m_showTimer->start();
} else {
m_hideTimer->start();
}
break;
}
default:
break;
}
});
connect(m_fakeWindow, &FakeWindow::dragEntered, this, [&] {});
}
}
void MainWindow::deleteFakeWindow()
{
if (m_fakeWindow) {
removeEventFilter(this);
disconnect(m_fakeWindow);
m_fakeWindow->deleteLater();
m_fakeWindow = nullptr;
}
@ -178,12 +218,20 @@ void MainWindow::deleteFakeWindow()
void MainWindow::onPositionChanged()
{
setVisible(false);
initSlideWindow();
setVisible(true);
if (m_settings->visibility() == DockSettings::AlwaysHide) {
setVisible(false);
initSlideWindow();
setGeometry(windowRect());
clearViewStruts();
}
setGeometry(windowRect());
updateViewStruts();
if (m_settings->visibility() == DockSettings::AlwaysShow) {
setVisible(false);
initSlideWindow();
setVisible(true);
setGeometry(windowRect());
updateViewStruts();
}
emit positionChanged();
}
@ -198,8 +246,50 @@ void MainWindow::onIconSizeChanged()
void MainWindow::onVisibilityChanged()
{
if (m_settings->visibility() == DockSettings::AlwaysVisible)
return;
// Always show
if (m_settings->visibility() == DockSettings::AlwaysShow) {
setGeometry(windowRect());
setVisible(true);
updateViewStruts();
createFakeWindow();
// Delete fakewindow
if (m_fakeWindow) {
deleteFakeWindow();
}
}
// Always hide
if (m_settings->visibility() == DockSettings::AlwaysHide) {
clearViewStruts();
setGeometry(windowRect());
setVisible(false);
// Create
if (!m_fakeWindow)
createFakeWindow();
}
}
bool MainWindow::eventFilter(QObject *obj, QEvent *e)
{
switch (e->type()) {
case QEvent::Enter:
m_hideTimer->stop();
break;
case QEvent::Leave:
m_hideTimer->start();
break;
case QEvent::DragEnter:
case QEvent::DragMove:
m_hideTimer->stop();
break;
case QEvent::DragLeave:
case QEvent::Drop:
m_hideTimer->stop();
break;
default:
break;
}
return QQuickView::eventFilter(obj, e);
}

View file

@ -1,7 +1,7 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: rekols <revenmartin@gmail.com>
* 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
@ -46,6 +46,7 @@ private:
void resizeWindow();
void initSlideWindow();
void updateViewStruts();
void clearViewStruts();
void createFakeWindow();
void deleteFakeWindow();
@ -55,11 +56,17 @@ private slots:
void onIconSizeChanged();
void onVisibilityChanged();
protected:
bool eventFilter(QObject *obj, QEvent *e) override;
private:
DockSettings *m_settings;
ApplicationModel *m_appModel;
FakeWindow *m_fakeWindow;
TrashManager *m_trashManager;
QTimer *m_showTimer;
QTimer *m_hideTimer;
};
#endif // MAINWINDOW_H

View file

@ -186,6 +186,11 @@ void XWindowInterface::setViewStruts(QWindow *view, DockSettings::Direction dire
);
}
void XWindowInterface::clearViewStruts(QWindow *view)
{
KWindowSystem::setExtendedStrut(view->winId(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
void XWindowInterface::startInitWindows()
{
for (auto wid : KWindowSystem::self()->windows()) {

View file

@ -48,6 +48,7 @@ public:
bool isAcceptableWindow(quint64 wid);
void setViewStruts(QWindow *view, DockSettings::Direction direction, const QRect &rect);
void clearViewStruts(QWindow *view);
void startInitWindows();