Add smart hide
This commit is contained in:
parent
18628cb292
commit
87e03b6723
5 changed files with 73 additions and 6 deletions
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "activity.h"
|
||||
#include "docksettings.h"
|
||||
|
||||
#include <NETWM>
|
||||
#include <KWindowSystem>
|
||||
|
@ -34,6 +35,7 @@ Activity *Activity::self()
|
|||
|
||||
Activity::Activity(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_existsWindowMaximized(false)
|
||||
{
|
||||
onActiveWindowChanged();
|
||||
|
||||
|
@ -42,6 +44,11 @@ Activity::Activity(QObject *parent)
|
|||
this, &Activity::onActiveWindowChanged);
|
||||
}
|
||||
|
||||
bool Activity::existsWindowMaximized() const
|
||||
{
|
||||
return m_existsWindowMaximized;
|
||||
}
|
||||
|
||||
bool Activity::launchPad() const
|
||||
{
|
||||
return m_launchPad;
|
||||
|
@ -54,11 +61,33 @@ void Activity::onActiveWindowChanged()
|
|||
NET::WM2WindowClass);
|
||||
|
||||
bool launchPad = info.windowClassClass() == "cutefish-launcher";
|
||||
|
||||
if (m_launchPad != launchPad) {
|
||||
m_launchPad = launchPad;
|
||||
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_windowClass = info.windowClassClass().toLower();
|
||||
}
|
||||
|
|
|
@ -26,11 +26,13 @@ class Activity : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool launchPad READ launchPad NOTIFY launchPadChanged)
|
||||
Q_PROPERTY(bool existsWindowMaximized READ existsWindowMaximized NOTIFY existsWindowMaximizedChanged)
|
||||
|
||||
public:
|
||||
static Activity *self();
|
||||
explicit Activity(QObject *parent = nullptr);
|
||||
|
||||
bool existsWindowMaximized() const;
|
||||
bool launchPad() const;
|
||||
|
||||
private slots:
|
||||
|
@ -38,11 +40,13 @@ private slots:
|
|||
|
||||
signals:
|
||||
void launchPadChanged();
|
||||
void existsWindowMaximizedChanged();
|
||||
|
||||
private:
|
||||
QString m_windowClass;
|
||||
quint32 m_pid;
|
||||
|
||||
bool m_existsWindowMaximized;
|
||||
bool m_launchPad;
|
||||
};
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ public:
|
|||
enum Visibility {
|
||||
AlwaysShow = 0,
|
||||
// AutoHide,
|
||||
AlwaysHide
|
||||
AlwaysHide,
|
||||
IntellHide
|
||||
};
|
||||
Q_ENUMS(Visibility)
|
||||
|
||||
|
|
|
@ -75,10 +75,11 @@ MainWindow::MainWindow(QQuickView *parent)
|
|||
|
||||
m_hideTimer->setSingleShot(true);
|
||||
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.
|
||||
connect(m_activity, &Activity::launchPadChanged, this, &MainWindow::onVisibilityChanged);
|
||||
connect(m_activity, &Activity::existsWindowMaximizedChanged, this, &MainWindow::onVisibilityChanged);
|
||||
|
||||
// Screen change.
|
||||
connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &MainWindow::onPrimaryScreenChanged);
|
||||
|
@ -263,8 +264,8 @@ void MainWindow::createFakeWindow()
|
|||
|
||||
connect(m_fakeWindow, &FakeWindow::containsMouseChanged, this, [=](bool contains) {
|
||||
switch (m_settings->visibility()) {
|
||||
case DockSettings::AlwaysHide: {
|
||||
|
||||
case DockSettings::AlwaysHide:
|
||||
case DockSettings::IntellHide:{
|
||||
if (contains) {
|
||||
m_hideTimer->stop();
|
||||
|
||||
|
@ -285,8 +286,6 @@ void MainWindow::createFakeWindow()
|
|||
break;
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_fakeWindow, &FakeWindow::dragEntered, this, [&] {});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,6 +329,14 @@ void MainWindow::onPositionChanged()
|
|||
updateViewStruts();
|
||||
}
|
||||
|
||||
if (m_settings->visibility() == DockSettings::IntellHide) {
|
||||
setVisible(false);
|
||||
initSlideWindow();
|
||||
setVisible(true);
|
||||
setGeometry(windowRect());
|
||||
updateViewStruts();
|
||||
}
|
||||
|
||||
emit positionChanged();
|
||||
}
|
||||
|
||||
|
@ -361,6 +368,20 @@ void MainWindow::onVisibilityChanged()
|
|||
if (m_activity->launchPad())
|
||||
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
|
||||
if (m_settings->visibility() == DockSettings::AlwaysHide) {
|
||||
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)
|
||||
{
|
||||
switch (e->type()) {
|
||||
|
|
|
@ -70,6 +70,8 @@ private slots:
|
|||
void onIconSizeChanged();
|
||||
void onVisibilityChanged();
|
||||
|
||||
void onHideTimeout();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *e) override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue