diff --git a/autotests/tabbox/mock_tabboxhandler.cpp b/autotests/tabbox/mock_tabboxhandler.cpp index df88f74229..1cc82f0646 100644 --- a/autotests/tabbox/mock_tabboxhandler.cpp +++ b/autotests/tabbox/mock_tabboxhandler.cpp @@ -25,50 +25,50 @@ void MockTabBoxHandler::grabbedKeyEvent(QKeyEvent *event) const { } -QWeakPointer MockTabBoxHandler::activeClient() const +std::weak_ptr MockTabBoxHandler::activeClient() const { return m_activeClient; } -void MockTabBoxHandler::setActiveClient(const QWeakPointer &client) +void MockTabBoxHandler::setActiveClient(const std::weak_ptr &client) { m_activeClient = client; } -QWeakPointer MockTabBoxHandler::clientToAddToList(TabBox::TabBoxClient *client, int desktop) const +std::weak_ptr MockTabBoxHandler::clientToAddToList(TabBox::TabBoxClient *client, int desktop) const { - QList>::const_iterator it = m_windows.constBegin(); + QList>::const_iterator it = m_windows.constBegin(); for (; it != m_windows.constEnd(); ++it) { if ((*it).get() == client) { - return QWeakPointer(*it); + return std::weak_ptr(*it); } } - return QWeakPointer(); + return std::weak_ptr(); } -QWeakPointer MockTabBoxHandler::nextClientFocusChain(TabBox::TabBoxClient *client) const +std::weak_ptr MockTabBoxHandler::nextClientFocusChain(TabBox::TabBoxClient *client) const { - QList>::const_iterator it = m_windows.constBegin(); + QList>::const_iterator it = m_windows.constBegin(); for (; it != m_windows.constEnd(); ++it) { if ((*it).get() == client) { ++it; if (it == m_windows.constEnd()) { - return QWeakPointer(m_windows.first()); + return std::weak_ptr(m_windows.first()); } else { - return QWeakPointer(*it); + return std::weak_ptr(*it); } } } if (!m_windows.isEmpty()) { - return QWeakPointer(m_windows.last()); + return std::weak_ptr(m_windows.last()); } - return QWeakPointer(); + return std::weak_ptr(); } -QWeakPointer MockTabBoxHandler::firstClientFocusChain() const +std::weak_ptr MockTabBoxHandler::firstClientFocusChain() const { if (m_windows.isEmpty()) { - return QWeakPointer(); + return std::weak_ptr(); } return m_windows.first(); } @@ -78,7 +78,7 @@ bool MockTabBoxHandler::isInFocusChain(TabBox::TabBoxClient *client) const if (!client) { return false; } - QList>::const_iterator it = m_windows.constBegin(); + QList>::const_iterator it = m_windows.constBegin(); for (; it != m_windows.constEnd(); ++it) { if ((*it).get() == client) { return true; @@ -87,17 +87,17 @@ bool MockTabBoxHandler::isInFocusChain(TabBox::TabBoxClient *client) const return false; } -QWeakPointer MockTabBoxHandler::createMockWindow(const QString &caption) +std::weak_ptr MockTabBoxHandler::createMockWindow(const QString &caption) { - QSharedPointer client(new MockTabBoxClient(caption)); + std::shared_ptr client(new MockTabBoxClient(caption)); m_windows.append(client); m_activeClient = client; - return QWeakPointer(client); + return std::weak_ptr(client); } void MockTabBoxHandler::closeWindow(TabBox::TabBoxClient *client) { - QList>::iterator it = m_windows.begin(); + QList>::iterator it = m_windows.begin(); for (; it != m_windows.end(); ++it) { if ((*it).get() == client) { m_windows.erase(it); diff --git a/autotests/tabbox/mock_tabboxhandler.h b/autotests/tabbox/mock_tabboxhandler.h index f009c9e4d0..7f2be0f6a2 100644 --- a/autotests/tabbox/mock_tabboxhandler.h +++ b/autotests/tabbox/mock_tabboxhandler.h @@ -21,20 +21,20 @@ public: void activateAndClose() override { } - QWeakPointer activeClient() const override; - void setActiveClient(const QWeakPointer &client); + std::weak_ptr activeClient() const override; + void setActiveClient(const std::weak_ptr &client); int activeScreen() const override { return 0; } - QWeakPointer clientToAddToList(TabBox::TabBoxClient *client, int desktop) const override; + std::weak_ptr clientToAddToList(TabBox::TabBoxClient *client, int desktop) const override; int currentDesktop() const override { return 1; } - QWeakPointer desktopClient() const override + std::weak_ptr desktopClient() const override { - return QWeakPointer(); + return std::weak_ptr(); } QString desktopName(int desktop) const override { @@ -53,8 +53,8 @@ public: virtual void hideOutline() { } - QWeakPointer nextClientFocusChain(TabBox::TabBoxClient *client) const override; - QWeakPointer firstClientFocusChain() const override; + std::weak_ptr nextClientFocusChain(TabBox::TabBoxClient *client) const override; + std::weak_ptr firstClientFocusChain() const override; bool isInFocusChain(TabBox::TabBoxClient *client) const override; int nextDesktopFocusChain(int desktop) const override { @@ -93,12 +93,12 @@ public: } // mock methods - QWeakPointer createMockWindow(const QString &caption); + std::weak_ptr createMockWindow(const QString &caption); void closeWindow(TabBox::TabBoxClient *client); private: - QList> m_windows; - QWeakPointer m_activeClient; + QList> m_windows; + std::weak_ptr m_activeClient; }; } // namespace KWin #endif diff --git a/autotests/tabbox/test_tabbox_clientmodel.cpp b/autotests/tabbox/test_tabbox_clientmodel.cpp index 00669279ba..73361b3697 100644 --- a/autotests/tabbox/test_tabbox_clientmodel.cpp +++ b/autotests/tabbox/test_tabbox_clientmodel.cpp @@ -49,12 +49,12 @@ void TestTabBoxClientModel::testCreateClientListNoActiveClient() clientModel->createClientList(); QCOMPARE(clientModel->rowCount(), 0); // create two windows, rowCount() should go to two - QWeakPointer client = tabboxhandler.createMockWindow(QString("test")); + std::weak_ptr client = tabboxhandler.createMockWindow(QString("test")); tabboxhandler.createMockWindow(QString("test2")); clientModel->createClientList(); QCOMPARE(clientModel->rowCount(), 2); // let's ensure there is no active client - tabboxhandler.setActiveClient(QWeakPointer()); + tabboxhandler.setActiveClient(std::weak_ptr()); // now it should still have two members in the list clientModel->createClientList(); QCOMPARE(clientModel->rowCount(), 2); @@ -66,7 +66,7 @@ void TestTabBoxClientModel::testCreateClientListActiveClientNotInFocusChain() tabboxhandler.setConfig(TabBox::TabBoxConfig()); TabBox::ClientModel *clientModel = new TabBox::ClientModel(&tabboxhandler); // create two windows, rowCount() should go to two - QWeakPointer client = tabboxhandler.createMockWindow(QString("test")); + std::weak_ptr client = tabboxhandler.createMockWindow(QString("test")); client = tabboxhandler.createMockWindow(QString("test2")); clientModel->createClientList(); QCOMPARE(clientModel->rowCount(), 2); @@ -74,7 +74,7 @@ void TestTabBoxClientModel::testCreateClientListActiveClientNotInFocusChain() // simulate that the active client is not in the focus chain // for that we use the closeWindow of the MockTabBoxHandler which // removes the Client from the Focus Chain but leaves the active window as it is - QSharedPointer clientOwner = client.toStrongRef(); + std::shared_ptr clientOwner = client.lock(); tabboxhandler.closeWindow(clientOwner.get()); clientModel->createClientList(); QCOMPARE(clientModel->rowCount(), 1); diff --git a/src/tabbox/clientmodel.cpp b/src/tabbox/clientmodel.cpp index da2c44502b..79241d9302 100644 --- a/src/tabbox/clientmodel.cpp +++ b/src/tabbox/clientmodel.cpp @@ -47,7 +47,7 @@ QVariant ClientModel::data(const QModelIndex &index, int role) const if (clientIndex >= m_clientList.count()) { return QVariant(); } - QSharedPointer client = m_clientList[clientIndex].toStrongRef(); + std::shared_ptr client = m_clientList[clientIndex].lock(); if (!client) { return QVariant(); } @@ -61,9 +61,9 @@ QVariant ClientModel::data(const QModelIndex &index, int role) const return caption; } case ClientRole: - return QVariant::fromValue(client.data()); + return QVariant::fromValue(client.get()); case DesktopNameRole: { - return tabBox->desktopName(client.data()); + return tabBox->desktopName(client.get()); } case WIdRole: return client->internalId(); @@ -82,8 +82,8 @@ QVariant ClientModel::data(const QModelIndex &index, int role) const QString ClientModel::longestCaption() const { QString caption; - for (const QWeakPointer &clientPointer : std::as_const(m_clientList)) { - QSharedPointer client = clientPointer.toStrongRef(); + for (const std::weak_ptr &clientPointer : std::as_const(m_clientList)) { + std::shared_ptr client = clientPointer.lock(); if (!client) { continue; } @@ -136,12 +136,15 @@ QHash ClientModel::roleNames() const }; } -QModelIndex ClientModel::index(QWeakPointer client) const +QModelIndex ClientModel::index(std::weak_ptr client) const { - if (!m_clientList.contains(client)) { + const auto it = std::find_if(m_clientList.cbegin(), m_clientList.cend(), [c = client.lock()](auto &client) { + return client.lock() == c; + }); + if (it == m_clientList.cend()) { return QModelIndex(); } - int index = m_clientList.indexOf(client); + int index = std::distance(m_clientList.cbegin(), it); int row = index / columnCount(); int column = index % columnCount(); return createIndex(row, column); @@ -153,53 +156,56 @@ void ClientModel::createClientList(bool partialReset) } void ClientModel::createFocusChainClientList(int desktop, - const QSharedPointer &start, TabBoxClientList &stickyClients) + const std::shared_ptr &start, TabBoxClientList &stickyClients) { auto c = start; - if (!tabBox->isInFocusChain(c.data())) { - QSharedPointer firstClient = tabBox->firstClientFocusChain().toStrongRef(); + if (!tabBox->isInFocusChain(c.get())) { + std::shared_ptr firstClient = tabBox->firstClientFocusChain().lock(); if (firstClient) { c = firstClient; } } auto stop = c; do { - QSharedPointer add = tabBox->clientToAddToList(c.data(), desktop); - if (!add.isNull()) { + std::shared_ptr add = tabBox->clientToAddToList(c.get(), desktop).lock(); + if (add) { m_mutableClientList += add; - if (add.data()->isFirstInTabBox()) { + if (add->isFirstInTabBox()) { stickyClients << add; } } - c = tabBox->nextClientFocusChain(c.data()); + c = tabBox->nextClientFocusChain(c.get()).lock(); } while (c && c != stop); } void ClientModel::createStackingOrderClientList(int desktop, - const QSharedPointer &start, TabBoxClientList &stickyClients) + const std::shared_ptr &start, TabBoxClientList &stickyClients) { // TODO: needs improvement const TabBoxClientList stacking = tabBox->stackingOrder(); - auto c = stacking.first().toStrongRef(); + auto c = stacking.first().lock(); auto stop = c; int index = 0; while (c) { - QSharedPointer add = tabBox->clientToAddToList(c.data(), desktop); - if (!add.isNull()) { - if (start == add.data()) { - m_mutableClientList.removeAll(add); + std::shared_ptr add = tabBox->clientToAddToList(c.get(), desktop).lock(); + if (add) { + if (start == add) { + m_mutableClientList.erase(std::remove_if(m_mutableClientList.begin(), m_mutableClientList.end(), [&add](auto &client) { + return client.lock() == add; + }), + m_mutableClientList.end()); m_mutableClientList.prepend(add); } else { m_mutableClientList += add; } - if (add.data()->isFirstInTabBox()) { + if (add->isFirstInTabBox()) { stickyClients << add; } } if (index >= stacking.size() - 1) { c = nullptr; } else { - c = stacking[++index]; + c = stacking[++index].lock(); } if (c == stop) { @@ -210,10 +216,10 @@ void ClientModel::createStackingOrderClientList(int desktop, void ClientModel::createClientList(int desktop, bool partialReset) { - auto start = tabBox->activeClient().toStrongRef(); + auto start = tabBox->activeClient().lock(); // TODO: new clients are not added at correct position if (partialReset && !m_mutableClientList.isEmpty()) { - QSharedPointer firstClient = m_mutableClientList.constFirst(); + std::shared_ptr firstClient = m_mutableClientList.constFirst().lock(); if (firstClient) { start = firstClient; } @@ -236,23 +242,30 @@ void ClientModel::createClientList(int desktop, bool partialReset) if (tabBox->config().orderMinimizedMode() == TabBoxConfig::GroupByMinimized) { // Put all non-minimized included clients first. std::stable_partition(m_mutableClientList.begin(), m_mutableClientList.end(), [](const auto &client) { - return !client.toStrongRef()->isMinimized(); + return !client.lock()->isMinimized(); }); } - for (const QWeakPointer &c : std::as_const(stickyClients)) { - m_mutableClientList.removeAll(c); + for (const std::weak_ptr &c : std::as_const(stickyClients)) { + m_mutableClientList.erase(std::remove_if(m_mutableClientList.begin(), m_mutableClientList.end(), [c = c.lock()](auto &client) { + return client.lock() == c; + }), + m_mutableClientList.end()); m_mutableClientList.prepend(c); } if (tabBox->config().clientApplicationsMode() != TabBoxConfig::AllWindowsCurrentApplication && (tabBox->config().showDesktopMode() == TabBoxConfig::ShowDesktopClient || m_mutableClientList.isEmpty())) { - QWeakPointer desktopClient = tabBox->desktopClient(); - if (!desktopClient.isNull()) { + std::weak_ptr desktopClient = tabBox->desktopClient(); + if (!desktopClient.expired()) { m_mutableClientList.append(desktopClient); } } - if (m_clientList == m_mutableClientList) { + bool equal = m_clientList.size() == m_mutableClientList.size(); + for (int i = 0; i < m_clientList.size() && equal; i++) { + equal &= m_clientList[i].lock() == m_mutableClientList[i].lock(); + } + if (equal) { return; } @@ -267,7 +280,7 @@ void ClientModel::close(int i) if (!ind.isValid()) { return; } - QSharedPointer client = m_mutableClientList.at(i).toStrongRef(); + std::shared_ptr client = m_mutableClientList.at(i).lock(); if (client) { client->close(); } diff --git a/src/tabbox/clientmodel.h b/src/tabbox/clientmodel.h index 4a987f296e..5f56f8b330 100644 --- a/src/tabbox/clientmodel.h +++ b/src/tabbox/clientmodel.h @@ -59,7 +59,7 @@ public: * @return Returns the ModelIndex of given TabBoxClient or an invalid ModelIndex * if the model does not contain the given TabBoxClient. */ - QModelIndex index(QWeakPointer client) const; + QModelIndex index(std::weak_ptr client) const; /** * Generates a new list of TabBoxClients based on the current config. @@ -93,10 +93,10 @@ public Q_SLOTS: void activate(int index); private: - void createFocusChainClientList(int desktop, const QSharedPointer &start, - TabBoxClientList &stickyClients); - void createStackingOrderClientList(int desktop, const QSharedPointer &start, - TabBoxClientList &stickyClients); + void createFocusChainClientList(int desktop, const std::shared_ptr &start, + TabBoxClientList &stickyClients); + void createStackingOrderClientList(int desktop, const std::shared_ptr &start, + TabBoxClientList &stickyClients); TabBoxClientList m_clientList; TabBoxClientList m_mutableClientList; diff --git a/src/tabbox/tabbox.cpp b/src/tabbox/tabbox.cpp index 37881be11a..c32d402cff 100644 --- a/src/tabbox/tabbox.cpp +++ b/src/tabbox/tabbox.cpp @@ -107,23 +107,23 @@ QString TabBoxHandlerImpl::desktopName(int desktop) const return vd ? vd->name() : QString(); } -QWeakPointer TabBoxHandlerImpl::nextClientFocusChain(TabBoxClient *client) const +std::weak_ptr TabBoxHandlerImpl::nextClientFocusChain(TabBoxClient *client) const { if (TabBoxClientImpl *c = static_cast(client)) { auto next = Workspace::self()->focusChain()->nextMostRecentlyUsed(c->client()); if (next) { - return qWeakPointerCast(next->tabBoxClient()); + return std::static_pointer_cast(next->tabBoxClient().lock()); } } - return QWeakPointer(); + return std::weak_ptr(); } -QWeakPointer TabBoxHandlerImpl::firstClientFocusChain() const +std::weak_ptr TabBoxHandlerImpl::firstClientFocusChain() const { if (auto c = Workspace::self()->focusChain()->firstMostRecentlyUsed()) { - return qWeakPointerCast(c->tabBoxClient()); + return std::static_pointer_cast(c->tabBoxClient().lock()); } else { - return QWeakPointer(); + return std::weak_ptr(); } } @@ -145,12 +145,12 @@ int TabBoxHandlerImpl::numberOfDesktops() const return VirtualDesktopManager::self()->count(); } -QWeakPointer TabBoxHandlerImpl::activeClient() const +std::weak_ptr TabBoxHandlerImpl::activeClient() const { if (Workspace::self()->activeWindow()) { - return qWeakPointerCast(Workspace::self()->activeWindow()->tabBoxClient()); + return std::static_pointer_cast(Workspace::self()->activeWindow()->tabBoxClient().lock()); } else { - return QWeakPointer(); + return std::weak_ptr(); } } @@ -184,36 +184,22 @@ bool TabBoxHandlerImpl::checkActivity(TabBoxClient *client) const bool TabBoxHandlerImpl::checkApplications(TabBoxClient *client) const { - auto current = (static_cast(client))->client(); - TabBoxClientImpl *c; - QListIterator> i(clientList()); + const auto current = (static_cast(client))->client(); + const auto list = clientList(); switch (config().clientApplicationsMode()) { case TabBoxConfig::OneWindowPerApplication: // check if the list already contains an entry of this application - while (i.hasNext()) { - QSharedPointer client = i.next().toStrongRef(); - if (!client) { - continue; - } - if ((c = dynamic_cast(client.data()))) { - if (Window::belongToSameApplication(c->client(), current, Window::SameApplicationCheck::AllowCrossProcesses)) { - return false; - } + for (const auto &weakClient : list) { + const std::shared_ptr client = std::dynamic_pointer_cast(weakClient.lock()); + if (client && Window::belongToSameApplication(client->client(), current, Window::SameApplicationCheck::AllowCrossProcesses)) { + return false; } } return true; case TabBoxConfig::AllWindowsCurrentApplication: { - QSharedPointer pointer = tabBox->activeClient().toStrongRef(); - if (!pointer) { - return false; - } - if ((c = dynamic_cast(pointer.data()))) { - if (Window::belongToSameApplication(c->client(), current, Window::SameApplicationCheck::AllowCrossProcesses)) { - return true; - } - } - return false; + const std::shared_ptr client = std::dynamic_pointer_cast(tabBox->activeClient().lock()); + return client && Window::belongToSameApplication(client->client(), current, Window::SameApplicationCheck::AllowCrossProcesses); } default: // TabBoxConfig::AllWindowsAllApplications return true; @@ -246,10 +232,10 @@ bool TabBoxHandlerImpl::checkMultiScreen(TabBoxClient *client) const } } -QWeakPointer TabBoxHandlerImpl::clientToAddToList(TabBoxClient *client, int desktop) const +std::weak_ptr TabBoxHandlerImpl::clientToAddToList(TabBoxClient *client, int desktop) const { if (!client) { - return QWeakPointer(); + return std::weak_ptr(); } Window *ret = nullptr; Window *current = (static_cast(client))->client(); @@ -265,16 +251,22 @@ QWeakPointer TabBoxHandlerImpl::clientToAddToList(TabBoxClient *cl Window *modal = current->findModal(); if (modal == nullptr || modal == current) { ret = current; - } else if (!clientList().contains(qWeakPointerCast(modal->tabBoxClient()))) { - ret = modal; } else { - // nothing + const auto list = clientList(); + const bool contains = std::any_of(list.cbegin(), list.cend(), [c = std::static_pointer_cast(modal->tabBoxClient().lock())](auto &weak) { + return weak.lock() == c; + }); + if (contains) { + ret = modal; + } else { + // nothing + } } } if (ret) { - return qWeakPointerCast(ret->tabBoxClient()); + return std::static_pointer_cast(ret->tabBoxClient().lock()); } else { - return QWeakPointer(); + return std::weak_ptr(); } } @@ -284,7 +276,7 @@ TabBoxClientList TabBoxHandlerImpl::stackingOrder() const TabBoxClientList ret; for (Window *window : stacking) { if (window->isClient()) { - ret.append(qWeakPointerCast(window->tabBoxClient())); + ret.append(std::static_pointer_cast(window->tabBoxClient().lock())); } } return ret; @@ -326,15 +318,15 @@ void TabBoxHandlerImpl::shadeClient(TabBoxClient *c, bool b) const } } -QWeakPointer TabBoxHandlerImpl::desktopClient() const +std::weak_ptr TabBoxHandlerImpl::desktopClient() const { const auto stackingOrder = Workspace::self()->stackingOrder(); for (Window *window : stackingOrder) { if (window->isClient() && window->isDesktop() && window->isOnCurrentDesktop() && window->output() == workspace()->activeOutput()) { - return qWeakPointerCast(window->tabBoxClient()); + return window->tabBoxClient(); } } - return QWeakPointer(); + return std::weak_ptr(); } void TabBoxHandlerImpl::activateAndClose() @@ -659,12 +651,12 @@ QList TabBox::currentClientList() { const TabBoxClientList list = m_tabBox->clientList(); QList ret; - for (const QWeakPointer &clientPointer : list) { - QSharedPointer client = clientPointer.toStrongRef(); + for (const std::weak_ptr &clientPointer : list) { + std::shared_ptr client = clientPointer.lock(); if (!client) { continue; } - if (const TabBoxClientImpl *c = static_cast(client.data())) { + if (const TabBoxClientImpl *c = static_cast(client.get())) { ret.append(c->client()); } } @@ -683,7 +675,7 @@ QList TabBox::currentDesktopList() void TabBox::setCurrentClient(Window *newClient) { - setCurrentIndex(m_tabBox->index(qWeakPointerCast(newClient->tabBoxClient()))); + setCurrentIndex(m_tabBox->index(std::static_pointer_cast(newClient->tabBoxClient().lock()))); } void TabBox::setCurrentDesktop(int newDesktop) diff --git a/src/tabbox/tabbox.h b/src/tabbox/tabbox.h index 29adfe815a..b68166fc2e 100644 --- a/src/tabbox/tabbox.h +++ b/src/tabbox/tabbox.h @@ -42,13 +42,13 @@ public: ~TabBoxHandlerImpl() override; int activeScreen() const override; - QWeakPointer activeClient() const override; + std::weak_ptr activeClient() const override; int currentDesktop() const override; QString desktopName(TabBoxClient *client) const override; QString desktopName(int desktop) const override; bool isKWinCompositing() const override; - QWeakPointer nextClientFocusChain(TabBoxClient *client) const override; - QWeakPointer firstClientFocusChain() const override; + std::weak_ptr nextClientFocusChain(TabBoxClient *client) const override; + std::weak_ptr firstClientFocusChain() const override; bool isInFocusChain(TabBoxClient *client) const override; int nextDesktopFocusChain(int desktop) const override; int numberOfDesktops() const override; @@ -57,8 +57,8 @@ public: void raiseClient(TabBoxClient *client) const override; void restack(TabBoxClient *c, TabBoxClient *under) override; void shadeClient(TabBoxClient *c, bool b) const override; - QWeakPointer clientToAddToList(KWin::TabBox::TabBoxClient *client, int desktop) const override; - QWeakPointer desktopClient() const override; + std::weak_ptr clientToAddToList(KWin::TabBox::TabBoxClient *client, int desktop) const override; + std::weak_ptr desktopClient() const override; void activateAndClose() override; void highlightWindows(TabBoxClient *window = nullptr, QWindow *controller = nullptr) override; bool noModifierGrab() const override; diff --git a/src/tabbox/tabboxhandler.cpp b/src/tabbox/tabboxhandler.cpp index ff34e60b9b..d886160526 100644 --- a/src/tabbox/tabboxhandler.cpp +++ b/src/tabbox/tabboxhandler.cpp @@ -170,7 +170,7 @@ void TabBoxHandlerPrivate::updateHighlightWindows() } lastRaisedClient = currentClient; // don't elevate desktop - const auto desktop = q->desktopClient().toStrongRef(); + const auto desktop = q->desktopClient().lock(); if (currentClient && (!desktop || currentClient->internalId() != desktop->internalId())) { q->elevateClient(currentClient, w, true); } @@ -191,12 +191,12 @@ void TabBoxHandlerPrivate::updateHighlightWindows() TabBoxClientList order = q->stackingOrder(); int succIdx = order.count() + 1; for (int i = 0; i < order.count(); ++i) { - if (order.at(i).toStrongRef() == lastRaisedClient) { + if (order.at(i).lock().get() == lastRaisedClient) { succIdx = i + 1; break; } } - lastRaisedClientSucc = (succIdx < order.count()) ? order.at(succIdx).toStrongRef().data() : nullptr; + lastRaisedClientSucc = (succIdx < order.count()) ? order.at(succIdx).lock().get() : nullptr; q->raiseClient(lastRaisedClient); } } @@ -213,10 +213,10 @@ void TabBoxHandlerPrivate::endHighlightWindows(bool abort) TabBoxClient *currentClient = q->client(index); if (isHighlightWindows() && q->isKWinCompositing()) { const auto stackingOrder = q->stackingOrder(); - for (const QWeakPointer &clientPointer : stackingOrder) { - if (QSharedPointer client = clientPointer.toStrongRef()) { - if (client != currentClient) { // to not mess up with wanted ShadeActive/ShadeHover state - q->shadeClient(client.data(), true); + for (const std::weak_ptr &clientPointer : stackingOrder) { + if (std::shared_ptr client = clientPointer.lock()) { + if (client.get() != currentClient) { // to not mess up with wanted ShadeActive/ShadeHover state + q->shadeClient(client.get(), true); } } } @@ -407,9 +407,9 @@ void TabBoxHandler::initHighlightWindows() { if (isKWinCompositing()) { const auto stack = stackingOrder(); - for (const QWeakPointer &clientPointer : stack) { - if (QSharedPointer client = clientPointer.toStrongRef()) { - shadeClient(client.data(), false); + for (const std::weak_ptr &clientPointer : stack) { + if (std::shared_ptr client = clientPointer.lock()) { + shadeClient(client.get(), false); } } } @@ -561,7 +561,7 @@ bool TabBoxHandler::containsPos(const QPoint &pos) const return false; } -QModelIndex TabBoxHandler::index(QWeakPointer client) const +QModelIndex TabBoxHandler::index(std::weak_ptr client) const { return d->clientModel()->index(client); } @@ -594,14 +594,14 @@ void TabBoxHandler::createModel(bool partialReset) bool lastRaisedSucc = false; const auto clients = stackingOrder(); for (const auto &clientPointer : clients) { - QSharedPointer client = clientPointer.toStrongRef(); + std::shared_ptr client = clientPointer.lock(); if (!client) { continue; } - if (client.data() == d->lastRaisedClient) { + if (client.get() == d->lastRaisedClient) { lastRaised = true; } - if (client.data() == d->lastRaisedClientSucc) { + if (client.get() == d->lastRaisedClientSucc) { lastRaisedSucc = true; } } diff --git a/src/tabbox/tabboxhandler.h b/src/tabbox/tabboxhandler.h index 8ecb23d3f3..3e965764db 100644 --- a/src/tabbox/tabboxhandler.h +++ b/src/tabbox/tabboxhandler.h @@ -67,7 +67,7 @@ class ClientModel; class TabBoxConfig; class TabBoxClient; class TabBoxHandlerPrivate; -typedef QList> TabBoxClientList; +typedef QList> TabBoxClientList; /** * This class is a wrapper around KWin Workspace. It is used for accessing the @@ -91,12 +91,12 @@ public: * @return The current active TabBoxClient or NULL * if there is no active client. */ - virtual QWeakPointer activeClient() const = 0; + virtual std::weak_ptr activeClient() const = 0; /** * @param client The client which is starting point to find the next client * @return The next TabBoxClient in focus chain */ - virtual QWeakPointer nextClientFocusChain(TabBoxClient *client) const = 0; + virtual std::weak_ptr nextClientFocusChain(TabBoxClient *client) const = 0; /** * This method is used by the ClientModel to find an entrance into the focus chain in case * there is no active Client. @@ -104,7 +104,7 @@ public: * @return The first Client of the focus chain * @since 4.9.1 */ - virtual QWeakPointer firstClientFocusChain() const = 0; + virtual std::weak_ptr firstClientFocusChain() const = 0; /** * Checks whether the given @p client is part of the focus chain at all. * This is useful to figure out whether the currently active Client can be used @@ -194,11 +194,11 @@ public: * @param allDesktops Add clients from all desktops or only from current * @return The client to be included in the list or NULL if it isn't to be included */ - virtual QWeakPointer clientToAddToList(TabBoxClient *client, int desktop) const = 0; + virtual std::weak_ptr clientToAddToList(TabBoxClient *client, int desktop) const = 0; /** * @return The first desktop window in the stacking order. */ - virtual QWeakPointer desktopClient() const = 0; + virtual std::weak_ptr desktopClient() const = 0; /** * Activates the currently selected client and closes the TabBox. */ @@ -297,7 +297,7 @@ public: * if the model does not contain the given TabBoxClient. * @see ClientModel::index */ - QModelIndex index(QWeakPointer client) const; + QModelIndex index(std::weak_ptr client) const; /** * @return Returns the current list of TabBoxClients. * If TabBoxMode is not TabBoxConfig::ClientTabBox an empty list will diff --git a/src/window.cpp b/src/window.cpp index 3edafdd94e..ee8bfe11d7 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -78,7 +78,7 @@ Window::Window() , m_wmClientLeader(XCB_WINDOW_NONE) , m_skipCloseAnimation(false) #if KWIN_BUILD_TABBOX - , m_tabBoxClient(QSharedPointer::create(this)) + , m_tabBoxClient(std::make_shared(this)) #endif , m_colorScheme(QStringLiteral("kdeglobals")) , m_moveResizeOutput(workspace()->activeOutput()) diff --git a/src/window.h b/src/window.h index 7c21812341..ee0b188f29 100644 --- a/src/window.h +++ b/src/window.h @@ -821,9 +821,9 @@ public: int stackingOrder() const; void setStackingOrder(int order); ///< @internal - QWeakPointer tabBoxClient() const + std::weak_ptr tabBoxClient() const { - return m_tabBoxClient.toWeakRef(); + return m_tabBoxClient; } bool isFirstInTabBox() const { @@ -1894,7 +1894,7 @@ private: QRectF moveToArea(const QRectF &geometry, const QRectF &oldArea, const QRectF &newArea); QRectF ensureSpecialStateGeometry(const QRectF &geometry); - QSharedPointer m_tabBoxClient; + std::shared_ptr m_tabBoxClient; bool m_firstInTabBox = false; bool m_skipTaskbar = false; /**