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
00058 QString val;
00059
00060 val = config->readEntry ("FocusPolicy", "ClickToFocus");
00061 focusPolicy = ClickToFocus;
00062 if ( val == "FocusFollowsMouse" )
00063 focusPolicy = FocusFollowsMouse;
00064 else if ( val == "FocusUnderMouse" )
00065 focusPolicy = FocusUnderMouse;
00066 else if ( val == "FocusStrictlyUnderMouse" )
00067 focusPolicy = FocusStrictlyUnderMouse;
00068
00069 val = config->readEntry ("AltTabStyle", "KDE");
00070 altTabStyle = KDE;
00071 if ( val == "CDE" )
00072 altTabStyle = CDE;
00073
00074 separateScreenFocus = config->readBoolEntry( "SeparateScreenFocus", true );
00075 activeMouseScreen = config->readBoolEntry( "ActiveMouseScreen", focusPolicy != ClickToFocus );
00076
00077 rollOverDesktops = config->readBoolEntry("RollOverDesktops", TRUE);
00078
00079
00080
00081 focusStealingPreventionLevel = config->readNumEntry( "FocusStealingPreventionLevel", 1 );
00082 focusStealingPreventionLevel = KMAX( 0, KMIN( 4, focusStealingPreventionLevel ));
00083 if( !focusPolicyIsReasonable())
00084 focusStealingPreventionLevel = 0;
00085
00086 KConfig *gc = new KConfig("kdeglobals", false, false);
00087 bool isVirtual = KApplication::desktop()->isVirtualDesktop();
00088 gc->setGroup("Windows");
00089 xineramaEnabled = gc->readBoolEntry ("XineramaEnabled", isVirtual ) &&
00090 isVirtual;
00091 if (xineramaEnabled)
00092 {
00093 xineramaPlacementEnabled = gc->readBoolEntry ("XineramaPlacementEnabled", true);
00094 xineramaMovementEnabled = gc->readBoolEntry ("XineramaMovementEnabled", true);
00095 xineramaMaximizeEnabled = gc->readBoolEntry ("XineramaMaximizeEnabled", true);
00096 xineramaFullscreenEnabled = gc->readBoolEntry ("XineramaFullscreenEnabled", true);
00097 }
00098 else
00099 {
00100 xineramaPlacementEnabled = xineramaMovementEnabled = xineramaMaximizeEnabled = xineramaFullscreenEnabled = false;
00101 }
00102 delete gc;
00103
00104 placement = Placement::policyFromString( config->readEntry("Placement"), true );
00105 xineramaPlacementScreen = KCLAMP( config->readNumEntry( "XineramaPlacementScreen", -1 ),
00106 -1, qApp->desktop()->numScreens() - 1 );
00107
00108 animateShade = config->readBoolEntry("AnimateShade", TRUE );
00109 animateMinimize = config->readBoolEntry("AnimateMinimize", TRUE );
00110 animateMinimizeSpeed = config->readNumEntry("AnimateMinimizeSpeed", 5 );
00111
00112 if( focusPolicy == ClickToFocus )
00113 {
00114 autoRaise = false;
00115 autoRaiseInterval = 0;
00116 delayFocus = false;
00117 delayFocusInterval = 0;
00118 }
00119 else
00120 {
00121 autoRaise = config->readBoolEntry("AutoRaise", FALSE );
00122 autoRaiseInterval = config->readNumEntry("AutoRaiseInterval", 0 );
00123 delayFocus = config->readBoolEntry("DelayFocus", FALSE );
00124 delayFocusInterval = config->readNumEntry("DelayFocusInterval", 0 );
00125 }
00126
00127 shadeHover = config->readBoolEntry("ShadeHover", FALSE );
00128 shadeHoverInterval = config->readNumEntry("ShadeHoverInterval", 250 );
00129
00130
00131 clickRaise = autoRaise || config->readBoolEntry("ClickRaise", TRUE );
00132
00133 borderSnapZone = config->readNumEntry("BorderSnapZone", 10);
00134 windowSnapZone = config->readNumEntry("WindowSnapZone", 10);
00135 snapOnlyWhenOverlapping=config->readBoolEntry("SnapOnlyWhenOverlapping",FALSE);
00136 electric_borders = config->readNumEntry("ElectricBorders", 0);
00137 electric_border_delay = config->readNumEntry("ElectricBorderDelay", 150);
00138
00139 OpTitlebarDblClick = windowOperation( config->readEntry("TitlebarDoubleClickCommand", "Shade"), true );
00140 d->OpMaxButtonLeftClick = windowOperation( config->readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true );
00141 d->OpMaxButtonMiddleClick = windowOperation( config->readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true );
00142 d->OpMaxButtonRightClick = windowOperation( config->readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true );
00143
00144 ignorePositionClasses = config->readListEntry("IgnorePositionClasses");
00145 ignoreFocusStealingClasses = config->readListEntry("IgnoreFocusStealingClasses");
00146
00147
00148 for( QStringList::Iterator it = ignorePositionClasses.begin();
00149 it != ignorePositionClasses.end();
00150 ++it )
00151 (*it) = (*it).lower();
00152 for( QStringList::Iterator it = ignoreFocusStealingClasses.begin();
00153 it != ignoreFocusStealingClasses.end();
00154 ++it )
00155 (*it) = (*it).lower();
00156
00157 killPingTimeout = config->readNumEntry( "KillPingTimeout", 5000 );
00158 hideUtilityWindowsForInactive = config->readBoolEntry( "HideUtilityWindowsForInactive", true );
00159 showDesktopIsMinimizeAll = config->readBoolEntry( "ShowDesktopIsMinimizeAll", false );
00160
00161
00162 config->setGroup( "MouseBindings");
00163 CmdActiveTitlebar1 = mouseCommand(config->readEntry("CommandActiveTitlebar1","Raise"), true );
00164 CmdActiveTitlebar2 = mouseCommand(config->readEntry("CommandActiveTitlebar2","Lower"), true );
00165 CmdActiveTitlebar3 = mouseCommand(config->readEntry("CommandActiveTitlebar3","Operations menu"), true );
00166 CmdInactiveTitlebar1 = mouseCommand(config->readEntry("CommandInactiveTitlebar1","Activate and raise"), true );
00167 CmdInactiveTitlebar2 = mouseCommand(config->readEntry("CommandInactiveTitlebar2","Activate and lower"), true );
00168 CmdInactiveTitlebar3 = mouseCommand(config->readEntry("CommandInactiveTitlebar3","Operations menu"), true );
00169 CmdTitlebarWheel = mouseWheelCommand(config->readEntry("CommandTitlebarWheel","Nothing"));
00170 CmdWindow1 = mouseCommand(config->readEntry("CommandWindow1","Activate, raise and pass click"), false );
00171 CmdWindow2 = mouseCommand(config->readEntry("CommandWindow2","Activate and pass click"), false );
00172 CmdWindow3 = mouseCommand(config->readEntry("CommandWindow3","Activate and pass click"), false );
00173 CmdAllModKey = (config->readEntry("CommandAllKey","Alt") == "Meta") ? Qt::Key_Meta : Qt::Key_Alt;
00174 CmdAll1 = mouseCommand(config->readEntry("CommandAll1","Move"), false );
00175 CmdAll2 = mouseCommand(config->readEntry("CommandAll2","Toggle raise and lower"), false );
00176 CmdAll3 = mouseCommand(config->readEntry("CommandAll3","Resize"), false );
00177 CmdAllWheel = mouseWheelCommand(config->readEntry("CommandAllWheel","Nothing"));
00178
00179
00180 config->setGroup( "Notification Messages" );
00181 useTranslucency = config->readBoolEntry("UseTranslucency", false);
00182 config->setGroup( "Translucency");
00183 translucentActiveWindows = config->readBoolEntry("TranslucentActiveWindows", false);
00184 activeWindowOpacity = uint((config->readNumEntry("ActiveWindowOpacity", 100)/100.0)*0xFFFFFFFF);
00185 translucentInactiveWindows = config->readBoolEntry("TranslucentInactiveWindows", false);
00186 inactiveWindowOpacity = uint((config->readNumEntry("InactiveWindowOpacity", 75)/100.0)*0xFFFFFFFF);
00187 translucentMovingWindows = config->readBoolEntry("TranslucentMovingWindows", false);
00188 movingWindowOpacity = uint((config->readNumEntry("MovingWindowOpacity", 50)/100.0)*0xFFFFFFFF);
00189 translucentDocks = config->readBoolEntry("TranslucentDocks", false);
00190 dockOpacity = uint((config->readNumEntry("DockOpacity", 80)/100.0)*0xFFFFFFFF);
00191 keepAboveAsActive = config->readBoolEntry("TreatKeepAboveAsActive", true);
00192
00193 useTitleMenuSlider = true;
00194 activeWindowShadowSize = config->readNumEntry("ActiveWindowShadowSize", 200);
00195 inactiveWindowShadowSize = config->readNumEntry("InactiveWindowShadowSize", 100);
00196 dockShadowSize = config->readNumEntry("DockShadowSize", 80);
00197 removeShadowsOnMove = config->readBoolEntry("RemoveShadowsOnMove", true);
00198 removeShadowsOnResize = config->readBoolEntry("RemoveShadowsOnResize", true);
00199 onlyDecoTranslucent = config->readBoolEntry("OnlyDecoTranslucent",false);
00200 if (resetKompmgr = config->readBoolEntry("ResetKompmgr", false))
00201 config->writeEntry("ResetKompmgr",FALSE);
00202
00203
00204
00205
00206
00207
00208
00209 KConfig globalConfig("kdeglobals");
00210 globalConfig.setGroup("KDE");
00211 topmenus = globalConfig.readBoolEntry( "macStyle", false );
00212
00213 KConfig kdesktopcfg( "kdesktoprc", true );
00214 kdesktopcfg.setGroup( "Menubar" );
00215 desktop_topmenu = kdesktopcfg.readBoolEntry( "ShowMenubar", false );
00216 if( desktop_topmenu )
00217 topmenus = true;
00218
00219 QToolTip::setGloballyEnabled( d->show_tooltips );
00220
00221 return changed;
00222 }
00223
00224
00225
00226
00227
00228
00229 Options::WindowOperation Options::windowOperation(const QString &name, bool restricted )
00230 {
00231 if (name == "Move")
00232 return restricted ? MoveOp : UnrestrictedMoveOp;
00233 else if (name == "Resize")
00234 return restricted ? ResizeOp : UnrestrictedResizeOp;
00235 else if (name == "Maximize")
00236 return MaximizeOp;
00237 else if (name == "Minimize")
00238 return MinimizeOp;
00239 else if (name == "Close")
00240 return CloseOp;
00241 else if (name == "OnAllDesktops")
00242 return OnAllDesktopsOp;
00243 else if (name == "Shade")
00244 return ShadeOp;
00245 else if (name == "Operations")
00246 return OperationsOp;
00247 else if (name == "Maximize (vertical only)")
00248 return VMaximizeOp;
00249 else if (name == "Maximize (horizontal only)")
00250 return HMaximizeOp;
00251 else if (name == "Lower")
00252 return LowerOp;
00253 return NoOp;
00254 }
00255
00256 Options::MouseCommand Options::mouseCommand(const QString &name, bool restricted )
00257 {
00258 QString lowerName = name.lower();
00259 if (lowerName == "raise") return MouseRaise;
00260 if (lowerName == "lower") return MouseLower;
00261 if (lowerName == "operations menu") return MouseOperationsMenu;
00262 if (lowerName == "toggle raise and lower") return MouseToggleRaiseAndLower;
00263 if (lowerName == "activate and raise") return MouseActivateAndRaise;
00264 if (lowerName == "activate and lower") return MouseActivateAndLower;
00265 if (lowerName == "activate") return MouseActivate;
00266 if (lowerName == "activate, raise and pass click") return MouseActivateRaiseAndPassClick;
00267 if (lowerName == "activate and pass click") return MouseActivateAndPassClick;
00268 if (lowerName == "activate, raise and move")
00269 return restricted ? MouseActivateRaiseAndMove : MouseActivateRaiseAndUnrestrictedMove;
00270 if (lowerName == "move") return restricted ? MouseMove : MouseUnrestrictedMove;
00271 if (lowerName == "resize") return restricted ? MouseResize : MouseUnrestrictedResize;
00272 if (lowerName == "shade") return MouseShade;
00273 if (lowerName == "minimize") return MouseMinimize;
00274 if (lowerName == "nothing") return MouseNothing;
00275 return MouseNothing;
00276 }
00277
00278 Options::MouseWheelCommand Options::mouseWheelCommand(const QString &name)
00279 {
00280 QString lowerName = name.lower();
00281 if (lowerName == "raise/lower") return MouseWheelRaiseLower;
00282 if (lowerName == "shade/unshade") return MouseWheelShadeUnshade;
00283 if (lowerName == "maximize/restore") return MouseWheelMaximizeRestore;
00284 if (lowerName == "above/below") return MouseWheelAboveBelow;
00285 if (lowerName == "previous/next desktop") return MouseWheelPreviousNextDesktop;
00286 if (lowerName == "change opacity") return MouseWheelChangeOpacity;
00287 return MouseWheelNothing;
00288 }
00289
00290 bool Options::showGeometryTip()
00291 {
00292 return show_geometry_tip;
00293 }
00294
00295 int Options::electricBorders()
00296 {
00297 return electric_borders;
00298 }
00299
00300 int Options::electricBorderDelay()
00301 {
00302 return electric_border_delay;
00303 }
00304
00305 bool Options::checkIgnoreFocusStealing( const Client* c )
00306 {
00307 return ignoreFocusStealingClasses.contains(QString::fromLatin1(c->resourceClass()));
00308 }
00309
00310 Options::MouseCommand Options::wheelToMouseCommand( MouseWheelCommand com, int delta )
00311 {
00312 switch( com )
00313 {
00314 case MouseWheelRaiseLower:
00315 return delta > 0 ? MouseRaise : MouseLower;
00316 case MouseWheelShadeUnshade:
00317 return delta > 0 ? MouseSetShade : MouseUnsetShade;
00318 case MouseWheelMaximizeRestore:
00319 return delta > 0 ? MouseMaximize : MouseRestore;
00320 case MouseWheelAboveBelow:
00321 return delta > 0 ? MouseAbove : MouseBelow;
00322 case MouseWheelPreviousNextDesktop:
00323 return delta > 0 ? MousePreviousDesktop : MouseNextDesktop;
00324 case MouseWheelChangeOpacity:
00325 return delta > 0 ? MouseOpacityMore : MouseOpacityLess;
00326 default:
00327 return MouseNothing;
00328 }
00329 }
00330 #endif
00331
00332 Options::MoveResizeMode Options::stringToMoveResizeMode( const QString& s )
00333 {
00334 return s == "Opaque" ? Opaque : Transparent;
00335 }
00336
00337 const char* Options::moveResizeModeToString( MoveResizeMode mode )
00338 {
00339 return mode == Opaque ? "Opaque" : "Transparent";
00340 }
00341
00342 }