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