From 97ba1ebd1ec510727d699689f01160925c22fed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 24 Jan 2013 15:25:34 +0100 Subject: [PATCH] Use KConfigXT in KWin::Options For the time being the current design of Options is more or less kept to not have to adjust KWin code all over the place. Also for some parts the generated class from KConfigXT cannot be used due to inter-settings dependencies defined in the setters. Options now holds a pointer to a Settings object which is generated from KConfigXT and uses it to read the default values and the individual settings. This means the static default value methods are dropped and the variables are initialized with a normal default value (all int 0, all boolean false and so on) in the initializer list. Afterwards the values are set to the correct default value through KConfigXT. So far for the first step only Windows category is using KConfigXT. REVIEW: 108572 --- CMakeLists.txt | 2 + kwin.kcfg | 2 +- options.cpp | 171 +++++++++++++++++++++++-------------------------- options.h | 91 +------------------------- settings.kcfgc | 7 ++ 5 files changed, 92 insertions(+), 181 deletions(-) create mode 100644 settings.kcfgc diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fbaa3ee2..2f44c5706 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,6 +170,8 @@ if(KWIN_HAVE_EGL) set(kwin_KDEINIT_SRCS ${kwin_KDEINIT_SRCS} eglonxbackend.cpp) endif(KWIN_HAVE_EGL) +kde4_add_kcfg_files(kwin_KDEINIT_SRCS settings.kcfgc) + qt4_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.KWin.xml dbusinterface.h KWin::DBusInterface ) qt4_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.kwin.Compositing.xml composite.h KWin::Compositor ) qt4_add_dbus_adaptor( kwin_KDEINIT_SRCS org.kde.kwin.Effects.xml effects.h KWin::EffectsHandlerImpl ) diff --git a/kwin.kcfg b/kwin.kcfg index bc5170efb..3d254fbf0 100644 --- a/kwin.kcfg +++ b/kwin.kcfg @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" > - + Switch to Window Tab to the Left/Right diff --git a/options.cpp b/options.cpp index 798460f2a..893b1fa89 100644 --- a/options.cpp +++ b/options.cpp @@ -38,6 +38,7 @@ along with this program. If not, see . #include "client.h" #include "compositingprefs.h" +#include "settings.h" #include "xcbutils.h" #include @@ -119,30 +120,31 @@ int currentRefreshRate() Options::Options(QObject *parent) : QObject(parent) - , m_focusPolicy(Options::defaultFocusPolicy()) - , m_nextFocusPrefersMouse(Options::defaultNextFocusPrefersMouse()) - , m_clickRaise(Options::defaultClickRaise()) - , m_autoRaise(Options::defaultAutoRaise()) - , m_autoRaiseInterval(Options::defaultAutoRaiseInterval()) - , m_delayFocusInterval(Options::defaultDelayFocusInterval()) - , m_shadeHover(Options::defaultShadeHover()) - , m_shadeHoverInterval(Options::defaultShadeHoverInterval()) - , m_separateScreenFocus(Options::defaultSeparateScreenFocus()) - , m_activeMouseScreen(Options::defaultActiveMouseScreen()) - , m_placement(Options::defaultPlacement()) - , m_borderSnapZone(Options::defaultBorderSnapZone()) - , m_windowSnapZone(Options::defaultWindowSnapZone()) - , m_centerSnapZone(Options::defaultCenterSnapZone()) - , m_snapOnlyWhenOverlapping(Options::defaultSnapOnlyWhenOverlapping()) - , m_showDesktopIsMinimizeAll(Options::defaultShowDesktopIsMinimizeAll()) - , m_rollOverDesktops(Options::defaultRollOverDesktops()) - , m_focusStealingPreventionLevel(Options::defaultFocusStealingPreventionLevel()) - , m_legacyFullscreenSupport(Options::defaultLegacyFullscreenSupport()) - , m_killPingTimeout(Options::defaultKillPingTimeout()) - , m_hideUtilityWindowsForInactive(Options::defaultHideUtilityWindowsForInactive()) - , m_inactiveTabsSkipTaskbar(Options::defaultInactiveTabsSkipTaskbar()) - , m_autogroupSimilarWindows(Options::defaultAutogroupSimilarWindows()) - , m_autogroupInForeground(Options::defaultAutogroupInForeground()) + , m_settings(new Settings(KGlobal::config())) + , m_focusPolicy(ClickToFocus) + , m_nextFocusPrefersMouse(false) + , m_clickRaise(false) + , m_autoRaise(false) + , m_autoRaiseInterval(0) + , m_delayFocusInterval(0) + , m_shadeHover(false) + , m_shadeHoverInterval(0) + , m_separateScreenFocus(false) + , m_activeMouseScreen(false) + , m_placement(Placement::NoPlacement) + , m_borderSnapZone(0) + , m_windowSnapZone(0) + , m_centerSnapZone(0) + , m_snapOnlyWhenOverlapping(false) + , m_showDesktopIsMinimizeAll(false) + , m_rollOverDesktops(false) + , m_focusStealingPreventionLevel(0) + , m_legacyFullscreenSupport(false) + , m_killPingTimeout(0) + , m_hideUtilityWindowsForInactive(false) + , m_inactiveTabsSkipTaskbar(false) + , m_autogroupSimilarWindows(false) + , m_autogroupInForeground(false) , m_compositingMode(Options::defaultCompositingMode()) , m_useCompositing(Options::defaultUseCompositing()) , m_compositingInitialized(Options::defaultCompositingInitialized()) @@ -176,14 +178,16 @@ Options::Options(QObject *parent) , CmdAll3(Options::defaultCommandAll3()) , CmdAllWheel(Options::defaultCommandAllWheel()) , CmdAllModKey(Options::defaultKeyCmdAllModKey()) - , electric_border_maximize(Options::defaultElectricBorderMaximize()) - , electric_border_tiling(Options::defaultElectricBorderTiling()) - , electric_border_corner_ratio(Options::defaultElectricBorderCornerRatio()) - , borderless_maximized_windows(Options::defaultBorderlessMaximizedWindows()) - , show_geometry_tip(Options::defaultShowGeometryTip()) - , condensed_title(Options::defaultCondensedTitle()) + , electric_border_maximize(false) + , electric_border_tiling(false) + , electric_border_corner_ratio(0.0) + , borderless_maximized_windows(false) + , show_geometry_tip(false) + , condensed_title(false) , animationSpeed(Options::defaultAnimationSpeed()) { + m_settings->setDefaults(); + syncFromKcfgc(); } Options::~Options() @@ -793,77 +797,19 @@ unsigned long Options::updateSettings() unsigned long Options::loadConfig() { KSharedConfig::Ptr _config = KGlobal::config(); + m_settings->readConfig(); unsigned long changed = 0; - changed |= KDecorationOptions::updateSettings(_config.data()); // read decoration settings + changed |= KDecorationOptions::updateSettings(m_settings->config()); // read decoration settings - KConfigGroup config(_config, "Windows"); - setShowGeometryTip(config.readEntry("GeometryTip", Options::defaultShowGeometryTip())); - setCondensedTitle(config.readEntry("CondensedTitle", Options::defaultCondensedTitle())); - - QString val; - - val = config.readEntry("FocusPolicy", "ClickToFocus"); - if (val == "FocusFollowsMouse") { - setFocusPolicy(FocusFollowsMouse); - } else if (val == "FocusUnderMouse") { - setFocusPolicy(FocusUnderMouse); - } else if (val == "FocusStrictlyUnderMouse") { - setFocusPolicy(FocusStrictlyUnderMouse); - } else { - setFocusPolicy(Options::defaultFocusPolicy()); - } - - setNextFocusPrefersMouse(config.readEntry("NextFocusPrefersMouse", Options::defaultNextFocusPrefersMouse())); - - setSeparateScreenFocus(config.readEntry("SeparateScreenFocus", Options::defaultSeparateScreenFocus())); - setActiveMouseScreen(config.readEntry("ActiveMouseScreen", m_focusPolicy != ClickToFocus)); - - setRollOverDesktops(config.readEntry("RollOverDesktops", Options::defaultRollOverDesktops())); - - setLegacyFullscreenSupport(config.readEntry("LegacyFullscreenSupport", Options::defaultLegacyFullscreenSupport())); - - setFocusStealingPreventionLevel(config.readEntry("FocusStealingPreventionLevel", Options::defaultFocusStealingPreventionLevel())); - -#ifdef KWIN_BUILD_DECORATIONS - setPlacement(Placement::policyFromString(config.readEntry("Placement"), true)); -#else - setPlacement(Placement::Maximizing); -#endif - - setAutoRaise(config.readEntry("AutoRaise", Options::defaultAutoRaise())); - setAutoRaiseInterval(config.readEntry("AutoRaiseInterval", Options::defaultAutoRaiseInterval())); - setDelayFocusInterval(config.readEntry("DelayFocusInterval", Options::defaultDelayFocusInterval())); - - setShadeHover(config.readEntry("ShadeHover", Options::defaultShadeHover())); - setShadeHoverInterval(config.readEntry("ShadeHoverInterval", Options::defaultShadeHoverInterval())); - - setClickRaise(config.readEntry("ClickRaise", Options::defaultClickRaise())); - - setBorderSnapZone(config.readEntry("BorderSnapZone", Options::defaultBorderSnapZone())); - setWindowSnapZone(config.readEntry("WindowSnapZone", Options::defaultWindowSnapZone())); - setCenterSnapZone(config.readEntry("CenterSnapZone", Options::defaultCenterSnapZone())); - setSnapOnlyWhenOverlapping(config.readEntry("SnapOnlyWhenOverlapping", Options::defaultSnapOnlyWhenOverlapping())); + syncFromKcfgc(); // Electric borders - setElectricBorderMaximize(config.readEntry("ElectricBorderMaximize", Options::defaultElectricBorderMaximize())); - setElectricBorderTiling(config.readEntry("ElectricBorderTiling", Options::defaultElectricBorderTiling())); - const float ebr = config.readEntry("ElectricBorderCornerRatio", Options::defaultElectricBorderCornerRatio()); - setElectricBorderCornerRatio(qMin(qMax(ebr, 0.0f), 1.0f)); - + KConfigGroup config(_config, "Windows"); OpTitlebarDblClick = windowOperation(config.readEntry("TitlebarDoubleClickCommand", "Maximize"), true); setOpMaxButtonLeftClick(windowOperation(config.readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true)); setOpMaxButtonMiddleClick(windowOperation(config.readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true)); setOpMaxButtonRightClick(windowOperation(config.readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true)); - setKillPingTimeout(config.readEntry("KillPingTimeout", Options::defaultKillPingTimeout())); - setHideUtilityWindowsForInactive(config.readEntry("HideUtilityWindowsForInactive", Options::defaultHideUtilityWindowsForInactive())); - setInactiveTabsSkipTaskbar(config.readEntry("InactiveTabsSkipTaskbar", Options::defaultInactiveTabsSkipTaskbar())); - setAutogroupSimilarWindows(config.readEntry("AutogroupSimilarWindows", Options::defaultAutogroupSimilarWindows())); - setAutogroupInForeground(config.readEntry("AutogroupInForeground", Options::defaultAutogroupInForeground())); - setShowDesktopIsMinimizeAll(config.readEntry("ShowDesktopIsMinimizeAll", Options::defaultShowDesktopIsMinimizeAll())); - - setBorderlessMaximizedWindows(config.readEntry("BorderlessMaximizedWindows", Options::defaultBorderlessMaximizedWindows())); - // Mouse bindings config = KConfigGroup(_config, "MouseBindings"); // TODO: add properties for missing options @@ -893,6 +839,47 @@ unsigned long Options::loadConfig() return changed; } +void Options::syncFromKcfgc() +{ + setShowGeometryTip(m_settings->geometryTip()); + setCondensedTitle(m_settings->condensedTitle()); + setFocusPolicy(m_settings->focusPolicy()); + setNextFocusPrefersMouse(m_settings->nextFocusPrefersMouse()); + setSeparateScreenFocus(m_settings->separateScreenFocus()); + setActiveMouseScreen(m_settings->activeMouseScreen()); + setRollOverDesktops(m_settings->rollOverDesktops()); + setLegacyFullscreenSupport(m_settings->legacyFullscreenSupport()); + setFocusStealingPreventionLevel(m_settings->focusStealingPreventionLevel()); + +#ifdef KWIN_BUILD_DECORATIONS + setPlacement(m_settings->placement()); +#else + setPlacement(Placement::Maximizing); +#endif + + setAutoRaise(m_settings->autoRaise()); + setAutoRaiseInterval(m_settings->autoRaiseInterval()); + setDelayFocusInterval(m_settings->delayFocusInterval()); + setShadeHover(m_settings->shadeHover()); + setShadeHoverInterval(m_settings->shadeHoverInterval()); + setClickRaise(m_settings->clickRaise()); + setBorderSnapZone(m_settings->borderSnapZone()); + setWindowSnapZone(m_settings->windowSnapZone()); + setCenterSnapZone(m_settings->centerSnapZone()); + setSnapOnlyWhenOverlapping(m_settings->snapOnlyWhenOverlapping()); + setKillPingTimeout(m_settings->killPingTimeout()); + setHideUtilityWindowsForInactive(m_settings->hideUtilityWindowsForInactive()); + setInactiveTabsSkipTaskbar(m_settings->inactiveTabsSkipTaskbar()); + setAutogroupSimilarWindows(m_settings->autogroupSimilarWindows()); + setAutogroupInForeground(m_settings->autogroupInForeground()); + setShowDesktopIsMinimizeAll(m_settings->showDesktopIsMinimizeAll()); + setBorderlessMaximizedWindows(m_settings->borderlessMaximizedWindows()); + setElectricBorderMaximize(m_settings->electricBorderMaximize()); + setElectricBorderTiling(m_settings->electricBorderTiling()); + setElectricBorderCornerRatio(m_settings->electricBorderCornerRatio()); + +} + bool Options::loadCompositingConfig (bool force) { KSharedConfig::Ptr _config = KGlobal::config(); diff --git a/options.h b/options.h index f910f55b2..b6de1d596 100644 --- a/options.h +++ b/options.h @@ -36,6 +36,7 @@ namespace KWin class Client; class CompositingPrefs; +class Settings; class Options : public QObject, public KDecorationOptions { @@ -611,64 +612,6 @@ public: void setGlLegacy(bool glLegacy); // default values - static FocusPolicy defaultFocusPolicy() { - return ClickToFocus; - } - static bool defaultNextFocusPrefersMouse() { - return false; - } - static bool defaultClickRaise() { - return true; - } - static bool defaultAutoRaise() { - return false; - } - static int defaultAutoRaiseInterval() { - return 750; - } - static int defaultDelayFocusInterval() { - return 300; - } - static bool defaultShadeHover() { - return false; - } - static int defaultShadeHoverInterval() { - return 250; - } - static bool defaultSeparateScreenFocus() { - return false; - } - static bool defaultActiveMouseScreen() { - // TODO: used to be m_focusPolicy != ClickToFocus - return true; - } - static Placement::Policy defaultPlacement() { - return Placement::Default; - } - static int defaultBorderSnapZone() { - return 10; - } - static int defaultWindowSnapZone() { - return 10; - } - static int defaultCenterSnapZone() { - return 0; - } - static bool defaultSnapOnlyWhenOverlapping() { - return false; - } - static bool defaultShowDesktopIsMinimizeAll() { - return false; - } - static bool defaultRollOverDesktops() { - return true; - } - static int defaultFocusStealingPreventionLevel() { - return 1; - } - static bool defaultLegacyFullscreenSupport() { - return false; - } static WindowOperation defaultOperationTitlebarDblClick() { return MaximizeOp; } @@ -720,36 +663,6 @@ public: static uint defaultKeyCmdAllModKey() { return Qt::Key_Alt; } - static bool defaultShowGeometryTip() { - return false; - } - static bool defaultCondensedTitle() { - return false; - } - static bool defaultElectricBorderMaximize() { - return true; - } - static bool defaultElectricBorderTiling() { - return true; - } - static float defaultElectricBorderCornerRatio() { - return 0.25; - } - static bool defaultBorderlessMaximizedWindows() { - return false; - } - static int defaultKillPingTimeout() { - return 5000; - } - static bool defaultHideUtilityWindowsForInactive() { - return true; - } - static bool defaultInactiveTabsSkipTaskbar() { - return false; - } - static bool defaultAutogroupSimilarWindows() { - return false; - } static bool defaultAutogroupInForeground() { return true; } @@ -890,6 +803,8 @@ public Q_SLOTS: private: void setElectricBorders(int borders); + void syncFromKcfgc(); + QScopedPointer m_settings; FocusPolicy m_focusPolicy; bool m_nextFocusPrefersMouse; bool m_clickRaise; diff --git a/settings.kcfgc b/settings.kcfgc new file mode 100644 index 000000000..5656eb1a1 --- /dev/null +++ b/settings.kcfgc @@ -0,0 +1,7 @@ +File=kwin.kcfg +NameSpace=KWin +ClassName=Settings +# options.h is needed for FocusPolicy +# placement.h is needed for Placement::Policy +IncludeFiles=\"options.h\", \"placement.h\" +UseEnumTypes=true