2010-09-21 14:31:40 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2010 Rohan Prabhu <rohan@rohanprabhu.com>
|
2011-12-18 20:21:31 +00:00
|
|
|
Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
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 "workspace.h"
|
|
|
|
#include "meta.h"
|
|
|
|
|
|
|
|
KWin::Workspace* SWrapper::Workspace::centralObject = 0;
|
2011-12-18 20:21:31 +00:00
|
|
|
|
|
|
|
QScriptValue SWrapper::valueForClient(KWin::Client *client, QScriptEngine *engine) {
|
|
|
|
return engine->newQObject(client);
|
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
SWrapper::Workspace::Workspace(QObject* parent) : QObject(parent)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralObject == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-09-21 14:31:40 +00:00
|
|
|
SWrapper::WorkspaceProxy* proxy = SWrapper::WorkspaceProxy::instance();
|
|
|
|
|
2011-08-17 21:51:55 +00:00
|
|
|
QObject::connect(centralObject, SIGNAL(desktopPresenceChanged(KWin::Client*,int)),
|
|
|
|
this, SLOT(sl_desktopPresenceChanged(KWin::Client*,int))
|
2010-09-21 14:31:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
QObject::connect(centralObject, SIGNAL(currentDesktopChanged(int)),
|
|
|
|
this, SLOT(sl_currentDesktopChanged(int))
|
|
|
|
);
|
|
|
|
|
|
|
|
QObject::connect(centralObject, SIGNAL(clientAdded(KWin::Client*)),
|
|
|
|
this, SLOT(sl_clientAdded(KWin::Client*))
|
|
|
|
);
|
|
|
|
|
|
|
|
QObject::connect(centralObject, SIGNAL(clientRemoved(KWin::Client*)),
|
|
|
|
this, SLOT(sl_clientRemoved(KWin::Client*))
|
|
|
|
);
|
|
|
|
|
|
|
|
QObject::connect(centralObject, SIGNAL(clientActivated(KWin::Client*)),
|
|
|
|
this, SLOT(sl_clientActivated(KWin::Client*))
|
|
|
|
);
|
|
|
|
|
|
|
|
QObject::connect(centralObject, SIGNAL(groupAdded(KWin::Group*)),
|
|
|
|
this, SLOT(sl_groupAdded(KWin::Group*))
|
|
|
|
);
|
|
|
|
|
|
|
|
QObject::connect(proxy, SIGNAL(clientMinimized(KWin::Client*)),
|
|
|
|
this, SLOT(sl_clientMinimized(KWin::Client*))
|
|
|
|
);
|
|
|
|
|
|
|
|
QObject::connect(proxy, SIGNAL(clientUnminimized(KWin::Client*)),
|
|
|
|
this, SLOT(sl_clientUnminimized(KWin::Client*))
|
|
|
|
);
|
|
|
|
|
2011-08-17 21:51:55 +00:00
|
|
|
QObject::connect(proxy, SIGNAL(clientMaximizeSet(KWin::Client*,QPair<bool,bool>)),
|
|
|
|
this, SLOT(sl_clientMaximizeSet(KWin::Client*,QPair<bool,bool>))
|
2010-09-21 14:31:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
QObject::connect(proxy, SIGNAL(clientManaging(KWin::Client*)),
|
|
|
|
this, SLOT(sl_clientManaging(KWin::Client*))
|
|
|
|
);
|
|
|
|
|
|
|
|
QObject::connect(proxy, SIGNAL(killWindowCalled(KWin::Client*)),
|
|
|
|
this, SLOT(sl_killWindowCalled(KWin::Client*))
|
|
|
|
);
|
|
|
|
|
2011-08-17 21:51:55 +00:00
|
|
|
QObject::connect(proxy, SIGNAL(clientFullScreenSet(KWin::Client*,bool,bool)),
|
|
|
|
this, SLOT(sl_clientFullScreenSet(KWin::Client*,bool,bool))
|
2010-09-21 14:31:40 +00:00
|
|
|
);
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2011-08-17 21:51:55 +00:00
|
|
|
QObject::connect(proxy, SIGNAL(clientSetKeepAbove(KWin::Client*,bool)),
|
|
|
|
this, SLOT(sl_clientSetKeepAbove(KWin::Client*,bool))
|
2010-10-29 19:06:54 +00:00
|
|
|
);
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_desktopPresenceChanged(KWin::Client* client, int prev_desk)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
emit desktopPresenceChanged(valueForClient(client, centralEngine),
|
2010-09-21 14:31:40 +00:00
|
|
|
centralEngine->toScriptValue(prev_desk)
|
|
|
|
);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_clientAdded(KWin::Client* client)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
emit clientAdded(valueForClient(client, centralEngine));
|
2010-09-21 14:31:40 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_clientFullScreenSet(KWin::Client* client, bool set, bool user)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
emit clientFullScreenSet(valueForClient(client, centralEngine),
|
2010-09-21 14:31:40 +00:00
|
|
|
centralEngine->toScriptValue<bool>(set),
|
|
|
|
centralEngine->toScriptValue<bool>(user)
|
|
|
|
);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2010-10-29 19:06:54 +00:00
|
|
|
void SWrapper::Workspace::sl_clientSetKeepAbove(KWin::Client* client, bool set)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-10-29 19:06:54 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
emit clientSetKeepAbove(valueForClient(client, centralEngine),
|
2010-10-29 19:06:54 +00:00
|
|
|
centralEngine->toScriptValue<bool>(set)
|
|
|
|
);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_currentDesktopChanged(int prev_desk)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-09-21 14:31:40 +00:00
|
|
|
emit currentDesktopChanged(centralEngine->toScriptValue(prev_desk));
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_clientRemoved(KWin::Client* client)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
emit clientRemoved(valueForClient(client, centralEngine));
|
2010-09-21 14:31:40 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_clientManaging(KWin::Client* client)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
emit clientManaging(valueForClient(client, centralEngine));
|
2010-09-21 14:31:40 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_clientMinimized(KWin::Client* client)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
emit clientMinimized(valueForClient(client, centralEngine));
|
2010-09-21 14:31:40 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_clientUnminimized(KWin::Client* client)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
emit clientUnminimized(valueForClient(client, centralEngine));
|
|
|
|
emit clientRestored(valueForClient(client, centralEngine));
|
2010-09-21 14:31:40 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_clientMaximizeSet(KWin::Client* client, QPair<bool, bool> param)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-09-21 14:31:40 +00:00
|
|
|
QScriptValue temp = centralEngine->newObject();
|
|
|
|
temp.setProperty("v", centralEngine->toScriptValue(param.first));
|
|
|
|
temp.setProperty("h", centralEngine->toScriptValue(param.second));
|
2011-12-18 20:21:31 +00:00
|
|
|
emit clientMaximizeSet(valueForClient(client, centralEngine), temp);
|
2010-09-21 14:31:40 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_killWindowCalled(KWin::Client* client)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
emit killWindowCalled(valueForClient(client, centralEngine));
|
2010-09-21 14:31:40 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_clientActivated(KWin::Client* client)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (centralEngine == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
emit clientActivated(valueForClient(client, centralEngine));
|
2010-09-21 14:31:40 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::sl_groupAdded(KWin::Group* group)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-09-21 14:31:40 +00:00
|
|
|
Q_UNUSED(group);
|
|
|
|
//TODO
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
bool SWrapper::Workspace::initialize(KWin::Workspace* wspace)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (wspace == 0) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-09-21 14:31:40 +00:00
|
|
|
SWrapper::Workspace::centralObject = wspace;
|
|
|
|
return true;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
QScriptValue SWrapper::Workspace::getAllClients(QScriptContext* ctx, QScriptEngine* eng)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-12-18 20:21:31 +00:00
|
|
|
const KWin::ClientList x = centralObject->stackingOrder();
|
2010-09-21 14:31:40 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (ctx->argumentCount() == 0) {
|
2011-12-18 20:21:31 +00:00
|
|
|
QScriptValue array = eng->newArray(x.size());
|
|
|
|
for (int i=0; i<x.size(); ++i) {
|
|
|
|
array.setProperty(i, valueForClient(x.at(i), eng));
|
|
|
|
}
|
|
|
|
return array;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-09-21 14:31:40 +00:00
|
|
|
KWin::ClientList ret;
|
|
|
|
int desk_no = (ctx->argument(0)).toNumber();
|
2011-01-30 14:34:42 +00:00
|
|
|
if ((desk_no >= 1) && (desk_no > SWrapper::Workspace::centralObject->numberOfDesktops())) {
|
2010-09-21 14:31:40 +00:00
|
|
|
return QScriptValue();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-12-18 20:21:31 +00:00
|
|
|
QScriptValue array = eng->newArray();
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < x.size(); i++) {
|
|
|
|
if (x.at(i)->desktop() == desk_no) {
|
2010-09-21 14:31:40 +00:00
|
|
|
ret.append(x.at(i));
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-12-18 20:21:31 +00:00
|
|
|
for (int i=0; i<ret.size(); ++i) {
|
|
|
|
array.setProperty(i, valueForClient(ret.at(i), eng));
|
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
2011-12-18 20:21:31 +00:00
|
|
|
return array;
|
2010-09-21 14:31:40 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
QScriptValue SWrapper::Workspace::activeClient(QScriptContext* ctx, QScriptEngine* eng)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-09-21 14:31:40 +00:00
|
|
|
Q_UNUSED(ctx);
|
2011-12-18 20:21:31 +00:00
|
|
|
return valueForClient(centralObject->activeClient(), eng);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
QScriptValue SWrapper::Workspace::setCurrentDesktop(QScriptContext* ctx, QScriptEngine* /*eng*/)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (ctx->argumentCount() >= 1) {
|
|
|
|
int num = ((ctx->argument(0)).isNumber()) ? ((ctx->argument(0)).toNumber()) : (-1);
|
|
|
|
if (num != -1) {
|
2010-09-21 14:31:40 +00:00
|
|
|
centralObject->setCurrentDesktop(num);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
return QScriptValue();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
QScriptValue SWrapper::Workspace::dimensions(QScriptContext* ctx, QScriptEngine* eng)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-09-21 14:31:40 +00:00
|
|
|
Q_UNUSED(ctx);
|
|
|
|
return eng->toScriptValue(QSize(centralObject->workspaceWidth(), centralObject->workspaceHeight()));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
QScriptValue SWrapper::Workspace::desktopGridSize(QScriptContext* ctx, QScriptEngine* eng)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-09-21 14:31:40 +00:00
|
|
|
Q_UNUSED(ctx);
|
|
|
|
return eng->toScriptValue(centralObject->desktopGridSize());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
QScriptValue SWrapper::Workspace::clientGroups(QScriptContext* ctx, QScriptEngine* eng)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-09-21 14:31:40 +00:00
|
|
|
Q_UNUSED(ctx);
|
|
|
|
return eng->toScriptValue<QList<KWin::ClientGroup*> >(centralObject->clientGroups);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
int SWrapper::Workspace::currentDesktop() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-09-21 14:31:40 +00:00
|
|
|
return centralObject->currentDesktop();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-21 14:31:40 +00:00
|
|
|
|
|
|
|
void SWrapper::Workspace::attach(QScriptEngine* engine)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-09-21 14:31:40 +00:00
|
|
|
QScriptValue func;
|
|
|
|
centralEngine = engine;
|
|
|
|
|
|
|
|
QScriptValue self = engine->newQObject(
|
|
|
|
this,
|
|
|
|
QScriptEngine::QtOwnership,
|
|
|
|
QScriptEngine::ExcludeSuperClassContents | QScriptEngine::ExcludeDeleteLater
|
|
|
|
);
|
|
|
|
|
|
|
|
func = engine->newFunction(setCurrentDesktop, 1);
|
|
|
|
self.setProperty("setCurrentDesktop", func, QScriptValue::Undeletable);
|
|
|
|
|
|
|
|
func = engine->newFunction(getAllClients, 0);
|
|
|
|
self.setProperty("getAllClients", func, QScriptValue::Undeletable);
|
|
|
|
|
|
|
|
func = engine->newFunction(dimensions, 0);
|
|
|
|
self.setProperty("dimensions", func, QScriptValue::Undeletable);
|
|
|
|
|
|
|
|
func = engine->newFunction(desktopGridSize, 0);
|
|
|
|
self.setProperty("desktopGridSize", func, QScriptValue::Undeletable);
|
|
|
|
self.setProperty("activeClient", engine->newFunction(activeClient, 0), QScriptValue::Undeletable);
|
|
|
|
self.setProperty("clientGroups", engine->newFunction(clientGroups, 0), QScriptValue::Undeletable);
|
|
|
|
|
|
|
|
(engine->globalObject()).setProperty("workspace", self, QScriptValue::Undeletable);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|