kwin Library API Documentation

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 #include <qpalette.h>
00015 #include <qpixmap.h>
00016 #include <kapplication.h>
00017 #include <kconfig.h>
00018 #include <kglobal.h>
00019 #include <kglobalsettings.h>
00020 #include <qtooltip.h>
00021 
00022 #include "client.h"
00023 
00024 namespace KWinInternal
00025 {
00026 
00027 Options::Options()
00028     :   electric_borders( 0 ),
00029         electric_border_delay(0)
00030     {
00031     d = new KDecorationOptionsPrivate;
00032     d->defaultKWinSettings();
00033     updateSettings();
00034     }
00035 
00036 Options::~Options()
00037     {
00038     delete d;
00039     }
00040 
00041 unsigned long Options::updateSettings()
00042     {
00043     KConfig *config = KGlobal::config();
00044     unsigned long changed = 0;
00045     changed |= d->updateKWinSettings( config ); // read decoration settings
00046 
00047     config->setGroup( "Windows" );
00048     moveMode = config->readEntry("MoveMode", "Opaque" ) == "Opaque"?Opaque:Transparent;
00049     resizeMode = config->readEntry("ResizeMode", "Opaque" ) == "Opaque"?Opaque:Transparent;
00050     show_geometry_tip = config->readBoolEntry("GeometryTip", false);
00051 
00052     QString val;
00053 
00054     val = config->readEntry ("FocusPolicy", "ClickToFocus");
00055     focusPolicy = ClickToFocus; // what a default :-)
00056     if ( val == "FocusFollowsMouse" )
00057         focusPolicy = FocusFollowsMouse;
00058     else if ( val == "FocusUnderMouse" )
00059         focusPolicy = FocusUnderMouse;
00060     else if ( val == "FocusStrictlyUnderMouse" )
00061         focusPolicy = FocusStrictlyUnderMouse;
00062 
00063     val = config->readEntry ("AltTabStyle", "KDE");
00064     altTabStyle = KDE; // what a default :-)
00065     if ( val == "CDE" )
00066         altTabStyle = CDE;
00067 
00068     rollOverDesktops = config->readBoolEntry("RollOverDesktops", TRUE);
00069     
00070 //    focusStealingPreventionLevel = config->readNumEntry( "FocusStealingPreventionLevel", 2 );
00071     // TODO use low level for now
00072     focusStealingPreventionLevel = config->readNumEntry( "FocusStealingPreventionLevel", 1 );
00073     focusStealingPreventionLevel = KMAX( 0, KMIN( 4, focusStealingPreventionLevel ));
00074     if( !focusPolicyIsReasonable()) // #48786, comments #7 and later
00075         focusStealingPreventionLevel = 0;
00076 
00077     KConfig *gc = new KConfig("kdeglobals", false, false);
00078     bool isVirtual = KApplication::desktop()->isVirtualDesktop();
00079     gc->setGroup("Windows");
00080     xineramaEnabled = gc->readBoolEntry ("XineramaEnabled", isVirtual ) &&
00081                       isVirtual;
00082     if (xineramaEnabled) 
00083         {
00084         xineramaPlacementEnabled = gc->readBoolEntry ("XineramaPlacementEnabled", true);
00085         xineramaMovementEnabled = gc->readBoolEntry ("XineramaMovementEnabled", true);
00086         xineramaMaximizeEnabled = gc->readBoolEntry ("XineramaMaximizeEnabled", true);
00087         }
00088     else 
00089         {
00090         xineramaPlacementEnabled = xineramaMovementEnabled = xineramaMaximizeEnabled = false;
00091         }
00092     delete gc;
00093 
00094     val = config->readEntry("Placement","Smart");
00095     if (val == "Random")               placement = Random;
00096     else if (val == "Cascade")              placement = Cascade;
00097     else if (val == "Centered")     placement = Centered;
00098     else if (val == "ZeroCornered") placement = ZeroCornered;
00099     else                            placement = Smart;
00100 
00101     animateShade = config->readBoolEntry("AnimateShade", TRUE );
00102 
00103     animateMinimize = config->readBoolEntry("AnimateMinimize", TRUE );
00104     animateMinimizeSpeed = config->readNumEntry("AnimateMinimizeSpeed", 5 );
00105 
00106     if( focusPolicy == ClickToFocus ) 
00107         {
00108         autoRaise = false;
00109         autoRaiseInterval = 0;
00110         }
00111     else 
00112         {
00113         autoRaise = config->readBoolEntry("AutoRaise", FALSE );
00114         autoRaiseInterval = config->readNumEntry("AutoRaiseInterval", 0 );
00115         }
00116 
00117     shadeHover = config->readBoolEntry("ShadeHover", FALSE );
00118     shadeHoverInterval = config->readNumEntry("ShadeHoverInterval", 250 );
00119 
00120     // important: autoRaise implies ClickRaise
00121     clickRaise = autoRaise || config->readBoolEntry("ClickRaise", TRUE );
00122 
00123     borderSnapZone = config->readNumEntry("BorderSnapZone", 10);
00124     windowSnapZone = config->readNumEntry("WindowSnapZone", 10);
00125     snapOnlyWhenOverlapping=config->readBoolEntry("SnapOnlyWhenOverlapping",FALSE);
00126     electric_borders = config->readNumEntry("ElectricBorders", 0);
00127     electric_border_delay = config->readNumEntry("ElectricBorderDelay", 150);
00128 
00129     OpTitlebarDblClick = windowOperation( config->readEntry("TitlebarDoubleClickCommand", "Shade"), true );
00130 
00131     ignorePositionClasses = config->readListEntry("IgnorePositionClasses");
00132     ignoreFocusStealingClasses = config->readListEntry("IgnoreFocusStealingClasses");
00133     // Qt3.2 and older had resource class all lowercase, but Qt3.3 has it capitalized
00134     // therefore Client::resourceClass() forces lowercase, force here lowercase as well
00135     for( QStringList::Iterator it = ignorePositionClasses.begin();
00136          it != ignorePositionClasses.end();
00137          ++it )
00138         (*it) = (*it).lower();
00139     for( QStringList::Iterator it = ignoreFocusStealingClasses.begin();
00140          it != ignoreFocusStealingClasses.end();
00141          ++it )
00142         (*it) = (*it).lower();
00143 
00144     // Mouse bindings
00145     config->setGroup( "MouseBindings");
00146     CmdActiveTitlebar1 = mouseCommand(config->readEntry("CommandActiveTitlebar1","Raise"), true );
00147     CmdActiveTitlebar2 = mouseCommand(config->readEntry("CommandActiveTitlebar2","Lower"), true );
00148     CmdActiveTitlebar3 = mouseCommand(config->readEntry("CommandActiveTitlebar3","Operations menu"), true );
00149     CmdInactiveTitlebar1 = mouseCommand(config->readEntry("CommandInactiveTitlebar1","Activate and raise"), true );
00150     CmdInactiveTitlebar2 = mouseCommand(config->readEntry("CommandInactiveTitlebar2","Activate and lower"), true );
00151     CmdInactiveTitlebar3 = mouseCommand(config->readEntry("CommandInactiveTitlebar3","Operations menu"), true );
00152     CmdWindow1 = mouseCommand(config->readEntry("CommandWindow1","Activate, raise and pass click"), false );
00153     CmdWindow2 = mouseCommand(config->readEntry("CommandWindow2","Activate and pass click"), false );
00154     CmdWindow3 = mouseCommand(config->readEntry("CommandWindow3","Activate and pass click"), false );
00155     CmdAllModKey = (config->readEntry("CommandAllKey","Alt") == "Meta") ? Qt::Key_Meta : Qt::Key_Alt;
00156     CmdAll1 = mouseCommand(config->readEntry("CommandAll1","Move"), false );
00157     CmdAll2 = mouseCommand(config->readEntry("CommandAll2","Toggle raise and lower"), false );
00158     CmdAll3 = mouseCommand(config->readEntry("CommandAll3","Resize"), false );
00159 
00160     // Read button tooltip animation effect from kdeglobals
00161     // Since we want to allow users to enable window decoration tooltips
00162     // and not kstyle tooltips and vise-versa, we don't read the
00163     // "EffectNoTooltip" setting from kdeglobals.
00164     KConfig globalConfig("kdeglobals");
00165     globalConfig.setGroup("KDE");
00166     topmenus = globalConfig.readBoolEntry( "macStyle", false );
00167 
00168     KConfig kdesktopcfg( "kdesktoprc", true );
00169     kdesktopcfg.setGroup( "Menubar" );
00170     desktop_topmenu = kdesktopcfg.readBoolEntry( "ShowMenubar", false );
00171     if( desktop_topmenu )
00172         topmenus = true;
00173         
00174     QToolTip::setGloballyEnabled( d->show_tooltips );
00175 
00176     return changed;
00177     }
00178 
00179 
00180 // restricted should be true for operations that the user may not be able to repeat
00181 // if the window is moved out of the workspace (e.g. if the user moves a window
00182 // by the titlebar, and moves it too high beneath Kicker at the top edge, they
00183 // may not be able to move it back, unless they know about Alt+LMB)
00184 Options::WindowOperation Options::windowOperation(const QString &name, bool restricted )
00185     {
00186     if (name == "Move")
00187         return restricted ? MoveOp : UnrestrictedMoveOp;
00188     else if (name == "Resize")
00189         return restricted ? ResizeOp : UnrestrictedResizeOp;
00190     else if (name == "Maximize")
00191         return MaximizeOp;
00192     else if (name == "Minimize")
00193         return MinimizeOp;
00194     else if (name == "Close")
00195         return CloseOp;
00196     else if (name == "OnAllDesktops")
00197         return OnAllDesktopsOp;
00198     else if (name == "Shade")
00199         return ShadeOp;
00200     else if (name == "Operations")
00201         return OperationsOp;
00202     else if (name == "Maximize (vertical only)")
00203         return VMaximizeOp;
00204     else if (name == "Maximize (horizontal only)")
00205         return HMaximizeOp;
00206     else if (name == "Lower")
00207         return LowerOp;
00208     return NoOp;
00209     }
00210 
00211 Options::MouseCommand Options::mouseCommand(const QString &name, bool restricted )
00212     {
00213     QString lowerName = name.lower();
00214     if (lowerName == "raise") return MouseRaise;
00215     if (lowerName == "lower") return MouseLower;
00216     if (lowerName == "operations menu") return MouseOperationsMenu;
00217     if (lowerName == "toggle raise and lower") return MouseToggleRaiseAndLower;
00218     if (lowerName == "activate and raise") return MouseActivateAndRaise;
00219     if (lowerName == "activate and lower") return MouseActivateAndLower;
00220     if (lowerName == "activate") return MouseActivate;
00221     if (lowerName == "activate, raise and pass click") return MouseActivateRaiseAndPassClick;
00222     if (lowerName == "activate and pass click") return MouseActivateAndPassClick;
00223     if (lowerName == "activate, raise and move")
00224         return restricted ? MouseActivateRaiseAndMove : MouseActivateRaiseAndUnrestrictedMove;
00225     if (lowerName == "move") return restricted ? MouseMove : MouseUnrestrictedMove;
00226     if (lowerName == "resize") return restricted ? MouseResize : MouseUnrestrictedResize;
00227     if (lowerName == "shade") return MouseShade;
00228     if (lowerName == "minimize") return MouseMinimize;
00229     if (lowerName == "nothing") return MouseNothing;
00230     return MouseNothing;
00231     }
00232 
00233 bool Options::showGeometryTip()
00234     {
00235     return show_geometry_tip;
00236     }
00237 
00238 int Options::electricBorders()
00239     {
00240     return electric_borders;
00241     }
00242 
00243 int Options::electricBorderDelay()
00244     {
00245     return electric_border_delay;
00246     }
00247 
00248 bool Options::checkIgnoreFocusStealing( const Client* c )
00249     {
00250     return ignoreFocusStealingClasses.contains(QString::fromLatin1(c->resourceClass()));
00251     }
00252 
00253 } // namespace
KDE Logo
This file is part of the documentation for kwin Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Apr 11 13:44:53 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003