00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "options.h"
00023
00024 #ifndef KCMRULES
00025
00026 #include <QPalette>
00027 #include <QPixmap>
00028 #include <kapplication.h>
00029 #include <kconfig.h>
00030 #include <kglobal.h>
00031 #include <kglobalsettings.h>
00032
00033 #include <QDesktopWidget>
00034
00035 #include "client.h"
00036 #include "compositingprefs.h"
00037
00038 #include <kephal/screens.h>
00039
00040 #endif
00041
00042 namespace KWin
00043 {
00044
00045 #ifndef KCMRULES
00046
00047 Options::Options()
00048 : electric_borders( 0 )
00049 , electric_border_delay( 0 )
00050 {
00051 updateSettings();
00052 }
00053
00054 Options::~Options()
00055 {
00056 }
00057
00058 unsigned long Options::updateSettings()
00059 {
00060 KSharedConfig::Ptr _config = KGlobal::config();
00061 unsigned long changed = 0;
00062 changed |= KDecorationOptions::updateSettings( _config.data() );
00063
00064 KConfigGroup config( _config, "Windows" );
00065 moveMode = stringToMoveResizeMode( config.readEntry("MoveMode", "Opaque" ));
00066 resizeMode = stringToMoveResizeMode( config.readEntry("ResizeMode", "Opaque" ));
00067 show_geometry_tip = config.readEntry("GeometryTip", false);
00068
00069 QString val;
00070
00071 val = config.readEntry ("FocusPolicy", "ClickToFocus");
00072 focusPolicy = ClickToFocus;
00073 if ( val == "FocusFollowsMouse" )
00074 focusPolicy = FocusFollowsMouse;
00075 else if ( val == "FocusUnderMouse" )
00076 focusPolicy = FocusUnderMouse;
00077 else if ( val == "FocusStrictlyUnderMouse" )
00078 focusPolicy = FocusStrictlyUnderMouse;
00079
00080 val = config.readEntry ("AltTabStyle", "KDE");
00081 altTabStyle = KDE;
00082 if ( val == "CDE" )
00083 altTabStyle = CDE;
00084
00085 separateScreenFocus = config.readEntry( "SeparateScreenFocus", false );
00086 activeMouseScreen = config.readEntry( "ActiveMouseScreen", focusPolicy != ClickToFocus );
00087
00088 rollOverDesktops = config.readEntry("RollOverDesktops", true);
00089
00090
00091
00092 focusStealingPreventionLevel = config.readEntry( "FocusStealingPreventionLevel", 1 );
00093 focusStealingPreventionLevel = qMax( 0, qMin( 4, focusStealingPreventionLevel ));
00094 if( !focusPolicyIsReasonable())
00095 focusStealingPreventionLevel = 0;
00096
00097 xineramaEnabled = config.readEntry ("XineramaEnabled", true);
00098 xineramaPlacementEnabled = config.readEntry ("XineramaPlacementEnabled", true);
00099 xineramaMovementEnabled = config.readEntry ("XineramaMovementEnabled", true);
00100 xineramaMaximizeEnabled = config.readEntry ("XineramaMaximizeEnabled", true);
00101 xineramaFullscreenEnabled = config.readEntry ("XineramaFullscreenEnabled", true);
00102
00103 placement = Placement::policyFromString( config.readEntry("Placement"), true );
00104 xineramaPlacementScreen = qBound( -1, config.readEntry( "XineramaPlacementScreen", -1 ),
00105 Kephal::ScreenUtils::numScreens() - 1 );
00106
00107 if( focusPolicy == ClickToFocus )
00108 {
00109 autoRaise = false;
00110 autoRaiseInterval = 0;
00111 delayFocus = false;
00112 delayFocusInterval = 0;
00113 }
00114 else
00115 {
00116 autoRaise = config.readEntry("AutoRaise", false);
00117 autoRaiseInterval = config.readEntry("AutoRaiseInterval", 0 );
00118 delayFocus = config.readEntry("DelayFocus", false);
00119 delayFocusInterval = config.readEntry("DelayFocusInterval", 0 );
00120 }
00121
00122 shadeHover = config.readEntry("ShadeHover", false);
00123 shadeHoverInterval = config.readEntry("ShadeHoverInterval", 250 );
00124
00125
00126 clickRaise = autoRaise || config.readEntry("ClickRaise", true);
00127
00128 borderSnapZone = config.readEntry("BorderSnapZone", 10);
00129 windowSnapZone = config.readEntry("WindowSnapZone", 10);
00130 centerSnapZone = config.readEntry("CenterSnapZone", 0);
00131 snapOnlyWhenOverlapping = config.readEntry("SnapOnlyWhenOverlapping", false);
00132 electric_borders = config.readEntry("ElectricBorders", 0);
00133 electric_border_delay = config.readEntry("ElectricBorderDelay", 150);
00134
00135 OpTitlebarDblClick = windowOperation( config.readEntry("TitlebarDoubleClickCommand", "Maximize"), true );
00136 setOpMaxButtonLeftClick( windowOperation( config.readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true ));
00137 setOpMaxButtonMiddleClick( windowOperation( config.readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true ));
00138 setOpMaxButtonRightClick( windowOperation( config.readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true ));
00139
00140 ignorePositionClasses = config.readEntry("IgnorePositionClasses",QStringList());
00141 ignoreFocusStealingClasses = config.readEntry("IgnoreFocusStealingClasses",QStringList());
00142
00143
00144 for( QStringList::Iterator it = ignorePositionClasses.begin();
00145 it != ignorePositionClasses.end();
00146 ++it )
00147 (*it) = (*it).toLower();
00148 for( QStringList::Iterator it = ignoreFocusStealingClasses.begin();
00149 it != ignoreFocusStealingClasses.end();
00150 ++it )
00151 (*it) = (*it).toLower();
00152
00153 killPingTimeout = config.readEntry( "KillPingTimeout", 5000 );
00154 hideUtilityWindowsForInactive = config.readEntry( "HideUtilityWindowsForInactive", true);
00155 showDesktopIsMinimizeAll = config.readEntry( "ShowDesktopIsMinimizeAll", false );
00156
00157
00158 config = KConfigGroup( _config, "MouseBindings" );
00159 CmdActiveTitlebar1 = mouseCommand(config.readEntry("CommandActiveTitlebar1","Raise"), true );
00160 CmdActiveTitlebar2 = mouseCommand(config.readEntry("CommandActiveTitlebar2","Lower"), true );
00161 CmdActiveTitlebar3 = mouseCommand(config.readEntry("CommandActiveTitlebar3","Operations menu"), true );
00162 CmdInactiveTitlebar1 = mouseCommand(config.readEntry("CommandInactiveTitlebar1","Activate and raise"), true );
00163 CmdInactiveTitlebar2 = mouseCommand(config.readEntry("CommandInactiveTitlebar2","Activate and lower"), true );
00164 CmdInactiveTitlebar3 = mouseCommand(config.readEntry("CommandInactiveTitlebar3","Operations menu"), true );
00165 CmdTitlebarWheel = mouseWheelCommand(config.readEntry("CommandTitlebarWheel","Nothing"));
00166 CmdWindow1 = mouseCommand(config.readEntry("CommandWindow1","Activate, raise and pass click"), false );
00167 CmdWindow2 = mouseCommand(config.readEntry("CommandWindow2","Activate and pass click"), false );
00168 CmdWindow3 = mouseCommand(config.readEntry("CommandWindow3","Activate and pass click"), false );
00169 CmdAllModKey = (config.readEntry("CommandAllKey","Alt") == "Meta") ? Qt::Key_Meta : Qt::Key_Alt;
00170 CmdAll1 = mouseCommand(config.readEntry("CommandAll1","Move"), false );
00171 CmdAll2 = mouseCommand(config.readEntry("CommandAll2","Toggle raise and lower"), false );
00172 CmdAll3 = mouseCommand(config.readEntry("CommandAll3","Resize"), false );
00173 CmdAllWheel = mouseWheelCommand(config.readEntry("CommandAllWheel","Nothing"));
00174
00175 config=KConfigGroup(_config,"Compositing");
00176 refreshRate = config.readEntry( "RefreshRate", 0 );
00177
00178
00179
00180
00181
00182
00183 #if 0
00184 FIXME: we have no mac style menu implementation in kwin anymore, so this just breaks
00185 things for people!
00186 KConfig _globalConfig("kdeglobals");
00187 KConfigGroup globalConfig(&_globalConfig, "KDE");
00188 topmenus = globalConfig.readEntry("macStyle", false);
00189 #else
00190 topmenus = false;
00191 #endif
00192
00193
00194
00195
00196
00197 CompositingPrefs prefs;
00198 prefs.detect();
00199 reloadCompositingSettings( prefs );
00200
00201 return changed;
00202 }
00203
00204 void Options::reloadCompositingSettings(const CompositingPrefs& prefs)
00205 {
00206 KSharedConfig::Ptr _config = KGlobal::config();
00207 KConfigGroup config(_config, "Compositing");
00208
00209
00210 useCompositing = config.readEntry("Enabled", prefs.enableCompositing());
00211 QString compositingBackend = config.readEntry("Backend", "OpenGL");
00212 if( compositingBackend == "XRender" )
00213 compositingMode = XRenderCompositing;
00214 else
00215 compositingMode = OpenGLCompositing;
00216 disableCompositingChecks = config.readEntry("DisableChecks", false);
00217 QString glmode = config.readEntry("GLMode", "TFP" ).toUpper();
00218 if( glmode == "TFP" )
00219 glMode = GLTFP;
00220 else if( glmode == "SHM" )
00221 glMode = GLSHM;
00222 else
00223 glMode = GLFallback;
00224 glDirect = config.readEntry("GLDirect", prefs.enableDirectRendering() );
00225 glVSync = config.readEntry("GLVSync", prefs.enableVSync() );
00226 smoothScale = qBound( -1, config.readEntry( "GLTextureFilter", -1 ), 2 );
00227 glStrictBinding = config.readEntry( "GLStrictBinding", prefs.strictBinding());
00228
00229 xrenderSmoothScale = config.readEntry("XRenderSmoothScale", false );
00230
00231 hiddenPreviews = HiddenPreviewsShown;
00232
00233 int hps = config.readEntry( "HiddenPreviews", 5 );
00234 if( hps == 4 )
00235 hiddenPreviews = HiddenPreviewsNever;
00236 else if( hps == 5 )
00237 hiddenPreviews = HiddenPreviewsShown;
00238 else if( hps == 6 )
00239 hiddenPreviews = HiddenPreviewsAlways;
00240
00241 unredirectFullscreen = config.readEntry( "UnredirectFullscreen", true );
00242 animationSpeed = qBound( 0, config.readEntry( "AnimationSpeed", 3 ), 6 );
00243
00244 if( !disableCompositingChecks && !prefs.validateSetup( compositingMode ))
00245 useCompositing = false;
00246 }
00247
00248
00249
00250
00251
00252
00253 Options::WindowOperation Options::windowOperation(const QString &name, bool restricted )
00254 {
00255 if (name == "Move")
00256 return restricted ? MoveOp : UnrestrictedMoveOp;
00257 else if (name == "Resize")
00258 return restricted ? ResizeOp : UnrestrictedResizeOp;
00259 else if (name == "Maximize")
00260 return MaximizeOp;
00261 else if (name == "Minimize")
00262 return MinimizeOp;
00263 else if (name == "Close")
00264 return CloseOp;
00265 else if (name == "OnAllDesktops")
00266 return OnAllDesktopsOp;
00267 else if (name == "Shade")
00268 return ShadeOp;
00269 else if (name == "Operations")
00270 return OperationsOp;
00271 else if (name == "Maximize (vertical only)")
00272 return VMaximizeOp;
00273 else if (name == "Maximize (horizontal only)")
00274 return HMaximizeOp;
00275 else if (name == "Lower")
00276 return LowerOp;
00277 return NoOp;
00278 }
00279
00280 Options::MouseCommand Options::mouseCommand(const QString &name, bool restricted )
00281 {
00282 QString lowerName = name.toLower();
00283 if (lowerName == "raise") return MouseRaise;
00284 if (lowerName == "lower") return MouseLower;
00285 if (lowerName == "operations menu") return MouseOperationsMenu;
00286 if (lowerName == "toggle raise and lower") return MouseToggleRaiseAndLower;
00287 if (lowerName == "activate and raise") return MouseActivateAndRaise;
00288 if (lowerName == "activate and lower") return MouseActivateAndLower;
00289 if (lowerName == "activate") return MouseActivate;
00290 if (lowerName == "activate, raise and pass click") return MouseActivateRaiseAndPassClick;
00291 if (lowerName == "activate and pass click") return MouseActivateAndPassClick;
00292 if (lowerName == "activate, raise and move")
00293 return restricted ? MouseActivateRaiseAndMove : MouseActivateRaiseAndUnrestrictedMove;
00294 if (lowerName == "move") return restricted ? MouseMove : MouseUnrestrictedMove;
00295 if (lowerName == "resize") return restricted ? MouseResize : MouseUnrestrictedResize;
00296 if (lowerName == "shade") return MouseShade;
00297 if (lowerName == "minimize") return MouseMinimize;
00298 if (lowerName == "nothing") return MouseNothing;
00299 return MouseNothing;
00300 }
00301
00302 Options::MouseWheelCommand Options::mouseWheelCommand(const QString &name)
00303 {
00304 QString lowerName = name.toLower();
00305 if (lowerName == "raise/lower") return MouseWheelRaiseLower;
00306 if (lowerName == "shade/unshade") return MouseWheelShadeUnshade;
00307 if (lowerName == "maximize/restore") return MouseWheelMaximizeRestore;
00308 if (lowerName == "above/below") return MouseWheelAboveBelow;
00309 if (lowerName == "previous/next desktop") return MouseWheelPreviousNextDesktop;
00310 if (lowerName == "change opacity") return MouseWheelChangeOpacity;
00311 return MouseWheelNothing;
00312 }
00313
00314 bool Options::showGeometryTip()
00315 {
00316 return show_geometry_tip;
00317 }
00318
00319 int Options::electricBorders()
00320 {
00321 return electric_borders;
00322 }
00323
00324 int Options::electricBorderDelay()
00325 {
00326 return electric_border_delay;
00327 }
00328
00329 bool Options::checkIgnoreFocusStealing( const Client* c )
00330 {
00331 return ignoreFocusStealingClasses.contains(QString::fromLatin1(c->resourceClass()));
00332 }
00333
00334 Options::MouseCommand Options::wheelToMouseCommand( MouseWheelCommand com, int delta )
00335 {
00336 switch( com )
00337 {
00338 case MouseWheelRaiseLower:
00339 return delta > 0 ? MouseRaise : MouseLower;
00340 case MouseWheelShadeUnshade:
00341 return delta > 0 ? MouseSetShade : MouseUnsetShade;
00342 case MouseWheelMaximizeRestore:
00343 return delta > 0 ? MouseMaximize : MouseRestore;
00344 case MouseWheelAboveBelow:
00345 return delta > 0 ? MouseAbove : MouseBelow;
00346 case MouseWheelPreviousNextDesktop:
00347 return delta > 0 ? MousePreviousDesktop : MouseNextDesktop;
00348 case MouseWheelChangeOpacity:
00349 return delta > 0 ? MouseOpacityMore : MouseOpacityLess;
00350 default:
00351 return MouseNothing;
00352 }
00353 }
00354 #endif
00355
00356 Options::MoveResizeMode Options::stringToMoveResizeMode( const QString& s )
00357 {
00358 return s == "Opaque" ? Opaque : Transparent;
00359 }
00360
00361 const char* Options::moveResizeModeToString( MoveResizeMode mode )
00362 {
00363 return mode == Opaque ? "Opaque" : "Transparent";
00364 }
00365
00366 double Options::animationTimeFactor() const
00367 {
00368 const double factors[] = { 0, 0.2, 0.5, 1, 2, 4, 20 };
00369 return factors[ animationSpeed ];
00370 }
00371
00372 }