~ubuntu-branches/ubuntu/precise/kde-workspace/precise-updates

« back to all changes in this revision

Viewing changes to .pc/enable_kwinactive.diff/kwin/scripting/scripting.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac, Rodrigo Belem, Philip Muškovac
  • Date: 2012-04-10 19:37:37 UTC
  • Revision ID: package-import@ubuntu.com-20120410193737-rhsuhcb6mfsdom0f
Tags: 4:4.8.2a-0ubuntu2
[ Rodrigo Belem ]
* Move kwin4_effect_builtins.so to kde-window-manager
* Move libkwinnvidiahack4 to its own package
* Add breaks/replaces for kde-window-manager-common on
  libkwinnvidiahack4 and kde-window-manager << 4:4.8.2a-0ubuntu2~
* Enable kwinactive (LP: #956186)
* Build the source twice to create kwinactive binaries
* Add the packages
  - kde-window-manager-active
  - kde-window-manager-active-gles
  - libkwinactiveglutils1
  - libkwinactiveglesutils1
  - libkwinactiveeffects1abi3
  - libkwinactivenvidiahack4
* Fix kwinactive build failure with the patch
  kubuntu_active_fix_kwin_xrender_disable.diff

[ Philip Muškovac ]
* kde-window-manager/-gles depends on libkwinnvidiahack4
  kde-window-manager-active/-gles depends on libkwinactivenvidiahack4
* use ${allLibaries} to generate the library dependencies for
  kde-workspace-dev again

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 "scripting.h"
 
22
#include <kstandarddirs.h>
 
23
 
 
24
KWin::Scripting::Scripting()
 
25
{
 
26
    // Default constructor no longer used, scripting can
 
27
    // be disabled by calling kwin --noscript
 
28
}
 
29
 
 
30
void KWin::Scripting::start()
 
31
{
 
32
    QStringList scriptFilters;
 
33
    QString sDirectory = KStandardDirs::locateLocal("data", "kwin/scripts/");
 
34
 
 
35
    if (sDirectory.isEmpty()) {
 
36
        // Abort scripting setup. No location found to locate scripts
 
37
        return;
 
38
    }
 
39
 
 
40
    scriptFilters << "*.kwinscript" << "*.kws" << "*.kwinqs";
 
41
    scriptsDir.setPath(sDirectory);
 
42
    scriptList = scriptsDir.entryList(scriptFilters, QDir::Files | QDir::Readable | QDir::Executable);
 
43
 
 
44
    for (int i = 0; i < scriptList.size(); i++) {
 
45
        scripts.append(new KWin::Script(new QScriptEngine(), scriptsDir.filePath(scriptList.at(i)), scriptsDir));
 
46
    }
 
47
 
 
48
    // Initialize singletons. Currently, only KWin::Workspace.
 
49
    SWrapper::Workspace::initialize(KWin::Workspace::self());
 
50
 
 
51
    runScripts();
 
52
}
 
53
 
 
54
void KWin::Scripting::runScript(KWin::Script* script)
 
55
{
 
56
    if (script->scriptFile.open(QIODevice::ReadOnly)) {
 
57
        script->workspace = new SWrapper::Workspace(script->engine);
 
58
        (script->workspace)->attach(script->engine);
 
59
        ((script->engine)->globalObject()).setProperty("QTimer", constructTimerClass((script->engine)));
 
60
        ((script->engine)->globalObject()).setProperty("ClientGroup", SWrapper::ClientGroup::publishClientGroupClass((script->engine)));
 
61
        ((script->engine)->globalObject()).setProperty("chelate", KWin::Chelate::publishChelate(script->engine));
 
62
        ((script->engine)->globalObject()).setProperty("ch", KWin::Chelate::publishChelate(script->engine));
 
63
        QObject::connect((script->engine), SIGNAL(signalHandlerException(QScriptValue)), this, SLOT(sigException(QScriptValue)));
 
64
        KWin::MetaScripting::registration(script->engine);
 
65
 
 
66
        if (scriptsDir.exists(script->configFile)) {
 
67
            QSettings scriptSettings(scriptsDir.filePath(script->configFile), QSettings::IniFormat);
 
68
            QHash<QString, QVariant> scriptConfig;
 
69
            QStringList keys = scriptSettings.allKeys();
 
70
 
 
71
            for (int i = 0; i < keys.size(); i++) {
 
72
                scriptConfig.insert(keys.at(i), scriptSettings.value(keys.at(i)));
 
73
            }
 
74
 
 
75
            KWin::MetaScripting::supplyConfig(script->engine, QVariant(scriptConfig));
 
76
        } else {
 
77
            KWin::MetaScripting::supplyConfig(script->engine);
 
78
        }
 
79
 
 
80
        QScriptValue ret = (script->engine)->evaluate(QString((script->scriptFile).readAll()));
 
81
 
 
82
        if (ret.isError()) {
 
83
            sigException(ret);
 
84
        }
 
85
    }
 
86
}
 
87
 
 
88
 
 
89
void KWin::Scripting::runScripts()
 
90
{
 
91
    for (int i = 0; i < scripts.size(); i++) {
 
92
        runScript(scripts.at(i));
 
93
    }
 
94
}
 
95
 
 
96
void KWin::Scripting::sigException(const QScriptValue& exception)
 
97
{
 
98
    QScriptValue ret = exception;
 
99
    if (ret.isError()) {
 
100
        kDebug(1212) << "defaultscript encountered an error at [Line " << uncaughtExceptionLineNumber() << "]";
 
101
        kDebug(1212) << "Message: " << ret.toString();
 
102
        kDebug(1212) << "-----------------";
 
103
 
 
104
        QScriptValueIterator iter(ret);
 
105
        while (iter.hasNext()) {
 
106
            iter.next();
 
107
            qDebug() << " " << iter.name() << ": " << iter.value().toString();
 
108
        }
 
109
    }
 
110
}
 
111
 
 
112
KWin::Scripting::~Scripting()
 
113
{
 
114
    for (int i = 0; i < scripts.size(); i++) {
 
115
        delete scripts.at(i);
 
116
    }
 
117
}