From 651a0cca47a5ed8b469978d14d7b66a2257f3e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 26 Jan 2012 22:56:24 +0100 Subject: [PATCH] Export clientArea methods to scripting For this a new MetaObject "KWin" is exported to have the enum ClientAreaOption available in scripts. Unfortunately this requires duplicating the enum from kwinglobals.h. --- scripting/scripting.cpp | 1 + scripting/workspace_wrapper.cpp | 15 ++++++++++ scripting/workspace_wrapper.h | 49 +++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/scripting/scripting.cpp b/scripting/scripting.cpp index dbfa6dd321..d95f6075c3 100644 --- a/scripting/scripting.cpp +++ b/scripting/scripting.cpp @@ -82,6 +82,7 @@ void KWin::Script::run() QScriptEngine::ExcludeSuperClassContents | QScriptEngine::ExcludeDeleteLater); m_engine->globalObject().setProperty("workspace", workspace, QScriptValue::Undeletable); m_engine->globalObject().setProperty("QTimer", constructTimerClass(m_engine)); + m_engine->globalObject().setProperty("KWin", m_engine->newQMetaObject(&WorkspaceWrapper::staticMetaObject)); QObject::connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), this, SLOT(sigException(QScriptValue))); KWin::MetaScripting::registration(m_engine); diff --git a/scripting/workspace_wrapper.cpp b/scripting/workspace_wrapper.cpp index 6e487b5e59..dc4e988710 100644 --- a/scripting/workspace_wrapper.cpp +++ b/scripting/workspace_wrapper.cpp @@ -91,6 +91,21 @@ int WorkspaceWrapper::displayHeight() const return KWin::displayWidth(); } +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 +{ + 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); +} + void WorkspaceWrapper::setupClientConnections(KWin::Client *client) { connect(client, SIGNAL(clientMinimized(KWin::Client*,bool)), SIGNAL(clientMinimized(KWin::Client*))); diff --git a/scripting/workspace_wrapper.h b/scripting/workspace_wrapper.h index 5562d2a5af..291ae141d9 100644 --- a/scripting/workspace_wrapper.h +++ b/scripting/workspace_wrapper.h @@ -24,6 +24,7 @@ along with this program. If not, see . #include #include +#include namespace KWin { @@ -33,6 +34,7 @@ class Client; class WorkspaceWrapper : public QObject { Q_OBJECT + Q_ENUMS(ClientAreaOption) Q_PROPERTY(int currentDesktop READ currentDesktop WRITE setCurrentDesktop NOTIFY currentDesktopChanged) Q_PROPERTY(KWin::Client *activeClient READ activeClient WRITE setActiveClient NOTIFY clientActivated) // TODO: write and notify? @@ -84,6 +86,28 @@ signals: void numberDesktopsChanged(int oldNumberOfDesktops); 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 + }; + WorkspaceWrapper(QObject* parent = 0); #define GETTERSETTERDEF( rettype, getter, setter ) \ rettype getter() const; \ @@ -103,6 +127,31 @@ void setter( rettype val ); QSize displaySize() const; Q_INVOKABLE QList< KWin::Client* > clientList() 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 Client* client) const; private Q_SLOTS: void setupClientConnections(KWin::Client* client);