scripting: Prefer VirtualDesktop objects
This commit is contained in:
parent
0218a8f3ba
commit
9371fc8ae9
10 changed files with 45 additions and 57 deletions
|
@ -38,8 +38,8 @@ Rectangle {
|
|||
organized = false;
|
||||
}
|
||||
|
||||
function switchTo(desktopId) {
|
||||
KWinComponents.Workspace.currentDesktop = desktopId;
|
||||
function switchTo(desktop) {
|
||||
KWinComponents.Workspace.currentDesktop = desktop;
|
||||
effect.deactivate(effect.animationDuration);
|
||||
}
|
||||
|
||||
|
@ -98,11 +98,15 @@ Rectangle {
|
|||
} else if (event.key === Qt.Key_Minus) {
|
||||
removeButton.clicked();
|
||||
} else if (event.key >= Qt.Key_F1 && event.key <= Qt.Key_F12) {
|
||||
const desktopId = (event.key - Qt.Key_F1) + 1;
|
||||
switchTo(desktopId);
|
||||
const desktopId = event.key - Qt.Key_F1;
|
||||
if (desktopId < gridRepeater.count) {
|
||||
switchTo(gridRepeater.itemAt(desktopId).desktop);
|
||||
}
|
||||
} else if (event.key >= Qt.Key_0 && event.key <= Qt.Key_9) {
|
||||
const desktopId = event.key === Qt.Key_0 ? 10 : (event.key - Qt.Key_0);
|
||||
switchTo(desktopId);
|
||||
const desktopId = event.key === Qt.Key_0 ? 9 : (event.key - Qt.Key_1);
|
||||
if (desktopId < gridRepeater.count) {
|
||||
switchTo(gridRepeater.itemAt(desktopId).desktop);
|
||||
}
|
||||
} else if (event.key === Qt.Key_Up) {
|
||||
event.accepted = selectNext(WindowHeap.Direction.Up);
|
||||
if (!event.accepted) {
|
||||
|
@ -138,7 +142,7 @@ Rectangle {
|
|||
} else if (event.key === Qt.Key_Return || event.key === Qt.Key_Space) {
|
||||
for (let i = 0; i < gridRepeater.count; i++) {
|
||||
if (gridRepeater.itemAt(i).focus) {
|
||||
switchTo(gridRepeater.itemAt(i).desktop.x11DesktopNumber)
|
||||
switchTo(gridRepeater.itemAt(i).desktop)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -249,7 +253,7 @@ Rectangle {
|
|||
id: thumbnail
|
||||
|
||||
panelOpacity: grid.panelOpacity
|
||||
readonly property bool current: KWinComponents.Workspace.currentVirtualDesktop === desktop
|
||||
readonly property bool current: KWinComponents.Workspace.currentDesktop === desktop
|
||||
z: dragActive ? 1 : 0
|
||||
onCurrentChanged: {
|
||||
if (current) {
|
||||
|
@ -278,7 +282,7 @@ Rectangle {
|
|||
TapHandler {
|
||||
acceptedButtons: Qt.LeftButton
|
||||
onTapped: {
|
||||
KWinComponents.Workspace.currentVirtualDesktop = thumbnail.desktop;
|
||||
KWinComponents.Workspace.currentDesktop = thumbnail.desktop;
|
||||
container.effect.deactivate(container.effect.animationDuration);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ Item {
|
|||
}
|
||||
ScriptAction {
|
||||
script: {
|
||||
KWinComponents.Workspace.currentVirtualDesktop = delegate.desktop;
|
||||
KWinComponents.Workspace.currentDesktop = delegate.desktop;
|
||||
effect.quickDeactivate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ FocusScope {
|
|||
KWinComponents.DesktopBackgroundItem {
|
||||
id: backgroundItem
|
||||
activity: KWinComponents.Workspace.currentActivity
|
||||
desktop: KWinComponents.Workspace.currentVirtualDesktop
|
||||
desktop: KWinComponents.Workspace.currentDesktop
|
||||
outputName: targetScreen.name
|
||||
property real blurRadius: 0
|
||||
|
||||
|
@ -185,7 +185,7 @@ FocusScope {
|
|||
anchors.fill: parent
|
||||
clientModel: stackModel
|
||||
desktopModel: desktopModel
|
||||
selectedDesktop: KWinComponents.Workspace.currentVirtualDesktop
|
||||
selectedDesktop: KWinComponents.Workspace.currentDesktop
|
||||
heap: heap
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ FocusScope {
|
|||
Keys.forwardTo: searchResults
|
||||
model: KWinComponents.ClientFilterModel {
|
||||
activity: KWinComponents.Workspace.currentActivity
|
||||
desktop: KWinComponents.Workspace.currentVirtualDesktop
|
||||
desktop: KWinComponents.Workspace.currentDesktop
|
||||
screenName: targetScreen.name
|
||||
clientModel: stackModel
|
||||
filter: effect.searchText
|
||||
|
@ -295,7 +295,7 @@ FocusScope {
|
|||
|
||||
Repeater {
|
||||
model: KWinComponents.ClientFilterModel {
|
||||
desktop: KWinComponents.Workspace.currentVirtualDesktop
|
||||
desktop: KWinComponents.Workspace.currentDesktop
|
||||
screenName: targetScreen.name
|
||||
clientModel: stackModel
|
||||
windowType: KWinComponents.ClientFilterModel.Dock
|
||||
|
|
|
@ -22,8 +22,8 @@ Item {
|
|||
|
||||
readonly property bool selected: windowHeap.selectedIndex === index
|
||||
|
||||
// -1 is a special value which means "All Desktops"
|
||||
readonly property bool presentOnCurrentDesktop: client.desktop === KWinComponents.Workspace.currentDesktop || client.desktop === -1
|
||||
// no desktops is a special value which means "All Desktops"
|
||||
readonly property bool presentOnCurrentDesktop: !client.desktops.length || client.desktops.indexOf(KWinComponents.Workspace.currentDesktop) !== -1
|
||||
readonly property bool initialHidden: client.minimized || !presentOnCurrentDesktop
|
||||
readonly property bool activeHidden: {
|
||||
if (windowHeap.showOnly === "activeClass") {
|
||||
|
|
|
@ -53,7 +53,7 @@ FocusScope {
|
|||
Repeater {
|
||||
model: KWinComponents.ClientFilterModel {
|
||||
activity: KWinComponents.Workspace.currentActivity
|
||||
desktop: KWinComponents.Workspace.currentVirtualDesktop
|
||||
desktop: KWinComponents.Workspace.currentDesktop
|
||||
screenName: targetScreen.name
|
||||
clientModel: KWinComponents.ClientModel {}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ Item {
|
|||
|
||||
KWinComponents.DesktopBackgroundItem {
|
||||
activity: KWinComponents.Workspace.currentActivity
|
||||
desktop: KWinComponents.Workspace.currentVirtualDesktop
|
||||
desktop: KWinComponents.Workspace.currentDesktop
|
||||
outputName: targetScreen.name
|
||||
|
||||
layer.enabled: true
|
||||
|
@ -192,7 +192,7 @@ Item {
|
|||
switch (container.effect.mode) {
|
||||
case WindowView.ModeCurrentDesktop:
|
||||
case WindowView.ModeWindowClassCurrentDesktop:
|
||||
return KWinComponents.Workspace.currentVirtualDesktop;
|
||||
return KWinComponents.Workspace.currentDesktop;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ Item {
|
|||
asynchronous: true
|
||||
|
||||
model: KWinComponents.ClientFilterModel {
|
||||
desktop: KWinComponents.Workspace.currentVirtualDesktop
|
||||
desktop: KWinComponents.Workspace.currentDesktop
|
||||
screenName: targetScreen.name
|
||||
clientModel: stackModel
|
||||
windowType: KWinComponents.ClientFilterModel.Dock
|
||||
|
|
|
@ -151,6 +151,7 @@ KWin::Script::Script(int id, QString scriptName, QString pluginName, QObject *pa
|
|||
}
|
||||
|
||||
qRegisterMetaType<QList<KWin::Window *>>();
|
||||
qRegisterMetaType<QVector<KWin::VirtualDesktop *>>();
|
||||
}
|
||||
|
||||
KWin::Script::~Script()
|
||||
|
|
|
@ -34,9 +34,10 @@ WorkspaceWrapper::WorkspaceWrapper(QObject *parent)
|
|||
connect(ws, &Workspace::windowAdded, this, &WorkspaceWrapper::setupClientConnections);
|
||||
connect(ws, &Workspace::windowRemoved, this, &WorkspaceWrapper::clientRemoved);
|
||||
connect(ws, &Workspace::windowActivated, this, &WorkspaceWrapper::clientActivated);
|
||||
connect(vds, &VirtualDesktopManager::countChanged, this, &WorkspaceWrapper::numberDesktopsChanged);
|
||||
connect(vds, &VirtualDesktopManager::desktopCreated, this, &WorkspaceWrapper::desktopsChanged);
|
||||
connect(vds, &VirtualDesktopManager::desktopRemoved, this, &WorkspaceWrapper::desktopsChanged);
|
||||
connect(vds, &VirtualDesktopManager::layoutChanged, this, &WorkspaceWrapper::desktopLayoutChanged);
|
||||
connect(vds, &VirtualDesktopManager::currentChanged, this, &WorkspaceWrapper::currentVirtualDesktopChanged);
|
||||
connect(vds, &VirtualDesktopManager::currentChanged, this, &WorkspaceWrapper::currentDesktopChanged);
|
||||
connect(ws, &Workspace::windowDemandsAttentionChanged, this, &WorkspaceWrapper::clientDemandsAttentionChanged);
|
||||
#if KWIN_BUILD_ACTIVITIES
|
||||
if (KWin::Activities *activities = ws->activities()) {
|
||||
|
@ -63,26 +64,21 @@ WorkspaceWrapper::WorkspaceWrapper(QObject *parent)
|
|||
}
|
||||
}
|
||||
|
||||
VirtualDesktop *WorkspaceWrapper::currentVirtualDesktop() const
|
||||
VirtualDesktop *WorkspaceWrapper::currentDesktop() const
|
||||
{
|
||||
return VirtualDesktopManager::self()->currentDesktop();
|
||||
}
|
||||
|
||||
int WorkspaceWrapper::numberOfDesktops() const
|
||||
QVector<VirtualDesktop *> WorkspaceWrapper::desktops() const
|
||||
{
|
||||
return VirtualDesktopManager::self()->count();
|
||||
return VirtualDesktopManager::self()->desktops();
|
||||
}
|
||||
|
||||
void WorkspaceWrapper::setCurrentVirtualDesktop(VirtualDesktop *desktop)
|
||||
void WorkspaceWrapper::setCurrentDesktop(VirtualDesktop *desktop)
|
||||
{
|
||||
VirtualDesktopManager::self()->setCurrent(desktop);
|
||||
}
|
||||
|
||||
void WorkspaceWrapper::setNumberOfDesktops(int count)
|
||||
{
|
||||
VirtualDesktopManager::self()->setCount(count);
|
||||
}
|
||||
|
||||
Window *WorkspaceWrapper::activeClient() const
|
||||
{
|
||||
return workspace()->activeWindow();
|
||||
|
@ -274,14 +270,9 @@ void WorkspaceWrapper::createDesktop(int position, const QString &name) const
|
|||
VirtualDesktopManager::self()->createVirtualDesktop(position, name);
|
||||
}
|
||||
|
||||
void WorkspaceWrapper::removeDesktop(int position) const
|
||||
void WorkspaceWrapper::removeDesktop(VirtualDesktop *desktop) const
|
||||
{
|
||||
VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForX11Id(position + 1);
|
||||
if (!vd) {
|
||||
return;
|
||||
}
|
||||
|
||||
VirtualDesktopManager::self()->removeVirtualDesktop(vd->id());
|
||||
VirtualDesktopManager::self()->removeVirtualDesktop(desktop->id());
|
||||
}
|
||||
|
||||
QString WorkspaceWrapper::supportInformation() const
|
||||
|
|
|
@ -29,7 +29,8 @@ class X11Window;
|
|||
class WorkspaceWrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(KWin::VirtualDesktop *currentVirtualDesktop READ currentVirtualDesktop WRITE setCurrentVirtualDesktop NOTIFY currentVirtualDesktopChanged)
|
||||
Q_PROPERTY(QVector<KWin::VirtualDesktop *> desktops READ desktops NOTIFY desktopsChanged)
|
||||
Q_PROPERTY(KWin::VirtualDesktop *currentDesktop READ currentDesktop WRITE setCurrentDesktop NOTIFY currentDesktopChanged)
|
||||
Q_PROPERTY(KWin::Window *activeClient READ activeClient WRITE setActiveClient NOTIFY clientActivated)
|
||||
// TODO: write and notify?
|
||||
Q_PROPERTY(QSize desktopGridSize READ desktopGridSize NOTIFY desktopLayoutChanged)
|
||||
|
@ -38,10 +39,6 @@ class WorkspaceWrapper : public QObject
|
|||
Q_PROPERTY(int workspaceWidth READ workspaceWidth)
|
||||
Q_PROPERTY(int workspaceHeight READ workspaceHeight)
|
||||
Q_PROPERTY(QSize workspaceSize READ workspaceSize)
|
||||
/**
|
||||
* The number of desktops currently used. Minimum number of desktops is 1, maximum 20.
|
||||
*/
|
||||
Q_PROPERTY(int desktops READ numberOfDesktops WRITE setNumberOfDesktops NOTIFY numberDesktopsChanged)
|
||||
Q_PROPERTY(int activeScreen READ activeScreen)
|
||||
Q_PROPERTY(int numScreens READ numScreens NOTIFY numberScreensChanged)
|
||||
Q_PROPERTY(QString currentActivity READ currentActivity WRITE setCurrentActivity NOTIFY currentActivityChanged)
|
||||
|
@ -80,11 +77,9 @@ Q_SIGNALS:
|
|||
void clientFullScreenSet(KWin::X11Window *client, bool fullScreen, bool user);
|
||||
void clientSetKeepAbove(KWin::X11Window *client, bool keepAbove);
|
||||
/**
|
||||
* Signal emitted whenever the number of desktops changed.
|
||||
* To get the current number of desktops use the property desktops.
|
||||
* @param oldNumberOfDesktops The previous number of desktops.
|
||||
* This signal is emitted when a virtual desktop is added or removed.
|
||||
*/
|
||||
void numberDesktopsChanged(uint oldNumberOfDesktops);
|
||||
void desktopsChanged();
|
||||
/**
|
||||
* Signal emitted whenever the layout of virtual desktops changed.
|
||||
* That is desktopGrid(Size/Width/Height) will have new values.
|
||||
|
@ -137,10 +132,8 @@ Q_SIGNALS:
|
|||
void virtualScreenGeometryChanged();
|
||||
/**
|
||||
* This signal is emitted when the current virtual desktop changes.
|
||||
*
|
||||
* @since 5.23
|
||||
*/
|
||||
void currentVirtualDesktopChanged();
|
||||
void currentDesktopChanged();
|
||||
/**
|
||||
* This signal is emitted when the cursor position changes.
|
||||
* @see cursorPos()
|
||||
|
@ -191,7 +184,6 @@ public:
|
|||
#define GETTERSETTERDEF(rettype, getter, setter) \
|
||||
rettype getter() const; \
|
||||
void setter(rettype val);
|
||||
GETTERSETTERDEF(int, numberOfDesktops, setNumberOfDesktops)
|
||||
GETTERSETTERDEF(QString, currentActivity, setCurrentActivity)
|
||||
GETTERSETTERDEF(KWin::Window *, activeClient, setActiveClient)
|
||||
#undef GETTERSETTERDEF
|
||||
|
@ -208,8 +200,9 @@ public:
|
|||
QRect virtualScreenGeometry() const;
|
||||
QPoint cursorPos() const;
|
||||
|
||||
VirtualDesktop *currentVirtualDesktop() const;
|
||||
void setCurrentVirtualDesktop(VirtualDesktop *desktop);
|
||||
QVector<VirtualDesktop *> desktops() const;
|
||||
VirtualDesktop *currentDesktop() const;
|
||||
void setCurrentDesktop(VirtualDesktop *desktop);
|
||||
|
||||
Q_INVOKABLE int screenAt(const QPointF &pos) const;
|
||||
|
||||
|
@ -249,10 +242,9 @@ public:
|
|||
*/
|
||||
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].
|
||||
* Removes the specified virtual desktop.
|
||||
*/
|
||||
Q_SCRIPTABLE void removeDesktop(int position) const;
|
||||
Q_SCRIPTABLE void removeDesktop(KWin::VirtualDesktop *desktop) const;
|
||||
/**
|
||||
* Provides support information about the currently running KWin instance.
|
||||
*/
|
||||
|
|
|
@ -11,7 +11,7 @@ var registeredBorders = [];
|
|||
|
||||
function isRelevant(client) {
|
||||
return client.minimizable &&
|
||||
(client.onAllDesktops || client.desktop === workspace.currentDesktop);
|
||||
(!client.desktops.length || client.desktops.indexOf(workspace.currentDesktop) != -1);
|
||||
(!client.activities.length || client.activities.indexOf(workspace.currentActivity.toString()) > -1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue