From 7f1baf66f9c0a6f8034b98dde9bfb8ae8870fea1 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 13 Aug 2021 09:37:20 +0300 Subject: [PATCH] Port some code away from AbstractClient::setDesktop() to AbstractClient::setDesktops() The main motivation behind this change is to reduce the number of usages of int-based virtual desktop apis. int-based desktop ids are highly unreliable. For example, if a new virtual desktop is inserted in the middle or removed in the middle, the desktop ids will change. This makes working with virtual desktops code more challenging due to its behavior. This is not an issue with VirtualDesktop objects. --- src/abstract_client.cpp | 9 +++++---- src/xdgshellclient.cpp | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/abstract_client.cpp b/src/abstract_client.cpp index 6f0ef457b8..21d0a3523d 100644 --- a/src/abstract_client.cpp +++ b/src/abstract_client.cpp @@ -542,10 +542,11 @@ void AbstractClient::setOnAllDesktops(bool b) if ((b && isOnAllDesktops()) || (!b && !isOnAllDesktops())) return; - if (b) - setDesktop(NET::OnAllDesktops); - else - setDesktop(VirtualDesktopManager::self()->current()); + if (b) { + setDesktops({}); + } else { + setDesktops({VirtualDesktopManager::self()->currentDesktop()}); + } } int AbstractClient::desktop() const diff --git a/src/xdgshellclient.cpp b/src/xdgshellclient.cpp index f49879377b..0fa13380e2 100644 --- a/src/xdgshellclient.cpp +++ b/src/xdgshellclient.cpp @@ -358,7 +358,7 @@ XdgToplevelClient::XdgToplevelClient(XdgToplevelInterface *shellSurface) { setupWindowManagementIntegration(); setupPlasmaShellIntegration(); - setDesktop(VirtualDesktopManager::self()->current()); + setDesktops({VirtualDesktopManager::self()->currentDesktop()}); #if KWIN_BUILD_ACTIVITIES if (auto a = Activities::self()) { setOnActivities({a->current()}); @@ -1739,7 +1739,7 @@ XdgPopupClient::XdgPopupClient(XdgPopupInterface *shellSurface) : XdgSurfaceClient(shellSurface->xdgSurface()) , m_shellSurface(shellSurface) { - setDesktop(VirtualDesktopManager::self()->current()); + setDesktops({VirtualDesktopManager::self()->currentDesktop()}); #if KWIN_BUILD_ACTIVITIES if (auto a = Activities::self()) { setOnActivities({a->current()});