1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-30 21:47:55 +03:00

update LastActiveWindow with signals

This commit is contained in:
Michail Vourlakos 2019-06-04 23:04:27 +03:00
parent c0e3004717
commit 4ae9b1b91c
5 changed files with 73 additions and 30 deletions

@ -32,10 +32,14 @@ namespace Tracker {
TrackedGeneralInfo::TrackedGeneralInfo(Tracker::Windows *tracker, Latte::View *view) TrackedGeneralInfo::TrackedGeneralInfo(Tracker::Windows *tracker, Latte::View *view)
: QObject(tracker) , : QObject(tracker) ,
m_wm(tracker->wm()), m_wm(tracker->wm()),
m_view(view) m_view(view),
m_tracker(tracker)
{ {
m_lastActiveWindow = new LastActiveWindow(this); m_lastActiveWindow = new LastActiveWindow(this);
connect(tracker, &Windows::windowChanged, this, &TrackedGeneralInfo::windowChanged);
connect(tracker, &Windows::activeWindowChanged, this, &TrackedGeneralInfo::windowChanged);
emit lastActiveWindowChanged(); emit lastActiveWindowChanged();
} }
@ -135,6 +139,19 @@ AbstractWindowInterface *TrackedGeneralInfo::wm()
return m_wm; return m_wm;
} }
void TrackedGeneralInfo::setActiveWindow(const WindowId &wid)
{
m_lastActiveWindow->setInformation(m_tracker->infoFor(wid));
}
void TrackedGeneralInfo::windowChanged(const WindowId &wid)
{
if (m_lastActiveWindow->winId() == wid && !wid.isNull()) {
m_lastActiveWindow->setInformation(m_tracker->infoFor(wid));
}
}
} }
} }
} }

@ -74,9 +74,14 @@ public:
Latte::View *view(); Latte::View *view();
AbstractWindowInterface *wm(); AbstractWindowInterface *wm();
void setActiveWindow(const WindowId &wid);
signals: signals:
void lastActiveWindowChanged(); void lastActiveWindowChanged();
private slots:
void windowChanged(const WindowId &wid);
private: private:
bool m_enabled; bool m_enabled;
bool m_activeWindowMaximized; bool m_activeWindowMaximized;
@ -89,6 +94,7 @@ private:
SchemeColors *m_activeWindowScheme{nullptr}; SchemeColors *m_activeWindowScheme{nullptr};
AbstractWindowInterface *m_wm{nullptr}; AbstractWindowInterface *m_wm{nullptr};
Tracker::Windows *m_tracker{nullptr};
}; };
} }

@ -60,15 +60,9 @@ void Windows::init()
connect(m_wm, &AbstractWindowInterface::windowChanged, this, [&](WindowId wid) { connect(m_wm, &AbstractWindowInterface::windowChanged, this, [&](WindowId wid) {
m_windows[wid] = m_wm->requestInfo(wid); m_windows[wid] = m_wm->requestInfo(wid);
for (const auto view : m_views.keys()) {
WindowId lastWinId = m_views[view]->lastActiveWindow()->winId();
if (lastWinId == wid) {
m_views[view]->lastActiveWindow()->setInformation(m_windows[lastWinId]);
}
}
updateViewsHints(); updateViewsHints();
emit windowChanged(wid);
}); });
connect(m_wm, &AbstractWindowInterface::windowRemoved, this, [&](WindowId wid) { connect(m_wm, &AbstractWindowInterface::windowRemoved, this, [&](WindowId wid) {
@ -84,16 +78,19 @@ void Windows::init()
}); });
connect(m_wm, &AbstractWindowInterface::activeWindowChanged, this, [&](WindowId wid) { connect(m_wm, &AbstractWindowInterface::activeWindowChanged, this, [&](WindowId wid) {
//! for some reason this is needed in order to update properly activeness values
//! when the active window changes the previous active windows should be also updated
for (const auto view : m_views.keys()) { for (const auto view : m_views.keys()) {
WindowId lastWinId = m_views[view]->lastActiveWindow()->winId(); WindowId lastWinId = m_views[view]->lastActiveWindow()->winId();
if (m_windows.contains(lastWinId)) { if ((lastWinId) != wid && m_windows.contains(lastWinId)) {
m_windows[lastWinId] = m_wm->requestInfo(lastWinId); m_windows[lastWinId] = m_wm->requestInfo(lastWinId);
m_views[view]->lastActiveWindow()->setInformation(m_windows[lastWinId]);
} }
} }
m_windows[wid] = m_wm->requestInfo(wid); m_windows[wid] = m_wm->requestInfo(wid);
updateViewsHints(); updateViewsHints();
emit activeWindowChanged(wid);
}); });
connect(m_wm, &AbstractWindowInterface::currentDesktopChanged, this, [&] { connect(m_wm, &AbstractWindowInterface::currentDesktopChanged, this, [&] {
@ -324,7 +321,7 @@ LastActiveWindow *Windows::lastActiveWindow(Latte::View *view)
return m_views[view]->lastActiveWindow(); return m_views[view]->lastActiveWindow();
} }
bool Windows::isValidFor(WindowId wid) const bool Windows::isValidFor(const WindowId &wid) const
{ {
if (!m_windows.contains(wid)) { if (!m_windows.contains(wid)) {
return false; return false;
@ -333,7 +330,7 @@ bool Windows::isValidFor(WindowId wid) const
return m_windows[wid].isValid() && !m_windows[wid].isPlasmaDesktop(); return m_windows[wid].isValid() && !m_windows[wid].isPlasmaDesktop();
} }
QIcon Windows::iconFor(WindowId wid) QIcon Windows::iconFor(const WindowId &wid)
{ {
if (!m_windows.contains(wid)) { if (!m_windows.contains(wid)) {
return QIcon(); return QIcon();
@ -355,7 +352,7 @@ QIcon Windows::iconFor(WindowId wid)
return m_windows[wid].icon(); return m_windows[wid].icon();
} }
QString Windows::appNameFor(WindowId wid) QString Windows::appNameFor(const WindowId &wid)
{ {
if (!m_windows.contains(wid)) { if (!m_windows.contains(wid)) {
return QString(); return QString();
@ -371,6 +368,17 @@ QString Windows::appNameFor(WindowId wid)
return m_windows[wid].appName(); return m_windows[wid].appName();
} }
WindowInfoWrap Windows::infoFor(const WindowId &wid) const
{
if (!m_windows.contains(wid)) {
return WindowInfoWrap();
}
return m_windows[wid];
}
//! Windows Criteria Functions //! Windows Criteria Functions
bool Windows::inCurrentDesktopActivity(const WindowInfoWrap &winfo) bool Windows::inCurrentDesktopActivity(const WindowInfoWrap &winfo)
@ -397,16 +405,16 @@ bool Windows::isActiveInViewScreen(Latte::View *view, const WindowInfoWrap &winf
bool Windows::isMaximizedInViewScreen(Latte::View *view, const WindowInfoWrap &winfo) bool Windows::isMaximizedInViewScreen(Latte::View *view, const WindowInfoWrap &winfo)
{ {
auto viewIntersectsMaxVert = [&]() noexcept -> bool { auto viewIntersectsMaxVert = [&]() noexcept -> bool {
return ((winfo.isMaxVert() return ((winfo.isMaxVert()
|| (view->screen() && view->screen()->availableSize().height() <= winfo.geometry().height())) || (view->screen() && view->screen()->availableSize().height() <= winfo.geometry().height()))
&& intersects(view, winfo)); && intersects(view, winfo));
}; };
auto viewIntersectsMaxHoriz = [&]() noexcept -> bool { auto viewIntersectsMaxHoriz = [&]() noexcept -> bool {
return ((winfo.isMaxHoriz() return ((winfo.isMaxHoriz()
|| (view->screen() && view->screen()->availableSize().width() <= winfo.geometry().width())) || (view->screen() && view->screen()->availableSize().width() <= winfo.geometry().width()))
&& intersects(view, winfo)); && intersects(view, winfo));
}; };
//! updated implementation to identify the screen that the maximized window is present //! updated implementation to identify the screen that the maximized window is present
//! in order to avoid: https://bugs.kde.org/show_bug.cgi?id=397700 //! in order to avoid: https://bugs.kde.org/show_bug.cgi?id=397700
@ -531,7 +539,6 @@ void Windows::updateHints(Latte::View *view)
} }
if (isActiveInViewScreen(view, winfo)) { if (isActiveInViewScreen(view, winfo)) {
m_views[view]->lastActiveWindow()->setInformation(winfo);
foundActiveInCurScreen = true; foundActiveInCurScreen = true;
activeWinId = winfo.wid(); activeWinId = winfo.wid();
} }
@ -598,6 +605,11 @@ void Windows::updateHints(Latte::View *view)
setTouchingWindowScheme(view, nullptr); setTouchingWindowScheme(view, nullptr);
} }
//! update LastActiveWindow
if (foundActiveInCurScreen) {
m_views[view]->setActiveWindow(activeWinId);
}
//! Debug //! Debug
//qDebug() << "TRACKING | SCREEN: " << view->positioner()->currentScreenId() << " , EDGE:" << view->location() << " , ENABLED:" << enabled(view); //qDebug() << "TRACKING | SCREEN: " << view->positioner()->currentScreenId() << " , EDGE:" << view->location() << " , ENABLED:" << enabled(view);
//qDebug() << "TRACKING | activeWindowTouching: " << foundActiveTouchInCurScreen << " ,activeWindowMaximized: " << activeWindowMaximized(view); //qDebug() << "TRACKING | activeWindowTouching: " << foundActiveTouchInCurScreen << " ,activeWindowMaximized: " << activeWindowMaximized(view);

@ -67,9 +67,10 @@ public:
SchemeColors *touchingWindowScheme(Latte::View *view) const; SchemeColors *touchingWindowScheme(Latte::View *view) const;
LastActiveWindow *lastActiveWindow(Latte::View *view); LastActiveWindow *lastActiveWindow(Latte::View *view);
bool isValidFor(WindowId wid) const; bool isValidFor(const WindowId &wid) const;
QIcon iconFor(WindowId wid); QIcon iconFor(const WindowId &wid);
QString appNameFor(WindowId wid); QString appNameFor(const WindowId &wid);
WindowInfoWrap infoFor(const WindowId &wid) const;
void setPlasmaDesktop(WindowId wid); void setPlasmaDesktop(WindowId wid);
@ -85,6 +86,11 @@ signals:
void activeWindowSchemeChanged(const Latte::View *view); void activeWindowSchemeChanged(const Latte::View *view);
void touchingWindowSchemeChanged(const Latte::View *view); void touchingWindowSchemeChanged(const Latte::View *view);
//! overloading WM signals in order to update first m_windows and afterwards
//! inform consumers for window changes
void activeWindowChanged(const WindowId &wid);
void windowChanged(const WindowId &wid);
private slots: private slots:
void updateAvailableScreenGeometries(); void updateAvailableScreenGeometries();

@ -63,12 +63,13 @@ public:
, m_isPlasmaDesktop(o.m_isPlasmaDesktop) , m_isPlasmaDesktop(o.m_isPlasmaDesktop)
, m_isKeepAbove(o.m_isKeepAbove) , m_isKeepAbove(o.m_isKeepAbove)
, m_hasSkipTaskbar(o.m_hasSkipTaskbar) , m_hasSkipTaskbar(o.m_hasSkipTaskbar)
, m_isOnAllDesktops(o.m_isOnAllDesktops) { , m_isOnAllDesktops(o.m_isOnAllDesktops)
, m_display(o.m_display) {
} }
WindowInfoWrap(WindowInfoWrap &&o) noexcept WindowInfoWrap(WindowInfoWrap &&o) noexcept
: m_wid(std::move(o.m_wid)) : m_wid(o.m_wid)
, m_geometry(std::move(o.m_geometry)) , m_geometry(o.m_geometry)
, m_isValid(o.m_isValid) , m_isValid(o.m_isValid)
, m_isActive(o.m_isActive) , m_isActive(o.m_isActive)
, m_isMinimized(o.m_isMinimized) , m_isMinimized(o.m_isMinimized)
@ -79,7 +80,8 @@ public:
, m_isPlasmaDesktop(o.m_isPlasmaDesktop) , m_isPlasmaDesktop(o.m_isPlasmaDesktop)
, m_isKeepAbove(o.m_isKeepAbove) , m_isKeepAbove(o.m_isKeepAbove)
, m_hasSkipTaskbar(o.m_hasSkipTaskbar) , m_hasSkipTaskbar(o.m_hasSkipTaskbar)
, m_isOnAllDesktops(o.m_isOnAllDesktops) { , m_isOnAllDesktops(o.m_isOnAllDesktops)
, m_display(o.m_display) {
} }
inline WindowInfoWrap &operator=(WindowInfoWrap &&rhs) noexcept; inline WindowInfoWrap &operator=(WindowInfoWrap &&rhs) noexcept;