1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2010 Rohan Prabhu <rohan@rohanprabhu.com>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*********************************************************************/
21
#include "workspace.h"
24
KWin::Workspace* SWrapper::Workspace::centralObject = 0;
25
SWrapper::Client* SWrapper::Workspace::clientHolder = 0;
27
SWrapper::Workspace::Workspace(QObject* parent) : QObject(parent)
29
if (centralObject == 0) {
32
SWrapper::WorkspaceProxy* proxy = SWrapper::WorkspaceProxy::instance();
34
QObject::connect(centralObject, SIGNAL(desktopPresenceChanged(KWin::Client*, int)),
35
this, SLOT(sl_desktopPresenceChanged(KWin::Client*, int))
38
QObject::connect(centralObject, SIGNAL(currentDesktopChanged(int)),
39
this, SLOT(sl_currentDesktopChanged(int))
42
QObject::connect(centralObject, SIGNAL(clientAdded(KWin::Client*)),
43
this, SLOT(sl_clientAdded(KWin::Client*))
46
QObject::connect(centralObject, SIGNAL(clientRemoved(KWin::Client*)),
47
this, SLOT(sl_clientRemoved(KWin::Client*))
50
QObject::connect(centralObject, SIGNAL(clientActivated(KWin::Client*)),
51
this, SLOT(sl_clientActivated(KWin::Client*))
54
QObject::connect(centralObject, SIGNAL(groupAdded(KWin::Group*)),
55
this, SLOT(sl_groupAdded(KWin::Group*))
58
QObject::connect(proxy, SIGNAL(clientMinimized(KWin::Client*)),
59
this, SLOT(sl_clientMinimized(KWin::Client*))
62
QObject::connect(proxy, SIGNAL(clientUnminimized(KWin::Client*)),
63
this, SLOT(sl_clientUnminimized(KWin::Client*))
66
QObject::connect(proxy, SIGNAL(clientMaximizeSet(KWin::Client*, QPair<bool, bool>)),
67
this, SLOT(sl_clientMaximizeSet(KWin::Client*, QPair<bool, bool>))
70
QObject::connect(proxy, SIGNAL(clientManaging(KWin::Client*)),
71
this, SLOT(sl_clientManaging(KWin::Client*))
74
QObject::connect(proxy, SIGNAL(killWindowCalled(KWin::Client*)),
75
this, SLOT(sl_killWindowCalled(KWin::Client*))
78
QObject::connect(proxy, SIGNAL(clientFullScreenSet(KWin::Client*, bool, bool)),
79
this, SLOT(sl_clientFullScreenSet(KWin::Client*, bool, bool))
82
QObject::connect(proxy, SIGNAL(clientSetKeepAbove(KWin::Client*, bool)),
83
this, SLOT(sl_clientSetKeepAbove(KWin::Client*, bool))
90
void SWrapper::Workspace::sl_desktopPresenceChanged(KWin::Client* client, int prev_desk)
92
if (centralEngine == 0) {
95
emit desktopPresenceChanged(centralEngine->toScriptValue(client),
96
centralEngine->toScriptValue(prev_desk)
101
void SWrapper::Workspace::sl_clientAdded(KWin::Client* client)
103
if (centralEngine == 0) {
106
emit clientAdded(centralEngine->toScriptValue(client));
110
void SWrapper::Workspace::sl_clientFullScreenSet(KWin::Client* client, bool set, bool user)
112
if (centralEngine == 0) {
115
emit clientFullScreenSet(centralEngine->toScriptValue<KWin::Client*>(client),
116
centralEngine->toScriptValue<bool>(set),
117
centralEngine->toScriptValue<bool>(user)
122
void SWrapper::Workspace::sl_clientSetKeepAbove(KWin::Client* client, bool set)
124
if (centralEngine == 0) {
127
emit clientSetKeepAbove(centralEngine->toScriptValue<KWin::Client*>(client),
128
centralEngine->toScriptValue<bool>(set)
133
void SWrapper::Workspace::sl_currentDesktopChanged(int prev_desk)
135
if (centralEngine == 0) {
138
emit currentDesktopChanged(centralEngine->toScriptValue(prev_desk));
142
void SWrapper::Workspace::sl_clientRemoved(KWin::Client* client)
144
if (centralEngine == 0) {
147
emit clientRemoved(centralEngine->toScriptValue(client));
151
void SWrapper::Workspace::sl_clientManaging(KWin::Client* client)
153
if (centralEngine == 0) {
156
emit clientManaging(centralEngine->toScriptValue(client));
160
void SWrapper::Workspace::sl_clientMinimized(KWin::Client* client)
162
if (centralEngine == 0) {
165
emit clientMinimized(centralEngine->toScriptValue(client));
169
void SWrapper::Workspace::sl_clientUnminimized(KWin::Client* client)
171
if (centralEngine == 0) {
174
emit clientUnminimized(centralEngine->toScriptValue<KWin::Client*>(client));
175
emit clientRestored(centralEngine->toScriptValue<KWin::Client*>(client));
179
void SWrapper::Workspace::sl_clientMaximizeSet(KWin::Client* client, QPair<bool, bool> param)
181
if (centralEngine == 0) {
184
QScriptValue temp = centralEngine->newObject();
185
temp.setProperty("v", centralEngine->toScriptValue(param.first));
186
temp.setProperty("h", centralEngine->toScriptValue(param.second));
187
emit clientMaximizeSet(centralEngine->toScriptValue(client), temp);
191
void SWrapper::Workspace::sl_killWindowCalled(KWin::Client* client)
193
if (centralEngine == 0) {
196
emit killWindowCalled(centralEngine->toScriptValue(client));
200
void SWrapper::Workspace::sl_clientActivated(KWin::Client* client)
202
if (centralEngine == 0) {
205
emit clientActivated(centralEngine->toScriptValue(client));
209
void SWrapper::Workspace::sl_groupAdded(KWin::Group* group)
215
bool SWrapper::Workspace::initialize(KWin::Workspace* wspace)
220
SWrapper::Workspace::centralObject = wspace;
221
SWrapper::Workspace::clientHolder = new SWrapper::Client(0);
226
QScriptValue SWrapper::Workspace::getAllClients(QScriptContext* ctx, QScriptEngine* eng)
228
KWin::ClientList x = centralObject->stackingOrder();
230
if (ctx->argumentCount() == 0) {
231
return eng->toScriptValue(x);
233
KWin::ClientList ret;
234
int desk_no = (ctx->argument(0)).toNumber();
235
if ((desk_no >= 1) && (desk_no > SWrapper::Workspace::centralObject->numberOfDesktops())) {
236
return QScriptValue();
238
for (int i = 0; i < x.size(); i++) {
239
if (x.at(i)->desktop() == desk_no) {
244
return eng->toScriptValue(ret);
249
QScriptValue SWrapper::Workspace::activeClient(QScriptContext* ctx, QScriptEngine* eng)
252
return eng->toScriptValue<KWin::Client*>(centralObject->activeClient());
255
QScriptValue SWrapper::Workspace::setCurrentDesktop(QScriptContext* ctx, QScriptEngine* /*eng*/)
257
if (ctx->argumentCount() >= 1) {
258
int num = ((ctx->argument(0)).isNumber()) ? ((ctx->argument(0)).toNumber()) : (-1);
260
centralObject->setCurrentDesktop(num);
264
return QScriptValue();
267
QScriptValue SWrapper::Workspace::dimensions(QScriptContext* ctx, QScriptEngine* eng)
270
return eng->toScriptValue(QSize(centralObject->workspaceWidth(), centralObject->workspaceHeight()));
273
QScriptValue SWrapper::Workspace::desktopGridSize(QScriptContext* ctx, QScriptEngine* eng)
276
return eng->toScriptValue(centralObject->desktopGridSize());
279
QScriptValue SWrapper::Workspace::clientGroups(QScriptContext* ctx, QScriptEngine* eng)
282
return eng->toScriptValue<QList<KWin::ClientGroup*> >(centralObject->clientGroups);
285
int SWrapper::Workspace::currentDesktop() const
287
return centralObject->currentDesktop();
290
void SWrapper::Workspace::attach(QScriptEngine* engine)
293
centralEngine = engine;
295
QScriptValue self = engine->newQObject(
297
QScriptEngine::QtOwnership,
298
QScriptEngine::ExcludeSuperClassContents | QScriptEngine::ExcludeDeleteLater
301
func = engine->newFunction(setCurrentDesktop, 1);
302
self.setProperty("setCurrentDesktop", func, QScriptValue::Undeletable);
304
func = engine->newFunction(getAllClients, 0);
305
self.setProperty("getAllClients", func, QScriptValue::Undeletable);
307
func = engine->newFunction(dimensions, 0);
308
self.setProperty("dimensions", func, QScriptValue::Undeletable);
310
func = engine->newFunction(desktopGridSize, 0);
311
self.setProperty("desktopGridSize", func, QScriptValue::Undeletable);
312
self.setProperty("activeClient", engine->newFunction(activeClient, 0), QScriptValue::Undeletable);
313
self.setProperty("clientGroups", engine->newFunction(clientGroups, 0), QScriptValue::Undeletable);
315
(engine->globalObject()).setProperty("workspace", self, QScriptValue::Undeletable);