From 3ed63d4c45c1adde72cfebab4ec30498970a4808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 12 Apr 2012 19:42:49 +0200 Subject: [PATCH] Reparse Configuration at startup asynchronous Options loading is split into three parts: * reparse configuration * loading of non-compositing related options * loading of composited related options not needing CompositingPrefs At startup the reparsing of configuration is done through a Thread to gain a little bit of less waiting. Before something else accesses the KConfig for the first time we wait for the thread to finish and perform the other two loading operations of Options. The settings depending on CompositingPrefs will only be invoked if a compositor is going to be needed. REVIEW: 104562 --- main.cpp | 6 ++---- options.cpp | 59 ++++++++++++++++++++++++++++++++++----------------- options.h | 11 ++++++++++ workspace.cpp | 7 ++++++ 4 files changed, 59 insertions(+), 24 deletions(-) diff --git a/main.cpp b/main.cpp index 6055d49a30..36e5786bfb 100644 --- a/main.cpp +++ b/main.cpp @@ -302,10 +302,9 @@ Application::Application() // Reset crashes count if we stay up for more that 15 seconds QTimer::singleShot(15 * 1000, this, SLOT(resetCrashesCount())); - // If KWin was already running it saved its configuration after loosing the selection -> Reread - config->reparseConfiguration(); - initting = true; // Startup... + // first load options - done internally by a different thread + options = new Options; // Install X11 error handler XSetErrorHandler(x11ErrorHandler); @@ -321,7 +320,6 @@ Application::Application() // 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. - options = new Options; // create workspace. (void) new Workspace(isSessionRestored()); diff --git a/options.cpp b/options.cpp index 6eabc7896b..7bb35d0dad 100644 --- a/options.cpp +++ b/options.cpp @@ -191,7 +191,6 @@ Options::Options(QObject *parent) , show_geometry_tip(Options::defaultShowGeometryTip()) , animationSpeed(Options::defaultAnimationSpeed()) { - updateSettings(); } Options::~Options() @@ -781,7 +780,33 @@ void Options::setElectricBorders(int borders) emit electricBordersChanged(); } +void Options::reparseConfiguration() +{ + KGlobal::config()->reparseConfiguration(); +} + unsigned long Options::updateSettings() +{ + unsigned long changed = loadConfig(); + // Read button tooltip animation effect from kdeglobals + // Since we want to allow users to enable window decoration tooltips + // and not kstyle tooltips and vise-versa, we don't read the + // "EffectNoTooltip" setting from kdeglobals. + + +// QToolTip::setGloballyEnabled( d->show_tooltips ); +// KDE4 this probably needs to be done manually in clients + + // Driver-specific config detection + setCompositingInitialized(false); + reloadCompositingSettings(); + + emit configChanged(); + + return changed; +} + +unsigned long Options::loadConfig() { KSharedConfig::Ptr _config = KGlobal::config(); unsigned long changed = 0; @@ -895,25 +920,10 @@ unsigned long Options::updateSettings() setMaxFpsInterval(qRound(1000.0 / config.readEntry("MaxFPS", Options::defaultMaxFps()))); setRefreshRate(config.readEntry("RefreshRate", Options::defaultRefreshRate())); - // Read button tooltip animation effect from kdeglobals - // Since we want to allow users to enable window decoration tooltips - // and not kstyle tooltips and vise-versa, we don't read the - // "EffectNoTooltip" setting from kdeglobals. - - -// QToolTip::setGloballyEnabled( d->show_tooltips ); -// KDE4 this probably needs to be done manually in clients - - // Driver-specific config detection - setCompositingInitialized(false); - reloadCompositingSettings(); - - emit configChanged(); - return changed; } -void Options::reloadCompositingSettings(bool force) +bool Options::loadCompositingConfig (bool force) { KSharedConfig::Ptr _config = KGlobal::config(); KConfigGroup config(_config, "Compositing"); @@ -954,15 +964,22 @@ void Options::reloadCompositingSettings(bool force) if (m_compositingMode == NoCompositing) { setUseCompositing(false); - return; // do not even detect compositing preferences if explicitly disabled + return false; // do not even detect compositing preferences if explicitly disabled } // it's either enforced by env or by initial resume from "suspend" or we check the settings setUseCompositing(useCompositing || force || config.readEntry("Enabled", Options::defaultUseCompositing())); if (!m_useCompositing) - return; // not enforced or necessary and not "enabled" by setting + return false; // not enforced or necessary and not "enabled" by settings + return true; +} +void Options::reloadCompositingSettings(bool force) +{ + if (!loadCompositingConfig(force)) { + return; + } // from now on we've an initial setup and don't have to reload settings on compositing activation // see Workspace::setupCompositing(), composite.cpp setCompositingInitialized(true); @@ -971,7 +988,9 @@ void Options::reloadCompositingSettings(bool force) CompositingPrefs prefs; prefs.detect(); - setUseCompositing(config.readEntry("Enabled" , prefs.recommendCompositing())); + KSharedConfig::Ptr _config = KGlobal::config(); + KConfigGroup config(_config, "Compositing"); + setGlDirect(prefs.enableDirectRendering()); setGlVSync(config.readEntry("GLVSync", prefs.enableVSync())); setGlSmoothScale(qBound(-1, config.readEntry("GLTextureFilter", Options::defaultGlSmoothScale()), 2)); diff --git a/options.h b/options.h index 4d37d8bc42..cd4282f380 100644 --- a/options.h +++ b/options.h @@ -871,6 +871,17 @@ public: static int defaultAnimationSpeed() { return 3; } + + /** + * Performs loading all settings except compositing related. + **/ + unsigned long loadConfig(); + /** + * Performs loading of compositing settings which do not depend on OpenGL. + **/ + bool loadCompositingConfig(bool force); + void reparseConfiguration(); + //---------------------- Q_SIGNALS: void configChanged(); diff --git a/workspace.cpp b/workspace.cpp index b5fb7bb20c..ca82319971 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -157,6 +157,9 @@ Workspace::Workspace(bool restore) , m_finishingCompositing(false) , m_scripting(NULL) { + // If KWin was already running it saved its configuration after loosing the selection -> Reread + QFuture reparseConfigFuture = QtConcurrent::run(options, &Options::reparseConfiguration); + (void) new KWinAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); @@ -171,6 +174,10 @@ Workspace::Workspace(bool restore) desktopGrid_[1] = 0; _self = this; + // PluginMgr needs access to the config file, so we need to wait for it for finishing + reparseConfigFuture.waitForFinished(); + options->loadConfig(); + options->loadCompositingConfig(false); mgr = new PluginMgr; QX11Info info; default_colormap = DefaultColormap(display(), info.screen());