Add smart hide

This commit is contained in:
reionwong 2021-09-04 11:28:06 +08:00
parent 18628cb292
commit 87e03b6723
5 changed files with 73 additions and 6 deletions

View file

@ -18,6 +18,7 @@
*/ */
#include "activity.h" #include "activity.h"
#include "docksettings.h"
#include <NETWM> #include <NETWM>
#include <KWindowSystem> #include <KWindowSystem>
@ -34,6 +35,7 @@ Activity *Activity::self()
Activity::Activity(QObject *parent) Activity::Activity(QObject *parent)
: QObject(parent) : QObject(parent)
, m_existsWindowMaximized(false)
{ {
onActiveWindowChanged(); onActiveWindowChanged();
@ -42,6 +44,11 @@ Activity::Activity(QObject *parent)
this, &Activity::onActiveWindowChanged); this, &Activity::onActiveWindowChanged);
} }
bool Activity::existsWindowMaximized() const
{
return m_existsWindowMaximized;
}
bool Activity::launchPad() const bool Activity::launchPad() const
{ {
return m_launchPad; return m_launchPad;
@ -54,11 +61,33 @@ void Activity::onActiveWindowChanged()
NET::WM2WindowClass); NET::WM2WindowClass);
bool launchPad = info.windowClassClass() == "cutefish-launcher"; bool launchPad = info.windowClassClass() == "cutefish-launcher";
if (m_launchPad != launchPad) { if (m_launchPad != launchPad) {
m_launchPad = launchPad; m_launchPad = launchPad;
emit launchPadChanged(); emit launchPadChanged();
} }
if (DockSettings::self()->visibility() == DockSettings::IntellHide) {
bool existsWindowMaximized = false;
for (WId wid : KWindowSystem::windows()) {
KWindowInfo i(wid, NET::WMState);
if (i.isMinimized())
continue;
if (i.hasState(NET::MaxVert) || i.hasState(NET::MaxHoriz)) {
existsWindowMaximized = true;
break;
}
}
if (m_existsWindowMaximized != existsWindowMaximized) {
m_existsWindowMaximized = existsWindowMaximized;
emit existsWindowMaximizedChanged();
}
}
m_pid = info.pid(); m_pid = info.pid();
m_windowClass = info.windowClassClass().toLower(); m_windowClass = info.windowClassClass().toLower();
} }

View file

@ -26,11 +26,13 @@ class Activity : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool launchPad READ launchPad NOTIFY launchPadChanged) Q_PROPERTY(bool launchPad READ launchPad NOTIFY launchPadChanged)
Q_PROPERTY(bool existsWindowMaximized READ existsWindowMaximized NOTIFY existsWindowMaximizedChanged)
public: public:
static Activity *self(); static Activity *self();
explicit Activity(QObject *parent = nullptr); explicit Activity(QObject *parent = nullptr);
bool existsWindowMaximized() const;
bool launchPad() const; bool launchPad() const;
private slots: private slots:
@ -38,11 +40,13 @@ private slots:
signals: signals:
void launchPadChanged(); void launchPadChanged();
void existsWindowMaximizedChanged();
private: private:
QString m_windowClass; QString m_windowClass;
quint32 m_pid; quint32 m_pid;
bool m_existsWindowMaximized;
bool m_launchPad; bool m_launchPad;
}; };

View file

@ -42,7 +42,8 @@ public:
enum Visibility { enum Visibility {
AlwaysShow = 0, AlwaysShow = 0,
// AutoHide, // AutoHide,
AlwaysHide AlwaysHide,
IntellHide
}; };
Q_ENUMS(Visibility) Q_ENUMS(Visibility)

View file

@ -75,10 +75,11 @@ MainWindow::MainWindow(QQuickView *parent)
m_hideTimer->setSingleShot(true); m_hideTimer->setSingleShot(true);
m_hideTimer->setInterval(500); m_hideTimer->setInterval(500);
connect(m_hideTimer, &QTimer::timeout, this, [=] { setVisible(false); }); connect(m_hideTimer, &QTimer::timeout, this, &MainWindow::onHideTimeout);
// When the current window changes. // When the current window changes.
connect(m_activity, &Activity::launchPadChanged, this, &MainWindow::onVisibilityChanged); connect(m_activity, &Activity::launchPadChanged, this, &MainWindow::onVisibilityChanged);
connect(m_activity, &Activity::existsWindowMaximizedChanged, this, &MainWindow::onVisibilityChanged);
// Screen change. // Screen change.
connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &MainWindow::onPrimaryScreenChanged); connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &MainWindow::onPrimaryScreenChanged);
@ -263,8 +264,8 @@ void MainWindow::createFakeWindow()
connect(m_fakeWindow, &FakeWindow::containsMouseChanged, this, [=](bool contains) { connect(m_fakeWindow, &FakeWindow::containsMouseChanged, this, [=](bool contains) {
switch (m_settings->visibility()) { switch (m_settings->visibility()) {
case DockSettings::AlwaysHide: { case DockSettings::AlwaysHide:
case DockSettings::IntellHide:{
if (contains) { if (contains) {
m_hideTimer->stop(); m_hideTimer->stop();
@ -285,8 +286,6 @@ void MainWindow::createFakeWindow()
break; break;
} }
}); });
connect(m_fakeWindow, &FakeWindow::dragEntered, this, [&] {});
} }
} }
@ -330,6 +329,14 @@ void MainWindow::onPositionChanged()
updateViewStruts(); updateViewStruts();
} }
if (m_settings->visibility() == DockSettings::IntellHide) {
setVisible(false);
initSlideWindow();
setVisible(true);
setGeometry(windowRect());
updateViewStruts();
}
emit positionChanged(); emit positionChanged();
} }
@ -361,6 +368,20 @@ void MainWindow::onVisibilityChanged()
if (m_activity->launchPad()) if (m_activity->launchPad())
return; return;
if (m_settings->visibility() == DockSettings::IntellHide) {
clearViewStruts();
setGeometry(windowRect());
if (m_activity->existsWindowMaximized() && !m_hideBlocked) {
setVisible(false);
} else {
setVisible(true);
}
if (!m_fakeWindow)
createFakeWindow();
}
// Always hide // Always hide
if (m_settings->visibility() == DockSettings::AlwaysHide) { if (m_settings->visibility() == DockSettings::AlwaysHide) {
clearViewStruts(); clearViewStruts();
@ -373,6 +394,16 @@ void MainWindow::onVisibilityChanged()
} }
} }
void MainWindow::onHideTimeout()
{
if (m_settings->visibility() == DockSettings::IntellHide
&& !m_activity->existsWindowMaximized()) {
return;
}
setVisible(false);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *e) bool MainWindow::eventFilter(QObject *obj, QEvent *e)
{ {
switch (e->type()) { switch (e->type()) {

View file

@ -70,6 +70,8 @@ private slots:
void onIconSizeChanged(); void onIconSizeChanged();
void onVisibilityChanged(); void onVisibilityChanged();
void onHideTimeout();
protected: protected:
bool eventFilter(QObject *obj, QEvent *e) override; bool eventFilter(QObject *obj, QEvent *e) override;