~arjunak234-deactivatedaccount/kde-workspace/fix125114

« back to all changes in this revision

Viewing changes to kwin/scripting/workspace.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2010 Rohan Prabhu <rohan@rohanprabhu.com>
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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
*********************************************************************/
 
20
 
 
21
#include "workspace.h"
 
22
#include "meta.h"
 
23
 
 
24
KWin::Workspace*  SWrapper::Workspace::centralObject = 0;
 
25
SWrapper::Client* SWrapper::Workspace::clientHolder  = 0;
 
26
 
 
27
SWrapper::Workspace::Workspace(QObject* parent) : QObject(parent)
 
28
{
 
29
    if (centralObject == 0) {
 
30
        return;
 
31
    } else {
 
32
        SWrapper::WorkspaceProxy* proxy = SWrapper::WorkspaceProxy::instance();
 
33
 
 
34
        QObject::connect(centralObject, SIGNAL(desktopPresenceChanged(KWin::Client*, int)),
 
35
                         this, SLOT(sl_desktopPresenceChanged(KWin::Client*, int))
 
36
                        );
 
37
 
 
38
        QObject::connect(centralObject, SIGNAL(currentDesktopChanged(int)),
 
39
                         this, SLOT(sl_currentDesktopChanged(int))
 
40
                        );
 
41
 
 
42
        QObject::connect(centralObject, SIGNAL(clientAdded(KWin::Client*)),
 
43
                         this, SLOT(sl_clientAdded(KWin::Client*))
 
44
                        );
 
45
 
 
46
        QObject::connect(centralObject, SIGNAL(clientRemoved(KWin::Client*)),
 
47
                         this, SLOT(sl_clientRemoved(KWin::Client*))
 
48
                        );
 
49
 
 
50
        QObject::connect(centralObject, SIGNAL(clientActivated(KWin::Client*)),
 
51
                         this, SLOT(sl_clientActivated(KWin::Client*))
 
52
                        );
 
53
 
 
54
        QObject::connect(centralObject, SIGNAL(groupAdded(KWin::Group*)),
 
55
                         this, SLOT(sl_groupAdded(KWin::Group*))
 
56
                        );
 
57
 
 
58
        QObject::connect(proxy, SIGNAL(clientMinimized(KWin::Client*)),
 
59
                         this, SLOT(sl_clientMinimized(KWin::Client*))
 
60
                        );
 
61
 
 
62
        QObject::connect(proxy, SIGNAL(clientUnminimized(KWin::Client*)),
 
63
                         this, SLOT(sl_clientUnminimized(KWin::Client*))
 
64
                        );
 
65
 
 
66
        QObject::connect(proxy, SIGNAL(clientMaximizeSet(KWin::Client*, QPair<bool, bool>)),
 
67
                         this, SLOT(sl_clientMaximizeSet(KWin::Client*, QPair<bool, bool>))
 
68
                        );
 
69
 
 
70
        QObject::connect(proxy, SIGNAL(clientManaging(KWin::Client*)),
 
71
                         this, SLOT(sl_clientManaging(KWin::Client*))
 
72
                        );
 
73
 
 
74
        QObject::connect(proxy, SIGNAL(killWindowCalled(KWin::Client*)),
 
75
                         this, SLOT(sl_killWindowCalled(KWin::Client*))
 
76
                        );
 
77
 
 
78
        QObject::connect(proxy, SIGNAL(clientFullScreenSet(KWin::Client*, bool, bool)),
 
79
                         this, SLOT(sl_clientFullScreenSet(KWin::Client*, bool, bool))
 
80
                        );
 
81
 
 
82
        QObject::connect(proxy, SIGNAL(clientSetKeepAbove(KWin::Client*, bool)),
 
83
                         this, SLOT(sl_clientSetKeepAbove(KWin::Client*, bool))
 
84
                        );
 
85
 
 
86
 
 
87
    }
 
88
}
 
89
 
 
90
void SWrapper::Workspace::sl_desktopPresenceChanged(KWin::Client* client, int prev_desk)
 
91
{
 
92
    if (centralEngine == 0) {
 
93
        return;
 
94
    } else {
 
95
        emit desktopPresenceChanged(centralEngine->toScriptValue(client),
 
96
                                    centralEngine->toScriptValue(prev_desk)
 
97
                                   );
 
98
    }
 
99
}
 
100
 
 
101
void SWrapper::Workspace::sl_clientAdded(KWin::Client* client)
 
102
{
 
103
    if (centralEngine == 0) {
 
104
        return;
 
105
    } else {
 
106
        emit clientAdded(centralEngine->toScriptValue(client));
 
107
    }
 
108
}
 
109
 
 
110
void SWrapper::Workspace::sl_clientFullScreenSet(KWin::Client* client, bool set, bool user)
 
111
{
 
112
    if (centralEngine == 0) {
 
113
        return;
 
114
    } else {
 
115
        emit clientFullScreenSet(centralEngine->toScriptValue<KWin::Client*>(client),
 
116
                                 centralEngine->toScriptValue<bool>(set),
 
117
                                 centralEngine->toScriptValue<bool>(user)
 
118
                                );
 
119
    }
 
120
}
 
121
 
 
122
void SWrapper::Workspace::sl_clientSetKeepAbove(KWin::Client* client, bool set)
 
123
{
 
124
    if (centralEngine == 0) {
 
125
        return;
 
126
    } else {
 
127
        emit clientSetKeepAbove(centralEngine->toScriptValue<KWin::Client*>(client),
 
128
                                centralEngine->toScriptValue<bool>(set)
 
129
                               );
 
130
    }
 
131
}
 
132
 
 
133
void SWrapper::Workspace::sl_currentDesktopChanged(int prev_desk)
 
134
{
 
135
    if (centralEngine == 0) {
 
136
        return;
 
137
    } else {
 
138
        emit currentDesktopChanged(centralEngine->toScriptValue(prev_desk));
 
139
    }
 
140
}
 
141
 
 
142
void SWrapper::Workspace::sl_clientRemoved(KWin::Client* client)
 
143
{
 
144
    if (centralEngine == 0) {
 
145
        return;
 
146
    } else {
 
147
        emit clientRemoved(centralEngine->toScriptValue(client));
 
148
    }
 
149
}
 
150
 
 
151
void SWrapper::Workspace::sl_clientManaging(KWin::Client* client)
 
152
{
 
153
    if (centralEngine == 0) {
 
154
        return;
 
155
    } else {
 
156
        emit clientManaging(centralEngine->toScriptValue(client));
 
157
    }
 
158
}
 
159
 
 
160
void SWrapper::Workspace::sl_clientMinimized(KWin::Client* client)
 
161
{
 
162
    if (centralEngine == 0) {
 
163
        return;
 
164
    } else {
 
165
        emit clientMinimized(centralEngine->toScriptValue(client));
 
166
    }
 
167
}
 
168
 
 
169
void SWrapper::Workspace::sl_clientUnminimized(KWin::Client* client)
 
170
{
 
171
    if (centralEngine == 0) {
 
172
        return;
 
173
    } else {
 
174
        emit clientUnminimized(centralEngine->toScriptValue<KWin::Client*>(client));
 
175
        emit clientRestored(centralEngine->toScriptValue<KWin::Client*>(client));
 
176
    }
 
177
}
 
178
 
 
179
void SWrapper::Workspace::sl_clientMaximizeSet(KWin::Client* client, QPair<bool, bool> param)
 
180
{
 
181
    if (centralEngine == 0) {
 
182
        return;
 
183
    } else {
 
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);
 
188
    }
 
189
}
 
190
 
 
191
void SWrapper::Workspace::sl_killWindowCalled(KWin::Client* client)
 
192
{
 
193
    if (centralEngine == 0) {
 
194
        return;
 
195
    } else {
 
196
        emit killWindowCalled(centralEngine->toScriptValue(client));
 
197
    }
 
198
}
 
199
 
 
200
void SWrapper::Workspace::sl_clientActivated(KWin::Client* client)
 
201
{
 
202
    if (centralEngine == 0) {
 
203
        return;
 
204
    } else {
 
205
        emit clientActivated(centralEngine->toScriptValue(client));
 
206
    }
 
207
}
 
208
 
 
209
void SWrapper::Workspace::sl_groupAdded(KWin::Group* group)
 
210
{
 
211
    Q_UNUSED(group);
 
212
    //TODO
 
213
}
 
214
 
 
215
bool SWrapper::Workspace::initialize(KWin::Workspace* wspace)
 
216
{
 
217
    if (wspace == 0) {
 
218
        return false;
 
219
    } else {
 
220
        SWrapper::Workspace::centralObject = wspace;
 
221
        SWrapper::Workspace::clientHolder = new SWrapper::Client(0);
 
222
        return true;
 
223
    }
 
224
}
 
225
 
 
226
QScriptValue SWrapper::Workspace::getAllClients(QScriptContext* ctx, QScriptEngine* eng)
 
227
{
 
228
    KWin::ClientList x = centralObject->stackingOrder();
 
229
 
 
230
    if (ctx->argumentCount() == 0) {
 
231
        return eng->toScriptValue(x);
 
232
    } else {
 
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();
 
237
        } else {
 
238
            for (int i = 0; i < x.size(); i++) {
 
239
                if (x.at(i)->desktop() == desk_no) {
 
240
                    ret.append(x.at(i));
 
241
                }
 
242
            }
 
243
 
 
244
            return eng->toScriptValue(ret);
 
245
        }
 
246
    }
 
247
}
 
248
 
 
249
QScriptValue SWrapper::Workspace::activeClient(QScriptContext* ctx, QScriptEngine* eng)
 
250
{
 
251
    Q_UNUSED(ctx);
 
252
    return eng->toScriptValue<KWin::Client*>(centralObject->activeClient());
 
253
}
 
254
 
 
255
QScriptValue SWrapper::Workspace::setCurrentDesktop(QScriptContext* ctx, QScriptEngine* /*eng*/)
 
256
{
 
257
    if (ctx->argumentCount() >= 1) {
 
258
        int num = ((ctx->argument(0)).isNumber()) ? ((ctx->argument(0)).toNumber()) : (-1);
 
259
        if (num != -1) {
 
260
            centralObject->setCurrentDesktop(num);
 
261
        }
 
262
    }
 
263
 
 
264
    return QScriptValue();
 
265
}
 
266
 
 
267
QScriptValue SWrapper::Workspace::dimensions(QScriptContext* ctx, QScriptEngine* eng)
 
268
{
 
269
    Q_UNUSED(ctx);
 
270
    return eng->toScriptValue(QSize(centralObject->workspaceWidth(), centralObject->workspaceHeight()));
 
271
}
 
272
 
 
273
QScriptValue SWrapper::Workspace::desktopGridSize(QScriptContext* ctx, QScriptEngine* eng)
 
274
{
 
275
    Q_UNUSED(ctx);
 
276
    return eng->toScriptValue(centralObject->desktopGridSize());
 
277
}
 
278
 
 
279
QScriptValue SWrapper::Workspace::clientGroups(QScriptContext* ctx, QScriptEngine* eng)
 
280
{
 
281
    Q_UNUSED(ctx);
 
282
    return eng->toScriptValue<QList<KWin::ClientGroup*> >(centralObject->clientGroups);
 
283
}
 
284
 
 
285
int SWrapper::Workspace::currentDesktop() const
 
286
{
 
287
    return centralObject->currentDesktop();
 
288
}
 
289
 
 
290
void SWrapper::Workspace::attach(QScriptEngine* engine)
 
291
{
 
292
    QScriptValue func;
 
293
    centralEngine = engine;
 
294
 
 
295
    QScriptValue self = engine->newQObject(
 
296
                            this,
 
297
                            QScriptEngine::QtOwnership,
 
298
                            QScriptEngine::ExcludeSuperClassContents | QScriptEngine::ExcludeDeleteLater
 
299
                        );
 
300
 
 
301
    func = engine->newFunction(setCurrentDesktop, 1);
 
302
    self.setProperty("setCurrentDesktop", func, QScriptValue::Undeletable);
 
303
 
 
304
    func = engine->newFunction(getAllClients, 0);
 
305
    self.setProperty("getAllClients", func, QScriptValue::Undeletable);
 
306
 
 
307
    func = engine->newFunction(dimensions, 0);
 
308
    self.setProperty("dimensions", func, QScriptValue::Undeletable);
 
309
 
 
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);
 
314
 
 
315
    (engine->globalObject()).setProperty("workspace", self, QScriptValue::Undeletable);
 
316
}