From 2ce4d166a1cea38f52cc0203258500a402ed0b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 9 Jul 2011 10:32:26 +0200 Subject: [PATCH] Move loading of the TabBox Config XML into a thread This should improve the KWin startup time as some IO is moved into another thread. Till the config is loaded the TabBox blocks all signals to activate the TabBox, but it is unlikely that alt+tab is tried to be used before KWin is completely started. --- tabbox.cpp | 36 +++++++++++++++++++++++++++++++++--- tabbox.h | 3 +++ tabbox/tabboxhandler.cpp | 15 ++++++++++----- tabbox/tabboxhandler.h | 1 + 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/tabbox.cpp b/tabbox.cpp index 0c75a75989..f3381fbb01 100644 --- a/tabbox.cpp +++ b/tabbox.cpp @@ -280,6 +280,7 @@ TabBox::TabBox(QObject *parent) , m_desktopGrab(false) , m_tabGrab(false) , m_forcedGlobalMouseGrab(false) + , m_ready(false) { m_isShown = false; m_defaultConfig = TabBoxConfig(); @@ -308,11 +309,9 @@ TabBox::TabBox(QObject *parent) m_desktopListConfig.setDesktopSwitchingMode(TabBoxConfig::StaticDesktopSwitching); m_desktopListConfig.setLayout(TabBoxConfig::VerticalLayout); m_tabBox = new TabBoxHandlerImpl(this); - m_tabBox->setConfig(m_defaultConfig); - + connect(m_tabBox, SIGNAL(ready()), SLOT(handlerReady())); m_tabBoxMode = TabBoxDesktopMode; // init variables - reconfigure(); connect(&m_delayedShowTimer, SIGNAL(timeout()), this, SLOT(show())); } @@ -320,6 +319,13 @@ TabBox::~TabBox() { } +void TabBox::handlerReady() +{ + m_tabBox->setConfig(m_defaultConfig); + reconfigure(); + m_ready = true; +} + void TabBox::initShortcuts(KActionCollection* keys) { KAction *a = NULL; @@ -752,26 +758,41 @@ void TabBox::navigatingThroughWindows(bool forward, const KShortcut& shortcut, T void TabBox::slotWalkThroughWindows() { + if (!m_ready){ + return; + } navigatingThroughWindows(true, m_cutWalkThroughWindows, TabBoxWindowsMode); } void TabBox::slotWalkBackThroughWindows() { + if (!m_ready){ + return; + } navigatingThroughWindows(false, m_cutWalkThroughWindowsReverse, TabBoxWindowsMode); } void TabBox::slotWalkThroughWindowsAlternative() { + if (!m_ready){ + return; + } navigatingThroughWindows(true, m_cutWalkThroughWindowsAlternative, TabBoxWindowsAlternativeMode); } void TabBox::slotWalkBackThroughWindowsAlternative() { + if (!m_ready){ + return; + } navigatingThroughWindows(false, m_cutWalkThroughWindowsAlternativeReverse, TabBoxWindowsAlternativeMode); } void TabBox::slotWalkThroughDesktops() { + if (!m_ready){ + return; + } if (isGrabbed()) return; if (areModKeysDepressed(m_cutWalkThroughDesktops)) { @@ -784,6 +805,9 @@ void TabBox::slotWalkThroughDesktops() void TabBox::slotWalkBackThroughDesktops() { + if (!m_ready){ + return; + } if (isGrabbed()) return; if (areModKeysDepressed(m_cutWalkThroughDesktopsReverse)) { @@ -796,6 +820,9 @@ void TabBox::slotWalkBackThroughDesktops() void TabBox::slotWalkThroughDesktopList() { + if (!m_ready){ + return; + } if (isGrabbed()) return; if (areModKeysDepressed(m_cutWalkThroughDesktopList)) { @@ -808,6 +835,9 @@ void TabBox::slotWalkThroughDesktopList() void TabBox::slotWalkBackThroughDesktopList() { + if (!m_ready){ + return; + } if (isGrabbed()) return; if (areModKeysDepressed(m_cutWalkThroughDesktopListReverse)) { diff --git a/tabbox.h b/tabbox.h index f83ae4507d..9c77fa0ab5 100644 --- a/tabbox.h +++ b/tabbox.h @@ -188,6 +188,8 @@ public slots: void slotWalkThroughWindowsAlternativeKeyChanged(const QKeySequence& seq); void slotWalkBackThroughWindowsAlternativeKeyChanged(const QKeySequence& seq); + void handlerReady(); + signals: void tabBoxAdded(int); void tabBoxClosed(); @@ -239,6 +241,7 @@ private: KShortcut m_cutWalkThroughGroupWindows, m_cutWalkThroughGroupWindowsReverse; KShortcut m_cutWalkThroughWindowsAlternative, m_cutWalkThroughWindowsAlternativeReverse; bool m_forcedGlobalMouseGrab; + bool m_ready; // indicates whether the config is completely loaded }; } // namespace TabBox } // namespace diff --git a/tabbox/tabboxhandler.cpp b/tabbox/tabboxhandler.cpp index 5ffb27810f..39b09b75cd 100644 --- a/tabbox/tabboxhandler.cpp +++ b/tabbox/tabboxhandler.cpp @@ -30,6 +30,8 @@ along with this program. If not, see . #include "tabboxview.h" // Qt #include +#include +#include #include #include #include @@ -94,11 +96,10 @@ TabBoxHandlerPrivate::TabBoxHandlerPrivate(TabBoxHandler *q) view = new TabBoxView(); // load the layouts - parseConfig(KStandardDirs::locate("data", "kwin/DefaultTabBoxLayouts.xml")); - view->clientDelegate()->setConfig(tabBoxLayouts.value("Default")); - view->additionalClientDelegate()->setConfig(tabBoxLayouts.value("Text")); - view->desktopDelegate()->setConfig(tabBoxLayouts.value("Desktop")); - view->desktopDelegate()->setLayouts(tabBoxLayouts); + QFuture< void> future = QtConcurrent::run(this, &TabBoxHandlerPrivate::parseConfig, KStandardDirs::locate("data", "kwin/DefaultTabBoxLayouts.xml")); + QFutureWatcher< void > *watcher = new QFutureWatcher< void >(q); + watcher->setFuture(future); + q->connect(watcher, SIGNAL(finished()), q, SIGNAL(ready())); } TabBoxHandlerPrivate::~TabBoxHandlerPrivate() @@ -325,6 +326,10 @@ void TabBoxHandlerPrivate::parseConfig(const QString& fileName) tabBoxLayouts.insert(layoutName, currentLayout); } } // for loop layouts + view->clientDelegate()->setConfig(tabBoxLayouts.value("Default")); + view->additionalClientDelegate()->setConfig(tabBoxLayouts.value("Text")); + view->desktopDelegate()->setConfig(tabBoxLayouts.value("Desktop")); + view->desktopDelegate()->setLayouts(tabBoxLayouts); } /*********************************************** diff --git a/tabbox/tabboxhandler.h b/tabbox/tabboxhandler.h index af5a2c8de9..cefec5f587 100644 --- a/tabbox/tabboxhandler.h +++ b/tabbox/tabboxhandler.h @@ -339,6 +339,7 @@ signals: * @see setConfig */ void configChanged(); + void ready(); private: friend class TabBoxHandlerPrivate;