diff --git a/autotests/integration/tabbox_test.cpp b/autotests/integration/tabbox_test.cpp index bc5300773b..40e48a86f9 100644 --- a/autotests/integration/tabbox_test.cpp +++ b/autotests/integration/tabbox_test.cpp @@ -93,9 +93,9 @@ void TabBoxTest::testCapsLock() QVERIFY(c3->isActive()); // Setup tabbox signal spies - QSignalSpy tabboxAddedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxAdded); + QSignalSpy tabboxAddedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxAdded); QVERIFY(tabboxAddedSpy.isValid()); - QSignalSpy tabboxClosedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxClosed); + QSignalSpy tabboxClosedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxClosed); QVERIFY(tabboxClosedSpy.isValid()); // enable capslock @@ -111,19 +111,19 @@ void TabBoxTest::testCapsLock() Test::keyboardKeyReleased(KEY_TAB, timestamp++); QVERIFY(tabboxAddedSpy.wait()); - QVERIFY(TabBox::TabBox::self()->isGrabbed()); + QVERIFY(workspace()->tabbox()->isGrabbed()); // release alt Test::keyboardKeyReleased(KEY_LEFTALT, timestamp++); QCOMPARE(tabboxClosedSpy.count(), 1); - QCOMPARE(TabBox::TabBox::self()->isGrabbed(), false); + QCOMPARE(workspace()->tabbox()->isGrabbed(), false); // release caps lock Test::keyboardKeyPressed(KEY_CAPSLOCK, timestamp++); Test::keyboardKeyReleased(KEY_CAPSLOCK, timestamp++); QCOMPARE(input()->keyboardModifiers(), Qt::NoModifier); QCOMPARE(tabboxClosedSpy.count(), 1); - QCOMPARE(TabBox::TabBox::self()->isGrabbed(), false); + QCOMPARE(workspace()->tabbox()->isGrabbed(), false); QCOMPARE(workspace()->activeWindow(), c2); surface3.reset(); @@ -156,9 +156,9 @@ void TabBoxTest::testMoveForward() QVERIFY(c3->isActive()); // Setup tabbox signal spies - QSignalSpy tabboxAddedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxAdded); + QSignalSpy tabboxAddedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxAdded); QVERIFY(tabboxAddedSpy.isValid()); - QSignalSpy tabboxClosedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxClosed); + QSignalSpy tabboxClosedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxClosed); QVERIFY(tabboxClosedSpy.isValid()); // press alt+tab @@ -169,12 +169,12 @@ void TabBoxTest::testMoveForward() Test::keyboardKeyReleased(KEY_TAB, timestamp++); QVERIFY(tabboxAddedSpy.wait()); - QVERIFY(TabBox::TabBox::self()->isGrabbed()); + QVERIFY(workspace()->tabbox()->isGrabbed()); // release alt Test::keyboardKeyReleased(KEY_LEFTALT, timestamp++); QCOMPARE(tabboxClosedSpy.count(), 1); - QCOMPARE(TabBox::TabBox::self()->isGrabbed(), false); + QCOMPARE(workspace()->tabbox()->isGrabbed(), false); QCOMPARE(workspace()->activeWindow(), c2); surface3.reset(); @@ -207,9 +207,9 @@ void TabBoxTest::testMoveBackward() QVERIFY(c3->isActive()); // Setup tabbox signal spies - QSignalSpy tabboxAddedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxAdded); + QSignalSpy tabboxAddedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxAdded); QVERIFY(tabboxAddedSpy.isValid()); - QSignalSpy tabboxClosedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxClosed); + QSignalSpy tabboxClosedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxClosed); QVERIFY(tabboxClosedSpy.isValid()); // press alt+shift+tab @@ -222,14 +222,14 @@ void TabBoxTest::testMoveBackward() Test::keyboardKeyReleased(KEY_TAB, timestamp++); QVERIFY(tabboxAddedSpy.wait()); - QVERIFY(TabBox::TabBox::self()->isGrabbed()); + QVERIFY(workspace()->tabbox()->isGrabbed()); // release alt Test::keyboardKeyReleased(KEY_LEFTSHIFT, timestamp++); QCOMPARE(tabboxClosedSpy.count(), 0); Test::keyboardKeyReleased(KEY_LEFTALT, timestamp++); QCOMPARE(tabboxClosedSpy.count(), 1); - QCOMPARE(TabBox::TabBox::self()->isGrabbed(), false); + QCOMPARE(workspace()->tabbox()->isGrabbed(), false); QCOMPARE(workspace()->activeWindow(), c1); surface3.reset(); diff --git a/src/effects.cpp b/src/effects.cpp index 7026401567..fc0c3b4524 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -206,7 +206,7 @@ EffectsHandlerImpl::EffectsHandlerImpl(Compositor *compositor, Scene *scene) #endif connect(ws, &Workspace::stackingOrderChanged, this, &EffectsHandler::stackingOrderChanged); #if KWIN_BUILD_TABBOX - TabBox::TabBox *tabBox = TabBox::TabBox::self(); + TabBox::TabBox *tabBox = workspace()->tabbox(); connect(tabBox, &TabBox::TabBox::tabBoxAdded, this, &EffectsHandler::tabBoxAdded); connect(tabBox, &TabBox::TabBox::tabBoxUpdated, this, &EffectsHandler::tabBoxUpdated); connect(tabBox, &TabBox::TabBox::tabBoxClosed, this, &EffectsHandler::tabBoxClosed); @@ -1157,7 +1157,7 @@ void EffectsHandlerImpl::setTabBoxWindow(EffectWindow *w) #if KWIN_BUILD_TABBOX auto window = static_cast(w)->window(); if (window->isClient()) { - TabBox::TabBox::self()->setCurrentClient(window); + workspace()->tabbox()->setCurrentClient(window); } #else Q_UNUSED(w) @@ -1167,7 +1167,7 @@ void EffectsHandlerImpl::setTabBoxWindow(EffectWindow *w) void EffectsHandlerImpl::setTabBoxDesktop(int desktop) { #if KWIN_BUILD_TABBOX - TabBox::TabBox::self()->setCurrentDesktop(desktop); + workspace()->tabbox()->setCurrentDesktop(desktop); #else Q_UNUSED(desktop) #endif @@ -1176,7 +1176,7 @@ void EffectsHandlerImpl::setTabBoxDesktop(int desktop) EffectWindowList EffectsHandlerImpl::currentTabBoxWindowList() const { #if KWIN_BUILD_TABBOX - const auto clients = TabBox::TabBox::self()->currentClientList(); + const auto clients = workspace()->tabbox()->currentClientList(); EffectWindowList ret; ret.reserve(clients.size()); std::transform(std::cbegin(clients), std::cend(clients), @@ -1193,28 +1193,28 @@ EffectWindowList EffectsHandlerImpl::currentTabBoxWindowList() const void EffectsHandlerImpl::refTabBox() { #if KWIN_BUILD_TABBOX - TabBox::TabBox::self()->reference(); + workspace()->tabbox()->reference(); #endif } void EffectsHandlerImpl::unrefTabBox() { #if KWIN_BUILD_TABBOX - TabBox::TabBox::self()->unreference(); + workspace()->tabbox()->unreference(); #endif } void EffectsHandlerImpl::closeTabBox() { #if KWIN_BUILD_TABBOX - TabBox::TabBox::self()->close(); + workspace()->tabbox()->close(); #endif } QList EffectsHandlerImpl::currentTabBoxDesktopList() const { #if KWIN_BUILD_TABBOX - return TabBox::TabBox::self()->currentDesktopList(); + return workspace()->tabbox()->currentDesktopList(); #else return QList(); #endif @@ -1223,7 +1223,7 @@ QList EffectsHandlerImpl::currentTabBoxDesktopList() const int EffectsHandlerImpl::currentTabBoxDesktop() const { #if KWIN_BUILD_TABBOX - return TabBox::TabBox::self()->currentDesktop(); + return workspace()->tabbox()->currentDesktop(); #else return -1; #endif @@ -1232,7 +1232,7 @@ int EffectsHandlerImpl::currentTabBoxDesktop() const EffectWindow *EffectsHandlerImpl::currentTabBoxWindow() const { #if KWIN_BUILD_TABBOX - if (auto c = TabBox::TabBox::self()->currentClient()) { + if (auto c = workspace()->tabbox()->currentClient()) { return c->effectWindow(); } #endif diff --git a/src/events.cpp b/src/events.cpp index b9fdb4bd55..9af023d3c1 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -825,7 +825,7 @@ void X11Window::updateMouseGrab() xcb_ungrab_button(kwinApp()->x11Connection(), XCB_BUTTON_INDEX_ANY, m_wrapper, XCB_MOD_MASK_ANY); #if KWIN_BUILD_TABBOX - if (TabBox::TabBox::self()->forcedGlobalMouseGrab()) { // see TabBox::establishTabBoxGrab() + if (workspace()->tabbox()->forcedGlobalMouseGrab()) { // see TabBox::establishTabBoxGrab() m_wrapper.grabButton(XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC); return; } diff --git a/src/input.cpp b/src/input.cpp index 08d77ea270..44aaba5b51 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1646,14 +1646,14 @@ public: bool pointerEvent(QMouseEvent *event, quint32 button) override { Q_UNUSED(button) - if (!TabBox::TabBox::self() || !TabBox::TabBox::self()->isGrabbed()) { + if (!workspace()->tabbox() || !workspace()->tabbox()->isGrabbed()) { return false; } - return TabBox::TabBox::self()->handleMouseEvent(event); + return workspace()->tabbox()->handleMouseEvent(event); } bool keyEvent(QKeyEvent *event) override { - if (!TabBox::TabBox::self() || !TabBox::TabBox::self()->isGrabbed()) { + if (!workspace()->tabbox() || !workspace()->tabbox()->isGrabbed()) { return false; } auto seat = waylandServer()->seat(); @@ -1664,18 +1664,18 @@ public: passToWaylandServer(event); if (event->type() == QEvent::KeyPress) { - TabBox::TabBox::self()->keyPress(event->modifiers() | event->key()); + workspace()->tabbox()->keyPress(event->modifiers() | event->key()); } else if (static_cast(event)->modifiersRelevantForGlobalShortcuts() == Qt::NoModifier) { - TabBox::TabBox::self()->modifiersReleased(); + workspace()->tabbox()->modifiersReleased(); } return true; } bool wheelEvent(QWheelEvent *event) override { - if (!TabBox::TabBox::self() || !TabBox::TabBox::self()->isGrabbed()) { + if (!workspace()->tabbox() || !workspace()->tabbox()->isGrabbed()) { return false; } - return TabBox::TabBox::self()->handleWheelEvent(event); + return workspace()->tabbox()->handleWheelEvent(event); } }; #endif diff --git a/src/tabbox/tabbox.cpp b/src/tabbox/tabbox.cpp index 46dce6ff7a..74b585e85e 100644 --- a/src/tabbox/tabbox.cpp +++ b/src/tabbox/tabbox.cpp @@ -440,18 +440,9 @@ QUuid TabBoxClientImpl::internalId() const /********************************************************* * TabBox *********************************************************/ -TabBox *TabBox::s_self = nullptr; -TabBox *TabBox::create(QObject *parent) -{ - Q_ASSERT(!s_self); - s_self = new TabBox(parent); - return s_self; -} - -TabBox::TabBox(QObject *parent) - : QObject(parent) - , m_displayRefcount(0) +TabBox::TabBox() + : m_displayRefcount(0) , m_desktopGrab(false) , m_tabGrab(false) , m_noModifierGrab(false) @@ -506,10 +497,7 @@ TabBox::TabBox(QObject *parent) connect(Workspace::self(), &Workspace::configChanged, this, &TabBox::reconfigure); } -TabBox::~TabBox() -{ - s_self = nullptr; -} +TabBox::~TabBox() = default; void TabBox::handlerReady() { @@ -526,7 +514,7 @@ void TabBox::key(const KLazyLocalizedString &actionName, Slot slot, const QKeySe a->setObjectName(QString::fromUtf8(actionName.untranslatedText())); a->setText(actionName.toString()); KGlobalAccel::self()->setGlobalShortcut(a, QList() << shortcut); - input()->registerShortcut(shortcut, a, TabBox::self(), slot); + input()->registerShortcut(shortcut, a, this, slot); auto cuts = KGlobalAccel::self()->shortcut(a); globalShortcutChanged(a, cuts.isEmpty() ? QKeySequence() : cuts.first()); } diff --git a/src/tabbox/tabbox.h b/src/tabbox/tabbox.h index 9e568880e7..24fef5ff24 100644 --- a/src/tabbox/tabbox.h +++ b/src/tabbox/tabbox.h @@ -106,7 +106,8 @@ class KWIN_EXPORT TabBox : public QObject { Q_OBJECT public: - ~TabBox() override; + explicit TabBox(); + ~TabBox(); /** * Returns the currently displayed client ( only works in TabBoxWindowsMode ). @@ -261,9 +262,6 @@ public: } void setCurrentIndex(QModelIndex index, bool notifyEffects = true); - static TabBox *self(); - static TabBox *create(QObject *parent); - public Q_SLOTS: /** * Notify effects that the tab box is being shown, and only display the @@ -357,16 +355,9 @@ private: QList m_borderActivate, m_borderAlternativeActivate; QHash m_touchActivate; QHash m_touchAlternativeActivate; - QScopedPointer m_x11EventFilter; - - static TabBox *s_self; + std::unique_ptr m_x11EventFilter; }; -inline TabBox *TabBox::self() -{ - return s_self; -} - } // namespace TabBox } // namespace #endif diff --git a/src/tabbox/x11_filter.cpp b/src/tabbox/x11_filter.cpp index 46abaea22a..f751b5869d 100644 --- a/src/tabbox/x11_filter.cpp +++ b/src/tabbox/x11_filter.cpp @@ -29,7 +29,8 @@ X11Filter::X11Filter() bool X11Filter::event(xcb_generic_event_t *event) { - if (!TabBox::TabBox::self()->isGrabbed()) { + const auto tab = workspace()->tabbox(); + if (!tab->isGrabbed()) { return false; } const uint8_t eventType = event->response_type & ~0x80; @@ -38,7 +39,6 @@ bool X11Filter::event(xcb_generic_event_t *event) case XCB_BUTTON_RELEASE: { auto e = reinterpret_cast(event); xcb_allow_events(connection(), XCB_ALLOW_ASYNC_POINTER, XCB_CURRENT_TIME); - const auto tab = TabBox::TabBox::self(); if (!tab->isShown() && tab->isDisplayed()) { if (effects && static_cast(effects)->isMouseInterception()) { // pass on to effects, effects will filter out the event @@ -67,7 +67,7 @@ bool X11Filter::event(xcb_generic_event_t *event) bool X11Filter::buttonPress(xcb_button_press_event_t *event) { // press outside Tabbox? - const auto tab = TabBox::TabBox::self(); + const auto tab = workspace()->tabbox(); QPoint pos(event->root_x, event->root_y); if ((!tab->isShown() && tab->isDisplayed()) || (!tabBox->containsPos(pos) && (event->detail == XCB_BUTTON_INDEX_1 || event->detail == XCB_BUTTON_INDEX_2 || event->detail == XCB_BUTTON_INDEX_3))) { @@ -99,7 +99,7 @@ void X11Filter::keyPress(xcb_generic_event_t *event) int keyQt; xcb_key_press_event_t *keyEvent = reinterpret_cast(event); KKeyServer::xcbKeyPressEventToQt(keyEvent, &keyQt); - TabBox::TabBox::self()->keyPress(keyQt); + workspace()->tabbox()->keyPress(keyQt); } void X11Filter::keyRelease(xcb_generic_event_t *event) @@ -141,7 +141,7 @@ void X11Filter::keyRelease(xcb_generic_event_t *event) } } if (release) { - TabBox::TabBox::self()->modifiersReleased(); + workspace()->tabbox()->modifiersReleased(); } } diff --git a/src/useractions.cpp b/src/useractions.cpp index 72df2e12d1..a74f2fa353 100644 --- a/src/useractions.cpp +++ b/src/useractions.cpp @@ -1103,7 +1103,7 @@ void Workspace::initShortcuts() initShortcut("Invert Screen Colors", i18n("Invert Screen Colors"), 0, kwinApp()->platform(), &Platform::invertScreen); #if KWIN_BUILD_TABBOX - TabBox::TabBox::self()->initShortcuts(); + m_tabbox->initShortcuts(); #endif vds->initShortcuts(); m_userActionsMenu->discard(); // so that it's recreated next time diff --git a/src/window.cpp b/src/window.cpp index 76f42ba9ec..9e050a1ad8 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -4432,7 +4432,7 @@ void Window::setFullscreenGeometryRestore(const QRectF &geom) void Window::cleanTabBox() { #if KWIN_BUILD_TABBOX - TabBox::TabBox *tabBox = TabBox::TabBox::self(); + TabBox::TabBox *tabBox = workspace()->tabbox(); if (tabBox && tabBox->isDisplayed() && tabBox->currentClient() == this) { tabBox->nextPrev(true); } diff --git a/src/workspace.cpp b/src/workspace.cpp index 9c69950233..9e02997700 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -169,7 +169,7 @@ Workspace::Workspace() #if KWIN_BUILD_TABBOX // need to create the tabbox before compositing scene is setup - TabBox::TabBox::create(this); + m_tabbox = std::make_unique(); #endif if (!Compositor::self()) { @@ -1874,9 +1874,8 @@ void Workspace::setWasUserInteraction() void Workspace::updateTabbox() { #if KWIN_BUILD_TABBOX - TabBox::TabBox *tabBox = TabBox::TabBox::self(); - if (tabBox->isDisplayed()) { - tabBox->reset(true); + if (m_tabbox->isDisplayed()) { + m_tabbox->reset(true); } #endif } @@ -2866,6 +2865,13 @@ Screens *Workspace::screens() const return m_screens.get(); } +#if KWIN_BUILD_TABBOX +TabBox::TabBox *Workspace::tabbox() const +{ + return m_tabbox.get(); +} +#endif + #if KWIN_BUILD_ACTIVITIES Activities *Workspace::activities() const { diff --git a/src/workspace.h b/src/workspace.h index 9ce2d82a08..343a8ce53e 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -45,6 +45,11 @@ class Tree; class Window; } +namespace TabBox +{ +class TabBox; +} + class Window; class Output; class ColorMapper; @@ -445,6 +450,9 @@ public: RuleBook *rulebook() const; ScreenEdges *screenEdges() const; Screens *screens() const; +#if KWIN_BUILD_TABBOX + TabBox::TabBox *tabbox() const; +#endif #if KWIN_BUILD_ACTIVITIES Activities *activities() const; #endif @@ -724,6 +732,9 @@ private: std::unique_ptr m_rulebook; std::unique_ptr m_screenEdges; std::unique_ptr m_screens; +#if KWIN_BUILD_TABBOX + std::unique_ptr m_tabbox; +#endif #if KWIN_BUILD_ACTIVITIES std::unique_ptr m_activities; #endif