From 9d8d7e28a1047a6950392e481b6ad8dbbf1fb651 Mon Sep 17 00:00:00 2001 From: Ismael Asensio Date: Sun, 10 Jul 2022 21:21:04 +0200 Subject: [PATCH] TabBox: Allow switchers to handle the tabbox hiding Previously, the switcher item got hidden immediately after selecting a window, so it wasn't possible to show an exit transition. Emit instead an `aboutToHide` signal and let the switchers that opt-in to handle when to hide the tabbox by just setting its `visible` property to `false`. In the default case we handle that signal by immediately hiding the tabbox as usual. For symmetry, add also a new `aboutToShow` signal which simplifies setting an enter transition. --- src/kcms/tabbox/layoutpreview.h | 3 +++ src/tabbox/switcheritem.cpp | 15 +++++++++++++++ src/tabbox/switcheritem.h | 10 +++++++++- src/tabbox/tabboxhandler.cpp | 23 +++++++++++++++++------ 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/kcms/tabbox/layoutpreview.h b/src/kcms/tabbox/layoutpreview.h index aaa0cd56cb..2d5ebd6436 100644 --- a/src/kcms/tabbox/layoutpreview.h +++ b/src/kcms/tabbox/layoutpreview.h @@ -114,6 +114,9 @@ Q_SIGNALS: void screenGeometryChanged(); void itemChanged(); + void aboutToShow(); + void aboutToHide(); + private: QAbstractItemModel *m_model; QObject *m_item; diff --git a/src/tabbox/switcheritem.cpp b/src/tabbox/switcheritem.cpp index 4bccd7b069..8fc4c2b66b 100644 --- a/src/tabbox/switcheritem.cpp +++ b/src/tabbox/switcheritem.cpp @@ -27,6 +27,7 @@ SwitcherItem::SwitcherItem(QObject *parent) , m_visible(false) , m_allDesktops(false) , m_currentIndex(0) + , m_automaticallyHide(false) { m_selectedIndexConnection = connect(tabBox, &TabBoxHandler::selectedIndexChanged, this, [this] { if (isVisible()) { @@ -104,6 +105,20 @@ void SwitcherItem::setNoModifierGrab(bool set) Q_EMIT noModifierGrabChanged(); } +bool SwitcherItem::automaticallyHide() const +{ + return m_automaticallyHide; +} + +void SwitcherItem::setAutomaticallyHide(bool value) +{ + if (m_automaticallyHide == value) { + return; + } + m_automaticallyHide = value; + Q_EMIT automaticallyHideChanged(); +} + bool SwitcherItem::compositing() { return Compositor::compositing(); diff --git a/src/tabbox/switcheritem.h b/src/tabbox/switcheritem.h index 2efc44acdc..f791825572 100644 --- a/src/tabbox/switcheritem.h +++ b/src/tabbox/switcheritem.h @@ -23,11 +23,12 @@ class SwitcherItem : public QObject Q_OBJECT Q_PROPERTY(QAbstractItemModel *model READ model NOTIFY modelChanged) Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged) - Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged) + Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) Q_PROPERTY(bool allDesktops READ isAllDesktops NOTIFY allDesktopsChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(bool noModifierGrab READ noModifierGrab NOTIFY noModifierGrabChanged) Q_PROPERTY(bool compositing READ compositing NOTIFY compositingChanged) + Q_PROPERTY(bool automaticallyHide READ automaticallyHide WRITE setAutomaticallyHide NOTIFY automaticallyHideChanged) /** * The main QML item that will be displayed in the Dialog @@ -52,12 +53,14 @@ public: return m_noModifierGrab; } bool compositing(); + bool automaticallyHide() const; // for usage from outside void setModel(QAbstractItemModel *model); void setAllDesktops(bool all); void setVisible(bool visible); void setNoModifierGrab(bool set); + void setAutomaticallyHide(bool value); Q_SIGNALS: void visibleChanged(); @@ -68,6 +71,10 @@ Q_SIGNALS: void itemChanged(); void noModifierGrabChanged(); void compositingChanged(); + void automaticallyHideChanged(); + + void aboutToShow(); + void aboutToHide(); private: QAbstractItemModel *m_model; @@ -77,6 +84,7 @@ private: int m_currentIndex; QMetaObject::Connection m_selectedIndexConnection; bool m_noModifierGrab = false; + bool m_automaticallyHide = true; }; inline QAbstractItemModel *SwitcherItem::model() const diff --git a/src/tabbox/tabboxhandler.cpp b/src/tabbox/tabboxhandler.cpp index e606e0ca3d..0d445b88dd 100644 --- a/src/tabbox/tabboxhandler.cpp +++ b/src/tabbox/tabboxhandler.cpp @@ -316,6 +316,19 @@ void TabBoxHandlerPrivate::show() item->setAllDesktops(config.clientDesktopMode() == TabBoxConfig::AllDesktopsClients); item->setCurrentIndex(indexRow); item->setNoModifierGrab(q->noModifierGrab()); + Q_EMIT item->aboutToShow(); + + // When SwitcherItem gets hidden, destroy also the window and main item + QObject::connect(item, &SwitcherItem::visibleChanged, q, [this, item]() { + if (!item->isVisible()) { + if (QQuickWindow *w = window()) { + w->hide(); + w->destroy(); + } + m_mainItem = nullptr; + } + }); + // everything is prepared, so let's make the whole thing visible item->setVisible(true); } @@ -391,14 +404,12 @@ void TabBoxHandler::hide(bool abort) } #ifndef KWIN_UNIT_TEST if (SwitcherItem *item = d->switcherItem()) { - item->setVisible(false); + Q_EMIT item->aboutToHide(); + if (item->automaticallyHide()) { + item->setVisible(false); + } } #endif - if (QQuickWindow *w = d->window()) { - w->hide(); - w->destroy(); - } - d->m_mainItem = nullptr; } QModelIndex TabBoxHandler::nextPrev(bool forward) const