ClientGroup becomes scriptable (again)
For this properties are defined in ClientGroup and several methods are changed to be slots (to be invokable from scripts). On Client the clientGroup is exported as a property. The existing wrapper around ClientGroup is dropped as it is no longer needed. Interestingly it was wrong anyway as it allowed to construct a new ClientGroup, which has to be done internally. At the same time the meta declarations get cleaned up a little bit.
This commit is contained in:
parent
3bc12489ac
commit
698eb631cd
10 changed files with 88 additions and 412 deletions
|
@ -123,7 +123,6 @@ if(KWIN_BUILD_SCRIPTING)
|
|||
scripting/scripting.cpp
|
||||
scripting/workspace.cpp
|
||||
scripting/meta.cpp
|
||||
scripting/s_clientgroup.cpp
|
||||
scripting/workspaceproxy.cpp
|
||||
scripting/timer.cpp
|
||||
)
|
||||
|
|
|
@ -1926,6 +1926,7 @@ void Client::setClientGroup(ClientGroup* group)
|
|||
unsigned long data[1] = {(unsigned long)workspace()->indexOfClientGroup(group)};
|
||||
XChangeProperty(display(), window(), atoms->kde_net_wm_tab_group, XA_CARDINAL, 32,
|
||||
PropModeReplace, (unsigned char*)(data), 1);
|
||||
emit clientGroupChanged();
|
||||
}
|
||||
|
||||
void Client::dontMoveResize()
|
||||
|
|
9
client.h
9
client.h
|
@ -218,6 +218,10 @@ class Client
|
|||
* Whether the Client should be excluded from window switching effects.
|
||||
**/
|
||||
Q_PROPERTY(bool skipSwitcher READ skipSwitcher WRITE setSkipSwitcher NOTIFY skipSwitcherChanged)
|
||||
/**
|
||||
* The "Window Tabs" Group this Client belongs to.
|
||||
**/
|
||||
Q_PROPERTY(KWin::ClientGroup* clientGroup READ clientGroup NOTIFY clientGroupChanged)
|
||||
public:
|
||||
Client(Workspace* ws);
|
||||
Window wrapperId() const;
|
||||
|
@ -641,6 +645,11 @@ signals:
|
|||
void moveResizedChanged();
|
||||
void iconChanged();
|
||||
void skipSwitcherChanged();
|
||||
/**
|
||||
* Emitted whenever the Client's ClientGroup changed. That is whenever the Client is moved to
|
||||
* another group, but not when a Client gets added or removed to the Client's ClientGroup.
|
||||
**/
|
||||
void clientGroupChanged();
|
||||
|
||||
private:
|
||||
void exportMappingState(int s); // ICCCM 4.1.3.1, 4.1.4, NETWM 2.5.1
|
||||
|
|
|
@ -266,6 +266,7 @@ void ClientGroup::setVisible(Client* c)
|
|||
for (ClientList::const_iterator i = clients_.constBegin(); i != clients_.constEnd(); ++i)
|
||||
if ((*i) != c)
|
||||
(*i)->setClientShown(false);
|
||||
emit visibleChanged();
|
||||
}
|
||||
|
||||
void ClientGroup::updateStates(Client* main, Client* only)
|
||||
|
@ -331,6 +332,9 @@ void ClientGroup::updateMinMaxSize()
|
|||
//kWarning(1212) << "ClientGroup's min size is greater than its max size. Setting max to min.";
|
||||
maxSize_ = minSize_;
|
||||
}
|
||||
// TODO: only emit if really changed
|
||||
emit minSizeChanged();
|
||||
emit maxSizeChanged();
|
||||
|
||||
// Ensure all windows are within these sizes
|
||||
const QSize size = clients_[visible_]->clientSize();
|
||||
|
|
|
@ -53,6 +53,22 @@ class Client;
|
|||
class ClientGroup : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
/**
|
||||
* Currently visible client in this group.
|
||||
**/
|
||||
Q_PROPERTY(KWin::Client* visible READ visible WRITE setVisible NOTIFY visibleChanged)
|
||||
/**
|
||||
* Combined minimum size of all clients in the group.
|
||||
**/
|
||||
Q_PROPERTY(QSize minSize READ minSize NOTIFY minSizeChanged)
|
||||
/**
|
||||
* Combined maximum size of all clients in the group.
|
||||
**/
|
||||
Q_PROPERTY(QSize maxSize READ maxSize NOTIFY maxSizeChanged)
|
||||
/**
|
||||
* The index of the visible Client in this group.
|
||||
**/
|
||||
Q_PROPERTY(int visibleClientIndex READ indexOfVisibleClient NOTIFY visibleChanged)
|
||||
public:
|
||||
/**
|
||||
* Creates a new group containing \p c.
|
||||
|
@ -60,11 +76,12 @@ public:
|
|||
ClientGroup(Client* c);
|
||||
~ClientGroup();
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Adds \p c to the group before \p before in the list. If \p becomeVisible is \i true then
|
||||
* the added client will become also the visible client.
|
||||
*/
|
||||
void add(Client* c, int before = -1, bool becomeVisible = false);
|
||||
void add(KWin::Client* c, int before = -1, bool becomeVisible = false);
|
||||
/**
|
||||
* Remove the client at index \p index from the group. If \p newGeom is set then the client
|
||||
* will move and resize to the specified geometry, otherwise it will stay where the group
|
||||
|
@ -77,7 +94,7 @@ public:
|
|||
* the specified geometry, otherwise it will stay where the group is located. If
|
||||
* \p toNullGroup is not true then the client will be added to a new group of its own.
|
||||
*/
|
||||
void remove(Client* c, const QRect& newGeom = QRect(), bool toNullGroup = false);
|
||||
void remove(KWin::Client* c, const QRect& newGeom = QRect(), bool toNullGroup = false);
|
||||
/**
|
||||
* Remove all clients from this group. Results in all clients except the first being moved
|
||||
to a group of their own.
|
||||
|
@ -95,7 +112,7 @@ public:
|
|||
/**
|
||||
* Move \p c to the position before \p before in the list.
|
||||
*/
|
||||
void move(Client* c, Client* before);
|
||||
void move(KWin::Client* c, KWin::Client* before);
|
||||
/**
|
||||
* Display the right-click client menu belonging to the client at index \p index at the
|
||||
* global coordinates specified by \p pos.
|
||||
|
@ -105,12 +122,13 @@ public:
|
|||
* Display the right-click client menu belonging to \p c at the global coordinates
|
||||
* specified by \p pos.
|
||||
*/
|
||||
void displayClientMenu(Client* c, const QPoint& pos);
|
||||
void displayClientMenu(KWin::Client* c, const QPoint& pos);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Returns the list index of \p c.
|
||||
*/
|
||||
int indexOfClient(Client* c);
|
||||
Q_SCRIPTABLE int indexOfClient(KWin::Client* c);
|
||||
/**
|
||||
* Returns the list index of the currently visible client in the group.
|
||||
*/
|
||||
|
@ -118,7 +136,7 @@ public:
|
|||
/**
|
||||
* Returns whether or not this group contains \p c.
|
||||
*/
|
||||
bool contains(Client* c);
|
||||
Q_SCRIPTABLE bool contains(KWin::Client* c);
|
||||
/**
|
||||
* Returns whether or not this group contains the active client.
|
||||
*/
|
||||
|
@ -163,6 +181,20 @@ public:
|
|||
*/
|
||||
void updateStates(Client* main, Client* only = NULL);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Emitted when the visible Client in this group changes.
|
||||
**/
|
||||
void visibleChanged();
|
||||
/**
|
||||
* Emitted when the group's minimum size changes.
|
||||
**/
|
||||
void minSizeChanged();
|
||||
/**
|
||||
* Emitted when the group's maximum size changes.
|
||||
**/
|
||||
void maxSizeChanged();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Regenerate the list of client captions and icons.
|
||||
|
@ -224,5 +256,7 @@ inline QSize ClientGroup::maxSize() const
|
|||
}
|
||||
|
||||
}
|
||||
Q_DECLARE_METATYPE(KWin::ClientGroup*)
|
||||
Q_DECLARE_METATYPE(QList<KWin::ClientGroup*>)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,27 +19,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*********************************************************************/
|
||||
|
||||
#include "meta.h"
|
||||
#include "client.h"
|
||||
#include "clientgroup.h"
|
||||
|
||||
Q_DECLARE_METATYPE(SWrapper::ClientGroup*)
|
||||
#include <QtScript/QScriptEngine>
|
||||
|
||||
using namespace KWin::MetaScripting;
|
||||
|
||||
// Meta for KWin::ClientGroup* objects
|
||||
QScriptValue ClientGroup::toScriptValue(QScriptEngine* eng, const KClientGroupRef& cGrp)
|
||||
{
|
||||
return SWrapper::ClientGroup::generate(eng, new SWrapper::ClientGroup(cGrp));
|
||||
return eng->newQObject(cGrp, QScriptEngine::QtOwnership,
|
||||
QScriptEngine::ExcludeChildObjects | QScriptEngine::ExcludeDeleteLater | QScriptEngine::PreferExistingWrapperObject);
|
||||
}
|
||||
|
||||
void ClientGroup::fromScriptValue(const QScriptValue& obj, KWin::ClientGroup*& cGrp)
|
||||
{
|
||||
SWrapper::ClientGroup* wrapper = qscriptvalue_cast<SWrapper::ClientGroup*>(obj);
|
||||
|
||||
if (wrapper == 0) {
|
||||
cGrp = 0;
|
||||
} else {
|
||||
cGrp = wrapper->getCentralObject();
|
||||
}
|
||||
cGrp = qobject_cast<KWin::ClientGroup*>(obj.toQObject());
|
||||
}
|
||||
// End of metas for KWin::ClientGroup* objects
|
||||
|
||||
|
@ -114,12 +110,24 @@ void Rect::fromScriptValue(const QScriptValue& obj, QRect &rect)
|
|||
}
|
||||
// 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);
|
||||
}
|
||||
|
||||
void Client::fromScriptValue(const QScriptValue &value, KWin::Client* &client)
|
||||
{
|
||||
client = qobject_cast<KWin::Client*>(value.toQObject());
|
||||
}
|
||||
|
||||
// Other helper functions
|
||||
void KWin::MetaScripting::registration(QScriptEngine* eng)
|
||||
{
|
||||
qScriptRegisterMetaType<QPoint>(eng, Point::toScriptValue, Point::fromScriptValue);
|
||||
qScriptRegisterMetaType<QSize>(eng, Size::toScriptValue, Size::fromScriptValue);
|
||||
qScriptRegisterMetaType<QRect>(eng, Rect::toScriptValue, Rect::fromScriptValue);
|
||||
qScriptRegisterMetaType<KClientRef>(eng, Client::toScriptValue, Client::fromScriptValue);
|
||||
qScriptRegisterMetaType<KClientGroupRef>(eng, ClientGroup::toScriptValue, ClientGroup::fromScriptValue);
|
||||
|
||||
qScriptRegisterSequenceMetaType<QStringList>(eng);
|
||||
|
|
|
@ -21,17 +21,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#ifndef KWIN_SCRIPTING_META_H
|
||||
#define KWIN_SCRIPTING_META_H
|
||||
|
||||
#include "s_clientgroup.h"
|
||||
#include <QStringList>
|
||||
#include <QScriptValueIterator>
|
||||
|
||||
typedef KWin::ClientGroup* KClientGroupRef;
|
||||
// forward declarations
|
||||
class QPoint;
|
||||
class QRect;
|
||||
class QScriptContext;
|
||||
class QSize;
|
||||
|
||||
Q_DECLARE_METATYPE(QPoint)
|
||||
Q_DECLARE_METATYPE(QSize)
|
||||
Q_DECLARE_METATYPE(QRect)
|
||||
Q_DECLARE_METATYPE(KClientGroupRef)
|
||||
Q_DECLARE_METATYPE(QList<KWin::ClientGroup*>)
|
||||
namespace KWin {
|
||||
class Client;
|
||||
class ClientGroup;
|
||||
}
|
||||
|
||||
typedef KWin::Client* KClientRef;
|
||||
typedef KWin::ClientGroup* KClientGroupRef;
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
|
@ -80,6 +84,11 @@ QScriptValue toScriptValue(QScriptEngine*, const QRect&);
|
|||
void fromScriptValue(const QScriptValue&, QRect&);
|
||||
}
|
||||
|
||||
namespace Client
|
||||
{
|
||||
QScriptValue toScriptValue(QScriptEngine *eng, const KClientRef &client);
|
||||
void fromScriptValue(const QScriptValue &value, KClientRef& client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the second QScriptValue in the first one.
|
||||
|
|
|
@ -1,309 +0,0 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2010 Rohan Prabhu <rohan@rohanprabhu.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
|
||||
#include "s_clientgroup.h"
|
||||
#include "meta.h"
|
||||
#include "workspace.h"
|
||||
|
||||
Q_DECLARE_METATYPE(SWrapper::ClientGroup*)
|
||||
|
||||
SWrapper::ClientGroup::ClientGroup(KWin::ClientGroup* group)
|
||||
{
|
||||
centralObject = group;
|
||||
|
||||
if (group == 0) {
|
||||
invalid = true;
|
||||
} else {
|
||||
setParent(group);
|
||||
invalid = false;
|
||||
}
|
||||
}
|
||||
|
||||
SWrapper::ClientGroup::ClientGroup(KWin::Client* client)
|
||||
{
|
||||
if (client == 0) {
|
||||
invalid = true;
|
||||
centralObject = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
KWin::ClientGroup* cGrp = client->clientGroup();
|
||||
|
||||
if (cGrp == 0) {
|
||||
cGrp = new KWin::ClientGroup(client);
|
||||
}
|
||||
|
||||
centralObject = cGrp;
|
||||
setParent(cGrp);
|
||||
invalid = false;
|
||||
}
|
||||
|
||||
KWin::ClientGroup* SWrapper::ClientGroup::getCentralObject()
|
||||
{
|
||||
return centralObject;
|
||||
}
|
||||
|
||||
/*
|
||||
* This was just to check how bindings were working..
|
||||
* Nothing to see here
|
||||
*
|
||||
QScriptValue SWrapper::ClientGroup::toString(QScriptContext* ctx, QScriptEngine* eng) {
|
||||
SWrapper::ClientGroup* self = qscriptvalue_cast<SWrapper::ClientGroup*>(ctx->thisObject());
|
||||
qDebug()<<"Generic object at ["<<(void*)self<<"]";
|
||||
|
||||
if (self != 0) {
|
||||
qDebug()<<" Wrapping: ["<<(void*)(self->centralObject)<<"] (i: "<<self->invalid<<")";
|
||||
}
|
||||
|
||||
return QScriptValue(eng, QString("."));
|
||||
}
|
||||
*/
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::add(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::Client* client = qobject_cast<KWin::Client*>(ctx->argument(0).toQObject());
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
|
||||
if ((client == 0) || (cGrp == 0)) {
|
||||
return QScriptValue(eng, (bool)0);
|
||||
} else {
|
||||
int before = (ctx->argument(1)).isUndefined() ? (-1) : ((ctx->argument(0)).toNumber());
|
||||
bool becomeVisible = (ctx->argument(2)).isUndefined() ? (false) : ((ctx->argument(0)).toBool());
|
||||
|
||||
if (client->clientGroup()) {
|
||||
(client->clientGroup())->remove(client);
|
||||
}
|
||||
|
||||
cGrp->add(client, before, becomeVisible);
|
||||
return QScriptValue(eng, (bool)1);
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::remove(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
QScriptValue arg = ctx->argument(0);
|
||||
QRect geom = eng->fromScriptValue<QRect>(ctx->argument(1));
|
||||
|
||||
if (cGrp == 0) {
|
||||
return eng->toScriptValue<bool>(0);
|
||||
}
|
||||
|
||||
if (arg.isNumber()) {
|
||||
cGrp->remove(arg.toNumber(), geom, false);
|
||||
return eng->toScriptValue<bool>(1);
|
||||
} else {
|
||||
KWin::Client* client = qobject_cast<KWin::Client*>(arg.toQObject());
|
||||
|
||||
if (client == 0) {
|
||||
return eng->toScriptValue<bool>(0);
|
||||
} else {
|
||||
cGrp->remove(client, geom, false);
|
||||
return eng->toScriptValue<bool>(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::contains(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
|
||||
if (cGrp == 0) {
|
||||
return QScriptValue();
|
||||
} else {
|
||||
KWin::Client* client = qobject_cast<KWin::Client*>(ctx->argument(0).toQObject());
|
||||
|
||||
if (client == 0) {
|
||||
return QScriptValue();
|
||||
} else {
|
||||
return eng->toScriptValue<bool>(cGrp->contains(client));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::indexOf(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
|
||||
if (cGrp == 0) {
|
||||
return QScriptValue();
|
||||
} else {
|
||||
KWin::Client* client = qobject_cast<KWin::Client*>(ctx->argument(0).toQObject());
|
||||
|
||||
if (client == 0) {
|
||||
return QScriptValue();
|
||||
} else {
|
||||
return eng->toScriptValue<int>(cGrp->indexOfClient(client));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::move(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
|
||||
// This is one weird function. It can be called like:
|
||||
// move(client, client) OR move(client, index) OR move(index, client)
|
||||
// move(index, index)
|
||||
// NOTE: other than move(client, client), all other calls are mapped to
|
||||
// move(index, index) using indexof(client)
|
||||
|
||||
QScriptValue arg1 = ctx->argument(0);
|
||||
QScriptValue arg2 = ctx->argument(1);
|
||||
|
||||
KWin::Client* cl1 = qobject_cast<KWin::Client*>(arg1.toQObject());
|
||||
KWin::Client* cl2 = qobject_cast<KWin::Client*>(arg2.toQObject());
|
||||
|
||||
if (cl1 != 0) {
|
||||
if (cl2 == 0) {
|
||||
if (!(arg2.isNumber())) {
|
||||
return eng->toScriptValue<bool>(0);
|
||||
} else {
|
||||
cGrp->move(cGrp->indexOfClient(cl1), (int)arg2.toNumber());
|
||||
return eng->toScriptValue<bool>(1);
|
||||
}
|
||||
} else {
|
||||
cGrp->move(cl1, cl2);
|
||||
return eng->toScriptValue<bool>(1);
|
||||
}
|
||||
} else {
|
||||
if (!(arg1.isNumber())) {
|
||||
return eng->toScriptValue<bool>(0);
|
||||
} else {
|
||||
if (cl2 != 0) {
|
||||
cGrp->move((int)arg1.toNumber(), cGrp->indexOfClient(cl2));
|
||||
return eng->toScriptValue<bool>(1);
|
||||
} else {
|
||||
if (!arg2.isNumber()) {
|
||||
return eng->toScriptValue<bool>(0);
|
||||
} else {
|
||||
cGrp->move((int)arg1.toNumber(), (int)arg2.toNumber());
|
||||
return eng->toScriptValue<bool>(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::removeAll(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
|
||||
if (cGrp == 0) {
|
||||
return eng->toScriptValue<bool>(0);
|
||||
} else {
|
||||
cGrp->removeAll();
|
||||
return eng->toScriptValue<bool>(1);
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::closeAll(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
|
||||
if (cGrp == 0) {
|
||||
return eng->toScriptValue<bool>(0);
|
||||
} else {
|
||||
cGrp->closeAll();
|
||||
return eng->toScriptValue<bool>(1);
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::minSize(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
|
||||
if (cGrp == 0) {
|
||||
return QScriptValue();
|
||||
} else {
|
||||
return eng->toScriptValue<QSize>(cGrp->minSize());
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::maxSize(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
|
||||
if (cGrp == 0) {
|
||||
return QScriptValue();
|
||||
} else {
|
||||
return eng->toScriptValue<QSize>(cGrp->maxSize());
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::clients(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
|
||||
if (cGrp == 0) {
|
||||
return QScriptValue();
|
||||
} else {
|
||||
KWin::ClientList clients = cGrp->clients();
|
||||
QScriptValue value = eng->newArray(clients.size());
|
||||
for (int i=0; i<clients.size(); ++i) {
|
||||
value.setProperty(i, SWrapper::valueForClient(clients.at(i), eng));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::visible(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
KWin::ClientGroup* cGrp = qscriptvalue_cast<KWin::ClientGroup*>(ctx->thisObject());
|
||||
|
||||
if (cGrp == 0) {
|
||||
return QScriptValue();
|
||||
} else {
|
||||
return valueForClient(cGrp->visible(), eng);
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::generate(QScriptEngine* eng, SWrapper::ClientGroup* cGroup)
|
||||
{
|
||||
QScriptValue temp = eng->newQObject(cGroup, QScriptEngine::AutoOwnership);
|
||||
|
||||
temp.setProperty("add", eng->newFunction(add, 3), QScriptValue::Undeletable);
|
||||
temp.setProperty("remove", eng->newFunction(remove, 1), QScriptValue::Undeletable);
|
||||
temp.setProperty("clients", eng->newFunction(clients, 0), QScriptValue::Undeletable);
|
||||
temp.setProperty("contains", eng->newFunction(contains, 1), QScriptValue::Undeletable);
|
||||
temp.setProperty("indexOf", eng->newFunction(indexOf, 1), QScriptValue::Undeletable);
|
||||
temp.setProperty("move", eng->newFunction(move, 2), QScriptValue::Undeletable);
|
||||
temp.setProperty("removeAll", eng->newFunction(removeAll, 0), QScriptValue::Undeletable);
|
||||
temp.setProperty("closeAll", eng->newFunction(closeAll, 0), QScriptValue::Undeletable);
|
||||
temp.setProperty("minSize", eng->newFunction(minSize, 0), QScriptValue::Undeletable);
|
||||
temp.setProperty("maxSize", eng->newFunction(maxSize, 0), QScriptValue::Undeletable);
|
||||
temp.setProperty("visible", eng->newFunction(visible, 0), QScriptValue::Undeletable);
|
||||
return temp;
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::construct(QScriptContext* ctx, QScriptEngine* eng)
|
||||
{
|
||||
return generate(eng, new SWrapper::ClientGroup(
|
||||
qobject_cast<KWin::Client*>(ctx->argument(0).toQObject())
|
||||
));
|
||||
}
|
||||
|
||||
QScriptValue SWrapper::ClientGroup::publishClientGroupClass(QScriptEngine* eng)
|
||||
{
|
||||
QScriptValue proto = generate(eng, new SWrapper::ClientGroup((KWin::ClientGroup*)0));
|
||||
eng->setDefaultPrototype(qMetaTypeId<SWrapper::ClientGroup*>(), proto);
|
||||
|
||||
return eng->newFunction(construct, proto);
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
/********************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2010 Rohan Prabhu <rohan@rohanprabhu.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************/
|
||||
|
||||
#ifndef KWIN_SCRIPTING_S_CLIENTGROUP_H
|
||||
#define KWIN_SCRIPTING_S_CLIENTGROUP_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QScriptEngine>
|
||||
#include "client.h"
|
||||
#include "clientgroup.h"
|
||||
|
||||
namespace SWrapper
|
||||
{
|
||||
|
||||
class ClientGroup : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
KWin::ClientGroup* centralObject;
|
||||
bool invalid;
|
||||
|
||||
public:
|
||||
ClientGroup(KWin::ClientGroup*);
|
||||
ClientGroup(KWin::Client*);
|
||||
|
||||
KWin::ClientGroup* getCentralObject();
|
||||
|
||||
/**
|
||||
* A lot of functions for the KWin::ClientGroup* object.
|
||||
* Mostly self-explanatory, works exactly like their C++
|
||||
* analogues.
|
||||
*/
|
||||
static QScriptValue add(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue remove(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue clients(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue setVisible(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue contains(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue indexOf(QScriptContext*, QScriptEngine*);
|
||||
|
||||
/** This is one weird function. It can be called like:
|
||||
* move(client, client) OR move(client, index) OR move(index, client)
|
||||
* move(index, index)
|
||||
* NOTE: other than move(client, client), all other calls are mapped to
|
||||
* move(index, index) using indexof(client)
|
||||
*/
|
||||
static QScriptValue move(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue removeAll(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue closeAll(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue minSize(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue maxSize(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue visible(QScriptContext*, QScriptEngine*);
|
||||
|
||||
static QScriptValue construct(QScriptContext*, QScriptEngine*);
|
||||
static QScriptValue generate(QScriptEngine*, SWrapper::ClientGroup*);
|
||||
static QScriptValue publishClientGroupClass(QScriptEngine*);
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
|
@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include "scripting.h"
|
||||
// own
|
||||
#include "meta.h"
|
||||
#include "s_clientgroup.h"
|
||||
// KDE
|
||||
#include <kstandarddirs.h>
|
||||
// Qt
|
||||
|
@ -79,7 +78,6 @@ void KWin::Script::run()
|
|||
if (m_scriptFile.open(QIODevice::ReadOnly)) {
|
||||
m_workspace->attach(m_engine);
|
||||
m_engine->globalObject().setProperty("QTimer", constructTimerClass(m_engine));
|
||||
m_engine->globalObject().setProperty("ClientGroup", SWrapper::ClientGroup::publishClientGroupClass(m_engine));
|
||||
QObject::connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), this, SLOT(sigException(QScriptValue)));
|
||||
KWin::MetaScripting::registration(m_engine);
|
||||
|
||||
|
|
Loading…
Reference in a new issue