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
*********************************************************************/
23
Q_DECLARE_METATYPE(SWrapper::Toplevel*)
25
SWrapper::Toplevel::Toplevel(KWin::Toplevel* tlevel)
31
KWin::Toplevel* SWrapper::Toplevel::extractClient(const QScriptValue& value)
33
SWrapper::Toplevel* tlevel = qscriptvalue_cast<SWrapper::Toplevel*>(value);
36
return tlevel->tl_centralObject;
47
MAP_GET(QRect, geometry)
48
MAP_GET(double, opacity)
49
MAP_GET(bool, hasAlpha)
51
QScriptValue SWrapper::Toplevel::pos(QScriptContext* ctx, QScriptEngine* eng)
53
KWin::Toplevel* central = extractClient(ctx->thisObject());
56
return QScriptValue();
58
return eng->toScriptValue(central->pos());
62
QScriptValue SWrapper::Toplevel::setOpacity(QScriptContext* ctx, QScriptEngine* eng)
64
KWin::Toplevel* central = extractClient(ctx->thisObject());
67
return eng->toScriptValue<bool>(0);
69
QScriptValue opac = ctx->argument(0);
70
if (opac.isUndefined() || !opac.isNumber()) {
71
return eng->toScriptValue<bool>(0);
73
qsreal _opac = opac.toNumber();
74
// For some access restrictions, setting any window
75
// completely transperent is not allowed. As if, a window
76
// with 0.001 is perceptible. huh
77
if ((_opac > 1) || (_opac <= 0)) {
78
return eng->toScriptValue<bool>(0);
80
central->setOpacity(_opac);
81
return eng->toScriptValue<bool>(1);
87
void SWrapper::Toplevel::tl_append(QScriptValue& value, QScriptEngine* eng)
89
QScriptValue func = eng->newFunction(pos, 0);
90
value.setProperty("pos", func, QScriptValue::Undeletable);
91
value.setProperty("x", eng->newFunction(x, 0), QScriptValue::Undeletable);
92
value.setProperty("y", eng->newFunction(y, 0), QScriptValue::Undeletable);
93
value.setProperty("size", eng->newFunction(size, 0), QScriptValue::Undeletable);
94
value.setProperty("width", eng->newFunction(width, 0), QScriptValue::Undeletable);
95
value.setProperty("height", eng->newFunction(height, 0), QScriptValue::Undeletable);
96
value.setProperty("geometry", eng->newFunction(geometry, 0), QScriptValue::Undeletable);
97
value.setProperty("opacity", eng->newFunction(opacity, 0), QScriptValue::Undeletable);
98
value.setProperty("hasAlpha", eng->newFunction(hasAlpha, 0), QScriptValue::Undeletable);
99
value.setProperty("setOpacity", eng->newFunction(setOpacity, 1), QScriptValue::Undeletable);