src/tabbox: port to standard smart pointers

This commit is contained in:
Xaver Hugl 2023-03-20 14:05:29 +01:00
parent ff5165f9dd
commit 3e94a3945c
11 changed files with 151 additions and 146 deletions

View file

@ -25,50 +25,50 @@ void MockTabBoxHandler::grabbedKeyEvent(QKeyEvent *event) const
{
}
QWeakPointer<TabBox::TabBoxClient> MockTabBoxHandler::activeClient() const
std::weak_ptr<TabBox::TabBoxClient> MockTabBoxHandler::activeClient() const
{
return m_activeClient;
}
void MockTabBoxHandler::setActiveClient(const QWeakPointer<TabBox::TabBoxClient> &client)
void MockTabBoxHandler::setActiveClient(const std::weak_ptr<TabBox::TabBoxClient> &client)
{
m_activeClient = client;
}
QWeakPointer<TabBox::TabBoxClient> MockTabBoxHandler::clientToAddToList(TabBox::TabBoxClient *client, int desktop) const
std::weak_ptr<TabBox::TabBoxClient> MockTabBoxHandler::clientToAddToList(TabBox::TabBoxClient *client, int desktop) const
{
QList<QSharedPointer<TabBox::TabBoxClient>>::const_iterator it = m_windows.constBegin();
QList<std::shared_ptr<TabBox::TabBoxClient>>::const_iterator it = m_windows.constBegin();
for (; it != m_windows.constEnd(); ++it) {
if ((*it).get() == client) {
return QWeakPointer<TabBox::TabBoxClient>(*it);
return std::weak_ptr<TabBox::TabBoxClient>(*it);
}
}
return QWeakPointer<TabBox::TabBoxClient>();
return std::weak_ptr<TabBox::TabBoxClient>();
}
QWeakPointer<TabBox::TabBoxClient> MockTabBoxHandler::nextClientFocusChain(TabBox::TabBoxClient *client) const
std::weak_ptr<TabBox::TabBoxClient> MockTabBoxHandler::nextClientFocusChain(TabBox::TabBoxClient *client) const
{
QList<QSharedPointer<TabBox::TabBoxClient>>::const_iterator it = m_windows.constBegin();
QList<std::shared_ptr<TabBox::TabBoxClient>>::const_iterator it = m_windows.constBegin();
for (; it != m_windows.constEnd(); ++it) {
if ((*it).get() == client) {
++it;
if (it == m_windows.constEnd()) {
return QWeakPointer<TabBox::TabBoxClient>(m_windows.first());
return std::weak_ptr<TabBox::TabBoxClient>(m_windows.first());
} else {
return QWeakPointer<TabBox::TabBoxClient>(*it);
return std::weak_ptr<TabBox::TabBoxClient>(*it);
}
}
}
if (!m_windows.isEmpty()) {
return QWeakPointer<TabBox::TabBoxClient>(m_windows.last());
return std::weak_ptr<TabBox::TabBoxClient>(m_windows.last());
}
return QWeakPointer<TabBox::TabBoxClient>();
return std::weak_ptr<TabBox::TabBoxClient>();
}
QWeakPointer<TabBox::TabBoxClient> MockTabBoxHandler::firstClientFocusChain() const
std::weak_ptr<TabBox::TabBoxClient> MockTabBoxHandler::firstClientFocusChain() const
{
if (m_windows.isEmpty()) {
return QWeakPointer<TabBox::TabBoxClient>();
return std::weak_ptr<TabBox::TabBoxClient>();
}
return m_windows.first();
}
@ -78,7 +78,7 @@ bool MockTabBoxHandler::isInFocusChain(TabBox::TabBoxClient *client) const
if (!client) {
return false;
}
QList<QSharedPointer<TabBox::TabBoxClient>>::const_iterator it = m_windows.constBegin();
QList<std::shared_ptr<TabBox::TabBoxClient>>::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<TabBox::TabBoxClient> MockTabBoxHandler::createMockWindow(const QString &caption)
std::weak_ptr<TabBox::TabBoxClient> MockTabBoxHandler::createMockWindow(const QString &caption)
{
QSharedPointer<TabBox::TabBoxClient> client(new MockTabBoxClient(caption));
std::shared_ptr<TabBox::TabBoxClient> client(new MockTabBoxClient(caption));
m_windows.append(client);
m_activeClient = client;
return QWeakPointer<TabBox::TabBoxClient>(client);
return std::weak_ptr<TabBox::TabBoxClient>(client);
}
void MockTabBoxHandler::closeWindow(TabBox::TabBoxClient *client)
{
QList<QSharedPointer<TabBox::TabBoxClient>>::iterator it = m_windows.begin();
QList<std::shared_ptr<TabBox::TabBoxClient>>::iterator it = m_windows.begin();
for (; it != m_windows.end(); ++it) {
if ((*it).get() == client) {
m_windows.erase(it);

View file

@ -21,20 +21,20 @@ public:
void activateAndClose() override
{
}
QWeakPointer<TabBox::TabBoxClient> activeClient() const override;
void setActiveClient(const QWeakPointer<TabBox::TabBoxClient> &client);
std::weak_ptr<TabBox::TabBoxClient> activeClient() const override;
void setActiveClient(const std::weak_ptr<TabBox::TabBoxClient> &client);
int activeScreen() const override
{
return 0;
}
QWeakPointer<TabBox::TabBoxClient> clientToAddToList(TabBox::TabBoxClient *client, int desktop) const override;
std::weak_ptr<TabBox::TabBoxClient> clientToAddToList(TabBox::TabBoxClient *client, int desktop) const override;
int currentDesktop() const override
{
return 1;
}
QWeakPointer<TabBox::TabBoxClient> desktopClient() const override
std::weak_ptr<TabBox::TabBoxClient> desktopClient() const override
{
return QWeakPointer<TabBox::TabBoxClient>();
return std::weak_ptr<TabBox::TabBoxClient>();
}
QString desktopName(int desktop) const override
{
@ -53,8 +53,8 @@ public:
virtual void hideOutline()
{
}
QWeakPointer<TabBox::TabBoxClient> nextClientFocusChain(TabBox::TabBoxClient *client) const override;
QWeakPointer<TabBox::TabBoxClient> firstClientFocusChain() const override;
std::weak_ptr<TabBox::TabBoxClient> nextClientFocusChain(TabBox::TabBoxClient *client) const override;
std::weak_ptr<TabBox::TabBoxClient> firstClientFocusChain() const override;
bool isInFocusChain(TabBox::TabBoxClient *client) const override;
int nextDesktopFocusChain(int desktop) const override
{
@ -93,12 +93,12 @@ public:
}
// mock methods
QWeakPointer<TabBox::TabBoxClient> createMockWindow(const QString &caption);
std::weak_ptr<TabBox::TabBoxClient> createMockWindow(const QString &caption);
void closeWindow(TabBox::TabBoxClient *client);
private:
QList<QSharedPointer<TabBox::TabBoxClient>> m_windows;
QWeakPointer<TabBox::TabBoxClient> m_activeClient;
QList<std::shared_ptr<TabBox::TabBoxClient>> m_windows;
std::weak_ptr<TabBox::TabBoxClient> m_activeClient;
};
} // namespace KWin
#endif

View file

@ -49,12 +49,12 @@ void TestTabBoxClientModel::testCreateClientListNoActiveClient()
clientModel->createClientList();
QCOMPARE(clientModel->rowCount(), 0);
// create two windows, rowCount() should go to two
QWeakPointer<TabBox::TabBoxClient> client = tabboxhandler.createMockWindow(QString("test"));
std::weak_ptr<TabBox::TabBoxClient> 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<TabBox::TabBoxClient>());
tabboxhandler.setActiveClient(std::weak_ptr<TabBox::TabBoxClient>());
// 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<TabBox::TabBoxClient> client = tabboxhandler.createMockWindow(QString("test"));
std::weak_ptr<TabBox::TabBoxClient> 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<TabBox::TabBoxClient> clientOwner = client.toStrongRef();
std::shared_ptr<TabBox::TabBoxClient> clientOwner = client.lock();
tabboxhandler.closeWindow(clientOwner.get());
clientModel->createClientList();
QCOMPARE(clientModel->rowCount(), 1);

View file

@ -47,7 +47,7 @@ QVariant ClientModel::data(const QModelIndex &index, int role) const
if (clientIndex >= m_clientList.count()) {
return QVariant();
}
QSharedPointer<TabBoxClient> client = m_clientList[clientIndex].toStrongRef();
std::shared_ptr<TabBoxClient> 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<void *>(client.data());
return QVariant::fromValue<void *>(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<TabBoxClient> &clientPointer : std::as_const(m_clientList)) {
QSharedPointer<TabBoxClient> client = clientPointer.toStrongRef();
for (const std::weak_ptr<TabBoxClient> &clientPointer : std::as_const(m_clientList)) {
std::shared_ptr<TabBoxClient> client = clientPointer.lock();
if (!client) {
continue;
}
@ -136,12 +136,15 @@ QHash<int, QByteArray> ClientModel::roleNames() const
};
}
QModelIndex ClientModel::index(QWeakPointer<TabBoxClient> client) const
QModelIndex ClientModel::index(std::weak_ptr<TabBoxClient> 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<TabBoxClient> &start, TabBoxClientList &stickyClients)
const std::shared_ptr<TabBoxClient> &start, TabBoxClientList &stickyClients)
{
auto c = start;
if (!tabBox->isInFocusChain(c.data())) {
QSharedPointer<TabBoxClient> firstClient = tabBox->firstClientFocusChain().toStrongRef();
if (!tabBox->isInFocusChain(c.get())) {
std::shared_ptr<TabBoxClient> firstClient = tabBox->firstClientFocusChain().lock();
if (firstClient) {
c = firstClient;
}
}
auto stop = c;
do {
QSharedPointer<TabBoxClient> add = tabBox->clientToAddToList(c.data(), desktop);
if (!add.isNull()) {
std::shared_ptr<TabBoxClient> 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<TabBoxClient> &start, TabBoxClientList &stickyClients)
const std::shared_ptr<TabBoxClient> &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<TabBoxClient> add = tabBox->clientToAddToList(c.data(), desktop);
if (!add.isNull()) {
if (start == add.data()) {
m_mutableClientList.removeAll(add);
std::shared_ptr<TabBoxClient> 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<TabBoxClient> firstClient = m_mutableClientList.constFirst();
std::shared_ptr<TabBoxClient> 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<TabBoxClient> &c : std::as_const(stickyClients)) {
m_mutableClientList.removeAll(c);
for (const std::weak_ptr<TabBoxClient> &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<TabBoxClient> desktopClient = tabBox->desktopClient();
if (!desktopClient.isNull()) {
std::weak_ptr<TabBoxClient> 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<TabBoxClient> client = m_mutableClientList.at(i).toStrongRef();
std::shared_ptr<TabBoxClient> client = m_mutableClientList.at(i).lock();
if (client) {
client->close();
}

View file

@ -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<TabBoxClient> client) const;
QModelIndex index(std::weak_ptr<TabBoxClient> 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<TabBoxClient> &start,
TabBoxClientList &stickyClients);
void createStackingOrderClientList(int desktop, const QSharedPointer<TabBoxClient> &start,
TabBoxClientList &stickyClients);
void createFocusChainClientList(int desktop, const std::shared_ptr<TabBoxClient> &start,
TabBoxClientList &stickyClients);
void createStackingOrderClientList(int desktop, const std::shared_ptr<TabBoxClient> &start,
TabBoxClientList &stickyClients);
TabBoxClientList m_clientList;
TabBoxClientList m_mutableClientList;

View file

@ -107,23 +107,23 @@ QString TabBoxHandlerImpl::desktopName(int desktop) const
return vd ? vd->name() : QString();
}
QWeakPointer<TabBoxClient> TabBoxHandlerImpl::nextClientFocusChain(TabBoxClient *client) const
std::weak_ptr<TabBoxClient> TabBoxHandlerImpl::nextClientFocusChain(TabBoxClient *client) const
{
if (TabBoxClientImpl *c = static_cast<TabBoxClientImpl *>(client)) {
auto next = Workspace::self()->focusChain()->nextMostRecentlyUsed(c->client());
if (next) {
return qWeakPointerCast<TabBoxClient, TabBoxClientImpl>(next->tabBoxClient());
return std::static_pointer_cast<TabBoxClientImpl>(next->tabBoxClient().lock());
}
}
return QWeakPointer<TabBoxClient>();
return std::weak_ptr<TabBoxClient>();
}
QWeakPointer<TabBoxClient> TabBoxHandlerImpl::firstClientFocusChain() const
std::weak_ptr<TabBoxClient> TabBoxHandlerImpl::firstClientFocusChain() const
{
if (auto c = Workspace::self()->focusChain()->firstMostRecentlyUsed()) {
return qWeakPointerCast<TabBoxClient, TabBoxClientImpl>(c->tabBoxClient());
return std::static_pointer_cast<TabBoxClientImpl>(c->tabBoxClient().lock());
} else {
return QWeakPointer<TabBoxClient>();
return std::weak_ptr<TabBoxClient>();
}
}
@ -145,12 +145,12 @@ int TabBoxHandlerImpl::numberOfDesktops() const
return VirtualDesktopManager::self()->count();
}
QWeakPointer<TabBoxClient> TabBoxHandlerImpl::activeClient() const
std::weak_ptr<TabBoxClient> TabBoxHandlerImpl::activeClient() const
{
if (Workspace::self()->activeWindow()) {
return qWeakPointerCast<TabBoxClient, TabBoxClientImpl>(Workspace::self()->activeWindow()->tabBoxClient());
return std::static_pointer_cast<TabBoxClientImpl>(Workspace::self()->activeWindow()->tabBoxClient().lock());
} else {
return QWeakPointer<TabBoxClient>();
return std::weak_ptr<TabBoxClient>();
}
}
@ -184,36 +184,22 @@ bool TabBoxHandlerImpl::checkActivity(TabBoxClient *client) const
bool TabBoxHandlerImpl::checkApplications(TabBoxClient *client) const
{
auto current = (static_cast<TabBoxClientImpl *>(client))->client();
TabBoxClientImpl *c;
QListIterator<QWeakPointer<TabBoxClient>> i(clientList());
const auto current = (static_cast<TabBoxClientImpl *>(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<TabBoxClient> client = i.next().toStrongRef();
if (!client) {
continue;
}
if ((c = dynamic_cast<TabBoxClientImpl *>(client.data()))) {
if (Window::belongToSameApplication(c->client(), current, Window::SameApplicationCheck::AllowCrossProcesses)) {
return false;
}
for (const auto &weakClient : list) {
const std::shared_ptr<TabBoxClientImpl> client = std::dynamic_pointer_cast<TabBoxClientImpl>(weakClient.lock());
if (client && Window::belongToSameApplication(client->client(), current, Window::SameApplicationCheck::AllowCrossProcesses)) {
return false;
}
}
return true;
case TabBoxConfig::AllWindowsCurrentApplication: {
QSharedPointer<TabBoxClient> pointer = tabBox->activeClient().toStrongRef();
if (!pointer) {
return false;
}
if ((c = dynamic_cast<TabBoxClientImpl *>(pointer.data()))) {
if (Window::belongToSameApplication(c->client(), current, Window::SameApplicationCheck::AllowCrossProcesses)) {
return true;
}
}
return false;
const std::shared_ptr<TabBoxClientImpl> client = std::dynamic_pointer_cast<TabBoxClientImpl>(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<TabBoxClient> TabBoxHandlerImpl::clientToAddToList(TabBoxClient *client, int desktop) const
std::weak_ptr<TabBoxClient> TabBoxHandlerImpl::clientToAddToList(TabBoxClient *client, int desktop) const
{
if (!client) {
return QWeakPointer<TabBoxClient>();
return std::weak_ptr<TabBoxClient>();
}
Window *ret = nullptr;
Window *current = (static_cast<TabBoxClientImpl *>(client))->client();
@ -265,16 +251,22 @@ QWeakPointer<TabBoxClient> TabBoxHandlerImpl::clientToAddToList(TabBoxClient *cl
Window *modal = current->findModal();
if (modal == nullptr || modal == current) {
ret = current;
} else if (!clientList().contains(qWeakPointerCast<TabBoxClient, TabBoxClientImpl>(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<TabBoxClientImpl>(modal->tabBoxClient().lock())](auto &weak) {
return weak.lock() == c;
});
if (contains) {
ret = modal;
} else {
// nothing
}
}
}
if (ret) {
return qWeakPointerCast<TabBoxClient, TabBoxClientImpl>(ret->tabBoxClient());
return std::static_pointer_cast<TabBoxClientImpl>(ret->tabBoxClient().lock());
} else {
return QWeakPointer<TabBoxClient>();
return std::weak_ptr<TabBoxClient>();
}
}
@ -284,7 +276,7 @@ TabBoxClientList TabBoxHandlerImpl::stackingOrder() const
TabBoxClientList ret;
for (Window *window : stacking) {
if (window->isClient()) {
ret.append(qWeakPointerCast<TabBoxClient, TabBoxClientImpl>(window->tabBoxClient()));
ret.append(std::static_pointer_cast<TabBoxClientImpl>(window->tabBoxClient().lock()));
}
}
return ret;
@ -326,15 +318,15 @@ void TabBoxHandlerImpl::shadeClient(TabBoxClient *c, bool b) const
}
}
QWeakPointer<TabBoxClient> TabBoxHandlerImpl::desktopClient() const
std::weak_ptr<TabBoxClient> 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<TabBoxClient, TabBoxClientImpl>(window->tabBoxClient());
return window->tabBoxClient();
}
}
return QWeakPointer<TabBoxClient>();
return std::weak_ptr<TabBoxClient>();
}
void TabBoxHandlerImpl::activateAndClose()
@ -659,12 +651,12 @@ QList<Window *> TabBox::currentClientList()
{
const TabBoxClientList list = m_tabBox->clientList();
QList<Window *> ret;
for (const QWeakPointer<TabBoxClient> &clientPointer : list) {
QSharedPointer<TabBoxClient> client = clientPointer.toStrongRef();
for (const std::weak_ptr<TabBoxClient> &clientPointer : list) {
std::shared_ptr<TabBoxClient> client = clientPointer.lock();
if (!client) {
continue;
}
if (const TabBoxClientImpl *c = static_cast<const TabBoxClientImpl *>(client.data())) {
if (const TabBoxClientImpl *c = static_cast<const TabBoxClientImpl *>(client.get())) {
ret.append(c->client());
}
}
@ -683,7 +675,7 @@ QList<int> TabBox::currentDesktopList()
void TabBox::setCurrentClient(Window *newClient)
{
setCurrentIndex(m_tabBox->index(qWeakPointerCast<TabBoxClient, TabBoxClientImpl>(newClient->tabBoxClient())));
setCurrentIndex(m_tabBox->index(std::static_pointer_cast<TabBoxClientImpl>(newClient->tabBoxClient().lock())));
}
void TabBox::setCurrentDesktop(int newDesktop)

View file

@ -42,13 +42,13 @@ public:
~TabBoxHandlerImpl() override;
int activeScreen() const override;
QWeakPointer<TabBoxClient> activeClient() const override;
std::weak_ptr<TabBoxClient> activeClient() const override;
int currentDesktop() const override;
QString desktopName(TabBoxClient *client) const override;
QString desktopName(int desktop) const override;
bool isKWinCompositing() const override;
QWeakPointer<TabBoxClient> nextClientFocusChain(TabBoxClient *client) const override;
QWeakPointer<TabBoxClient> firstClientFocusChain() const override;
std::weak_ptr<TabBoxClient> nextClientFocusChain(TabBoxClient *client) const override;
std::weak_ptr<TabBoxClient> 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<TabBoxClient> clientToAddToList(KWin::TabBox::TabBoxClient *client, int desktop) const override;
QWeakPointer<TabBoxClient> desktopClient() const override;
std::weak_ptr<TabBoxClient> clientToAddToList(KWin::TabBox::TabBoxClient *client, int desktop) const override;
std::weak_ptr<TabBoxClient> desktopClient() const override;
void activateAndClose() override;
void highlightWindows(TabBoxClient *window = nullptr, QWindow *controller = nullptr) override;
bool noModifierGrab() const override;

View file

@ -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<TabBoxClient> &clientPointer : stackingOrder) {
if (QSharedPointer<TabBoxClient> 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<TabBoxClient> &clientPointer : stackingOrder) {
if (std::shared_ptr<TabBoxClient> 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<TabBoxClient> &clientPointer : stack) {
if (QSharedPointer<TabBoxClient> client = clientPointer.toStrongRef()) {
shadeClient(client.data(), false);
for (const std::weak_ptr<TabBoxClient> &clientPointer : stack) {
if (std::shared_ptr<TabBoxClient> client = clientPointer.lock()) {
shadeClient(client.get(), false);
}
}
}
@ -561,7 +561,7 @@ bool TabBoxHandler::containsPos(const QPoint &pos) const
return false;
}
QModelIndex TabBoxHandler::index(QWeakPointer<KWin::TabBox::TabBoxClient> client) const
QModelIndex TabBoxHandler::index(std::weak_ptr<KWin::TabBox::TabBoxClient> 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<TabBoxClient> client = clientPointer.toStrongRef();
std::shared_ptr<TabBoxClient> 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;
}
}

View file

@ -67,7 +67,7 @@ class ClientModel;
class TabBoxConfig;
class TabBoxClient;
class TabBoxHandlerPrivate;
typedef QList<QWeakPointer<TabBoxClient>> TabBoxClientList;
typedef QList<std::weak_ptr<TabBoxClient>> 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<TabBoxClient> activeClient() const = 0;
virtual std::weak_ptr<TabBoxClient> 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<TabBoxClient> nextClientFocusChain(TabBoxClient *client) const = 0;
virtual std::weak_ptr<TabBoxClient> 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<TabBoxClient> firstClientFocusChain() const = 0;
virtual std::weak_ptr<TabBoxClient> 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<TabBoxClient> clientToAddToList(TabBoxClient *client, int desktop) const = 0;
virtual std::weak_ptr<TabBoxClient> clientToAddToList(TabBoxClient *client, int desktop) const = 0;
/**
* @return The first desktop window in the stacking order.
*/
virtual QWeakPointer<TabBoxClient> desktopClient() const = 0;
virtual std::weak_ptr<TabBoxClient> 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<TabBoxClient> client) const;
QModelIndex index(std::weak_ptr<TabBoxClient> client) const;
/**
* @return Returns the current list of TabBoxClients.
* If TabBoxMode is not TabBoxConfig::ClientTabBox an empty list will

View file

@ -78,7 +78,7 @@ Window::Window()
, m_wmClientLeader(XCB_WINDOW_NONE)
, m_skipCloseAnimation(false)
#if KWIN_BUILD_TABBOX
, m_tabBoxClient(QSharedPointer<TabBox::TabBoxClientImpl>::create(this))
, m_tabBoxClient(std::make_shared<TabBox::TabBoxClientImpl>(this))
#endif
, m_colorScheme(QStringLiteral("kdeglobals"))
, m_moveResizeOutput(workspace()->activeOutput())

View file

@ -821,9 +821,9 @@ public:
int stackingOrder() const;
void setStackingOrder(int order); ///< @internal
QWeakPointer<TabBox::TabBoxClientImpl> tabBoxClient() const
std::weak_ptr<TabBox::TabBoxClientImpl> 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<TabBox::TabBoxClientImpl> m_tabBoxClient;
std::shared_ptr<TabBox::TabBoxClientImpl> m_tabBoxClient;
bool m_firstInTabBox = false;
bool m_skipTaskbar = false;
/**