diff --git a/autotests/test_scripted_effectloader.cpp b/autotests/test_scripted_effectloader.cpp index 9af624869..f0e2049a0 100644 --- a/autotests/test_scripted_effectloader.cpp +++ b/autotests/test_scripted_effectloader.cpp @@ -1,424 +1,432 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2014 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "../effectloader.h" #include "mock_effectshandler.h" #include "../scripting/scriptedeffect.h" // for mocking #include "../input.h" #include "../screenedge.h" // KDE #include #include #include // Qt #include #include Q_DECLARE_METATYPE(KWin::LoadEffectFlag) Q_DECLARE_METATYPE(KWin::LoadEffectFlags) Q_DECLARE_METATYPE(KWin::Effect*) +Q_DECLARE_METATYPE(KSharedConfigPtr) Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core") namespace KWin { ScreenEdges *ScreenEdges::s_self = nullptr; void ScreenEdges::reserve(ElectricBorder, QObject *, const char *) { } InputRedirection *InputRedirection::s_self = nullptr; void InputRedirection::registerShortcut(const QKeySequence &, QAction *) { } namespace MetaScripting { void registration(QScriptEngine *) { } } } class TestScriptedEffectLoader : public QObject { Q_OBJECT private Q_SLOTS: + void initTestCase(); void testHasEffect_data(); void testHasEffect(); void testKnownEffects(); void testLoadEffect_data(); void testLoadEffect(); void testLoadScriptedEffect_data(); void testLoadScriptedEffect(); void testLoadAllEffects(); void testCancelLoadAllEffects(); }; +void TestScriptedEffectLoader::initTestCase() +{ + auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); + QCoreApplication::instance()->setProperty("config", QVariant::fromValue(config)); +} + void TestScriptedEffectLoader::testHasEffect_data() { QTest::addColumn("name"); QTest::addColumn("expected"); // all the built-in effects should fail QTest::newRow("blur") << QStringLiteral("blur") << false; QTest::newRow("Contrast") << QStringLiteral("contrast") << false; QTest::newRow("CoverSwitch") << QStringLiteral("coverswitch") << false; QTest::newRow("Cube") << QStringLiteral("cube") << false; QTest::newRow("CubeSlide") << QStringLiteral("cubeslide") << false; QTest::newRow("DesktopGrid") << QStringLiteral("desktopgrid") << false; QTest::newRow("DimInactive") << QStringLiteral("diminactive") << false; QTest::newRow("DimScreen") << QStringLiteral("dimscreen") << false; QTest::newRow("FallApart") << QStringLiteral("fallapart") << false; QTest::newRow("FlipSwitch") << QStringLiteral("flipswitch") << false; QTest::newRow("Glide") << QStringLiteral("glide") << false; QTest::newRow("HighlightWindow") << QStringLiteral("highlightwindow") << false; QTest::newRow("Invert") << QStringLiteral("invert") << false; QTest::newRow("Kscreen") << QStringLiteral("kscreen") << false; QTest::newRow("Logout") << QStringLiteral("logout") << false; QTest::newRow("LookingGlass") << QStringLiteral("lookingglass") << false; QTest::newRow("MagicLamp") << QStringLiteral("magiclamp") << false; QTest::newRow("Magnifier") << QStringLiteral("magnifier") << false; QTest::newRow("MinimizeAnimation") << QStringLiteral("minimizeanimation") << false; QTest::newRow("MouseClick") << QStringLiteral("mouseclick") << false; QTest::newRow("MouseMark") << QStringLiteral("mousemark") << false; QTest::newRow("PresentWindows") << QStringLiteral("presentwindows") << false; QTest::newRow("Resize") << QStringLiteral("resize") << false; QTest::newRow("ScreenEdge") << QStringLiteral("screenedge") << false; QTest::newRow("ScreenShot") << QStringLiteral("screenshot") << false; QTest::newRow("Sheet") << QStringLiteral("sheet") << false; QTest::newRow("ShowFps") << QStringLiteral("showfps") << false; QTest::newRow("ShowPaint") << QStringLiteral("showpaint") << false; QTest::newRow("Slide") << QStringLiteral("slide") << false; QTest::newRow("SlideBack") << QStringLiteral("slideback") << false; QTest::newRow("SlidingPopups") << QStringLiteral("slidingpopups") << false; QTest::newRow("SnapHelper") << QStringLiteral("snaphelper") << false; QTest::newRow("StartupFeedback") << QStringLiteral("startupfeedback") << false; QTest::newRow("ThumbnailAside") << QStringLiteral("thumbnailaside") << false; QTest::newRow("TrackMouse") << QStringLiteral("trackmouse") << false; QTest::newRow("WindowGeometry") << QStringLiteral("windowgeometry") << false; QTest::newRow("WobblyWindows") << QStringLiteral("wobblywindows") << false; QTest::newRow("Zoom") << QStringLiteral("zoom") << false; QTest::newRow("Non Existing") << QStringLiteral("InvalidName") << false; QTest::newRow("Fade - without kwin4_effect") << QStringLiteral("fade") << false; QTest::newRow("Fade + kwin4_effect") << QStringLiteral("kwin4_effect_fade") << true; QTest::newRow("Fade + kwin4_effect + CS") << QStringLiteral("kwin4_eFfect_fAde") << true; QTest::newRow("FadeDesktop") << QStringLiteral("kwin4_effect_fadedesktop") << true; QTest::newRow("DialogParent") << QStringLiteral("kwin4_effect_dialogparent") << true; QTest::newRow("Login") << QStringLiteral("kwin4_effect_login") << true; QTest::newRow("Maximize") << QStringLiteral("kwin4_effect_maximize") << true; QTest::newRow("ScaleIn") << QStringLiteral("kwin4_effect_scalein") << true; QTest::newRow("Translucency") << QStringLiteral("kwin4_effect_translucency") << true; } void TestScriptedEffectLoader::testHasEffect() { QFETCH(QString, name); QFETCH(bool, expected); MockEffectsHandler mockHandler(KWin::XRenderCompositing); KWin::ScriptedEffectLoader loader; QCOMPARE(loader.hasEffect(name), expected); // each available effect should also be supported QCOMPARE(loader.isEffectSupported(name), expected); if (expected) { mockHandler.setAnimationsSupported(false); QVERIFY(!loader.isEffectSupported(name)); } } void TestScriptedEffectLoader::testKnownEffects() { QStringList expectedEffects; expectedEffects << QStringLiteral("kwin4_effect_dialogparent") << QStringLiteral("kwin4_effect_fade") << QStringLiteral("kwin4_effect_fadedesktop") << QStringLiteral("kwin4_effect_login") << QStringLiteral("kwin4_effect_maximize") << QStringLiteral("kwin4_effect_scalein") << QStringLiteral("kwin4_effect_translucency"); KWin::ScriptedEffectLoader loader; QStringList result = loader.listOfKnownEffects(); // at least as many effects as we expect - system running the test could have more effects QVERIFY(result.size() >= expectedEffects.size()); for (const QString &effect : expectedEffects) { QVERIFY(result.contains(effect)); } } void TestScriptedEffectLoader::testLoadEffect_data() { QTest::addColumn("name"); QTest::addColumn("expected"); QTest::newRow("Non Existing") << QStringLiteral("InvalidName") << false; QTest::newRow("Fade - without kwin4_effect") << QStringLiteral("fade") << false; QTest::newRow("Fade + kwin4_effect") << QStringLiteral("kwin4_effect_fade") << true; QTest::newRow("Fade + kwin4_effect + CS") << QStringLiteral("kwin4_eFfect_fAde") << true; QTest::newRow("FadeDesktop") << QStringLiteral("kwin4_effect_fadedesktop") << true; QTest::newRow("DialogParent") << QStringLiteral("kwin4_effect_dialogparent") << true; QTest::newRow("Login") << QStringLiteral("kwin4_effect_login") << true; QTest::newRow("Maximize") << QStringLiteral("kwin4_effect_maximize") << true; QTest::newRow("ScaleIn") << QStringLiteral("kwin4_effect_scalein") << true; QTest::newRow("Translucency") << QStringLiteral("kwin4_effect_translucency") << true; } void TestScriptedEffectLoader::testLoadEffect() { QFETCH(QString, name); QFETCH(bool, expected); MockEffectsHandler mockHandler(KWin::XRenderCompositing); KWin::ScriptedEffectLoader loader; KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); loader.setConfig(config); qRegisterMetaType(); QSignalSpy spy(&loader, SIGNAL(effectLoaded(KWin::Effect*,QString))); // connect to signal to ensure that we delete the Effect again as the Effect doesn't have a parent connect(&loader, &KWin::ScriptedEffectLoader::effectLoaded, [&name](KWin::Effect *effect, const QString &effectName) { QCOMPARE(effectName, name.toLower()); effect->deleteLater(); } ); // try to load the Effect QCOMPARE(loader.loadEffect(name), expected); // loading again should fail QVERIFY(!loader.loadEffect(name)); // signal spy should have got the signal if it was expected QCOMPARE(spy.isEmpty(), !expected); if (!spy.isEmpty()) { QCOMPARE(spy.count(), 1); // if we caught a signal it should have the effect name we passed in QList arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 2); QCOMPARE(arguments.at(1).toString(), name.toLower()); } spy.clear(); QVERIFY(spy.isEmpty()); // now if we wait for the events being processed, the effect will get deleted and it should load again QTest::qWait(1); QCOMPARE(loader.loadEffect(name), expected); // signal spy should have got the signal if it was expected QCOMPARE(spy.isEmpty(), !expected); if (!spy.isEmpty()) { QCOMPARE(spy.count(), 1); // if we caught a signal it should have the effect name we passed in QList arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 2); QCOMPARE(arguments.at(1).toString(), name.toLower()); } } void TestScriptedEffectLoader::testLoadScriptedEffect_data() { QTest::addColumn("name"); QTest::addColumn("expected"); QTest::addColumn("loadFlags"); const KWin::LoadEffectFlags checkDefault = KWin::LoadEffectFlag::Load | KWin::LoadEffectFlag::CheckDefaultFunction; const KWin::LoadEffectFlags forceFlags = KWin::LoadEffectFlag::Load; const KWin::LoadEffectFlags dontLoadFlags = KWin::LoadEffectFlags(); // enabled by default QTest::newRow("Fade") << QStringLiteral("kwin4_effect_fade") << true << checkDefault; // not enabled by default QTest::newRow("Scalein") << QStringLiteral("kwin4_effect_scalein") << true << checkDefault; // Force an Effect which will load QTest::newRow("Scalein-Force") << QStringLiteral("kwin4_effect_scalein") << true << forceFlags; // Enforce no load of effect which is enabled by default QTest::newRow("Fade-DontLoad") << QStringLiteral("kwin4_effect_fade") << false << dontLoadFlags; // Enforce no load of effect which is not enabled by default, but enforced QTest::newRow("Scalein-DontLoad") << QStringLiteral("kwin4_effect_scalein") << false << dontLoadFlags; } void TestScriptedEffectLoader::testLoadScriptedEffect() { QFETCH(QString, name); QFETCH(bool, expected); QFETCH(KWin::LoadEffectFlags, loadFlags); MockEffectsHandler mockHandler(KWin::XRenderCompositing); KWin::ScriptedEffectLoader loader; KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); loader.setConfig(config); const auto services = KPackage::PackageLoader::self()->findPackages(QStringLiteral("KWin/Effect"), QStringLiteral("kwin/effects"), [name] (const KPluginMetaData &metadata) { return metadata.pluginId().compare(name, Qt::CaseInsensitive) == 0; } ); QCOMPARE(services.count(), 1); qRegisterMetaType(); QSignalSpy spy(&loader, SIGNAL(effectLoaded(KWin::Effect*,QString))); // connect to signal to ensure that we delete the Effect again as the Effect doesn't have a parent connect(&loader, &KWin::ScriptedEffectLoader::effectLoaded, [&name](KWin::Effect *effect, const QString &effectName) { QCOMPARE(effectName, name.toLower()); effect->deleteLater(); } ); // try to load the Effect QCOMPARE(loader.loadEffect(services.first(), loadFlags), expected); // loading again should fail QVERIFY(!loader.loadEffect(services.first(), loadFlags)); // signal spy should have got the signal if it was expected QCOMPARE(spy.isEmpty(), !expected); if (!spy.isEmpty()) { QCOMPARE(spy.count(), 1); // if we caught a signal it should have the effect name we passed in QList arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 2); QCOMPARE(arguments.at(1).toString(), name.toLower()); } spy.clear(); QVERIFY(spy.isEmpty()); // now if we wait for the events being processed, the effect will get deleted and it should load again QTest::qWait(1); QCOMPARE(loader.loadEffect(services.first(), loadFlags), expected); // signal spy should have got the signal if it was expected QCOMPARE(spy.isEmpty(), !expected); if (!spy.isEmpty()) { QCOMPARE(spy.count(), 1); // if we caught a signal it should have the effect name we passed in QList arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 2); QCOMPARE(arguments.at(1).toString(), name.toLower()); } } void TestScriptedEffectLoader::testLoadAllEffects() { MockEffectsHandler mockHandler(KWin::XRenderCompositing); KWin::ScriptedEffectLoader loader; KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); const QString kwin4 = QStringLiteral("kwin4_effect_"); // prepare the configuration to hard enable/disable the effects we want to load KConfigGroup plugins = config->group("Plugins"); plugins.writeEntry(kwin4 + QStringLiteral("dialogparentEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("fadeEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("fadedesktopEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("loginEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("maximizeEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("minimizeanimationEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("scaleinEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("translucencyEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("eyeonscreenEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("windowapertureEnabled"), false); plugins.writeEntry(kwin4 + QStringLiteral("morphingpopupsEnabled"), false); plugins.sync(); loader.setConfig(config); qRegisterMetaType(); QSignalSpy spy(&loader, SIGNAL(effectLoaded(KWin::Effect*,QString))); // connect to signal to ensure that we delete the Effect again as the Effect doesn't have a parent connect(&loader, &KWin::ScriptedEffectLoader::effectLoaded, [](KWin::Effect *effect) { effect->deleteLater(); } ); // the config is prepared so that no Effect gets loaded! loader.queryAndLoadAll(); // we need to wait some time because it's queued and in a thread QVERIFY(!spy.wait(100)); // now let's prepare a config which has one effect explicitly enabled plugins.writeEntry(kwin4 + QStringLiteral("scaleinEnabled"), true); plugins.sync(); loader.queryAndLoadAll(); // should load one effect in first go QVERIFY(spy.wait(100)); // and afterwards it should not load another one QVERIFY(!spy.wait(10)); QCOMPARE(spy.size(), 1); // if we caught a signal it should have the effect name we passed in QList arguments = spy.takeFirst(); QCOMPARE(arguments.count(), 2); QCOMPARE(arguments.at(1).toString(), kwin4 + QStringLiteral("scalein")); spy.clear(); // let's delete one of the default entries plugins.deleteEntry(kwin4 + QStringLiteral("fadeEnabled")); plugins.sync(); QVERIFY(spy.isEmpty()); loader.queryAndLoadAll(); // let's use qWait as we need to wait for two signals to be emitted QTRY_COMPARE(spy.size(), 2); QStringList loadedEffects; for (auto &list : spy) { QCOMPARE(list.size(), 2); loadedEffects << list.at(1).toString(); } qSort(loadedEffects); QCOMPARE(loadedEffects.at(0), kwin4 + QStringLiteral("fade")); QCOMPARE(loadedEffects.at(1), kwin4 + QStringLiteral("scalein")); } void TestScriptedEffectLoader::testCancelLoadAllEffects() { // this test verifies that no test gets loaded when the loader gets cleared MockEffectsHandler mockHandler(KWin::XRenderCompositing); KWin::ScriptedEffectLoader loader; // prepare the configuration to hard enable/disable the effects we want to load KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); const QString kwin4 = QStringLiteral("kwin4_effect_"); KConfigGroup plugins = config->group("Plugins"); plugins.writeEntry(kwin4 + QStringLiteral("scaleinEnabled"), true); plugins.sync(); loader.setConfig(config); qRegisterMetaType(); QSignalSpy spy(&loader, &KWin::ScriptedEffectLoader::effectLoaded); QVERIFY(spy.isValid()); loader.queryAndLoadAll(); loader.clear(); // Should not load any effect QVERIFY(!spy.wait(100)); QVERIFY(spy.isEmpty()); } QTEST_MAIN(TestScriptedEffectLoader) #include "test_scripted_effectloader.moc" diff --git a/main.cpp b/main.cpp index e5fc0c229..65fc15038 100644 --- a/main.cpp +++ b/main.cpp @@ -1,452 +1,455 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 1999, 2000 Matthias Ettrich Copyright (C) 2003 Lubos Lunak This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "main.h" #include // kwin #include "platform.h" #include "atoms.h" #include "composite.h" #include "cursor.h" #include "input.h" #include "logind.h" #include "options.h" #include "screens.h" #include "screenlockerwatcher.h" #include "sm.h" #include "workspace.h" #include "xcbutils.h" #include // KDE #include #include #include #include #include // Qt #include #include #include #include #include // system #ifdef HAVE_UNISTD_H #include #endif // HAVE_UNISTD_H #ifdef HAVE_MALLOC_H #include #endif // HAVE_MALLOC_H // xcb #include #ifndef XCB_GE_GENERIC #define XCB_GE_GENERIC 35 #endif +Q_DECLARE_METATYPE(KSharedConfigPtr) + namespace KWin { Options* options; Atoms* atoms; int screen_number = -1; bool is_multihead = false; int Application::crashes = 0; bool Application::isX11MultiHead() { return is_multihead; } void Application::setX11MultiHead(bool multiHead) { is_multihead = multiHead; } void Application::setX11ScreenNumber(int screenNumber) { screen_number = screenNumber; } int Application::x11ScreenNumber() { return screen_number; } Application::Application(Application::OperationMode mode, int &argc, char **argv) : QApplication(argc, argv) , m_eventFilter(new XcbEventFilter()) , m_configLock(false) , m_config() , m_operationMode(mode) { qRegisterMetaType("Options::WindowOperation"); qRegisterMetaType(); qRegisterMetaType("KWayland::Server::SurfaceInterface *"); + qRegisterMetaType(); } void Application::setConfigLock(bool lock) { m_configLock = lock; } Application::OperationMode Application::operationMode() const { return m_operationMode; } void Application::setOperationMode(OperationMode mode) { m_operationMode = mode; } bool Application::shouldUseWaylandForCompositing() const { return m_operationMode == OperationModeWaylandAndX11 || m_operationMode == OperationModeXwayland; } void Application::start() { setQuitOnLastWindowClosed(false); if (!m_config) { m_config = KSharedConfig::openConfig(); } if (!m_config->isImmutable() && m_configLock) { // TODO: This shouldn't be necessary //config->setReadOnly( true ); m_config->reparseConfiguration(); } performStartup(); } Application::~Application() { delete options; destroyAtoms(); } void Application::destroyAtoms() { delete atoms; atoms = nullptr; } void Application::resetCrashesCount() { crashes = 0; } void Application::setCrashCount(int count) { crashes = count; } bool Application::wasCrash() { return crashes > 0; } static const char description[] = I18N_NOOP("KDE window manager"); void Application::createAboutData() { KAboutData aboutData(QStringLiteral(KWIN_NAME), // The program name used internally i18n("KWin"), // A displayable program name string QStringLiteral(KWIN_VERSION_STRING), // The program version string i18n(description), // Short description of what the app does KAboutLicense::GPL, // The license this code is released under i18n("(c) 1999-2013, The KDE Developers")); // Copyright Statement aboutData.addAuthor(i18n("Matthias Ettrich"), QString(), QStringLiteral("ettrich@kde.org")); aboutData.addAuthor(i18n("Cristian Tibirna"), QString(), QStringLiteral("tibirna@kde.org")); aboutData.addAuthor(i18n("Daniel M. Duley"), QString(), QStringLiteral("mosfet@kde.org")); aboutData.addAuthor(i18n("Luboš Luňák"), QString(), QStringLiteral("l.lunak@kde.org")); aboutData.addAuthor(i18n("Martin Gräßlin"), i18n("Maintainer"), QStringLiteral("mgraesslin@kde.org")); KAboutData::setApplicationData(aboutData); } static const QString s_lockOption = QStringLiteral("lock"); static const QString s_crashesOption = QStringLiteral("crashes"); void Application::setupCommandLine(QCommandLineParser *parser) { QCommandLineOption lockOption(s_lockOption, i18n("Disable configuration options")); QCommandLineOption crashesOption(s_crashesOption, i18n("Indicate that KWin has recently crashed n times"), QStringLiteral("n")); parser->setApplicationDescription(i18n("KDE window manager")); parser->addVersionOption(); parser->addHelpOption(); parser->addOption(lockOption); parser->addOption(crashesOption); KAboutData::applicationData().setupCommandLine(parser); } void Application::processCommandLine(QCommandLineParser *parser) { setConfigLock(parser->isSet(s_lockOption)); Application::setCrashCount(parser->value(s_crashesOption).toInt()); } void Application::setupTranslator() { QTranslator *qtTranslator = new QTranslator(qApp); qtTranslator->load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); installTranslator(qtTranslator); } void Application::setupMalloc() { #ifdef M_TRIM_THRESHOLD // Prevent fragmentation of the heap by malloc (glibc). // // The default threshold is 128*1024, which can result in a large memory usage // due to fragmentation especially if we use the raster graphicssystem. On the // otherside if the threshold is too low, free() starts to permanently ask the kernel // about shrinking the heap. #ifdef HAVE_UNISTD_H const int pagesize = sysconf(_SC_PAGESIZE); #else const int pagesize = 4*1024; #endif // HAVE_UNISTD_H mallopt(M_TRIM_THRESHOLD, 5*pagesize); #endif // M_TRIM_THRESHOLD } void Application::setupLocalizedString() { KLocalizedString::setApplicationDomain("kwin"); } void Application::notifyKSplash() { // Tell KSplash that KWin has started QDBusMessage ksplashProgressMessage = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KSplash"), QStringLiteral("/KSplash"), QStringLiteral("org.kde.KSplash"), QStringLiteral("setStage")); ksplashProgressMessage.setArguments(QList() << QStringLiteral("wm")); QDBusConnection::sessionBus().asyncCall(ksplashProgressMessage); } void Application::createWorkspace() { // ensure the helper atoms are retrieved before we create the Workspace atoms->retrieveHelpers(); // we want all QQuickWindows with an alpha buffer, do here as Workspace might create QQuickWindows QQuickWindow::setDefaultAlphaBuffer(true); // This tries to detect compositing options and can use GLX. GLX problems // (X errors) shouldn't cause kwin to abort, so this is out of the // critical startup section where x errors cause kwin to abort. // create workspace. (void) new Workspace(m_originalSessionKey); emit workspaceCreated(); } void Application::createInput() { ScreenLockerWatcher::create(this); LogindIntegration::create(this); auto input = InputRedirection::create(this); input->init(); m_platform->createPlatformCursor(this); } void Application::createScreens() { if (Screens::self()) { return; } Screens::create(this); emit screensCreated(); } void Application::createAtoms() { atoms = new Atoms; } void Application::createOptions() { options = new Options; } void Application::createCompositor() { Compositor::create(this); } void Application::setupEventFilters() { installNativeEventFilter(m_eventFilter.data()); } void Application::destroyWorkspace() { delete Workspace::self(); } void Application::destroyCompositor() { delete Compositor::self(); } void Application::updateX11Time(xcb_generic_event_t *event) { xcb_timestamp_t time = XCB_TIME_CURRENT_TIME; const uint8_t eventType = event->response_type & ~0x80; switch(eventType) { case XCB_KEY_PRESS: case XCB_KEY_RELEASE: time = reinterpret_cast(event)->time; break; case XCB_BUTTON_PRESS: case XCB_BUTTON_RELEASE: time = reinterpret_cast(event)->time; break; case XCB_MOTION_NOTIFY: time = reinterpret_cast(event)->time; break; case XCB_ENTER_NOTIFY: case XCB_LEAVE_NOTIFY: time = reinterpret_cast(event)->time; break; case XCB_FOCUS_IN: case XCB_FOCUS_OUT: case XCB_KEYMAP_NOTIFY: case XCB_EXPOSE: case XCB_GRAPHICS_EXPOSURE: case XCB_NO_EXPOSURE: case XCB_VISIBILITY_NOTIFY: case XCB_CREATE_NOTIFY: case XCB_DESTROY_NOTIFY: case XCB_UNMAP_NOTIFY: case XCB_MAP_NOTIFY: case XCB_MAP_REQUEST: case XCB_REPARENT_NOTIFY: case XCB_CONFIGURE_NOTIFY: case XCB_CONFIGURE_REQUEST: case XCB_GRAVITY_NOTIFY: case XCB_RESIZE_REQUEST: case XCB_CIRCULATE_NOTIFY: case XCB_CIRCULATE_REQUEST: // no timestamp return; case XCB_PROPERTY_NOTIFY: time = reinterpret_cast(event)->time; break; case XCB_SELECTION_CLEAR: time = reinterpret_cast(event)->time; break; case XCB_SELECTION_REQUEST: time = reinterpret_cast(event)->time; break; case XCB_SELECTION_NOTIFY: time = reinterpret_cast(event)->time; break; case XCB_COLORMAP_NOTIFY: case XCB_CLIENT_MESSAGE: case XCB_MAPPING_NOTIFY: case XCB_GE_GENERIC: // no timestamp return; default: // extension handling if (Xcb::Extensions::self()) { if (eventType == Xcb::Extensions::self()->shapeNotifyEvent()) { time = reinterpret_cast(event)->server_time; } if (eventType == Xcb::Extensions::self()->damageNotifyEvent()) { time = reinterpret_cast(event)->timestamp; } } break; } setX11Time(time); } bool XcbEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long int *result) { Q_UNUSED(result) if (eventType != "xcb_generic_event_t") { return false; } auto event = static_cast(message); kwinApp()->updateX11Time(event); if (!Workspace::self()) { // Workspace not yet created return false; } return Workspace::self()->workspaceEvent(event); } static bool s_useLibinput = false; void Application::setUseLibinput(bool use) { s_useLibinput = use; } bool Application::usesLibinput() { return s_useLibinput; } QProcessEnvironment Application::processStartupEnvironment() const { return QProcessEnvironment::systemEnvironment(); } void Application::initPlatform(const KPluginMetaData &plugin) { Q_ASSERT(!m_platform); m_platform = qobject_cast(plugin.instantiate()); if (m_platform) { m_platform->setParent(this); #if HAVE_INPUT // check whether it needs libinput const QJsonObject &metaData = plugin.rawData(); auto it = metaData.find(QStringLiteral("input")); if (it != metaData.end()) { if ((*it).isBool()) { if (!(*it).toBool()) { qCDebug(KWIN_CORE) << "Platform does not support input, enforcing libinput support"; setUseLibinput(true); } } } #endif } } } // namespace diff --git a/main.h b/main.h index a7dd47dd6..0758da840 100644 --- a/main.h +++ b/main.h @@ -1,242 +1,243 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 1999, 2000 Matthias Ettrich Copyright (C) 2003 Lubos Lunak This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #ifndef MAIN_H #define MAIN_H #include #include #include #include #include // Qt #include #include #include class KPluginMetaData; class QCommandLineParser; namespace KWin { class Platform; class XcbEventFilter : public QAbstractNativeEventFilter { public: virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long int *result) override; }; class KWIN_EXPORT Application : public QApplication { Q_OBJECT Q_PROPERTY(quint32 x11Time READ x11Time WRITE setX11Time) Q_PROPERTY(quint32 x11RootWindow READ x11RootWindow CONSTANT) Q_PROPERTY(void *x11Connection READ x11Connection NOTIFY x11ConnectionChanged) Q_PROPERTY(int x11ScreenNumber READ x11ScreenNumber CONSTANT) + Q_PROPERTY(KSharedConfigPtr config READ config WRITE setConfig) public: /** * @brief This enum provides the various operation modes of KWin depending on the available * Windowing Systems at startup. For example whether KWin only talks to X11 or also to a Wayland * Compositor. * */ enum OperationMode { /** * @brief KWin uses only X11 for managing windows and compositing */ OperationModeX11, /** * @brief KWin uses X11 for managing windows, but renders to a Wayland compositor. * Input is received from the Wayland compositor. */ OperationModeWaylandAndX11, /** * @brief KWin uses Wayland and controls a nested Xwayland server. **/ OperationModeXwayland }; virtual ~Application(); void setConfigLock(bool lock); KSharedConfigPtr config() const { return m_config; } void setConfig(KSharedConfigPtr config) { m_config = config; } void start(); /** * @brief The operation mode used by KWin. * * @return OperationMode */ OperationMode operationMode() const; void setOperationMode(OperationMode mode); bool shouldUseWaylandForCompositing() const; void setupTranslator(); void setupCommandLine(QCommandLineParser *parser); void processCommandLine(QCommandLineParser *parser); xcb_timestamp_t x11Time() const { return m_x11Time; } void setX11Time(xcb_timestamp_t timestamp) { if (timestamp > m_x11Time) { m_x11Time = timestamp; } } void updateX11Time(xcb_generic_event_t *event); void createScreens(); static void setCrashCount(int count); static bool wasCrash(); /** * Creates the KAboutData object for the KWin instance and registers it as * KAboutData::setApplicationData. **/ static void createAboutData(); /** * @returns the X11 Screen number. If not applicable it's set to @c -1. **/ static int x11ScreenNumber(); /** * Sets the X11 screen number of this KWin instance to @p screenNumber. **/ static void setX11ScreenNumber(int screenNumber); /** * @returns whether this is a multi head setup on X11. **/ static bool isX11MultiHead(); /** * Sets whether this is a multi head setup on X11. */ static void setX11MultiHead(bool multiHead); /** * @returns the X11 root window. **/ xcb_window_t x11RootWindow() const { return m_rootWindow; } /** * @returns the X11 xcb connection **/ xcb_connection_t *x11Connection() const { return m_connection; } #ifdef KWIN_BUILD_ACTIVITIES bool usesKActivities() const { return m_useKActivities; } void setUseKActivities(bool use) { m_useKActivities = use; } #endif virtual QProcessEnvironment processStartupEnvironment() const; void initPlatform(const KPluginMetaData &plugin); Platform *platform() const { return m_platform; } static void setupMalloc(); static void setupLocalizedString(); static bool usesLibinput(); static void setUseLibinput(bool use); Q_SIGNALS: void x11ConnectionChanged(); void x11ConnectionAboutToBeDestroyed(); void workspaceCreated(); void screensCreated(); void virtualTerminalCreated(); protected: Application(OperationMode mode, int &argc, char **argv); virtual void performStartup() = 0; void notifyKSplash(); void createInput(); void createWorkspace(); void createAtoms(); void createOptions(); void createCompositor(); void setupEventFilters(); void destroyWorkspace(); void destroyCompositor(); /** * Inheriting classes should use this method to set the X11 root window * before accessing any X11 specific code pathes. **/ void setX11RootWindow(xcb_window_t root) { m_rootWindow = root; } /** * Inheriting classes should use this method to set the xcb connection * before accessing any X11 specific code pathes. **/ void setX11Connection(xcb_connection_t *c) { m_connection = c; emit x11ConnectionChanged(); } void destroyAtoms(); protected: QString m_originalSessionKey; static int crashes; private Q_SLOTS: void resetCrashesCount(); private: QScopedPointer m_eventFilter; bool m_configLock; KSharedConfigPtr m_config; OperationMode m_operationMode; xcb_timestamp_t m_x11Time = XCB_TIME_CURRENT_TIME; xcb_window_t m_rootWindow = XCB_WINDOW_NONE; xcb_connection_t *m_connection = nullptr; #ifdef KWIN_BUILD_ACTIVITIES bool m_useKActivities = true; #endif Platform *m_platform = nullptr; }; inline static Application *kwinApp() { return static_cast(QCoreApplication::instance()); } } // namespace #endif diff --git a/scripting/scriptedeffect.cpp b/scripting/scriptedeffect.cpp index 0d59b8930..ab99d8b32 100644 --- a/scripting/scriptedeffect.cpp +++ b/scripting/scriptedeffect.cpp @@ -1,639 +1,640 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2012 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "scriptedeffect.h" #include "meta.h" #include "scriptingutils.h" #include "workspace_wrapper.h" #include "../screenedge.h" -#include "../main.h" #include "scripting_logging.h" // KDE #include #include #include // Qt #include #include #include #include typedef KWin::EffectWindow* KEffectWindowRef; +Q_DECLARE_METATYPE(KSharedConfigPtr) + namespace KWin { QScriptValue kwinEffectScriptPrint(QScriptContext *context, QScriptEngine *engine) { ScriptedEffect *script = qobject_cast(context->callee().data().toQObject()); QString result; for (int i = 0; i < context->argumentCount(); ++i) { if (i > 0) { result.append(QLatin1Char(' ')); } result.append(context->argument(i).toString()); } qCDebug(KWIN_SCRIPTING) << script->scriptFile() << ":" << result; return engine->undefinedValue(); } QScriptValue kwinEffectScriptAnimationTime(QScriptContext *context, QScriptEngine *engine) { if (context->argumentCount() != 1) { return engine->undefinedValue(); } if (!context->argument(0).isNumber()) { return engine->undefinedValue(); } return Effect::animationTime(context->argument(0).toInteger()); } QScriptValue kwinEffectDisplayWidth(QScriptContext *context, QScriptEngine *engine) { Q_UNUSED(context) Q_UNUSED(engine) return displayWidth(); } QScriptValue kwinEffectDisplayHeight(QScriptContext *context, QScriptEngine *engine) { Q_UNUSED(context) Q_UNUSED(engine) return displayHeight(); } QScriptValue kwinScriptGlobalShortcut(QScriptContext *context, QScriptEngine *engine) { return globalShortcut(context, engine); } QScriptValue kwinScriptScreenEdge(QScriptContext *context, QScriptEngine *engine) { return registerScreenEdge(context, engine); } struct AnimationSettings { enum { Type = 1<<0, Curve = 1<<1, Delay = 1<<2, Duration = 1<<3 }; AnimationEffect::Attribute type; QEasingCurve::Type curve; FPx2 from; FPx2 to; int delay; uint duration; uint set; uint metaData; }; AnimationSettings animationSettingsFromObject(QScriptValue &object) { AnimationSettings settings; settings.set = 0; settings.metaData = 0; settings.to = qscriptvalue_cast(object.property(QStringLiteral("to"))); settings.from = qscriptvalue_cast(object.property(QStringLiteral("from"))); QScriptValue duration = object.property(QStringLiteral("duration")); if (duration.isValid() && duration.isNumber()) { settings.duration = duration.toUInt32(); settings.set |= AnimationSettings::Duration; } else { settings.duration = 0; } QScriptValue delay = object.property(QStringLiteral("delay")); if (delay.isValid() && delay.isNumber()) { settings.delay = delay.toInt32(); settings.set |= AnimationSettings::Delay; } else { settings.delay = 0; } QScriptValue curve = object.property(QStringLiteral("curve")); if (curve.isValid() && curve.isNumber()) { settings.curve = static_cast(curve.toInt32()); settings.set |= AnimationSettings::Curve; } else { settings.curve = QEasingCurve::Linear; } QScriptValue type = object.property(QStringLiteral("type")); if (type.isValid() && type.isNumber()) { settings.type = static_cast(type.toInt32()); settings.set |= AnimationSettings::Type; } else { settings.type = static_cast(-1); } return settings; } QList animationSettings(QScriptContext *context, ScriptedEffect *effect, EffectWindow **window) { QList settings; if (!effect) { context->throwError(QScriptContext::ReferenceError, QStringLiteral("Internal Scripted KWin Effect error")); return settings; } if (context->argumentCount() != 1) { context->throwError(QScriptContext::SyntaxError, QStringLiteral("Exactly one argument expected")); return settings; } if (!context->argument(0).isObject()) { context->throwError(QScriptContext::TypeError, QStringLiteral("Argument needs to be an object")); return settings; } QScriptValue object = context->argument(0); QScriptValue windowProperty = object.property(QStringLiteral("window")); if (!windowProperty.isValid() || !windowProperty.isObject()) { context->throwError(QScriptContext::TypeError, QStringLiteral("Window property missing in animation options")); return settings; } *window = qobject_cast(windowProperty.toQObject()); settings << animationSettingsFromObject(object); // global QScriptValue animations = object.property(QStringLiteral("animations")); // array if (animations.isValid()) { if (!animations.isArray()) { context->throwError(QScriptContext::TypeError, QStringLiteral("Animations provided but not an array")); settings.clear(); return settings; } const int length = static_cast(animations.property(QStringLiteral("length")).toInteger()); for (int i=0; ithrowError(QScriptContext::TypeError, QStringLiteral("Type property missing in animation options")); continue; } if (!(set & AnimationSettings::Duration)) { context->throwError(QScriptContext::TypeError, QStringLiteral("Duration property missing in animation options")); continue; } // Complete local animations from global settings if (!(s.set & AnimationSettings::Duration)) { s.duration = settings.at(0).duration; } if (!(s.set & AnimationSettings::Curve)) { s.curve = settings.at(0).curve; } if (!(s.set & AnimationSettings::Delay)) { s.delay = settings.at(0).delay; } s.metaData = 0; typedef QMap MetaTypeMap; static MetaTypeMap metaTypes({ {AnimationEffect::SourceAnchor, QStringLiteral("sourceAnchor")}, {AnimationEffect::TargetAnchor, QStringLiteral("targetAnchor")}, {AnimationEffect::RelativeSourceX, QStringLiteral("relativeSourceX")}, {AnimationEffect::RelativeSourceY, QStringLiteral("relativeSourceY")}, {AnimationEffect::RelativeTargetX, QStringLiteral("relativeTargetX")}, {AnimationEffect::RelativeTargetY, QStringLiteral("relativeTargetY")}, {AnimationEffect::Axis, QStringLiteral("axis")} }); for (MetaTypeMap::const_iterator it = metaTypes.constBegin(), end = metaTypes.constEnd(); it != end; ++it) { QScriptValue metaVal = value.property(*it); if (metaVal.isValid() && metaVal.isNumber()) { AnimationEffect::setMetaData(it.key(), metaVal.toInt32(), s.metaData); } } settings << s; } } } if (settings.count() == 1) { const uint set = settings.at(0).set; if (!(set & AnimationSettings::Type)) { context->throwError(QScriptContext::TypeError, QStringLiteral("Type property missing in animation options")); settings.clear(); } if (!(set & AnimationSettings::Duration)) { context->throwError(QScriptContext::TypeError, QStringLiteral("Duration property missing in animation options")); settings.clear(); } } else if (!(settings.at(0).set & AnimationSettings::Type)) { // invalid global settings.removeAt(0); // -> get rid of it, only used to complete the others } return settings; } QScriptValue kwinEffectAnimate(QScriptContext *context, QScriptEngine *engine) { ScriptedEffect *effect = qobject_cast(context->callee().data().toQObject()); EffectWindow *window; QList settings = animationSettings(context, effect, &window); if (settings.empty()) { context->throwError(QScriptContext::TypeError, QStringLiteral("No animations provided")); return engine->undefinedValue(); } if (!window) { context->throwError(QScriptContext::TypeError, QStringLiteral("Window property does not contain an EffectWindow")); return engine->undefinedValue(); } QScriptValue array = engine->newArray(settings.length()); int i = 0; foreach (const AnimationSettings &setting, settings) { array.setProperty(i, (uint)effect->animate(window, setting.type, setting.duration, setting.to, setting.from, setting.metaData, setting.curve, setting.delay)); ++i; } return array; } QScriptValue kwinEffectSet(QScriptContext *context, QScriptEngine *engine) { ScriptedEffect *effect = qobject_cast(context->callee().data().toQObject()); EffectWindow *window; QList settings = animationSettings(context, effect, &window); if (settings.empty()) { context->throwError(QScriptContext::TypeError, QStringLiteral("No animations provided")); return engine->undefinedValue(); } if (!window) { context->throwError(QScriptContext::TypeError, QStringLiteral("Window property does not contain an EffectWindow")); return engine->undefinedValue(); } QList animIds; foreach (const AnimationSettings &setting, settings) { animIds << QVariant(effect->set(window, setting.type, setting.duration, setting.to, setting.from, setting.metaData, setting.curve, setting.delay)); } return engine->newVariant(animIds); } QList animations(const QVariant &v, bool *ok) { QList animIds; *ok = false; if (v.isValid()) { quint64 animId = v.toULongLong(ok); if (*ok) animIds << animId; } if (!*ok) { // may still be a variantlist of variants being quint64 QList list = v.toList(); if (!list.isEmpty()) { foreach (const QVariant &vv, list) { quint64 animId = vv.toULongLong(ok); if (*ok) animIds << animId; } *ok = !animIds.isEmpty(); } } return animIds; } QScriptValue fpx2ToScriptValue(QScriptEngine *eng, const KWin::FPx2 &fpx2) { QScriptValue val = eng->newObject(); val.setProperty(QStringLiteral("value1"), fpx2[0]); val.setProperty(QStringLiteral("value2"), fpx2[1]); return val; } void fpx2FromScriptValue(const QScriptValue &value, KWin::FPx2 &fpx2) { if (value.isNull()) { fpx2 = FPx2(); return; } if (value.isNumber()) { fpx2 = FPx2(value.toNumber()); return; } if (value.isObject()) { QScriptValue value1 = value.property(QStringLiteral("value1")); QScriptValue value2 = value.property(QStringLiteral("value2")); if (!value1.isValid() || !value2.isValid() || !value1.isNumber() || !value2.isNumber()) { qCDebug(KWIN_SCRIPTING) << "Cannot cast scripted FPx2 to C++"; fpx2 = FPx2(); return; } fpx2 = FPx2(value1.toNumber(), value2.toNumber()); } } QScriptValue kwinEffectRetarget(QScriptContext *context, QScriptEngine *engine) { ScriptedEffect *effect = qobject_cast(context->callee().data().toQObject()); if (context->argumentCount() < 2 || context->argumentCount() > 3) { context->throwError(QScriptContext::SyntaxError, QStringLiteral("2 or 3 arguments expected")); return engine->undefinedValue(); } QVariant v = context->argument(0).toVariant(); bool ok = false; QList animIds = animations(v, &ok); if (!ok) { context->throwError(QScriptContext::TypeError, QStringLiteral("Argument needs to be one or several quint64")); return engine->undefinedValue(); } FPx2 target; fpx2FromScriptValue(context->argument(1), target); ok = false; const int remainingTime = context->argumentCount() == 3 ? context->argument(2).toVariant().toInt() : -1; foreach (const quint64 &animId, animIds) { ok = effect->retarget(animId, target, remainingTime); if (!ok) { break; } } return QScriptValue(ok); } QScriptValue kwinEffectCancel(QScriptContext *context, QScriptEngine *engine) { ScriptedEffect *effect = qobject_cast(context->callee().data().toQObject()); if (context->argumentCount() != 1) { context->throwError(QScriptContext::SyntaxError, QStringLiteral("Exactly one argument expected")); return engine->undefinedValue(); } QVariant v = context->argument(0).toVariant(); bool ok = false; QList animIds = animations(v, &ok); if (!ok) { context->throwError(QScriptContext::TypeError, QStringLiteral("Argument needs to be one or several quint64")); return engine->undefinedValue(); } foreach (const quint64 &animId, animIds) { ok |= engine->newVariant(effect->cancel(animId)).toBool(); } return engine->newVariant(ok); } QScriptValue effectWindowToScriptValue(QScriptEngine *eng, const KEffectWindowRef &window) { return eng->newQObject(window, QScriptEngine::QtOwnership, QScriptEngine::ExcludeChildObjects | QScriptEngine::ExcludeDeleteLater | QScriptEngine::PreferExistingWrapperObject); } void effectWindowFromScriptValue(const QScriptValue &value, EffectWindow* &window) { window = qobject_cast(value.toQObject()); } ScriptedEffect *ScriptedEffect::create(const KPluginMetaData &effect) { const QString name = effect.pluginId(); const QString scriptName = effect.value(QStringLiteral("X-Plasma-MainScript")); if (scriptName.isEmpty()) { qCDebug(KWIN_SCRIPTING) << "X-Plasma-MainScript not set"; return nullptr; } const QString scriptFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String(KWIN_NAME "/effects/") + name + QLatin1String("/contents/") + scriptName); if (scriptFile.isNull()) { qCDebug(KWIN_SCRIPTING) << "Could not locate the effect script"; return nullptr; } return ScriptedEffect::create(name, scriptFile, effect.value(QStringLiteral("X-KDE-Ordering")).toInt()); } ScriptedEffect *ScriptedEffect::create(const QString& effectName, const QString& pathToScript, int chainPosition) { ScriptedEffect *effect = new ScriptedEffect(); if (!effect->init(effectName, pathToScript)) { delete effect; return nullptr; } effect->m_chainPosition = chainPosition; return effect; } bool ScriptedEffect::supported() { return effects->animationsSupported(); } ScriptedEffect::ScriptedEffect() : AnimationEffect() , m_engine(new QScriptEngine(this)) , m_scriptFile(QString()) , m_config(nullptr) , m_chainPosition(0) { connect(m_engine, SIGNAL(signalHandlerException(QScriptValue)), SLOT(signalHandlerException(QScriptValue))); } ScriptedEffect::~ScriptedEffect() { } bool ScriptedEffect::init(const QString &effectName, const QString &pathToScript) { QFile scriptFile(pathToScript); if (!scriptFile.open(QIODevice::ReadOnly)) { qCDebug(KWIN_SCRIPTING) << "Could not open script file: " << pathToScript; return false; } m_effectName = effectName; m_scriptFile = pathToScript; // does the effect contain an KConfigXT file? const QString kconfigXTFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String(KWIN_NAME "/effects/") + m_effectName + QLatin1String("/contents/config/main.xml")); if (!kconfigXTFile.isNull()) { - KConfigGroup cg = kwinApp()->config()->group(QStringLiteral("Effect-%1").arg(m_effectName)); + KConfigGroup cg = QCoreApplication::instance()->property("config").value()->group(QStringLiteral("Effect-%1").arg(m_effectName)); QFile xmlFile(kconfigXTFile); m_config = new KConfigLoader(cg, &xmlFile, this); m_config->load(); } QScriptValue effectsObject = m_engine->newQObject(effects, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater); m_engine->globalObject().setProperty(QStringLiteral("effects"), effectsObject, QScriptValue::Undeletable); m_engine->globalObject().setProperty(QStringLiteral("Effect"), m_engine->newQMetaObject(&ScriptedEffect::staticMetaObject)); #ifndef KWIN_UNIT_TEST m_engine->globalObject().setProperty(QStringLiteral("KWin"), m_engine->newQMetaObject(&QtScriptWorkspaceWrapper::staticMetaObject)); #endif m_engine->globalObject().setProperty(QStringLiteral("QEasingCurve"), m_engine->newQMetaObject(&QEasingCurve::staticMetaObject)); m_engine->globalObject().setProperty(QStringLiteral("effect"), m_engine->newQObject(this, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater), QScriptValue::Undeletable); MetaScripting::registration(m_engine); qScriptRegisterMetaType(m_engine, effectWindowToScriptValue, effectWindowFromScriptValue); qScriptRegisterMetaType(m_engine, fpx2ToScriptValue, fpx2FromScriptValue); qScriptRegisterSequenceMetaType >(m_engine); // add our print QScriptValue printFunc = m_engine->newFunction(kwinEffectScriptPrint); printFunc.setData(m_engine->newQObject(this)); m_engine->globalObject().setProperty(QStringLiteral("print"), printFunc); // add our animationTime QScriptValue animationTimeFunc = m_engine->newFunction(kwinEffectScriptAnimationTime); animationTimeFunc.setData(m_engine->newQObject(this)); m_engine->globalObject().setProperty(QStringLiteral("animationTime"), animationTimeFunc); // add displayWidth and displayHeight QScriptValue displayWidthFunc = m_engine->newFunction(kwinEffectDisplayWidth); m_engine->globalObject().setProperty(QStringLiteral("displayWidth"), displayWidthFunc); QScriptValue displayHeightFunc = m_engine->newFunction(kwinEffectDisplayHeight); m_engine->globalObject().setProperty(QStringLiteral("displayHeight"), displayHeightFunc); // add global Shortcut registerGlobalShortcutFunction(this, m_engine, kwinScriptGlobalShortcut); registerScreenEdgeFunction(this, m_engine, kwinScriptScreenEdge); // add the animate method QScriptValue animateFunc = m_engine->newFunction(kwinEffectAnimate); animateFunc.setData(m_engine->newQObject(this)); m_engine->globalObject().setProperty(QStringLiteral("animate"), animateFunc); // and the set variant QScriptValue setFunc = m_engine->newFunction(kwinEffectSet); setFunc.setData(m_engine->newQObject(this)); m_engine->globalObject().setProperty(QStringLiteral("set"), setFunc); // retarget QScriptValue retargetFunc = m_engine->newFunction(kwinEffectRetarget); retargetFunc.setData(m_engine->newQObject(this)); m_engine->globalObject().setProperty(QStringLiteral("retarget"), retargetFunc); // cancel... QScriptValue cancelFunc = m_engine->newFunction(kwinEffectCancel); cancelFunc.setData(m_engine->newQObject(this)); m_engine->globalObject().setProperty(QStringLiteral("cancel"), cancelFunc); QScriptValue ret = m_engine->evaluate(QString::fromUtf8(scriptFile.readAll())); if (ret.isError()) { signalHandlerException(ret); return false; } scriptFile.close(); return true; } void ScriptedEffect::animationEnded(KWin::EffectWindow *w, Attribute a, uint meta) { AnimationEffect::animationEnded(w, a, meta); emit animationEnded(w, 0); } void ScriptedEffect::signalHandlerException(const QScriptValue &value) { if (value.isError()) { qCDebug(KWIN_SCRIPTING) << "KWin Effect script encountered an error at [Line " << m_engine->uncaughtExceptionLineNumber() << "]"; qCDebug(KWIN_SCRIPTING) << "Message: " << value.toString(); QScriptValueIterator iter(value); while (iter.hasNext()) { iter.next(); qCDebug(KWIN_SCRIPTING) << " " << iter.name() << ": " << iter.value().toString(); } } } quint64 ScriptedEffect::animate(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint metaData, QEasingCurve::Type curve, int delay) { QEasingCurve qec; if (curve < QEasingCurve::Custom) qec.setType(curve); else if (static_cast(curve) == static_cast(GaussianCurve)) qec.setCustomType(qecGaussian); return AnimationEffect::animate(w, a, metaData, ms, to, qec, delay, from); } quint64 ScriptedEffect::set(KWin::EffectWindow* w, KWin::AnimationEffect::Attribute a, int ms, KWin::FPx2 to, KWin::FPx2 from, uint metaData, QEasingCurve::Type curve, int delay) { QEasingCurve qec; if (curve < QEasingCurve::Custom) qec.setType(curve); else if (static_cast(curve) == static_cast(GaussianCurve)) qec.setCustomType(qecGaussian); return AnimationEffect::set(w, a, metaData, ms, to, qec, delay, from); } bool ScriptedEffect::retarget(quint64 animationId, KWin::FPx2 newTarget, int newRemainingTime) { return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); } bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) { void *e = w->data(static_cast(grabRole)).value(); if (e) { return e != this; } else { return false; } } void ScriptedEffect::reconfigure(ReconfigureFlags flags) { AnimationEffect::reconfigure(flags); if (m_config) { m_config->read(); } emit configChanged(); } void ScriptedEffect::registerShortcut(QAction *a, QScriptValue callback) { m_shortcutCallbacks.insert(a, callback); connect(a, SIGNAL(triggered(bool)), SLOT(globalShortcutTriggered())); } void ScriptedEffect::globalShortcutTriggered() { callGlobalShortcutCallback(this, sender()); } bool ScriptedEffect::borderActivated(ElectricBorder edge) { screenEdgeActivated(this, edge); return true; } QVariant ScriptedEffect::readConfig(const QString &key, const QVariant defaultValue) { if (!m_config) { return defaultValue; } return m_config->property(key); } } // namespace