From 0c5d47f3ae5704db1932d5090c3cea723f075e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Sun, 27 Feb 2011 23:39:32 +0100 Subject: [PATCH] unify composite activation, 'Enable' only controls initial state --- composite.cpp | 35 +- kcmkwin/kwincompositing/main.cpp | 91 ++--- kcmkwin/kwincompositing/main.h | 7 +- kcmkwin/kwincompositing/main.ui | 564 +++++++++++++++++-------------- options.cpp | 67 ++-- options.h | 4 +- scene.cpp | 2 +- workspace.cpp | 5 +- 8 files changed, 401 insertions(+), 374 deletions(-) diff --git a/composite.cpp b/composite.cpp index 9d16f68bd3..94b35aa0a1 100644 --- a/composite.cpp +++ b/composite.cpp @@ -89,39 +89,16 @@ void Workspace::setupCompositing() #ifdef KWIN_HAVE_COMPOSITING if (scene != NULL) return; - if (!options->useCompositing && getenv("KWIN_COMPOSE") == NULL) { - kDebug(1212) << "Compositing is turned off in options or disabled"; - return; - } else if (compositingSuspended) { + if (compositingSuspended) { kDebug(1212) << "Compositing is suspended"; return; } else if (!CompositingPrefs::compositingPossible()) { kError(1212) << "Compositing is not possible"; return; } - CompositingType type = options->compositingMode; - if (getenv("KWIN_COMPOSE")) { - char c = getenv("KWIN_COMPOSE")[ 0 ]; - switch(c) { - case 'O': - kDebug(1212) << "Compositing forced to OpenGL mode by environment variable"; - type = OpenGLCompositing; - break; - case 'X': - kDebug(1212) << "Compositing forced to XRender mode by environment variable"; - type = XRenderCompositing; - break; - case 'N': - if (getenv("KDE_FAILSAFE")) - kDebug(1212) << "Compositing disabled forcefully by KDE failsafe mode"; - else - kDebug(1212) << "Compositing disabled forcefully by environment variable"; - return; // Return not break - default: - kDebug(1212) << "Unknown KWIN_COMPOSE mode set, ignoring"; - break; - } - } + + if (!options->compositingInitialized) + options->reloadCompositingSettings(true); char selection_name[ 100 ]; sprintf(selection_name, "_NET_WM_CM_S%d", DefaultScreen(display())); @@ -129,7 +106,7 @@ void Workspace::setupCompositing() connect(cm_selection, SIGNAL(lostOwnership()), SLOT(lostCMSelection())); cm_selection->claim(true); // force claiming - switch(type) { + switch(options->compositingMode) { /*case 'B': kDebug( 1212 ) << "X compositing"; scene = new SceneBasic( this ); @@ -295,7 +272,7 @@ void Workspace::toggleCompositing() QString shortcut, message; if (KAction* action = qobject_cast(keys->action("Suspend Compositing"))) shortcut = action->globalShortcut().primary().toString(QKeySequence::NativeText); - if (!shortcut.isEmpty() && options->useCompositing) { + if (!shortcut.isEmpty()) { // display notification only if there is the shortcut message = i18n("Desktop effects have been suspended by another application.
" "You can resume using the '%1' shortcut.", shortcut); diff --git a/kcmkwin/kwincompositing/main.cpp b/kcmkwin/kwincompositing/main.cpp index 71e759ca59..e8abdfc7a8 100644 --- a/kcmkwin/kwincompositing/main.cpp +++ b/kcmkwin/kwincompositing/main.cpp @@ -23,6 +23,8 @@ along with this program. If not, see . #include "kwin_interface.h" #include +#include +#include #include #include #include @@ -74,13 +76,10 @@ KWinCompositingConfig::KWinCompositingConfig(QWidget *parent, const QVariantList : KCModule(KWinCompositingConfigFactory::componentData(), parent) , mKWinConfig(KSharedConfig::openConfig("kwinrc")) , m_showConfirmDialog(false) - , kwinInterface(NULL) { KGlobal::locale()->insertCatalog("kwin_effects"); ui.setupUi(this); layout()->setMargin(0); - ui.verticalSpacer->changeSize(20, KDialog::groupSpacingHint()); - ui.verticalSpacer_2->changeSize(20, KDialog::groupSpacingHint()); ui.tabWidget->setCurrentIndex(0); ui.statusTitleWidget->hide(); @@ -101,9 +100,6 @@ KWinCompositingConfig::KWinCompositingConfig(QWidget *parent, const QVariantList #define XRENDER_INDEX -1 #endif - kwinInterface = new OrgKdeKWinInterface("org.kde.kwin", "/KWin", QDBusConnection::sessionBus()); - - connect(ui.useCompositing, SIGNAL(toggled(bool)), this, SLOT(compositingEnabled(bool))); connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int))); connect(ui.useCompositing, SIGNAL(toggled(bool)), this, SLOT(changed())); @@ -128,8 +124,6 @@ KWinCompositingConfig::KWinCompositingConfig(QWidget *parent, const QVariantList connect(ui.glDirect, SIGNAL(toggled(bool)), this, SLOT(changed())); connect(ui.glVSync, SIGNAL(toggled(bool)), this, SLOT(changed())); - connect(ui.compositingStateButton, SIGNAL(clicked(bool)), kwinInterface, SLOT(toggleCompositing())); - connect(kwinInterface, SIGNAL(compositingToggled(bool)), this, SLOT(setupCompositingState(bool))); // Open the temporary config file // Temporary conf file is used to synchronize effect checkboxes with effect @@ -138,6 +132,16 @@ KWinCompositingConfig::KWinCompositingConfig(QWidget *parent, const QVariantList mTmpConfigFile.open(); mTmpConfig = KSharedConfig::openConfig(mTmpConfigFile.fileName()); + // toggle effects shortcut button stuff - /HAS/ to happen before load! + m_actionCollection = new KActionCollection( this, KComponentData("kwin") ); + m_actionCollection->setConfigGroup("Suspend Compositing"); + m_actionCollection->setConfigGlobal(true); + + KAction* a = static_cast(m_actionCollection->addAction( "Suspend Compositing" )); + a->setProperty("isConfigurationAction", true); + a->setGlobalShortcut( KShortcut( Qt::ALT + Qt::SHIFT + Qt::Key_F12 )); + connect(ui.toggleEffectsShortcut, SIGNAL(keySequenceChanged(const QKeySequence&)), this, SLOT(toggleEffectShortcutChanged(const QKeySequence&))); + // NOTICE: this is intended to workaround broken GL implementations that successfully segfault on glXQuery :-( KConfigGroup unsafeConfig(mKWinConfig, "Compositing"); const bool glUnsafe = unsafeConfig.readEntry("OpenGLIsUnsafe", false); @@ -158,7 +162,6 @@ KWinCompositingConfig::KWinCompositingConfig(QWidget *parent, const QVariantList ui.useCompositing->setEnabled(false); ui.useCompositing->setChecked(false); - compositingEnabled(false); QString text = i18n("Desktop effects are not available on this system due to the following technical issues:"); text += "
"; @@ -166,8 +169,6 @@ KWinCompositingConfig::KWinCompositingConfig(QWidget *parent, const QVariantList ui.statusTitleWidget->setText(text); ui.statusTitleWidget->setPixmap(KTitleWidget::InfoMessage, KTitleWidget::ImageLeft); ui.statusTitleWidget->show(); - - setupCompositingState(false, false); } KAboutData *about = new KAboutData(I18N_NOOP("kcmkwincompositing"), 0, @@ -225,14 +226,6 @@ void KWinCompositingConfig::reparseConfiguration(const QByteArray& conf) KSettings::Dispatcher::reparseConfiguration(conf); } -void KWinCompositingConfig::compositingEnabled(bool enabled) -{ - // Enable the other configuration tabs only when compositing is enabled. - ui.compositingOptionsContainer->setEnabled(enabled); - ui.tabWidget->setTabEnabled(1, enabled); - ui.tabWidget->setTabEnabled(2, enabled); -} - void KWinCompositingConfig::showConfirmDialog(bool reinitCompositing) { bool revert = false; @@ -252,7 +245,6 @@ void KWinCompositingConfig::showConfirmDialog(bool reinitCompositing) revert = true; else { // compositing is enabled now - setupCompositingState(kwinInterface->compositingActive()); checkLoadedEffects(); } } @@ -315,6 +307,12 @@ void KWinCompositingConfig::loadGeneralTab() KConfigGroup config(mKWinConfig, "Compositing"); bool enabled = config.readEntry("Enabled", mDefaultPrefs.recommendCompositing()); ui.useCompositing->setChecked(enabled); + + // this works by global shortcut magics - it will pick the current sc + // but the constructor line that adds the default alt+shift+f12 gsc is IMPORTANT! + if (KAction *a = qobject_cast(m_actionCollection->action("Suspend Compositing"))) + ui.toggleEffectsShortcut->setKeySequence(a->globalShortcut().primary()); + ui.animationSpeedCombo->setCurrentIndex(config.readEntry("AnimationSpeed", 3)); // Load effect settings @@ -356,46 +354,8 @@ void KWinCompositingConfig::loadGeneralTab() ui.desktopSwitchingCombo->setCurrentIndex(2); if (effectEnabled("fadedesktop", effectconfig)) ui.desktopSwitchingCombo->setCurrentIndex(3); - - if (enabled) - setupCompositingState(kwinInterface->compositingActive()); - else - setupCompositingState(false, false); } -void KWinCompositingConfig::setupCompositingState(bool active, bool enabled) -{ - if (!qgetenv("KDE_FAILSAFE").isNull()) - enabled = false; - // compositing state - QString stateIcon; - QString stateText; - QString stateButtonText; - if (enabled) { - // check if compositing is active or suspended - if (active) { - stateIcon = QString("dialog-ok-apply"); - stateText = i18n("Desktop effects are active"); - stateButtonText = i18n("Suspend Desktop Effects"); - } else { - stateIcon = QString("dialog-cancel"); - stateText = i18n("Desktop effects are temporarily disabled"); - stateButtonText = i18n("Resume Desktop Effects"); - } - } else { - // compositing is disabled - stateIcon = QString("dialog-cancel"); - stateText = i18n("Desktop effects are disabled"); - stateButtonText = i18n("Resume Desktop Effects"); - } - const int iconSize = (QApplication::fontMetrics().height() > 24) ? 32 : 22; - ui.compositingStateIcon->setPixmap(KIcon(stateIcon).pixmap(iconSize, iconSize)); - ui.compositingStateLabel->setText(stateText); - ui.compositingStateButton->setText(stateButtonText); - ui.compositingStateIcon->setEnabled(enabled); - ui.compositingStateLabel->setEnabled(enabled); - ui.compositingStateButton->setEnabled(enabled); -} void KWinCompositingConfig::toogleSmoothScaleUi(int compositingType) { @@ -404,6 +364,13 @@ void KWinCompositingConfig::toogleSmoothScaleUi(int compositingType) ui.scaleMethodLabel->setBuddy(compositingType == XRENDER_INDEX ? ui.xrScaleFilter : ui.glScaleFilter); } +void KWinCompositingConfig::toggleEffectShortcutChanged(const QKeySequence &seq) +{ + if (KAction *a = qobject_cast(m_actionCollection->action("Suspend Compositing"))) + a->setGlobalShortcut(KShortcut(seq), KAction::ActiveShortcut, KAction::NoAutoloading); + m_actionCollection->writeSettings(); +} + bool KWinCompositingConfig::effectEnabled(const QString& effect, const KConfigGroup& cfg) const { KService::List services = KServiceTypeTrader::self()->query( @@ -467,17 +434,9 @@ void KWinCompositingConfig::saveGeneralTab() { KConfigGroup config(mKWinConfig, "Compositing"); // Check if any critical settings that need confirmation have changed - if (ui.useCompositing->isChecked() && - ui.useCompositing->isChecked() != config.readEntry("Enabled", mDefaultPrefs.recommendCompositing())) - m_showConfirmDialog = true; - config.writeEntry("Enabled", ui.useCompositing->isChecked()); config.writeEntry("AnimationSpeed", ui.animationSpeedCombo->currentIndex()); - // disable the compositing state if compositing was turned off - if (!ui.useCompositing->isChecked()) - setupCompositingState(false, false); - // Save effects KConfigGroup effectconfig(mTmpConfig, "Plugins"); #define WRITE_EFFECT_CONFIG(effectname, widget) effectconfig.writeEntry("kwin4_effect_" effectname "Enabled", widget->isChecked()) diff --git a/kcmkwin/kwincompositing/main.h b/kcmkwin/kwincompositing/main.h index 313db49d12..84742b701f 100644 --- a/kcmkwin/kwincompositing/main.h +++ b/kcmkwin/kwincompositing/main.h @@ -33,6 +33,7 @@ along with this program. If not, see . #include "ktimerdialog.h" class KPluginSelector; +class KActionCollection; class QLabel; namespace KWin @@ -55,7 +56,6 @@ public: virtual QString quickHelp() const; public slots: - virtual void compositingEnabled(bool enabled); virtual void showConfirmDialog(bool reinitCompositing); void currentTabChanged(int tab); @@ -74,10 +74,10 @@ public slots: void checkLoadedEffects(); void configChanged(bool reinitCompositing); void initEffectSelector(); - void setupCompositingState(bool active, bool enabled = true); private slots: void toogleSmoothScaleUi(int compositingType); + void toggleEffectShortcutChanged(const QKeySequence &seq); private: bool effectEnabled(const QString& effect, const KConfigGroup& cfg) const; @@ -90,8 +90,7 @@ private: KTemporaryFile mTmpConfigFile; KSharedConfigPtr mTmpConfig; bool m_showConfirmDialog; - - OrgKdeKWinInterface* kwinInterface; + KActionCollection* m_actionCollection; }; } // namespace diff --git a/kcmkwin/kwincompositing/main.ui b/kcmkwin/kwincompositing/main.ui index 81cb437118..0700dc1779 100644 --- a/kcmkwin/kwincompositing/main.ui +++ b/kcmkwin/kwincompositing/main.ui @@ -6,8 +6,8 @@ 0 0 - 595 - 483 + 560 + 472 @@ -20,249 +20,323 @@ General - + - - - Enable desktop effects + + + 0 - - true - - - - - - - - 0 - - - - - Common Settings - - - - - - Improved window management - - - true - - - - - - - Various animations - - - true - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - You can find more effects, as well as effect-specific settings, in the "All Effects" tab above. - - - true - - - - - - - Effect for window switching: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - windowSwitchingCombo - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - - 0 - 0 - - - - 3 - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Activation + + + true + + - - Instant - + + + Enable desktop effects at startup + + + true + + - - Very Fast - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Desktop effects can be toggled anytime using this shortcut: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - Fast - + + + + + + + Simple effect setup + + + true + + + + + + Improved window management + + + true + + - - - Normal - + + + + Various animations + + + true + + - - - Slow - + + + + Effect for window switching: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + windowSwitchingCombo + + - - - Very Slow - + + + + + 0 + 0 + + + - - - Extremely Slow - + + + + Qt::Horizontal + + + + 40 + 20 + + + - - - - - - Animation speed: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - animationSpeedCombo - - - - - - - Effect for desktop switching: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - windowSwitchingCombo - - - - - - - - - - Compositing State - - - - - - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - - + + + + Effect for desktop switching: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + windowSwitchingCombo + + + + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Animation speed: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + animationSpeedCombo + + + + + + + + 0 + 0 + + + + 3 + + + + Instant + + + + + Very Fast + + + + + Fast + + + + + Normal + + + + + Slow + + + + + Very Slow + + + + + Extremely Slow + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + You can find more effects, as well as effect-specific settings, in the "All Effects" tab above. + + + Qt::AlignCenter + + + true + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -271,8 +345,8 @@ - 20 - 0 + 512 + 75 @@ -569,6 +643,11 @@ p, li { white-space: pre-wrap; } + + KKeySequenceWidget + QWidget +
kkeysequencewidget.h
+
KTitleWidget QWidget @@ -596,22 +675,5 @@ p, li { white-space: pre-wrap; } animationSpeedCombo - - - useCompositing - toggled(bool) - groupBox - setEnabled(bool) - - - 86 - 66 - - - 102 - 156 - - - - + diff --git a/options.cpp b/options.cpp index 9caf2b1bd0..e116a60ae2 100644 --- a/options.cpp +++ b/options.cpp @@ -98,6 +98,7 @@ Options::Options() : electric_borders(0) , electric_border_delay(0) { + compositingInitialized = false; updateSettings(); } @@ -264,39 +265,67 @@ FIXME: we have no mac style menu implementation in kwin anymore, so this just br // KDE4 this probably needs to be done manually in clients // Driver-specific config detection + compositingInitialized = false; reloadCompositingSettings(); return changed; } -void Options::reloadCompositingSettings() +void Options::reloadCompositingSettings(bool force) { KSharedConfig::Ptr _config = KGlobal::config(); KConfigGroup config(_config, "Compositing"); - // do not even detect compositing preferences if explicitly disabled - bool environmentForce = false; - if (getenv("KWIN_COMPOSE")) { - // if compositing is enforced by the environment variable, the preferences have to be read - const char c = getenv("KWIN_COMPOSE")[ 0 ]; - if (c == 'X' || c == 'O') - environmentForce = true; - } - if (config.hasKey("Enabled") && !config.readEntry("Enabled", true) && !environmentForce) { - useCompositing = false; - return; - } - // Compositing settings - CompositingPrefs prefs; - prefs.detect(); - - useCompositing = config.readEntry("Enabled" , prefs.recommendCompositing()); - QString compositingBackend = config.readEntry("Backend", "OpenGL"); if (compositingBackend == "XRender") compositingMode = XRenderCompositing; else compositingMode = OpenGLCompositing; + + useCompositing = false; + if (const char *c = getenv("KWIN_COMPOSE")) { + switch(c[0]) { + case 'O': + kDebug(1212) << "Compositing forced to OpenGL mode by environment variable"; + compositingMode = OpenGLCompositing; + useCompositing = true; + break; + case 'X': + kDebug(1212) << "Compositing forced to XRender mode by environment variable"; + compositingMode = XRenderCompositing; + useCompositing = true; + break; + case 'N': + if (getenv("KDE_FAILSAFE")) + kDebug(1212) << "Compositing disabled forcefully by KDE failsafe mode"; + else + kDebug(1212) << "Compositing disabled forcefully by environment variable"; + compositingMode = NoCompositing; + break; + default: + kDebug(1212) << "Unknown KWIN_COMPOSE mode set, ignoring"; + break; + } + } + + if (compositingMode == NoCompositing) + return; // 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 + useCompositing = useCompositing || force || config.readEntry("Enabled", true); + + if (!useCompositing) + return; // not enforced or necessary and not "enabled" by setting + + // from now on we've an initial setup and don't have to reload settigns on compositing activation + // see Workspace::setupCompositing(), composite.cpp + compositingInitialized = true; + + // Compositing settings + CompositingPrefs prefs; + prefs.detect(); + + useCompositing = config.readEntry("Enabled" , prefs.recommendCompositing()); disableCompositingChecks = config.readEntry("DisableChecks", false); glDirect = config.readEntry("GLDirect", prefs.enableDirectRendering()); glVSync = config.readEntry("GLVSync", prefs.enableVSync()); diff --git a/options.h b/options.h index e322d51c8b..0ef0b9206d 100644 --- a/options.h +++ b/options.h @@ -363,9 +363,10 @@ public: //---------------------- // Compositing settings - + void reloadCompositingSettings(bool force = false); CompositingType compositingMode; bool useCompositing; // Separate to mode so the user can toggle + bool compositingInitialized; // General preferences HiddenPreviews hiddenPreviews; @@ -431,7 +432,6 @@ private: int animationSpeed; // 0 - instant, 5 - very slow MouseCommand wheelToMouseCommand(MouseWheelCommand com, int delta); - void reloadCompositingSettings(); }; extern Options* options; diff --git a/scene.cpp b/scene.cpp index b6fb7636a3..eadaad0500 100644 --- a/scene.cpp +++ b/scene.cpp @@ -87,7 +87,7 @@ namespace KWin // Scene //**************************************** -Scene* scene; +Scene* scene = 0; Scene::Scene(Workspace* ws) : wspace(ws) diff --git a/workspace.cpp b/workspace.cpp index 922de171fb..61ce2fe7ba 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -217,6 +217,7 @@ Workspace::Workspace(bool restore) ); Extensions::init(); + compositingSuspended = !options->useCompositing; setupCompositing(); // Compatibility @@ -1100,7 +1101,7 @@ void Workspace::slotReconfigure() updateCurrentTopMenu(); } - if (options->useCompositing && !compositingSuspended) { + if (!compositingSuspended) { setupCompositing(); if (effects) // setupCompositing() may fail effects->reconfigure(); @@ -1143,7 +1144,6 @@ void Workspace::slotReinitCompositing() { // Reparse config. Config options will be reloaded by setupCompositing() KGlobal::config()->reparseConfiguration(); - options->updateSettings(); // Update any settings that can be set in the compositing kcm. updateElectricBorders(); @@ -1153,6 +1153,7 @@ void Workspace::slotReinitCompositing() // resume compositing if suspended compositingSuspended = false; + options->compositingInitialized = false; setupCompositing(); KDecorationFactory* factory = mgr->factory(); factory->reset(SettingCompositing);