~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/scripting/toplevel.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 "toplevel.h"
 
22
 
 
23
Q_DECLARE_METATYPE(SWrapper::Toplevel*)
 
24
 
 
25
SWrapper::Toplevel::Toplevel(KWin::Toplevel* tlevel)
 
26
    : QObject(tlevel)
 
27
{
 
28
    tl_centralObject = 0;
 
29
}
 
30
 
 
31
KWin::Toplevel* SWrapper::Toplevel::extractClient(const QScriptValue& value)
 
32
{
 
33
    SWrapper::Toplevel* tlevel = qscriptvalue_cast<SWrapper::Toplevel*>(value);
 
34
 
 
35
    if (tlevel != 0) {
 
36
        return tlevel->tl_centralObject;
 
37
    }
 
38
 
 
39
    return 0;
 
40
}
 
41
 
 
42
MAP_GET(int, x)
 
43
MAP_GET(int, y)
 
44
MAP_GET(QSize, size)
 
45
MAP_GET(int, width)
 
46
MAP_GET(int, height)
 
47
MAP_GET(QRect, geometry)
 
48
MAP_GET(double, opacity)
 
49
MAP_GET(bool, hasAlpha)
 
50
 
 
51
QScriptValue SWrapper::Toplevel::pos(QScriptContext* ctx, QScriptEngine* eng)
 
52
{
 
53
    KWin::Toplevel* central = extractClient(ctx->thisObject());
 
54
 
 
55
    if (central == 0) {
 
56
        return QScriptValue();
 
57
    } else {
 
58
        return eng->toScriptValue(central->pos());
 
59
    }
 
60
}
 
61
 
 
62
QScriptValue SWrapper::Toplevel::setOpacity(QScriptContext* ctx, QScriptEngine* eng)
 
63
{
 
64
    KWin::Toplevel* central = extractClient(ctx->thisObject());
 
65
 
 
66
    if (central == 0) {
 
67
        return eng->toScriptValue<bool>(0);
 
68
    } else {
 
69
        QScriptValue opac = ctx->argument(0);
 
70
        if (opac.isUndefined() || !opac.isNumber()) {
 
71
            return eng->toScriptValue<bool>(0);
 
72
        } else {
 
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);
 
79
            } else {
 
80
                central->setOpacity(_opac);
 
81
                return eng->toScriptValue<bool>(1);
 
82
            }
 
83
        }
 
84
    }
 
85
}
 
86
 
 
87
void SWrapper::Toplevel::tl_append(QScriptValue& value, QScriptEngine* eng)
 
88
{
 
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);
 
100
}