diff --git a/scripting/meta.cpp b/scripting/meta.cpp index 56e762d58..406bdc1eb 100644 --- a/scripting/meta.cpp +++ b/scripting/meta.cpp @@ -1,240 +1,241 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2010 Rohan Prabhu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "meta.h" #include "client.h" #include using namespace KWin::MetaScripting; // Meta for QPoint object QScriptValue Point::toScriptValue(QScriptEngine* eng, const QPoint& point) { QScriptValue temp = eng->newObject(); temp.setProperty(QStringLiteral("x"), point.x()); temp.setProperty(QStringLiteral("y"), point.y()); return temp; } void Point::fromScriptValue(const QScriptValue& obj, QPoint& point) { QScriptValue x = obj.property(QStringLiteral("x"), QScriptValue::ResolveLocal); QScriptValue y = obj.property(QStringLiteral("y"), QScriptValue::ResolveLocal); if (!x.isUndefined() && !y.isUndefined()) { point.setX(x.toInt32()); point.setY(y.toInt32()); } } // End of meta for QPoint object // Meta for QSize object QScriptValue Size::toScriptValue(QScriptEngine* eng, const QSize& size) { QScriptValue temp = eng->newObject(); temp.setProperty(QStringLiteral("w"), size.width()); temp.setProperty(QStringLiteral("h"), size.height()); return temp; } void Size::fromScriptValue(const QScriptValue& obj, QSize& size) { QScriptValue w = obj.property(QStringLiteral("w"), QScriptValue::ResolveLocal); QScriptValue h = obj.property(QStringLiteral("h"), QScriptValue::ResolveLocal); if (!w.isUndefined() && !h.isUndefined()) { size.setWidth(w.toInt32()); size.setHeight(h.toInt32()); } } // End of meta for QSize object // Meta for QRect object. Just a temporary measure, hope to // add a much better wrapping of the QRect object soon QScriptValue Rect::toScriptValue(QScriptEngine* eng, const QRect& rect) { QScriptValue temp = eng->newObject(); temp.setProperty(QStringLiteral("x"), rect.x()); temp.setProperty(QStringLiteral("y"), rect.y()); temp.setProperty(QStringLiteral("width"), rect.width()); temp.setProperty(QStringLiteral("height"), rect.height()); return temp; } void Rect::fromScriptValue(const QScriptValue& obj, QRect &rect) { QScriptValue w = obj.property(QStringLiteral("width"), QScriptValue::ResolveLocal); QScriptValue h = obj.property(QStringLiteral("height"), QScriptValue::ResolveLocal); QScriptValue x = obj.property(QStringLiteral("x"), QScriptValue::ResolveLocal); QScriptValue y = obj.property(QStringLiteral("y"), QScriptValue::ResolveLocal); if (!w.isUndefined() && !h.isUndefined() && !x.isUndefined() && !y.isUndefined()) { rect.setX(x.toInt32()); rect.setY(y.toInt32()); rect.setWidth(w.toInt32()); rect.setHeight(h.toInt32()); } } // End of meta for QRect object QScriptValue Client::toScriptValue(QScriptEngine *eng, const KClientRef &client) { return eng->newQObject(client, QScriptEngine::QtOwnership, QScriptEngine::ExcludeChildObjects | QScriptEngine::ExcludeDeleteLater | QScriptEngine::PreferExistingWrapperObject | QScriptEngine::AutoCreateDynamicProperties); } void Client::fromScriptValue(const QScriptValue &value, KWin::Client* &client) { client = qobject_cast(value.toQObject()); } QScriptValue Toplevel::toScriptValue(QScriptEngine *eng, const KToplevelRef &client) { return eng->newQObject(client, QScriptEngine::QtOwnership, QScriptEngine::ExcludeChildObjects | QScriptEngine::ExcludeDeleteLater | QScriptEngine::PreferExistingWrapperObject | QScriptEngine::AutoCreateDynamicProperties); } void Toplevel::fromScriptValue(const QScriptValue &value, KToplevelRef &client) { client = qobject_cast(value.toQObject()); } // Other helper functions void KWin::MetaScripting::registration(QScriptEngine* eng) { qScriptRegisterMetaType(eng, Point::toScriptValue, Point::fromScriptValue); qScriptRegisterMetaType(eng, Size::toScriptValue, Size::fromScriptValue); qScriptRegisterMetaType(eng, Rect::toScriptValue, Rect::fromScriptValue); qScriptRegisterMetaType(eng, Client::toScriptValue, Client::fromScriptValue); qScriptRegisterMetaType(eng, Toplevel::toScriptValue, Toplevel::fromScriptValue); qScriptRegisterSequenceMetaType(eng); + qScriptRegisterSequenceMetaType< QList >(eng); qScriptRegisterSequenceMetaType< QList >(eng); } QScriptValue KWin::MetaScripting::configExists(QScriptContext* ctx, QScriptEngine* eng) { QHash scriptConfig = (((ctx->thisObject()).data()).toVariant()).toHash(); QVariant val = scriptConfig.value((ctx->argument(0)).toString(), QVariant()); return eng->toScriptValue(val.isValid()); } QScriptValue KWin::MetaScripting::getConfigValue(QScriptContext* ctx, QScriptEngine* eng) { int num = ctx->argumentCount(); QHash scriptConfig = (((ctx->thisObject()).data()).toVariant()).toHash(); /* * Handle config.get() separately. Compute and return immediately. **/ if (num == 0) { QHash::const_iterator i; QScriptValue ret = eng->newArray(); for (i = scriptConfig.constBegin(); i != scriptConfig.constEnd(); ++i) { ret.setProperty(i.key(), eng->newVariant(i.value())); } return ret; } if ((num == 1) && !((ctx->argument(0)).isArray())) { QVariant val = scriptConfig.value((ctx->argument(0)).toString(), QVariant()); if (val.isValid()) { return eng->newVariant(val); } else { return QScriptValue(); } } else { QScriptValue ret = eng->newArray(); int j = 0; if ((ctx->argument(0)).isArray()) { bool simple = (num == 1) ? 0 : (ctx->argument(1)).toBool(); QScriptValue array = (ctx->argument(0)); int len = (array.property(QStringLiteral("length")).isValid()) ? array.property(QStringLiteral("length")).toNumber() : 0; for (int i = 0; i < len; i++) { QVariant val = scriptConfig.value(array.property(i).toString(), QVariant()); if (val.isValid()) { if (simple) { ret.setProperty(j, eng->newVariant(val)); } else { ret.setProperty(array.property(i).toString(), eng->newVariant(val)); } j++; } } } else { for (int i = 0; i < num; i++) { QVariant val = scriptConfig.value((ctx->argument(i)).toString(), QVariant()); if (val.isValid()) { ret.setProperty((ctx->argument(i)).toString(), eng->newVariant(val)); j = 1; } } } if (j == 0) { return QScriptValue(); } else { return ret; } } } void KWin::MetaScripting::supplyConfig(QScriptEngine* eng, const QVariant& scriptConfig) { QScriptValue configObject = eng->newObject(); configObject.setData(eng->newVariant(scriptConfig)); configObject.setProperty(QStringLiteral("get"), eng->newFunction(getConfigValue, 0), QScriptValue::Undeletable); configObject.setProperty(QStringLiteral("exists"), eng->newFunction(configExists, 0), QScriptValue::Undeletable); configObject.setProperty(QStringLiteral("loaded"), ((scriptConfig.toHash().empty()) ? eng->newVariant((bool)0) : eng->newVariant((bool)1)), QScriptValue::Undeletable); (eng->globalObject()).setProperty(QStringLiteral("config"), configObject); } void KWin::MetaScripting::supplyConfig(QScriptEngine* eng) { KWin::MetaScripting::supplyConfig(eng, QVariant(QHash())); } void KWin::MetaScripting::valueMerge(QScriptValue& first, QScriptValue second) { QScriptValueIterator value_it(second); while (value_it.hasNext()) { value_it.next(); first.setProperty(value_it.name(), value_it.value()); } } diff --git a/scripting/workspace_wrapper.cpp b/scripting/workspace_wrapper.cpp index 1099a8525..01636fe64 100644 --- a/scripting/workspace_wrapper.cpp +++ b/scripting/workspace_wrapper.cpp @@ -1,366 +1,366 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2010 Rohan Prabhu Copyright (C) 2011, 2012 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "workspace_wrapper.h" #include "../client.h" #include "../outline.h" #include "../screens.h" #include "../virtualdesktops.h" #include "../workspace.h" #ifdef KWIN_BUILD_ACTIVITIES #include "../activities.h" #endif #include #include namespace KWin { WorkspaceWrapper::WorkspaceWrapper(QObject* parent) : QObject(parent) { KWin::Workspace *ws = KWin::Workspace::self(); KWin::VirtualDesktopManager *vds = KWin::VirtualDesktopManager::self(); connect(ws, &Workspace::desktopPresenceChanged, this, &WorkspaceWrapper::desktopPresenceChanged); connect(ws, &Workspace::currentDesktopChanged, this, &WorkspaceWrapper::currentDesktopChanged); connect(ws, SIGNAL(clientAdded(KWin::Client*)), SIGNAL(clientAdded(KWin::Client*))); connect(ws, SIGNAL(clientAdded(KWin::Client*)), SLOT(setupClientConnections(KWin::Client*))); connect(ws, &Workspace::clientRemoved, this, &WorkspaceWrapper::clientRemoved); connect(ws, &Workspace::clientActivated, this, &WorkspaceWrapper::clientActivated); connect(vds, SIGNAL(countChanged(uint,uint)), SIGNAL(numberDesktopsChanged(uint))); connect(vds, SIGNAL(layoutChanged(int,int)), SIGNAL(desktopLayoutChanged())); connect(ws, &Workspace::clientDemandsAttentionChanged, this, &WorkspaceWrapper::clientDemandsAttentionChanged); #ifdef KWIN_BUILD_ACTIVITIES if (KWin::Activities *activities = KWin::Activities::self()) { connect(activities, SIGNAL(currentChanged(QString)), SIGNAL(currentActivityChanged(QString))); connect(activities, SIGNAL(added(QString)), SIGNAL(activitiesChanged(QString))); connect(activities, SIGNAL(added(QString)), SIGNAL(activityAdded(QString))); connect(activities, SIGNAL(removed(QString)), SIGNAL(activitiesChanged(QString))); connect(activities, SIGNAL(removed(QString)), SIGNAL(activityRemoved(QString))); } #endif connect(screens(), &Screens::sizeChanged, this, &WorkspaceWrapper::virtualScreenSizeChanged); connect(screens(), &Screens::geometryChanged, this, &WorkspaceWrapper::virtualScreenGeometryChanged); connect(screens(), &Screens::countChanged, this, [this] (int previousCount, int currentCount) { Q_UNUSED(previousCount) emit numberScreensChanged(currentCount); } ); connect(QApplication::desktop(), SIGNAL(resized(int)), SIGNAL(screenResized(int))); foreach (KWin::Client *client, ws->clientList()) { setupClientConnections(client); } } int WorkspaceWrapper::currentDesktop() const { return VirtualDesktopManager::self()->current(); } int WorkspaceWrapper::numberOfDesktops() const { return VirtualDesktopManager::self()->count(); } void WorkspaceWrapper::setCurrentDesktop(int desktop) { VirtualDesktopManager::self()->setCurrent(desktop); } void WorkspaceWrapper::setNumberOfDesktops(int count) { VirtualDesktopManager::self()->setCount(count); } -#define GETTER( klass, rettype, getterName ) \ -rettype klass::getterName( ) const { \ - return Workspace::self()->getterName(); \ +AbstractClient *WorkspaceWrapper::activeClient() const +{ + return workspace()->activeClient(); } -GETTER(WorkspaceWrapper, KWin::AbstractClient*, activeClient) -GETTER(QtScriptWorkspaceWrapper, QList< KWin::Client* >, clientList) - -#undef GETTER QString WorkspaceWrapper::currentActivity() const { #ifdef KWIN_BUILD_ACTIVITIES if (!Activities::self()) { return QString(); } return Activities::self()->current(); #else return QString(); #endif } QStringList WorkspaceWrapper::activityList() const { #ifdef KWIN_BUILD_ACTIVITIES if (!Activities::self()) { return QStringList(); } return Activities::self()->all(); #else return QStringList(); #endif } #define SLOTWRAPPER(name) \ void WorkspaceWrapper::name( ) { \ Workspace::self()->name(); \ } SLOTWRAPPER(slotSwitchToNextScreen) SLOTWRAPPER(slotWindowToNextScreen) SLOTWRAPPER(slotToggleShowDesktop) SLOTWRAPPER(slotWindowMaximize) SLOTWRAPPER(slotWindowMaximizeVertical) SLOTWRAPPER(slotWindowMaximizeHorizontal) SLOTWRAPPER(slotWindowMinimize) SLOTWRAPPER(slotWindowShade) SLOTWRAPPER(slotWindowRaise) SLOTWRAPPER(slotWindowLower) SLOTWRAPPER(slotWindowRaiseOrLower) SLOTWRAPPER(slotActivateAttentionWindow) SLOTWRAPPER(slotWindowPackLeft) SLOTWRAPPER(slotWindowPackRight) SLOTWRAPPER(slotWindowPackUp) SLOTWRAPPER(slotWindowPackDown) SLOTWRAPPER(slotWindowGrowHorizontal) SLOTWRAPPER(slotWindowGrowVertical) SLOTWRAPPER(slotWindowShrinkHorizontal) SLOTWRAPPER(slotWindowShrinkVertical) SLOTWRAPPER(slotIncreaseWindowOpacity) SLOTWRAPPER(slotLowerWindowOpacity) SLOTWRAPPER(slotWindowOperations) SLOTWRAPPER(slotWindowClose) SLOTWRAPPER(slotWindowMove) SLOTWRAPPER(slotWindowResize) SLOTWRAPPER(slotWindowAbove) SLOTWRAPPER(slotWindowBelow) SLOTWRAPPER(slotWindowOnAllDesktops) SLOTWRAPPER(slotWindowFullScreen) SLOTWRAPPER(slotWindowNoBorder) SLOTWRAPPER(slotWindowToNextDesktop) SLOTWRAPPER(slotWindowToPreviousDesktop) SLOTWRAPPER(slotWindowToDesktopRight) SLOTWRAPPER(slotWindowToDesktopLeft) SLOTWRAPPER(slotWindowToDesktopUp) SLOTWRAPPER(slotWindowToDesktopDown) #undef SLOTWRAPPER #define SLOTWRAPPER(name,modes) \ void WorkspaceWrapper::name() { \ Workspace::self()->quickTileWindow(modes); \ } SLOTWRAPPER(slotWindowQuickTileLeft, QuickTileFlag::Left) SLOTWRAPPER(slotWindowQuickTileRight, QuickTileFlag::Right) SLOTWRAPPER(slotWindowQuickTileTop, QuickTileFlag::Top) SLOTWRAPPER(slotWindowQuickTileBottom, QuickTileFlag::Bottom) SLOTWRAPPER(slotWindowQuickTileTopLeft, QuickTileFlag::Top | QuickTileFlag::Left) SLOTWRAPPER(slotWindowQuickTileTopRight, QuickTileFlag::Top | QuickTileFlag::Right) SLOTWRAPPER(slotWindowQuickTileBottomLeft, QuickTileFlag::Bottom | QuickTileFlag::Left) SLOTWRAPPER(slotWindowQuickTileBottomRight, QuickTileFlag::Bottom | QuickTileFlag::Right) #undef SLOTWRAPPER #define SLOTWRAPPER(name,direction) \ void WorkspaceWrapper::name() { \ Workspace::self()->switchWindow(Workspace::direction); \ } SLOTWRAPPER(slotSwitchWindowUp, DirectionNorth) SLOTWRAPPER(slotSwitchWindowDown, DirectionSouth) SLOTWRAPPER(slotSwitchWindowRight, DirectionEast) SLOTWRAPPER(slotSwitchWindowLeft, DirectionWest) #undef SLOTWRAPPER #define SLOTWRAPPER(name,direction) \ void WorkspaceWrapper::name( ) { \ VirtualDesktopManager::self()->moveTo(options->isRollOverDesktops()); \ } SLOTWRAPPER(slotSwitchDesktopNext,DesktopNext) SLOTWRAPPER(slotSwitchDesktopPrevious,DesktopPrevious) SLOTWRAPPER(slotSwitchDesktopRight,DesktopRight) SLOTWRAPPER(slotSwitchDesktopLeft,DesktopLeft) SLOTWRAPPER(slotSwitchDesktopUp,DesktopAbove) SLOTWRAPPER(slotSwitchDesktopDown,DesktopBelow) #undef SLOTWRAPPER void WorkspaceWrapper::setActiveClient(KWin::AbstractClient* client) { KWin::Workspace::self()->activateClient(client); } QSize WorkspaceWrapper::workspaceSize() const { return QSize(workspaceWidth(), workspaceHeight()); } QSize WorkspaceWrapper::displaySize() const { return screens()->displaySize(); } int WorkspaceWrapper::displayWidth() const { return displaySize().width(); } int WorkspaceWrapper::displayHeight() const { return displaySize().height(); } QRect WorkspaceWrapper::clientArea(ClientAreaOption option, const QPoint &p, int desktop) const { return Workspace::self()->clientArea(static_cast(option), p, desktop); } -QRect WorkspaceWrapper::clientArea(ClientAreaOption option, const KWin::Client *c) const +QRect WorkspaceWrapper::clientArea(ClientAreaOption option, const KWin::AbstractClient *c) const { return Workspace::self()->clientArea(static_cast(option), c); } QRect WorkspaceWrapper::clientArea(ClientAreaOption option, int screen, int desktop) const { return Workspace::self()->clientArea(static_cast(option), screen, desktop); } QString WorkspaceWrapper::desktopName(int desktop) const { return VirtualDesktopManager::self()->name(desktop); } QString WorkspaceWrapper::supportInformation() const { return Workspace::self()->supportInformation(); } void WorkspaceWrapper::setupClientConnections(KWin::Client *client) { connect(client, &Client::clientMinimized, this, &WorkspaceWrapper::clientMinimized); connect(client, &Client::clientUnminimized, this, &WorkspaceWrapper::clientUnminimized); connect(client, SIGNAL(clientManaging(KWin::Client*)), SIGNAL(clientManaging(KWin::Client*))); connect(client, SIGNAL(clientFullScreenSet(KWin::Client*,bool,bool)), SIGNAL(clientFullScreenSet(KWin::Client*,bool,bool))); connect(client, static_cast(&Client::clientMaximizedStateChanged), this, &WorkspaceWrapper::clientMaximizeSet); } void WorkspaceWrapper::showOutline(const QRect &geometry) { outline()->show(geometry); } void WorkspaceWrapper::showOutline(int x, int y, int width, int height) { outline()->show(QRect(x, y, width, height)); } void WorkspaceWrapper::hideOutline() { outline()->hide(); } Client *WorkspaceWrapper::getClient(qulonglong windowId) { return Workspace::self()->findClient(Predicate::WindowMatch, windowId); } QSize WorkspaceWrapper::desktopGridSize() const { return VirtualDesktopManager::self()->grid().size(); } int WorkspaceWrapper::desktopGridWidth() const { return desktopGridSize().width(); } int WorkspaceWrapper::desktopGridHeight() const { return desktopGridSize().height(); } int WorkspaceWrapper::workspaceHeight() const { return desktopGridHeight() * displayHeight(); } int WorkspaceWrapper::workspaceWidth() const { return desktopGridWidth() * displayWidth(); } int WorkspaceWrapper::numScreens() const { return screens()->count(); } int WorkspaceWrapper::activeScreen() const { return screens()->current(); } QRect WorkspaceWrapper::virtualScreenGeometry() const { return screens()->geometry(); } QSize WorkspaceWrapper::virtualScreenSize() const { return screens()->size(); } QtScriptWorkspaceWrapper::QtScriptWorkspaceWrapper(QObject* parent) : WorkspaceWrapper(parent) {} +QList QtScriptWorkspaceWrapper::clientList() const +{ + return workspace()->allClientList(); +} -QQmlListProperty DeclarativeScriptWorkspaceWrapper::clients() +QQmlListProperty DeclarativeScriptWorkspaceWrapper::clients() { - return QQmlListProperty(this, 0, &DeclarativeScriptWorkspaceWrapper::countClientList, &DeclarativeScriptWorkspaceWrapper::atClientList); + return QQmlListProperty(this, 0, &DeclarativeScriptWorkspaceWrapper::countClientList, &DeclarativeScriptWorkspaceWrapper::atClientList); } -int DeclarativeScriptWorkspaceWrapper::countClientList(QQmlListProperty *clients) +int DeclarativeScriptWorkspaceWrapper::countClientList(QQmlListProperty *clients) { Q_UNUSED(clients) - return Workspace::self()->clientList().size(); + return workspace()->allClientList().size(); } -KWin::Client *DeclarativeScriptWorkspaceWrapper::atClientList(QQmlListProperty *clients, int index) +KWin::AbstractClient *DeclarativeScriptWorkspaceWrapper::atClientList(QQmlListProperty *clients, int index) { Q_UNUSED(clients) - return Workspace::self()->clientList().at(index); + return workspace()->allClientList().at(index); } DeclarativeScriptWorkspaceWrapper::DeclarativeScriptWorkspaceWrapper(QObject* parent) : WorkspaceWrapper(parent) {} } // KWin diff --git a/scripting/workspace_wrapper.h b/scripting/workspace_wrapper.h index 18f00e03f..ceb558e40 100644 --- a/scripting/workspace_wrapper.h +++ b/scripting/workspace_wrapper.h @@ -1,379 +1,379 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2010 Rohan Prabhu Copyright (C) 2012 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #ifndef KWIN_SCRIPTING_WORKSPACE_WRAPPER_H #define KWIN_SCRIPTING_WORKSPACE_WRAPPER_H #include #include #include #include #include #include namespace KWin { // forward declarations class AbstractClient; class Client; class WorkspaceWrapper : public QObject { Q_OBJECT Q_ENUMS(ClientAreaOption) Q_ENUMS(ElectricBorder) Q_PROPERTY(int currentDesktop READ currentDesktop WRITE setCurrentDesktop NOTIFY currentDesktopChanged) Q_PROPERTY(KWin::AbstractClient *activeClient READ activeClient WRITE setActiveClient NOTIFY clientActivated) // TODO: write and notify? Q_PROPERTY(QSize desktopGridSize READ desktopGridSize NOTIFY desktopLayoutChanged) Q_PROPERTY(int desktopGridWidth READ desktopGridWidth NOTIFY desktopLayoutChanged) Q_PROPERTY(int desktopGridHeight READ desktopGridHeight NOTIFY desktopLayoutChanged) 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) /** * The same of the display, that is all screens. * @deprecated since 5.0 use virtualScreenSize **/ Q_PROPERTY(QSize displaySize READ displaySize) /** * The width of the display, that is width of all combined screens. * @deprecated since 5.0 use virtualScreenSize **/ Q_PROPERTY(int displayWidth READ displayWidth) /** * The height of the display, that is height of all combined screens. * @deprecated since 5.0 use virtualScreenSize **/ Q_PROPERTY(int displayHeight READ displayHeight) Q_PROPERTY(int activeScreen READ activeScreen) Q_PROPERTY(int numScreens READ numScreens NOTIFY numberScreensChanged) Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY currentActivityChanged) Q_PROPERTY(QStringList activities READ activityList NOTIFY activitiesChanged) /** * The bounding size of all screens combined. Overlapping areas * are not counted multiple times. * @see virtualScreenGeometry **/ Q_PROPERTY(QSize virtualScreenSize READ virtualScreenSize NOTIFY virtualScreenSizeChanged) /** * The bounding geometry of all outputs combined. Always starts at (0,0) and has * virtualScreenSize as it's size. * @see virtualScreenSize **/ Q_PROPERTY(QRect virtualScreenGeometry READ virtualScreenGeometry NOTIFY virtualScreenGeometryChanged) private: Q_DISABLE_COPY(WorkspaceWrapper) Q_SIGNALS: void desktopPresenceChanged(KWin::AbstractClient *client, int desktop); void currentDesktopChanged(int desktop, KWin::AbstractClient *client); void clientAdded(KWin::Client *client); void clientRemoved(KWin::AbstractClient *client); void clientManaging(KWin::Client *client); void clientMinimized(KWin::AbstractClient *client); void clientUnminimized(KWin::AbstractClient *client); void clientRestored(KWin::Client *client); void clientMaximizeSet(KWin::AbstractClient *client, bool h, bool v); void killWindowCalled(KWin::Client *client); void clientActivated(KWin::AbstractClient *client); void clientFullScreenSet(KWin::Client *client, bool fullScreen, bool user); void clientSetKeepAbove(KWin::Client *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. **/ void numberDesktopsChanged(uint oldNumberOfDesktops); /** * Signal emitted whenever the layout of virtual desktops changed. * That is desktopGrid(Size/Width/Height) will have new values. * @since 4.11 **/ void desktopLayoutChanged(); /** * The demands attention state for Client @p c changed to @p set. * @param c The Client for which demands attention changed * @param set New value of demands attention **/ void clientDemandsAttentionChanged(KWin::AbstractClient *client, bool set); /** * Signal emitted when the number of screens changes. * @param count The new number of screens **/ void numberScreensChanged(int count); /** * This signal is emitted when the size of @p screen changes. * Don't forget to fetch an updated client area. **/ void screenResized(int screen); /** * Signal emitted whenever the current activity changed. * @param id id of the new activity **/ void currentActivityChanged(const QString &id); /** * Signal emitted whenever the list of activities changed. * @param id id of the new activity **/ void activitiesChanged(const QString &id); /** * This signal is emitted when a new activity is added * @param id id of the new activity **/ void activityAdded(const QString &id); /** * This signal is emitted when the activity * is removed * @param id id of the removed activity **/ void activityRemoved(const QString &id); /** * Emitted whenever the virtualScreenSize changes. * @see virtualScreenSize() * @since 5.0 **/ void virtualScreenSizeChanged(); /** * Emitted whenever the virtualScreenGeometry changes. * @see virtualScreenGeometry() * @since 5.0 **/ void virtualScreenGeometryChanged(); public: //------------------------------------------------------------------ //enums copy&pasted from kwinglobals.h because qtscript is evil enum ClientAreaOption { ///< geometry where a window will be initially placed after being mapped PlacementArea, ///< window movement snapping area? ignore struts MovementArea, ///< geometry to which a window will be maximized MaximizeArea, ///< like MaximizeArea, but ignore struts - used e.g. for topmenu MaximizeFullArea, ///< area for fullscreen windows FullScreenArea, ///< whole workarea (all screens together) WorkArea, ///< whole area (all screens together), ignore struts FullArea, ///< one whole screen, ignore struts ScreenArea }; enum ElectricBorder { ElectricTop, ElectricTopRight, ElectricRight, ElectricBottomRight, ElectricBottom, ElectricBottomLeft, ElectricLeft, ElectricTopLeft, ELECTRIC_COUNT, ElectricNone }; protected: explicit WorkspaceWrapper(QObject* parent = nullptr); public: #define GETTERSETTERDEF( rettype, getter, setter ) \ rettype getter() const; \ void setter( rettype val ); GETTERSETTERDEF(int, numberOfDesktops, setNumberOfDesktops) GETTERSETTERDEF(int, currentDesktop, setCurrentDesktop) GETTERSETTERDEF(KWin::AbstractClient*, activeClient, setActiveClient) #undef GETTERSETTERDEF QSize desktopGridSize() const; int desktopGridWidth() const; int desktopGridHeight() const; int workspaceWidth() const; int workspaceHeight() const; QSize workspaceSize() const; int displayWidth() const; int displayHeight() const; QSize displaySize() const; int activeScreen() const; int numScreens() const; QString currentActivity() const; QStringList activityList() const; QSize virtualScreenSize() const; QRect virtualScreenGeometry() const; /** * Returns the geometry a Client can use with the specified option. * This method should be preferred over other methods providing screen sizes as the * various options take constraints such as struts set on panels into account. * This method is also multi screen aware, but there are also options to get full areas. * @param option The type of area which should be considered * @param screen The screen for which the area should be considered * @param desktop The desktop for which the area should be considered, in general there should not be a difference * @returns The specified screen geometry **/ Q_SCRIPTABLE QRect clientArea(ClientAreaOption option, int screen, int desktop) const; /** * Overloaded method for convenience. * @param option The type of area which should be considered * @param point The coordinates which have to be included in the area * @param desktop The desktop for which the area should be considered, in general there should not be a difference * @returns The specified screen geometry **/ Q_SCRIPTABLE QRect clientArea(ClientAreaOption option, const QPoint& point, int desktop) const; /** * Overloaded method for convenience. * @param client The Client for which the area should be retrieved * @returns The specified screen geometry **/ - Q_SCRIPTABLE QRect clientArea(ClientAreaOption option, const KWin::Client* client) const; + Q_SCRIPTABLE QRect clientArea(ClientAreaOption option, const KWin::AbstractClient *client) const; /** * Returns the name for the given @p desktop. **/ Q_SCRIPTABLE QString desktopName(int desktop) const; /** * Provides support information about the currently running KWin instance. **/ Q_SCRIPTABLE QString supportInformation() const; /** * Finds the Client with the given @p windowId. * @param windowId The window Id of the Client * @return The found Client or @c null **/ Q_SCRIPTABLE KWin::Client *getClient(qulonglong windowId); public Q_SLOTS: // all the available key bindings void slotSwitchDesktopNext(); void slotSwitchDesktopPrevious(); void slotSwitchDesktopRight(); void slotSwitchDesktopLeft(); void slotSwitchDesktopUp(); void slotSwitchDesktopDown(); void slotSwitchToNextScreen(); void slotWindowToNextScreen(); void slotToggleShowDesktop(); void slotWindowMaximize(); void slotWindowMaximizeVertical(); void slotWindowMaximizeHorizontal(); void slotWindowMinimize(); void slotWindowShade(); void slotWindowRaise(); void slotWindowLower(); void slotWindowRaiseOrLower(); void slotActivateAttentionWindow(); void slotWindowPackLeft(); void slotWindowPackRight(); void slotWindowPackUp(); void slotWindowPackDown(); void slotWindowGrowHorizontal(); void slotWindowGrowVertical(); void slotWindowShrinkHorizontal(); void slotWindowShrinkVertical(); void slotWindowQuickTileLeft(); void slotWindowQuickTileRight(); void slotWindowQuickTileTop(); void slotWindowQuickTileBottom(); void slotWindowQuickTileTopLeft(); void slotWindowQuickTileTopRight(); void slotWindowQuickTileBottomLeft(); void slotWindowQuickTileBottomRight(); void slotSwitchWindowUp(); void slotSwitchWindowDown(); void slotSwitchWindowRight(); void slotSwitchWindowLeft(); void slotIncreaseWindowOpacity(); void slotLowerWindowOpacity(); void slotWindowOperations(); void slotWindowClose(); void slotWindowMove(); void slotWindowResize(); void slotWindowAbove(); void slotWindowBelow(); void slotWindowOnAllDesktops(); void slotWindowFullScreen(); void slotWindowNoBorder(); void slotWindowToNextDesktop(); void slotWindowToPreviousDesktop(); void slotWindowToDesktopRight(); void slotWindowToDesktopLeft(); void slotWindowToDesktopUp(); void slotWindowToDesktopDown(); /** * Shows an outline at the specified @p geometry. * If an outline is already shown the outline is moved to the new position. * Use hideOutline to remove the outline again. **/ void showOutline(const QRect &geometry); /** * Overloaded method for convenience. **/ void showOutline(int x, int y, int width, int height); /** * Hides the outline previously shown by showOutline. **/ void hideOutline(); private Q_SLOTS: void setupClientConnections(KWin::Client* client); }; class QtScriptWorkspaceWrapper : public WorkspaceWrapper { Q_OBJECT public: /** * List of Clients currently managed by KWin. **/ - Q_INVOKABLE QList< KWin::Client* > clientList() const; + Q_INVOKABLE QList clientList() const; explicit QtScriptWorkspaceWrapper(QObject* parent = nullptr); }; class DeclarativeScriptWorkspaceWrapper : public WorkspaceWrapper { Q_OBJECT - Q_PROPERTY(QQmlListProperty clients READ clients) + Q_PROPERTY(QQmlListProperty clients READ clients) public: - QQmlListProperty clients(); - static int countClientList(QQmlListProperty *clients); - static KWin::Client *atClientList(QQmlListProperty *clients, int index); + QQmlListProperty clients(); + static int countClientList(QQmlListProperty *clients); + static KWin::AbstractClient *atClientList(QQmlListProperty *clients, int index); explicit DeclarativeScriptWorkspaceWrapper(QObject* parent = nullptr); }; } #endif