options.cpp
00001 /***************************************************************** 00002 KWin - the KDE window manager 00003 This file is part of the KDE project. 00004 00005 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org> 00006 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org> 00007 00008 You can Freely distribute this program under the GNU General Public 00009 License. See the file "COPYING" for the exact licensing terms. 00010 ******************************************************************/ 00011 00012 #include "options.h" 00013 00014 #ifndef KCMRULES 00015 00016 #include <tqpalette.h> 00017 #include <tqpixmap.h> 00018 #include <tdeapplication.h> 00019 #include <tdeconfig.h> 00020 #include <tdeglobal.h> 00021 #include <tdeglobalsettings.h> 00022 #include <tqtooltip.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 TDEConfig *config = TDEGlobal::config(); 00050 unsigned long changed = 0; 00051 changed |= d->updateKWinSettings( config ); // read decoration settings 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 TQString val; 00060 00061 val = config->readEntry ("FocusPolicy", "ClickToFocus"); 00062 focusPolicy = ClickToFocus; // what a default :-) 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; // what a default :-) 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 // focusStealingPreventionLevel = config->readNumEntry( "FocusStealingPreventionLevel", 2 ); 00081 // TODO use low level for now 00082 focusStealingPreventionLevel = config->readNumEntry( "FocusStealingPreventionLevel", 1 ); 00083 focusStealingPreventionLevel = KMAX( 0, KMIN( 4, focusStealingPreventionLevel )); 00084 if( !focusPolicyIsReasonable()) // #48786, comments #7 and later 00085 focusStealingPreventionLevel = 0; 00086 00087 TDEConfig *gc = new TDEConfig("kdeglobals", false, false); 00088 gc->setGroup("Windows"); 00089 xineramaEnabled = gc->readBoolEntry ("XineramaEnabled", true ); 00090 xineramaPlacementEnabled = gc->readBoolEntry ("XineramaPlacementEnabled", true); 00091 xineramaMovementEnabled = gc->readBoolEntry ("XineramaMovementEnabled", true); 00092 xineramaMaximizeEnabled = gc->readBoolEntry ("XineramaMaximizeEnabled", true); 00093 xineramaFullscreenEnabled = gc->readBoolEntry ("XineramaFullscreenEnabled", true); 00094 delete gc; 00095 00096 placement = Placement::policyFromString( config->readEntry("Placement"), true ); 00097 xineramaPlacementScreen = KCLAMP( config->readNumEntry( "XineramaPlacementScreen", -1 ), 00098 -1, tqApp->desktop()->numScreens() - 1 ); 00099 00100 animateShade = config->readBoolEntry("AnimateShade", TRUE ); 00101 animateMinimize = config->readBoolEntry("AnimateMinimize", TRUE ); 00102 animateMinimizeSpeed = config->readNumEntry("AnimateMinimizeSpeed", 5 ); 00103 00104 if( focusPolicy == ClickToFocus ) 00105 { 00106 autoRaise = false; 00107 autoRaiseInterval = 0; 00108 delayFocus = false; 00109 delayFocusInterval = 0; 00110 } 00111 else 00112 { 00113 autoRaise = config->readBoolEntry("AutoRaise", FALSE ); 00114 autoRaiseInterval = config->readNumEntry("AutoRaiseInterval", 0 ); 00115 delayFocus = config->readBoolEntry("DelayFocus", FALSE ); 00116 delayFocusInterval = config->readNumEntry("DelayFocusInterval", 0 ); 00117 } 00118 00119 shadeHover = config->readBoolEntry("ShadeHover", FALSE ); 00120 shadeHoverInterval = config->readNumEntry("ShadeHoverInterval", 250 ); 00121 00122 // important: autoRaise implies ClickRaise 00123 clickRaise = autoRaise || config->readBoolEntry("ClickRaise", TRUE ); 00124 00125 borderSnapZone = config->readNumEntry("BorderSnapZone", 10); 00126 windowSnapZone = config->readNumEntry("WindowSnapZone", 10); 00127 snapOnlyWhenOverlapping=config->readBoolEntry("SnapOnlyWhenOverlapping",FALSE); 00128 electric_borders = config->readNumEntry("ElectricBorders", 0); 00129 electric_border_delay = config->readNumEntry("ElectricBorderDelay", 150); 00130 00131 OpTitlebarDblClick = windowOperation( config->readEntry("TitlebarDoubleClickCommand", "Shade"), true ); 00132 d->OpMaxButtonLeftClick = windowOperation( config->readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true ); 00133 d->OpMaxButtonMiddleClick = windowOperation( config->readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true ); 00134 d->OpMaxButtonRightClick = windowOperation( config->readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true ); 00135 00136 ignorePositionClasses = config->readListEntry("IgnorePositionClasses"); 00137 ignoreFocusStealingClasses = config->readListEntry("IgnoreFocusStealingClasses"); 00138 // Qt3.2 and older had resource class all lowercase, but Qt3.3 has it capitalized 00139 // therefore Client::resourceClass() forces lowercase, force here lowercase as well 00140 for( TQStringList::Iterator it = ignorePositionClasses.begin(); 00141 it != ignorePositionClasses.end(); 00142 ++it ) 00143 (*it) = (*it).lower(); 00144 for( TQStringList::Iterator it = ignoreFocusStealingClasses.begin(); 00145 it != ignoreFocusStealingClasses.end(); 00146 ++it ) 00147 (*it) = (*it).lower(); 00148 00149 killPingTimeout = config->readNumEntry( "KillPingTimeout", 5000 ); 00150 hideUtilityWindowsForInactive = config->readBoolEntry( "HideUtilityWindowsForInactive", true ); 00151 showDesktopIsMinimizeAll = config->readBoolEntry( "ShowDesktopIsMinimizeAll", false ); 00152 00153 // Mouse bindings 00154 config->setGroup( "MouseBindings"); 00155 CmdActiveTitlebar1 = mouseCommand(config->readEntry("CommandActiveTitlebar1","Raise"), true ); 00156 CmdActiveTitlebar2 = mouseCommand(config->readEntry("CommandActiveTitlebar2","Lower"), true ); 00157 CmdActiveTitlebar3 = mouseCommand(config->readEntry("CommandActiveTitlebar3","Operations menu"), true ); 00158 CmdInactiveTitlebar1 = mouseCommand(config->readEntry("CommandInactiveTitlebar1","Activate and raise"), true ); 00159 CmdInactiveTitlebar2 = mouseCommand(config->readEntry("CommandInactiveTitlebar2","Activate and lower"), true ); 00160 CmdInactiveTitlebar3 = mouseCommand(config->readEntry("CommandInactiveTitlebar3","Operations menu"), true ); 00161 CmdTitlebarWheel = mouseWheelCommand(config->readEntry("CommandTitlebarWheel","Nothing")); 00162 CmdWindow1 = mouseCommand(config->readEntry("CommandWindow1","Activate, raise and pass click"), false ); 00163 CmdWindow2 = mouseCommand(config->readEntry("CommandWindow2","Activate and pass click"), false ); 00164 CmdWindow3 = mouseCommand(config->readEntry("CommandWindow3","Activate and pass click"), false ); 00165 CmdAllModKey = (config->readEntry("CommandAllKey","Alt") == "Meta") ? Qt::Key_Meta : Qt::Key_Alt; 00166 CmdAll1 = mouseCommand(config->readEntry("CommandAll1","Move"), false ); 00167 CmdAll2 = mouseCommand(config->readEntry("CommandAll2","Toggle raise and lower"), false ); 00168 CmdAll3 = mouseCommand(config->readEntry("CommandAll3","Resize"), false ); 00169 CmdAllWheel = mouseWheelCommand(config->readEntry("CommandAllWheel","Nothing")); 00170 00171 //translucency settings 00172 config->setGroup( "Notification Messages" ); 00173 useTranslucency = config->readBoolEntry("UseTranslucency", false); 00174 config->setGroup( "Translucency"); 00175 translucentActiveWindows = config->readBoolEntry("TranslucentActiveWindows", false); 00176 activeWindowOpacity = uint((config->readNumEntry("ActiveWindowOpacity", 100)/100.0)*0xFFFFFFFF); 00177 translucentInactiveWindows = config->readBoolEntry("TranslucentInactiveWindows", false); 00178 inactiveWindowOpacity = uint((config->readNumEntry("InactiveWindowOpacity", 75)/100.0)*0xFFFFFFFF); 00179 translucentMovingWindows = config->readBoolEntry("TranslucentMovingWindows", false); 00180 movingWindowOpacity = uint((config->readNumEntry("MovingWindowOpacity", 50)/100.0)*0xFFFFFFFF); 00181 translucentDocks = config->readBoolEntry("TranslucentDocks", false); 00182 dockOpacity = uint((config->readNumEntry("DockOpacity", 80)/100.0)*0xFFFFFFFF); 00183 keepAboveAsActive = config->readBoolEntry("TreatKeepAboveAsActive", true); 00184 //TODO: remove this variable 00185 useTitleMenuSlider = true; 00186 activeWindowShadowSize = config->readNumEntry("ActiveWindowShadowSize", 2*100); 00187 inactiveWindowShadowSize = config->readNumEntry("InactiveWindowShadowSize", 1*100); 00188 dockShadowSize = config->readNumEntry("DockShadowSize", 0*100); 00189 menuShadowSize = config->readNumEntry("MenuShadowSize", 1*100); 00190 removeShadowsOnMove = config->readBoolEntry("RemoveShadowsOnMove", false); 00191 removeShadowsOnResize = config->readBoolEntry("RemoveShadowsOnResize", false); 00192 onlyDecoTranslucent = config->readBoolEntry("OnlyDecoTranslucent",false); 00193 resetKompmgr = config->readBoolEntry("ResetKompmgr", false); 00194 if (resetKompmgr) 00195 config->writeEntry("ResetKompmgr",FALSE); 00196 00197 // window drop shadows 00198 config->setGroup("Style"); 00199 shadow_colour = config->readColorEntry("ShadowColour", &TQt::black); 00200 shadow_docks = config->readBoolEntry("ShadowDocks", false); 00201 shadow_menus = config->readBoolEntry("ShadowMenus", false); 00202 shadow_overrides = config->readBoolEntry("ShadowOverrides", false); 00203 shadow_topMenus = config->readBoolEntry("ShadowTopMenus", false); 00204 shadow_inactive_colour = config->readColorEntry("InactiveShadowColour", &TQt::black); 00205 shadow_inactive_enabled = config->readBoolEntry("InactiveShadowEnabled", false); 00206 shadow_inactive_opacity = config->readDoubleNumEntry("InactiveShadowOpacity", 0.70); 00207 shadow_inactive_thickness = config->readNumEntry("InactiveShadowThickness", 5); 00208 shadow_inactive_x_offset = config->readNumEntry("InactiveShadowXOffset", 0); 00209 shadow_inactive_y_offset = config->readNumEntry("InactiveShadowYOffset", 5); 00210 shadow_enabled = config->readBoolEntry("ShadowEnabled", false); 00211 shadow_opacity = config->readDoubleNumEntry("ShadowOpacity", 0.70); 00212 shadow_thickness = config->readNumEntry("ShadowThickness", 10); 00213 shadow_x_offset = config->readNumEntry("ShadowXOffset", 0); 00214 shadow_y_offset = config->readNumEntry("ShadowYOffset", 10); 00215 00216 00217 // Read button tooltip animation effect from kdeglobals 00218 // Since we want to allow users to enable window decoration tooltips 00219 // and not tdestyle tooltips and vise-versa, we don't read the 00220 // "EffectNoTooltip" setting from kdeglobals. 00221 TDEConfig globalConfig("kdeglobals"); 00222 globalConfig.setGroup("KDE"); 00223 topmenus = globalConfig.readBoolEntry( "macStyle", false ); 00224 00225 TDEConfig kdesktopcfg( "kdesktoprc", true ); 00226 kdesktopcfg.setGroup( "Menubar" ); 00227 desktop_topmenu = kdesktopcfg.readBoolEntry( "ShowMenubar", false ); 00228 if( desktop_topmenu ) 00229 topmenus = true; 00230 00231 TQToolTip::setGloballyEnabled( d->show_tooltips ); 00232 00233 return changed; 00234 } 00235 00236 00237 // restricted should be true for operations that the user may not be able to repeat 00238 // if the window is moved out of the workspace (e.g. if the user moves a window 00239 // by the titlebar, and moves it too high beneath Kicker at the top edge, they 00240 // may not be able to move it back, unless they know about Alt+LMB) 00241 Options::WindowOperation Options::windowOperation(const TQString &name, bool restricted ) 00242 { 00243 if (name == "Move") 00244 return restricted ? MoveOp : UnrestrictedMoveOp; 00245 else if (name == "Resize") 00246 return restricted ? ResizeOp : UnrestrictedResizeOp; 00247 else if (name == "Maximize") 00248 return MaximizeOp; 00249 else if (name == "Minimize") 00250 return MinimizeOp; 00251 else if (name == "Close") 00252 return CloseOp; 00253 else if (name == "OnAllDesktops") 00254 return OnAllDesktopsOp; 00255 else if (name == "Shade") 00256 return ShadeOp; 00257 else if (name == "Operations") 00258 return OperationsOp; 00259 else if (name == "Maximize (vertical only)") 00260 return VMaximizeOp; 00261 else if (name == "Maximize (horizontal only)") 00262 return HMaximizeOp; 00263 else if (name == "Lower") 00264 return LowerOp; 00265 else if (name == "Shadow") 00266 return ShadowOp; 00267 return NoOp; 00268 } 00269 00270 Options::MouseCommand Options::mouseCommand(const TQString &name, bool restricted ) 00271 { 00272 TQString lowerName = name.lower(); 00273 if (lowerName == "raise") return MouseRaise; 00274 if (lowerName == "lower") return MouseLower; 00275 if (lowerName == "operations menu") return MouseOperationsMenu; 00276 if (lowerName == "toggle raise and lower") return MouseToggleRaiseAndLower; 00277 if (lowerName == "activate and raise") return MouseActivateAndRaise; 00278 if (lowerName == "activate and lower") return MouseActivateAndLower; 00279 if (lowerName == "activate") return MouseActivate; 00280 if (lowerName == "activate, raise and pass click") return MouseActivateRaiseAndPassClick; 00281 if (lowerName == "activate and pass click") return MouseActivateAndPassClick; 00282 if (lowerName == "activate, raise and move") 00283 return restricted ? MouseActivateRaiseAndMove : MouseActivateRaiseAndUnrestrictedMove; 00284 if (lowerName == "move") return restricted ? MouseMove : MouseUnrestrictedMove; 00285 if (lowerName == "resize") return restricted ? MouseResize : MouseUnrestrictedResize; 00286 if (lowerName == "shade") return MouseShade; 00287 if (lowerName == "minimize") return MouseMinimize; 00288 if (lowerName == "nothing") return MouseNothing; 00289 return MouseNothing; 00290 } 00291 00292 Options::MouseWheelCommand Options::mouseWheelCommand(const TQString &name) 00293 { 00294 TQString lowerName = name.lower(); 00295 if (lowerName == "raise/lower") return MouseWheelRaiseLower; 00296 if (lowerName == "shade/unshade") return MouseWheelShadeUnshade; 00297 if (lowerName == "maximize/restore") return MouseWheelMaximizeRestore; 00298 if (lowerName == "above/below") return MouseWheelAboveBelow; 00299 if (lowerName == "previous/next desktop") return MouseWheelPreviousNextDesktop; 00300 if (lowerName == "change opacity") return MouseWheelChangeOpacity; 00301 return MouseWheelNothing; 00302 } 00303 00304 bool Options::showGeometryTip() 00305 { 00306 return show_geometry_tip; 00307 } 00308 00309 TQColor &Options::shadowColour(bool active) 00310 { 00311 return active ? shadow_colour : shadow_inactive_colour; 00312 } 00313 00314 bool Options::shadowWindowType(NET::WindowType t) 00315 { 00316 bool retval; 00317 00318 switch (t) 00319 { 00320 case NET::Dialog: 00321 case NET::Normal: 00322 retval = true; 00323 break; 00324 case NET::Desktop: 00325 case NET::Menu: 00326 retval = shadow_menus; 00327 break; 00328 case NET::Toolbar: 00329 retval = false; 00330 break; 00331 case NET::Dock: 00332 retval = shadow_docks; 00333 break; 00334 case NET::Override: 00335 retval = shadow_overrides; 00336 break; 00337 case NET::TopMenu: 00338 retval = shadow_topMenus; 00339 break; 00340 default: 00341 retval = false; 00342 break; 00343 } 00344 00345 return retval; 00346 } 00347 00348 bool Options::shadowEnabled(bool active) 00349 { 00350 return active ? shadow_enabled : 00351 (shadow_enabled && shadow_inactive_enabled); 00352 } 00353 00354 double Options::shadowOpacity(bool active) 00355 { 00356 return active ? shadow_opacity : shadow_inactive_opacity; 00357 } 00358 00359 int Options::shadowThickness(bool active) 00360 { 00361 return active ? shadow_thickness : shadow_inactive_thickness; 00362 } 00363 00364 int Options::shadowXOffset(bool active) 00365 { 00366 return active ? shadow_x_offset : shadow_inactive_x_offset; 00367 } 00368 00369 int Options::shadowYOffset(bool active) 00370 { 00371 return active ? shadow_y_offset : shadow_inactive_y_offset; 00372 } 00373 00374 int Options::electricBorders() 00375 { 00376 return electric_borders; 00377 } 00378 00379 int Options::electricBorderDelay() 00380 { 00381 return electric_border_delay; 00382 } 00383 00384 bool Options::checkIgnoreFocusStealing( const Client* c ) 00385 { 00386 return ignoreFocusStealingClasses.contains(TQString::fromLatin1(c->resourceClass())); 00387 } 00388 00389 Options::MouseCommand Options::wheelToMouseCommand( MouseWheelCommand com, int delta ) 00390 { 00391 switch( com ) 00392 { 00393 case MouseWheelRaiseLower: 00394 return delta > 0 ? MouseRaise : MouseLower; 00395 case MouseWheelShadeUnshade: 00396 return delta > 0 ? MouseSetShade : MouseUnsetShade; 00397 case MouseWheelMaximizeRestore: 00398 return delta > 0 ? MouseMaximize : MouseRestore; 00399 case MouseWheelAboveBelow: 00400 return delta > 0 ? MouseAbove : MouseBelow; 00401 case MouseWheelPreviousNextDesktop: 00402 return delta > 0 ? MousePreviousDesktop : MouseNextDesktop; 00403 case MouseWheelChangeOpacity: 00404 return delta > 0 ? MouseOpacityMore : MouseOpacityLess; 00405 default: 00406 return MouseNothing; 00407 } 00408 } 00409 #endif 00410 00411 Options::MoveResizeMode Options::stringToMoveResizeMode( const TQString& s ) 00412 { 00413 return s == "Opaque" ? Opaque : Transparent; 00414 } 00415 00416 const char* Options::moveResizeModeToString( MoveResizeMode mode ) 00417 { 00418 return mode == Opaque ? "Opaque" : "Transparent"; 00419 } 00420 00421 } // namespace