00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "options.h"
00013
00014 #ifndef KCMRULES
00015
00016 #include <qpalette.h>
00017 #include <qpixmap.h>
00018 #include <kapplication.h>
00019 #include <kconfig.h>
00020 #include <kglobal.h>
00021 #include <kglobalsettings.h>
00022 #include <qtooltip.h>
00023
00024 #include "client.h"
00025
00026 #endif
00027
00028 namespace KWinInternal
00029 {
00030
00031 #ifndef KCMRULES
00032
00033 Options::Options()
00034 : electric_borders( 0 ),
00035 electric_border_delay(0)
00036 {
00037 d = new KDecorationOptionsPrivate;
00038 d->defaultKWinSettings();
00039 updateSettings();
00040 }
00041
00042 Options::~Options()
00043 {
00044 delete d;
00045 }
00046
00047 unsigned long Options::updateSettings()
00048 {
00049 KConfig *config = KGlobal::config();
00050 unsigned long changed = 0;
00051 changed |= d->updateKWinSettings( config );
00052
00053 config->setGroup( "Windows" );
00054 moveMode = stringToMoveResizeMode( config->readEntry("MoveMode", "Opaque" ));
00055 resizeMode = stringToMoveResizeMode( config->readEntry("ResizeMode", "Opaque" ));
00056 show_geometry_tip = config->readBoolEntry("GeometryTip", false);
00057 tabboxOutline = config->readBoolEntry("TabboxOutline", true);
00058
00059 QString val;
00060
00061 val = config->readEntry ("FocusPolicy", "ClickToFocus");
00062 focusPolicy = ClickToFocus;
00063 if ( val == "FocusFollowsMouse" )
00064 focusPolicy = FocusFollowsMouse;
00065 else if ( val == "FocusUnderMouse" )
00066 focusPolicy = FocusUnderMouse;
00067 else if ( val == "FocusStrictlyUnderMouse" )
00068 focusPolicy = FocusStrictlyUnderMouse;
00069
00070 val = config->readEntry ("AltTabStyle", "KDE");
00071 altTabStyle = KDE;
00072 if ( val == "CDE" )
00073 altTabStyle = CDE;
00074
00075 separateScreenFocus = config->readBoolEntry( "SeparateScreenFocus", false );
00076 activeMouseScreen = config->readBoolEntry( "ActiveMouseScreen", focusPolicy != ClickToFocus );
00077
00078 rollOverDesktops = config->readBoolEntry("RollOverDesktops", TRUE);
00079
00080
00081
00082 focusStealingPreventionLevel = config->readNumEntry( "FocusStealingPreventionLevel", 1 );
00083 focusStealingPreventionLevel = KMAX( 0, KMIN( 4, focusStealingPreventionLevel ));
00084 if( !focusPolicyIsReasonable())
00085 focusStealingPreventionLevel = 0;
00086
00087 updateXineramaSettings();
00088
00089 placement = Placement::policyFromString( config->readEntry("Placement"), true );
00090 xineramaPlacementScreen = KCLAMP( config->readNumEntry( "XineramaPlacementScreen", -1 ),
00091 -1, qApp->desktop()->numScreens() - 1 );
00092
00093 animateShade = config->readBoolEntry("AnimateShade", TRUE );
00094 animateMinimize = config->readBoolEntry("AnimateMinimize", TRUE );
00095 animateMinimizeSpeed = config->readNumEntry("AnimateMinimizeSpeed", 5 );
00096
00097 if( focusPolicy == ClickToFocus )
00098 {
00099 autoRaise = false;
00100 autoRaiseInterval = 0;
00101 delayFocus = false;
00102 delayFocusInterval = 0;
00103 }
00104 else
00105 {
00106 autoRaise = config->readBoolEntry("AutoRaise", FALSE );
00107 autoRaiseInterval = config->readNumEntry("AutoRaiseInterval", 0 );
00108 delayFocus = config->readBoolEntry("DelayFocus", FALSE );
00109 delayFocusInterval = config->readNumEntry("DelayFocusInterval", 0 );
00110 }
00111
00112 shadeHover = config->readBoolEntry("ShadeHover", FALSE );
00113 shadeHoverInterval = config->readNumEntry("ShadeHoverInterval", 250 );
00114
00115
00116 clickRaise = autoRaise || config->readBoolEntry("ClickRaise", TRUE );
00117
00118 borderSnapZone = config->readNumEntry("BorderSnapZone", 10);
00119 windowSnapZone = config->readNumEntry("WindowSnapZone", 10);
00120 snapOnlyWhenOverlapping=config->readBoolEntry("SnapOnlyWhenOverlapping",FALSE);
00121 electric_borders = config->readNumEntry("ElectricBorders", 0);
00122 electric_border_delay = config->readNumEntry("ElectricBorderDelay", 150);
00123
00124 OpTitlebarDblClick = windowOperation( config->readEntry("TitlebarDoubleClickCommand", "Shade"), true );
00125 d->OpMaxButtonLeftClick = windowOperation( config->readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true );
00126 d->OpMaxButtonMiddleClick = windowOperation( config->readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true );
00127 d->OpMaxButtonRightClick = windowOperation( config->readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true );
00128
00129 ignorePositionClasses = config->readListEntry("IgnorePositionClasses");
00130 ignoreFocusStealingClasses = config->readListEntry("IgnoreFocusStealingClasses");
00131
00132
00133 for( QStringList::Iterator it = ignorePositionClasses.begin();
00134 it != ignorePositionClasses.end();
00135 ++it )
00136 (*it) = (*it).lower();
00137 for( QStringList::Iterator it = ignoreFocusStealingClasses.begin();
00138 it != ignoreFocusStealingClasses.end();
00139 ++it )
00140 (*it) = (*it).lower();
00141
00142 killPingTimeout = config->readNumEntry( "KillPingTimeout", 5000 );
00143 hideUtilityWindowsForInactive = config->readBoolEntry( "HideUtilityWindowsForInactive", true );
00144 showDesktopIsMinimizeAll = config->readBoolEntry( "ShowDesktopIsMinimizeAll", false );
00145
00146
00147 config->setGroup( "MouseBindings");
00148 CmdActiveTitlebar1 = mouseCommand(config->readEntry("CommandActiveTitlebar1","Raise"), true );
00149 CmdActiveTitlebar2 = mouseCommand(config->readEntry("CommandActiveTitlebar2","Lower"), true );
00150 CmdActiveTitlebar3 = mouseCommand(config->readEntry("CommandActiveTitlebar3","Operations menu"), true );
00151 CmdInactiveTitlebar1 = mouseCommand(config->readEntry("CommandInactiveTitlebar1","Activate and raise"), true );
00152 CmdInactiveTitlebar2 = mouseCommand(config->readEntry("CommandInactiveTitlebar2","Activate and lower"), true );
00153 CmdInactiveTitlebar3 = mouseCommand(config->readEntry("CommandInactiveTitlebar3","Operations menu"), true );
00154 CmdTitlebarWheel = mouseWheelCommand(config->readEntry("CommandTitlebarWheel","Nothing"));
00155 CmdWindow1 = mouseCommand(config->readEntry("CommandWindow1","Activate, raise and pass click"), false );
00156 CmdWindow2 = mouseCommand(config->readEntry("CommandWindow2","Activate and pass click"), false );
00157 CmdWindow3 = mouseCommand(config->readEntry("CommandWindow3","Activate and pass click"), false );
00158 CmdAllModKey = (config->readEntry("CommandAllKey","Alt") == "Meta") ? Qt::Key_Meta : Qt::Key_Alt;
00159 CmdAll1 = mouseCommand(config->readEntry("CommandAll1","Move"), false );
00160 CmdAll2 = mouseCommand(config->readEntry("CommandAll2","Toggle raise and lower"), false );
00161 CmdAll3 = mouseCommand(config->readEntry("CommandAll3","Resize"), false );
00162 CmdAllWheel = mouseWheelCommand(config->readEntry("CommandAllWheel","Nothing"));
00163
00164
00165 config->setGroup( "Notification Messages" );
00166 useTranslucency = config->readBoolEntry("UseTranslucency", false);
00167 config->setGroup( "Translucency");
00168 translucentActiveWindows = config->readBoolEntry("TranslucentActiveWindows", false);
00169 activeWindowOpacity = uint((config->readNumEntry("ActiveWindowOpacity", 100)/100.0)*0xFFFFFFFF);
00170 translucentInactiveWindows = config->readBoolEntry("TranslucentInactiveWindows", false);
00171 inactiveWindowOpacity = uint((config->readNumEntry("InactiveWindowOpacity", 75)/100.0)*0xFFFFFFFF);
00172 translucentMovingWindows = config->readBoolEntry("TranslucentMovingWindows", false);
00173 movingWindowOpacity = uint((config->readNumEntry("MovingWindowOpacity", 50)/100.0)*0xFFFFFFFF);
00174 translucentDocks = config->readBoolEntry("TranslucentDocks", false);
00175 dockOpacity = uint((config->readNumEntry("DockOpacity", 80)/100.0)*0xFFFFFFFF);
00176 keepAboveAsActive = config->readBoolEntry("TreatKeepAboveAsActive", true);
00177
00178 useTitleMenuSlider = true;
00179 activeWindowShadowSize = config->readNumEntry("ActiveWindowShadowSize", 200);
00180 inactiveWindowShadowSize = config->readNumEntry("InactiveWindowShadowSize", 100);
00181 dockShadowSize = config->readNumEntry("DockShadowSize", 80);
00182 removeShadowsOnMove = config->readBoolEntry("RemoveShadowsOnMove", true);
00183 removeShadowsOnResize = config->readBoolEntry("RemoveShadowsOnResize", true);
00184 onlyDecoTranslucent = config->readBoolEntry("OnlyDecoTranslucent",false);
00185 resetKompmgr = config->readBoolEntry("ResetKompmgr", false);
00186 if (resetKompmgr)
00187 config->writeEntry("ResetKompmgr",FALSE);
00188
00189
00190
00191
00192
00193
00194
00195 KConfig globalConfig("kdeglobals");
00196 globalConfig.setGroup("KDE");
00197 topmenus = globalConfig.readBoolEntry( "macStyle", false );
00198
00199 KConfig kdesktopcfg( "kdesktoprc", true );
00200 kdesktopcfg.setGroup( "Menubar" );
00201 desktop_topmenu = kdesktopcfg.readBoolEntry( "ShowMenubar", false );
00202 if( desktop_topmenu )
00203 topmenus = true;
00204
00205 QToolTip::setGloballyEnabled( d->show_tooltips );
00206
00207 return changed;
00208 }
00209
00210 void Options::updateXineramaSettings()
00211 {
00212 KConfig *gc = new KConfig("kdeglobals", false, false);
00213 bool isVirtual = KApplication::desktop()->isVirtualDesktop();
00214 gc->setGroup("Windows");
00215 xineramaEnabled = gc->readBoolEntry ("XineramaEnabled", isVirtual ) &&
00216 isVirtual;
00217 if (xineramaEnabled)
00218 {
00219 xineramaPlacementEnabled = gc->readBoolEntry ("XineramaPlacementEnabled", true);
00220 xineramaMovementEnabled = gc->readBoolEntry ("XineramaMovementEnabled", true);
00221 xineramaMaximizeEnabled = gc->readBoolEntry ("XineramaMaximizeEnabled", true);
00222 xineramaFullscreenEnabled = gc->readBoolEntry ("XineramaFullscreenEnabled", true);
00223 }
00224 else
00225 {
00226 xineramaPlacementEnabled = xineramaMovementEnabled = xineramaMaximizeEnabled = xineramaFullscreenEnabled = false;
00227 }
00228 delete gc;
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.lower();
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.lower();
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 }