• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KWin

options.cpp

Go to the documentation of this file.
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 This program is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2 of the License, or
00011 (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 *********************************************************************/
00021 
00022 #include "options.h"
00023 
00024 #ifndef KCMRULES
00025 
00026 #include <QPalette>
00027 #include <QPixmap>
00028 #include <kapplication.h>
00029 #include <kconfig.h>
00030 #include <kglobal.h>
00031 #include <kglobalsettings.h>
00032 
00033 #include <QDesktopWidget>
00034 
00035 #include "client.h"
00036 #include "compositingprefs.h"
00037 
00038 #endif
00039 
00040 namespace KWin
00041 {
00042 
00043 #ifndef KCMRULES
00044 
00045 Options::Options()
00046     :   electric_borders( 0 ),
00047         electric_border_delay(0)
00048     {
00049     updateSettings();
00050     }
00051 
00052 Options::~Options()
00053     {
00054     }
00055 
00056 unsigned long Options::updateSettings()
00057     {
00058     KSharedConfig::Ptr _config = KGlobal::config();
00059     unsigned long changed = 0;
00060     changed |= KDecorationOptions::updateSettings( _config.data() ); // read decoration settings
00061 
00062     KConfigGroup config(_config, "Windows");
00063     moveMode = stringToMoveResizeMode( config.readEntry("MoveMode", "Opaque" ));
00064     resizeMode = stringToMoveResizeMode( config.readEntry("ResizeMode", "Opaque" ));
00065     show_geometry_tip = config.readEntry("GeometryTip", false);
00066 
00067     QString val;
00068 
00069     val = config.readEntry ("FocusPolicy", "ClickToFocus");
00070     focusPolicy = ClickToFocus; // what a default :-)
00071     if ( val == "FocusFollowsMouse" )
00072         focusPolicy = FocusFollowsMouse;
00073     else if ( val == "FocusUnderMouse" )
00074         focusPolicy = FocusUnderMouse;
00075     else if ( val == "FocusStrictlyUnderMouse" )
00076         focusPolicy = FocusStrictlyUnderMouse;
00077 
00078     val = config.readEntry ("AltTabStyle", "KDE");
00079     altTabStyle = KDE; // what a default :-)
00080     if ( val == "CDE" )
00081         altTabStyle = CDE;
00082         
00083     separateScreenFocus = config.readEntry( "SeparateScreenFocus", false );
00084     activeMouseScreen = config.readEntry( "ActiveMouseScreen", focusPolicy != ClickToFocus );
00085 
00086     rollOverDesktops = config.readEntry("RollOverDesktops", true);
00087 
00088 //    focusStealingPreventionLevel = config.readEntry( "FocusStealingPreventionLevel", 2 );
00089     // TODO use low level for now
00090     focusStealingPreventionLevel = config.readEntry( "FocusStealingPreventionLevel", 1 );
00091     focusStealingPreventionLevel = qMax( 0, qMin( 4, focusStealingPreventionLevel ));
00092     if( !focusPolicyIsReasonable()) // #48786, comments #7 and later
00093         focusStealingPreventionLevel = 0;
00094 
00095     KConfigGroup gWindowsConfig( _config, "Windows"); // from kdeglobals
00096     xineramaEnabled = gWindowsConfig.readEntry ("XineramaEnabled", true);
00097     xineramaPlacementEnabled = gWindowsConfig.readEntry ("XineramaPlacementEnabled", true);
00098     xineramaMovementEnabled = gWindowsConfig.readEntry ("XineramaMovementEnabled", true);
00099     xineramaMaximizeEnabled = gWindowsConfig.readEntry ("XineramaMaximizeEnabled", true);
00100     xineramaFullscreenEnabled = gWindowsConfig.readEntry ("XineramaFullscreenEnabled", true);
00101 
00102     placement = Placement::policyFromString( config.readEntry("Placement"), true );
00103     xineramaPlacementScreen = qBound( -1, config.readEntry( "XineramaPlacementScreen", -1 ),
00104         qApp->desktop()->numScreens() - 1 );
00105 
00106     if( focusPolicy == ClickToFocus )
00107         {
00108         autoRaise = false;
00109         autoRaiseInterval = 0;
00110         delayFocus = false;
00111         delayFocusInterval = 0;
00112         }
00113     else
00114         {
00115         autoRaise = config.readEntry("AutoRaise", false);
00116         autoRaiseInterval = config.readEntry("AutoRaiseInterval", 0 );
00117         delayFocus = config.readEntry("DelayFocus", false);
00118         delayFocusInterval = config.readEntry("DelayFocusInterval", 0 );
00119         }
00120 
00121     shadeHover = config.readEntry("ShadeHover", false);
00122     shadeHoverInterval = config.readEntry("ShadeHoverInterval", 250 );
00123 
00124     // important: autoRaise implies ClickRaise
00125     clickRaise = autoRaise || config.readEntry("ClickRaise", true);
00126 
00127     borderSnapZone = config.readEntry("BorderSnapZone", 10);
00128     windowSnapZone = config.readEntry("WindowSnapZone", 10);
00129     snapOnlyWhenOverlapping = config.readEntry("SnapOnlyWhenOverlapping", false);
00130     electric_borders = config.readEntry("ElectricBorders", 0);
00131     electric_border_delay = config.readEntry("ElectricBorderDelay", 150);
00132 
00133     OpTitlebarDblClick = windowOperation( config.readEntry("TitlebarDoubleClickCommand", "Maximize"), true );
00134     setOpMaxButtonLeftClick( windowOperation( config.readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true ));
00135     setOpMaxButtonMiddleClick( windowOperation( config.readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true ));
00136     setOpMaxButtonRightClick( windowOperation( config.readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true ));
00137 
00138     ignorePositionClasses = config.readEntry("IgnorePositionClasses",QStringList());
00139     ignoreFocusStealingClasses = config.readEntry("IgnoreFocusStealingClasses",QStringList());
00140     // Qt3.2 and older had resource class all lowercase, but Qt3.3 has it capitalized
00141     // therefore Client::resourceClass() forces lowercase, force here lowercase as well
00142     for( QStringList::Iterator it = ignorePositionClasses.begin();
00143          it != ignorePositionClasses.end();
00144          ++it )
00145         (*it) = (*it).toLower();
00146     for( QStringList::Iterator it = ignoreFocusStealingClasses.begin();
00147          it != ignoreFocusStealingClasses.end();
00148          ++it )
00149         (*it) = (*it).toLower();
00150 
00151     killPingTimeout = config.readEntry( "KillPingTimeout", 5000 );
00152     hideUtilityWindowsForInactive = config.readEntry( "HideUtilityWindowsForInactive", true);
00153     showDesktopIsMinimizeAll = config.readEntry( "ShowDesktopIsMinimizeAll", false );
00154 
00155     // Mouse bindings
00156     config = KConfigGroup(_config,"MouseBindings");
00157     CmdActiveTitlebar1 = mouseCommand(config.readEntry("CommandActiveTitlebar1","Raise"), true );
00158     CmdActiveTitlebar2 = mouseCommand(config.readEntry("CommandActiveTitlebar2","Lower"), true );
00159     CmdActiveTitlebar3 = mouseCommand(config.readEntry("CommandActiveTitlebar3","Operations menu"), true );
00160     CmdInactiveTitlebar1 = mouseCommand(config.readEntry("CommandInactiveTitlebar1","Activate and raise"), true );
00161     CmdInactiveTitlebar2 = mouseCommand(config.readEntry("CommandInactiveTitlebar2","Activate and lower"), true );
00162     CmdInactiveTitlebar3 = mouseCommand(config.readEntry("CommandInactiveTitlebar3","Operations menu"), true );
00163     CmdTitlebarWheel = mouseWheelCommand(config.readEntry("CommandTitlebarWheel","Nothing"));
00164     CmdWindow1 = mouseCommand(config.readEntry("CommandWindow1","Activate, raise and pass click"), false );
00165     CmdWindow2 = mouseCommand(config.readEntry("CommandWindow2","Activate and pass click"), false );
00166     CmdWindow3 = mouseCommand(config.readEntry("CommandWindow3","Activate and pass click"), false );
00167     CmdAllModKey = (config.readEntry("CommandAllKey","Alt") == "Meta") ? Qt::Key_Meta : Qt::Key_Alt;
00168     CmdAll1 = mouseCommand(config.readEntry("CommandAll1","Move"), false );
00169     CmdAll2 = mouseCommand(config.readEntry("CommandAll2","Toggle raise and lower"), false );
00170     CmdAll3 = mouseCommand(config.readEntry("CommandAll3","Resize"), false );
00171     CmdAllWheel = mouseWheelCommand(config.readEntry("CommandAllWheel","Nothing"));
00172 
00173     config=KConfigGroup(_config,"Compositing");
00174     refreshRate = config.readEntry( "RefreshRate", 0 );
00175 
00176     // Read button tooltip animation effect from kdeglobals
00177     // Since we want to allow users to enable window decoration tooltips
00178     // and not kstyle tooltips and vise-versa, we don't read the
00179     // "EffectNoTooltip" setting from kdeglobals.
00180     KConfig _globalConfig( "kdeglobals" );
00181     KConfigGroup globalConfig(&_globalConfig, "KDE");
00182     topmenus = globalConfig.readEntry( "macStyle", false);
00183 
00184     KConfig _kdesktopcfg( "kdesktoprc" );
00185     KConfigGroup kdesktopcfg(&_kdesktopcfg, "Menubar" );
00186     desktop_topmenu = kdesktopcfg.readEntry( "ShowMenubar", false);
00187     if( desktop_topmenu )
00188         topmenus = true;
00189 
00190 //    QToolTip::setGloballyEnabled( d->show_tooltips );
00191 // KDE4 this probably needs to be done manually in clients
00192 
00193     // Driver-specific config detection
00194     CompositingPrefs prefs;
00195     prefs.detect();
00196     reloadCompositingSettings( prefs );
00197 
00198     return changed;
00199     }
00200 
00201 void Options::reloadCompositingSettings(const CompositingPrefs& prefs)
00202     {
00203     KSharedConfig::Ptr _config = KGlobal::config();
00204     KConfigGroup config(_config, "Compositing");
00205 
00206     // Compositing settings
00207     useCompositing = config.readEntry("Enabled", prefs.enableCompositing());
00208     QString compositingBackend = config.readEntry("Backend", "OpenGL");
00209     if( compositingBackend == "XRender" )
00210         compositingMode = XRenderCompositing;
00211     else
00212         compositingMode = OpenGLCompositing;
00213     QString glmode = config.readEntry("GLMode", "TFP" ).toUpper();
00214     if( glmode == "TFP" )
00215         glMode = GLTFP;
00216     else if( glmode == "SHM" )
00217         glMode = GLSHM;
00218     else
00219         glMode = GLFallback;
00220     glDirect = config.readEntry("GLDirect", prefs.enableDirectRendering() );
00221     glVSync = config.readEntry("GLVSync", prefs.enableVSync() );
00222     smoothScale = qBound( -1, config.readEntry( "GLTextureFilter", -1 ), 2 );
00223     glStrictBinding = config.readEntry( "GLStrictBinding", prefs.strictBinding());
00224 
00225     xrenderSmoothScale = config.readEntry("XRenderSmoothScale", false );
00226 
00227     const HiddenPreviews hps[] = { HiddenPreviewsNever, HiddenPreviewsKeep, HiddenPreviewUpdate, HiddenPreviewsActive };
00228     hiddenPreviews = hps[ qBound( 0, config.readEntry( "HiddenPreviews", 0 ), 3 ) ];
00229     }
00230 
00231 
00232 // restricted should be true for operations that the user may not be able to repeat
00233 // if the window is moved out of the workspace (e.g. if the user moves a window
00234 // by the titlebar, and moves it too high beneath Kicker at the top edge, they
00235 // may not be able to move it back, unless they know about Alt+LMB)
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.toLower();
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.toLower();
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 } // namespace

KWin

Skip menu "KWin"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal