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