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
master
Tiago Corrêa 2020-05-21 09:14:28 +03:00 committed by Vlad Zahorodnii
parent 3e337603e4
commit 232984c123
2 changed files with 26 additions and 0 deletions

View File

@ -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();

View File

@ -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.
*/