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