From 232984c1233a6866428ae961f4c8934d60a64be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Corr=C3=AAa?= Date: Thu, 21 May 2020 09:14:28 +0300 Subject: [PATCH] scripting: Provide methods to create and remove virtual desktops Summary: There are methods to create and remove virtual desktops via dbus, but I think it would be convenient to provide these methods for KWin scripts as well. Reviewers: #kwin, zzag Reviewed By: #kwin, zzag Subscribers: zzag, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D29786 --- scripting/workspace_wrapper.cpp | 15 +++++++++++++++ scripting/workspace_wrapper.h | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/scripting/workspace_wrapper.cpp b/scripting/workspace_wrapper.cpp index d9ac497377..6530986d40 100644 --- a/scripting/workspace_wrapper.cpp +++ b/scripting/workspace_wrapper.cpp @@ -272,6 +272,21 @@ QString WorkspaceWrapper::desktopName(int desktop) const return VirtualDesktopManager::self()->name(desktop); } +void WorkspaceWrapper::createDesktop(int position, const QString &name) const +{ + VirtualDesktopManager::self()->createVirtualDesktop(position, name); +} + +void WorkspaceWrapper::removeDesktop(int position) const +{ + VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForX11Id(position + 1); + if (!vd) { + return; + } + + VirtualDesktopManager::self()->removeVirtualDesktop(vd->id()); +} + QString WorkspaceWrapper::supportInformation() const { return Workspace::self()->supportInformation(); diff --git a/scripting/workspace_wrapper.h b/scripting/workspace_wrapper.h index 33262c2625..d0fb00108e 100644 --- a/scripting/workspace_wrapper.h +++ b/scripting/workspace_wrapper.h @@ -255,6 +255,17 @@ void setter( rettype val ); * Returns the name for the given @p desktop. */ Q_SCRIPTABLE QString desktopName(int desktop) const; + /** + * Create a new virtual desktop at the requested position. + * @param position The position of the desktop. It should be in range [0, count]. + * @param name The name for the new desktop, if empty the default name will be used. + */ + Q_SCRIPTABLE void createDesktop(int position, const QString &name) const; + /** + * Remove the virtual desktop at the requested position + * @param position The position of the desktop to be removed. It should be in range [0, count - 1]. + */ + Q_SCRIPTABLE void removeDesktop(int position) const; /** * Provides support information about the currently running KWin instance. */