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 tabboxOutline = config->readBoolEntry("TabboxOutline", true);
00058
00059 QString val;
00060
00061 val = config->readEntry ("FocusPolicy", "ClickToFocus");
00062 focusPolicy = ClickToFocus;
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;
00072 if ( val == "CDE" )
00073 altTabStyle = CDE;
00074
00075 separateScreenFocus = config->readBoolEntry( "SeparateScreenFocus", true );
00076 activeMouseScreen = config->readBoolEntry( "ActiveMouseScreen", focusPolicy != ClickToFocus );
00077
00078 rollOverDesktops = config->readBoolEntry("RollOverDesktops", TRUE);
00079
00080
00081
00082 focusStealingPreventionLevel = config->readNumEntry( "FocusStealingPreventionLevel", 1 );
00083 focusStealingPreventionLevel = KMAX( 0, KMIN( 4, focusStealingPreventionLevel ));
00084 if( !focusPolicyIsReasonable())
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
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
00148
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
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
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
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 if (resetKompmgr = config->readBoolEntry("ResetKompmgr", false))
00202 config->writeEntry("ResetKompmgr",FALSE);
00203
00204
00205
00206
00207
00208
00209
00210 KConfig globalConfig("kdeglobals");
00211 globalConfig.setGroup("KDE");
00212 topmenus = globalConfig.readBoolEntry( "macStyle", false );
00213
00214 KConfig kdesktopcfg( "kdesktoprc", true );
00215 kdesktopcfg.setGroup( "Menubar" );
00216 desktop_topmenu = kdesktopcfg.readBoolEntry( "ShowMenubar", false );
00217 if( desktop_topmenu )
00218 topmenus = true;
00219
00220 QToolTip::setGloballyEnabled( d->show_tooltips );
00221
00222 return changed;
00223 }
00224
00225
00226
00227
00228
00229
00230 Options::WindowOperation Options::windowOperation(const QString &name, bool restricted )
00231 {
00232 if (name == "Move")
00233 return restricted ? MoveOp : UnrestrictedMoveOp;
00234 else if (name == "Resize")
00235 return restricted ? ResizeOp : UnrestrictedResizeOp;
00236 else if (name == "Maximize")
00237 return MaximizeOp;
00238 else if (name == "Minimize")
00239 return MinimizeOp;
00240 else if (name == "Close")
00241 return CloseOp;
00242 else if (name == "OnAllDesktops")
00243 return OnAllDesktopsOp;
00244 else if (name == "Shade")
00245 return ShadeOp;
00246 else if (name == "Operations")
00247 return OperationsOp;
00248 else if (name == "Maximize (vertical only)")
00249 return VMaximizeOp;
00250 else if (name == "Maximize (horizontal only)")
00251 return HMaximizeOp;
00252 else if (name == "Lower")
00253 return LowerOp;
00254 return NoOp;
00255 }
00256
00257 Options::MouseCommand Options::mouseCommand(const QString &name, bool restricted )
00258 {
00259 QString lowerName = name.lower();
00260 if (lowerName == "raise") return MouseRaise;
00261 if (lowerName == "lower") return MouseLower;
00262 if (lowerName == "operations menu") return MouseOperationsMenu;
00263 if (lowerName == "toggle raise and lower") return MouseToggleRaiseAndLower;
00264 if (lowerName == "activate and raise") return MouseActivateAndRaise;
00265 if (lowerName == "activate and lower") return MouseActivateAndLower;
00266 if (lowerName == "activate") return MouseActivate;
00267 if (lowerName == "activate, raise and pass click") return MouseActivateRaiseAndPassClick;
00268 if (lowerName == "activate and pass click") return MouseActivateAndPassClick;
00269 if (lowerName == "activate, raise and move")
00270 return restricted ? MouseActivateRaiseAndMove : MouseActivateRaiseAndUnrestrictedMove;
00271 if (lowerName == "move") return restricted ? MouseMove : MouseUnrestrictedMove;
00272 if (lowerName == "resize") return restricted ? MouseResize : MouseUnrestrictedResize;
00273 if (lowerName == "shade") return MouseShade;
00274 if (lowerName == "minimize") return MouseMinimize;
00275 if (lowerName == "nothing") return MouseNothing;
00276 return MouseNothing;
00277 }
00278
00279 Options::MouseWheelCommand Options::mouseWheelCommand(const QString &name)
00280 {
00281 QString lowerName = name.lower();
00282 if (lowerName == "raise/lower") return MouseWheelRaiseLower;
00283 if (lowerName == "shade/unshade") return MouseWheelShadeUnshade;
00284 if (lowerName == "maximize/restore") return MouseWheelMaximizeRestore;
00285 if (lowerName == "above/below") return MouseWheelAboveBelow;
00286 if (lowerName == "previous/next desktop") return MouseWheelPreviousNextDesktop;
00287 if (lowerName == "change opacity") return MouseWheelChangeOpacity;
00288 return MouseWheelNothing;
00289 }
00290
00291 bool Options::showGeometryTip()
00292 {
00293 return show_geometry_tip;
00294 }
00295
00296 int Options::electricBorders()
00297 {
00298 return electric_borders;
00299 }
00300
00301 int Options::electricBorderDelay()
00302 {
00303 return electric_border_delay;
00304 }
00305
00306 bool Options::checkIgnoreFocusStealing( const Client* c )
00307 {
00308 return ignoreFocusStealingClasses.contains(QString::fromLatin1(c->resourceClass()));
00309 }
00310
00311 Options::MouseCommand Options::wheelToMouseCommand( MouseWheelCommand com, int delta )
00312 {
00313 switch( com )
00314 {
00315 case MouseWheelRaiseLower:
00316 return delta > 0 ? MouseRaise : MouseLower;
00317 case MouseWheelShadeUnshade:
00318 return delta > 0 ? MouseSetShade : MouseUnsetShade;
00319 case MouseWheelMaximizeRestore:
00320 return delta > 0 ? MouseMaximize : MouseRestore;
00321 case MouseWheelAboveBelow:
00322 return delta > 0 ? MouseAbove : MouseBelow;
00323 case MouseWheelPreviousNextDesktop:
00324 return delta > 0 ? MousePreviousDesktop : MouseNextDesktop;
00325 case MouseWheelChangeOpacity:
00326 return delta > 0 ? MouseOpacityMore : MouseOpacityLess;
00327 default:
00328 return MouseNothing;
00329 }
00330 }
00331 #endif
00332
00333 Options::MoveResizeMode Options::stringToMoveResizeMode( const QString& s )
00334 {
00335 return s == "Opaque" ? Opaque : Transparent;
00336 }
00337
00338 const char* Options::moveResizeModeToString( MoveResizeMode mode )
00339 {
00340 return mode == Opaque ? "Opaque" : "Transparent";
00341 }
00342
00343 }