1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-24 17:33:50 +03:00

fix #139, Un-hide Latte at desktop and activity changes

This commit is contained in:
Johan Smith Agudelo Rodriguez 2017-02-12 03:01:12 -05:00
parent 3ab252339c
commit ec3721a591
5 changed files with 69 additions and 19 deletions

View File

@ -64,6 +64,7 @@ signals:
void windowAdded(WId wid);
void windowRemoved(WId wid);
void currentDesktopChanged(int desktop);
void currentActivityChanged();
protected:
QQuickWindow *const m_view;

View File

@ -103,6 +103,10 @@ inline void VisibilityManagerPrivate::setMode(Dock::Visibility mode)
break;
case Dock::AutoHide: {
connections[0] = connect(wm.get(), &AbstractWindowInterface::currentDesktopChanged
, this, &VisibilityManagerPrivate::raiseDockTemporarily);
connections[1] = connect(wm.get(), &AbstractWindowInterface::currentActivityChanged
, this, &VisibilityManagerPrivate::raiseDockTemporarily);
raiseDock(containsMouse);
}
break;
@ -113,10 +117,9 @@ inline void VisibilityManagerPrivate::setMode(Dock::Visibility mode)
connections[1] = connect(wm.get(), &AbstractWindowInterface::windowChanged
, this, &VisibilityManagerPrivate::dodgeActive);
connections[2] = connect(wm.get(), &AbstractWindowInterface::currentDesktopChanged
, this, [&](int desktop) {
qDebug() << "desktop" << desktop;
dodgeActive(wm->activeWindow());
});
, this, &VisibilityManagerPrivate::raiseDockTemporarily);
connections[3] = connect(wm.get(), &AbstractWindowInterface::currentActivityChanged
, this, &VisibilityManagerPrivate::raiseDockTemporarily);
dodgeActive(wm->activeWindow());
}
break;
@ -127,9 +130,9 @@ inline void VisibilityManagerPrivate::setMode(Dock::Visibility mode)
connections[1] = connect(wm.get(), &AbstractWindowInterface::windowChanged
, this, &VisibilityManagerPrivate::dodgeMaximized);
connections[2] = connect(wm.get(), &AbstractWindowInterface::currentDesktopChanged
, this, [&](int) {
dodgeMaximized(wm->activeWindow());
});
, this, &VisibilityManagerPrivate::raiseDockTemporarily);
connections[3] = connect(wm.get(), &AbstractWindowInterface::currentActivityChanged
, this, &VisibilityManagerPrivate::raiseDockTemporarily);
dodgeMaximized(wm->activeWindow());
}
break;
@ -152,11 +155,16 @@ inline void VisibilityManagerPrivate::setMode(Dock::Visibility mode)
timerCheckWindows.start();
});
connections[3] = connect(wm.get(), &AbstractWindowInterface::currentDesktopChanged
, this, [&](int) {
timerCheckWindows.start();
});
, this, &VisibilityManagerPrivate::raiseDockTemporarily);
connections[4] = connect(wm.get(), &AbstractWindowInterface::currentActivityChanged
, this, &VisibilityManagerPrivate::raiseDockTemporarily);
timerCheckWindows.start();
}
break;
case Dock::None:
break;
}
saveConfig();
@ -225,11 +233,33 @@ inline void VisibilityManagerPrivate::raiseDock(bool raise)
} else if (!blockHiding && !dragEnter) {
timerShow.stop();
if (!timerHide.isActive())
if (hideNow) {
hideNow = false;
emit q->mustBeHide();
} else if (!timerHide.isActive())
timerHide.start();
}
}
void VisibilityManagerPrivate::raiseDockTemporarily()
{
if (raiseTemporarily)
return;
raiseTemporarily = true;
timerHide.stop();
timerShow.stop();
if (isHidden)
emit q->mustBeShown();
QTimer::singleShot(1800, this, [&](){
raiseTemporarily = false;
hideNow = true;
updateHiddenState();
});
}
void VisibilityManagerPrivate::updateHiddenState()
{
if (dragEnter)
@ -268,6 +298,9 @@ inline void VisibilityManagerPrivate::setDockGeometry(const QRect &geometry)
void VisibilityManagerPrivate::dodgeActive(WId wid)
{
if (raiseTemporarily)
return;
auto winfo = wm->requestInfo(wid);
if (!winfo.isValid())
@ -285,6 +318,9 @@ void VisibilityManagerPrivate::dodgeActive(WId wid)
void VisibilityManagerPrivate::dodgeMaximized(WId wid)
{
if (raiseTemporarily)
return;
auto winfo = wm->requestInfo(wid);
if (!winfo.isValid())
@ -302,6 +338,9 @@ void VisibilityManagerPrivate::dodgeMaximized(WId wid)
void VisibilityManagerPrivate::dodgeWindows(WId wid)
{
if (raiseTemporarily)
return;
if (windows.find(wid) == std::end(windows))
return;
@ -319,6 +358,9 @@ void VisibilityManagerPrivate::dodgeWindows(WId wid)
void VisibilityManagerPrivate::checkAllWindows()
{
if (raiseTemporarily)
return;
bool raise{true};
for (const auto &winfo : windows) {
@ -367,12 +409,12 @@ inline void VisibilityManagerPrivate::restoreConfig()
emit q->timerShowChanged();
emit q->timerHideChanged();
if (mode != Dock::AlwaysVisible) {
if (mode == Dock::AlwaysVisible) {
setMode(mode);
} else {
QTimer::singleShot(2400, this, [&, mode]() {
setMode(mode);
});
} else {
setMode(mode);
}
}

View File

@ -35,6 +35,7 @@ public:
void setTimerHide(int msec);
void raiseDock(bool raise);
void raiseDockTemporarily();
void updateHiddenState();
void setDockGeometry(const QRect &rect);
@ -56,7 +57,7 @@ public:
PlasmaQuick::ContainmentView *view;
std::unique_ptr<AbstractWindowInterface> wm;
Dock::Visibility mode{Dock::None};
std::array<QMetaObject::Connection, 4> connections;
std::array<QMetaObject::Connection, 5> connections;
std::unordered_map<WId, WindowInfoWrap> windows;
QTimer timerShow;
QTimer timerHide;
@ -66,6 +67,8 @@ public:
bool dragEnter{false};
bool blockHiding{false};
bool containsMouse{false};
bool raiseTemporarily{false};
bool hideNow{false};
};
}

View File

@ -32,7 +32,7 @@
namespace Latte {
XWindowInterface::XWindowInterface(QQuickWindow *const view, QObject *parent)
: AbstractWindowInterface(view, parent)
: AbstractWindowInterface(view, parent), activities(new KActivities::Consumer(this))
{
Q_ASSERT(view != nullptr);
@ -62,11 +62,12 @@ XWindowInterface::XWindowInterface(QQuickWindow *const view, QObject *parent)
connections << connect(KWindowSystem::self(), &KWindowSystem::currentDesktopChanged
, this, [&](int desktop) {
m_currentDesktop = desktop;
QTimer::singleShot(200, this, [&]() {
emit currentDesktopChanged(m_currentDesktop);
});
emit currentDesktopChanged(m_currentDesktop);
});
connections << connect(activities.data(), &KActivities::Consumer::currentActivityChanged
, this, &XWindowInterface::currentActivityChanged);
// fill windows list
foreach (const auto &wid, KWindowSystem::self()->windows()) {
addWindow(wid);

View File

@ -24,9 +24,11 @@
#include "abstractwindowinterface.h"
#include <QObject>
#include <QPointer>
#include <KWindowInfo>
#include <Plasma>
#include <KActivities/Consumer>
namespace Latte {
@ -55,6 +57,7 @@ private:
WId m_desktopId;
int m_currentDesktop;
QPointer<KActivities::Consumer> activities;
QList<QMetaObject::Connection> connections;
};