00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "options.h"
00013
00014 #ifndef KCMRULES
00015
00016 #include <tqpalette.h>
00017 #include <tqpixmap.h>
00018 #include <kapplication.h>
00019 #include <kconfig.h>
00020 #include <kglobal.h>
00021 #include <kglobalsettings.h>
00022 #include <tqtooltip.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 TQString 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", false );
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 gc->setGroup("Windows");
00089 xineramaEnabled = gc->readBoolEntry ("XineramaEnabled", true );
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 delete gc;
00095
00096 placement = Placement::policyFromString( config->readEntry("Placement"), true );
00097 xineramaPlacementScreen = KCLAMP( config->readNumEntry( "XineramaPlacementScreen", -1 ),
00098 -1, qApp->desktop()->numScreens() - 1 );
00099
00100 animateShade = config->readBoolEntry("AnimateShade", TRUE );
00101 animateMinimize = config->readBoolEntry("AnimateMinimize", TRUE );
00102 animateMinimizeSpeed = config->readNumEntry("AnimateMinimizeSpeed", 5 );
00103
00104 if( focusPolicy == ClickToFocus )
00105 {
00106 autoRaise = false;
00107 autoRaiseInterval = 0;
00108 delayFocus = false;
00109 delayFocusInterval = 0;
00110 }
00111 else
00112 {
00113 autoRaise = config->readBoolEntry("AutoRaise", FALSE );
00114 autoRaiseInterval = config->readNumEntry("AutoRaiseInterval", 0 );
00115 delayFocus = config->readBoolEntry("DelayFocus", FALSE );
00116 delayFocusInterval = config->readNumEntry("DelayFocusInterval", 0 );
00117 }
00118
00119 shadeHover = config->readBoolEntry("ShadeHover", FALSE );
00120 shadeHoverInterval = config->readNumEntry("ShadeHoverInterval", 250 );
00121
00122
00123 clickRaise = autoRaise || config->readBoolEntry("ClickRaise", TRUE );
00124
00125 borderSnapZone = config->readNumEntry("BorderSnapZone", 10);
00126 windowSnapZone = config->readNumEntry("WindowSnapZone", 10);
00127 snapOnlyWhenOverlapping=config->readBoolEntry("SnapOnlyWhenOverlapping",FALSE);
00128 electric_borders = config->readNumEntry("ElectricBorders", 0);
00129 electric_border_delay = config->readNumEntry("ElectricBorderDelay", 150);
00130
00131 OpTitlebarDblClick = windowOperation( config->readEntry("TitlebarDoubleClickCommand", "Shade"), true );
00132 d->OpMaxButtonLeftClick = windowOperation( config->readEntry("MaximizeButtonLeftClickCommand", "Maximize"), true );
00133 d->OpMaxButtonMiddleClick = windowOperation( config->readEntry("MaximizeButtonMiddleClickCommand", "Maximize (vertical only)"), true );
00134 d->OpMaxButtonRightClick = windowOperation( config->readEntry("MaximizeButtonRightClickCommand", "Maximize (horizontal only)"), true );
00135
00136 ignorePositionClasses = config->readListEntry("IgnorePositionClasses");
00137 ignoreFocusStealingClasses = config->readListEntry("IgnoreFocusStealingClasses");
00138
00139
00140 for( TQStringList::Iterator it = ignorePositionClasses.begin();
00141 it != ignorePositionClasses.end();
00142 ++it )
00143 (*it) = (*it).lower();
00144 for( TQStringList::Iterator it = ignoreFocusStealingClasses.begin();
00145 it != ignoreFocusStealingClasses.end();
00146 ++it )
00147 (*it) = (*it).lower();
00148
00149 killPingTimeout = config->readNumEntry( "KillPingTimeout", 5000 );
00150 hideUtilityWindowsForInactive = config->readBoolEntry( "HideUtilityWindowsForInactive", true );
00151 showDesktopIsMinimizeAll = config->readBoolEntry( "ShowDesktopIsMinimizeAll", false );
00152
00153
00154 config->setGroup( "MouseBindings");
00155 CmdActiveTitlebar1 = mouseCommand(config->readEntry("CommandActiveTitlebar1","Raise"), true );
00156 CmdActiveTitlebar2 = mouseCommand(config->readEntry("CommandActiveTitlebar2","Lower"), true );
00157 CmdActiveTitlebar3 = mouseCommand(config->readEntry("CommandActiveTitlebar3","Operations menu"), true );
00158 CmdInactiveTitlebar1 = mouseCommand(config->readEntry("CommandInactiveTitlebar1","Activate and raise"), true );
00159 CmdInactiveTitlebar2 = mouseCommand(config->readEntry("CommandInactiveTitlebar2","Activate and lower"), true );
00160 CmdInactiveTitlebar3 = mouseCommand(config->readEntry("CommandInactiveTitlebar3","Operations menu"), true );
00161 CmdTitlebarWheel = mouseWheelCommand(config->readEntry("CommandTitlebarWheel","Nothing"));
00162 CmdWindow1 = mouseCommand(config->readEntry("CommandWindow1","Activate, raise and pass click"), false );
00163 CmdWindow2 = mouseCommand(config->readEntry("CommandWindow2","Activate and pass click"), false );
00164 CmdWindow3 = mouseCommand(config->readEntry("CommandWindow3","Activate and pass click"), false );
00165 CmdAllModKey = (config->readEntry("CommandAllKey","Alt") == "Meta") ? Qt::Key_Meta : Qt::Key_Alt;
00166 CmdAll1 = mouseCommand(config->readEntry("CommandAll1","Move"), false );
00167 CmdAll2 = mouseCommand(config->readEntry("CommandAll2","Toggle raise and lower"), false );
00168 CmdAll3 = mouseCommand(config->readEntry("CommandAll3","Resize"), false );
00169 CmdAllWheel = mouseWheelCommand(config->readEntry("CommandAllWheel","Nothing"));
00170
00171
00172 config->setGroup( "Notification Messages" );
00173 useTranslucency = config->readBoolEntry("UseTranslucency", false);
00174 config->setGroup( "Translucency");
00175 translucentActiveWindows = config->readBoolEntry("TranslucentActiveWindows", false);
00176 activeWindowOpacity = uint((config->readNumEntry("ActiveWindowOpacity", 100)/100.0)*0xFFFFFFFF);
00177 translucentInactiveWindows = config->readBoolEntry("TranslucentInactiveWindows", false);
00178 inactiveWindowOpacity = uint((config->readNumEntry("InactiveWindowOpacity", 75)/100.0)*0xFFFFFFFF);
00179 translucentMovingWindows = config->readBoolEntry("TranslucentMovingWindows", false);
00180 movingWindowOpacity = uint((config->readNumEntry("MovingWindowOpacity", 50)/100.0)*0xFFFFFFFF);
00181 translucentDocks = config->readBoolEntry("TranslucentDocks", false);
00182 dockOpacity = uint((config->readNumEntry("DockOpacity", 80)/100.0)*0xFFFFFFFF);
00183 keepAboveAsActive = config->readBoolEntry("TreatKeepAboveAsActive", true);
00184
00185 useTitleMenuSlider = true;
00186 activeWindowShadowSize = config->readNumEntry("ActiveWindowShadowSize", 200);
00187 inactiveWindowShadowSize = config->readNumEntry("InactiveWindowShadowSize", 100);
00188 dockShadowSize = config->readNumEntry("DockShadowSize", 80);
00189 removeShadowsOnMove = config->readBoolEntry("RemoveShadowsOnMove", true);
00190 removeShadowsOnResize = config->readBoolEntry("RemoveShadowsOnResize", true);
00191 onlyDecoTranslucent = config->readBoolEntry("OnlyDecoTranslucent",false);
00192 resetKompmgr = config->readBoolEntry("ResetKompmgr", false);
00193 if (resetKompmgr)
00194 config->writeEntry("ResetKompmgr",FALSE);
00195
00196
00197 config->setGroup("Style");
00198 shadow_colour = config->readColorEntry("ShadowColour", &Qt::black);
00199 shadow_docks = config->readBoolEntry("ShadowDocks", false);
00200 shadow_overrides = config->readBoolEntry("ShadowOverrides", false);
00201 shadow_topMenus = config->readBoolEntry("ShadowTopMenus", false);
00202 shadow_inactive_colour = config->readColorEntry("InactiveShadowColour", &Qt::black);
00203 shadow_inactive_enabled = config->readBoolEntry("InactiveShadowEnabled", false);
00204 shadow_inactive_opacity = config->readDoubleNumEntry("InactiveShadowOpacity", 0.70);
00205 shadow_inactive_thickness = config->readNumEntry("InactiveShadowThickness", 5);
00206 shadow_inactive_x_offset = config->readNumEntry("InactiveShadowXOffset", 0);
00207 shadow_inactive_y_offset = config->readNumEntry("InactiveShadowYOffset", 5);
00208 shadow_enabled = config->readBoolEntry("ShadowEnabled", false);
00209 shadow_opacity = config->readDoubleNumEntry("ShadowOpacity", 0.70);
00210 shadow_thickness = config->readNumEntry("ShadowThickness", 10);
00211 shadow_x_offset = config->readNumEntry("ShadowXOffset", 0);
00212 shadow_y_offset = config->readNumEntry("ShadowYOffset", 10);
00213
00214
00215
00216
00217
00218
00219 KConfig globalConfig("kdeglobals");
00220 globalConfig.setGroup("KDE");
00221 topmenus = globalConfig.readBoolEntry( "macStyle", false );
00222
00223 KConfig kdesktopcfg( "kdesktoprc", true );
00224 kdesktopcfg.setGroup( "Menubar" );
00225 desktop_topmenu = kdesktopcfg.readBoolEntry( "ShowMenubar", false );
00226 if( desktop_topmenu )
00227 topmenus = true;
00228
00229 TQToolTip::setGloballyEnabled( d->show_tooltips );
00230
00231 return changed;
00232 }
00233
00234
00235
00236
00237
00238
00239 Options::WindowOperation Options::windowOperation(const TQString &name, bool restricted )
00240 {
00241 if (name == "Move")
00242 return restricted ? MoveOp : UnrestrictedMoveOp;
00243 else if (name == "Resize")
00244 return restricted ? ResizeOp : UnrestrictedResizeOp;
00245 else if (name == "Maximize")
00246 return MaximizeOp;
00247 else if (name == "Minimize")
00248 return MinimizeOp;
00249 else if (name == "Close")
00250 return CloseOp;
00251 else if (name == "OnAllDesktops")
00252 return OnAllDesktopsOp;
00253 else if (name == "Shade")
00254 return ShadeOp;
00255 else if (name == "Operations")
00256 return OperationsOp;
00257 else if (name == "Maximize (vertical only)")
00258 return VMaximizeOp;
00259 else if (name == "Maximize (horizontal only)")
00260 return HMaximizeOp;
00261 else if (name == "Lower")
00262 return LowerOp;
00263 else if (name == "Shadow")
00264 return ShadowOp;
00265 return NoOp;
00266 }
00267
00268 Options::MouseCommand Options::mouseCommand(const TQString &name, bool restricted )
00269 {
00270 TQString lowerName = name.lower();
00271 if (lowerName == "raise") return MouseRaise;
00272 if (lowerName == "lower") return MouseLower;
00273 if (lowerName == "operations menu") return MouseOperationsMenu;
00274 if (lowerName == "toggle raise and lower") return MouseToggleRaiseAndLower;
00275 if (lowerName == "activate and raise") return MouseActivateAndRaise;
00276 if (lowerName == "activate and lower") return MouseActivateAndLower;
00277 if (lowerName == "activate") return MouseActivate;
00278 if (lowerName == "activate, raise and pass click") return MouseActivateRaiseAndPassClick;
00279 if (lowerName == "activate and pass click") return MouseActivateAndPassClick;
00280 if (lowerName == "activate, raise and move")
00281 return restricted ? MouseActivateRaiseAndMove : MouseActivateRaiseAndUnrestrictedMove;
00282 if (lowerName == "move") return restricted ? MouseMove : MouseUnrestrictedMove;
00283 if (lowerName == "resize") return restricted ? MouseResize : MouseUnrestrictedResize;
00284 if (lowerName == "shade") return MouseShade;
00285 if (lowerName == "minimize") return MouseMinimize;
00286 if (lowerName == "nothing") return MouseNothing;
00287 return MouseNothing;
00288 }
00289
00290 Options::MouseWheelCommand Options::mouseWheelCommand(const TQString &name)
00291 {
00292 TQString lowerName = name.lower();
00293 if (lowerName == "raise/lower") return MouseWheelRaiseLower;
00294 if (lowerName == "shade/unshade") return MouseWheelShadeUnshade;
00295 if (lowerName == "maximize/restore") return MouseWheelMaximizeRestore;
00296 if (lowerName == "above/below") return MouseWheelAboveBelow;
00297 if (lowerName == "previous/next desktop") return MouseWheelPreviousNextDesktop;
00298 if (lowerName == "change opacity") return MouseWheelChangeOpacity;
00299 return MouseWheelNothing;
00300 }
00301
00302 bool Options::showGeometryTip()
00303 {
00304 return show_geometry_tip;
00305 }
00306
00307 TQColor &Options::shadowColour(bool active)
00308 {
00309 return active ? shadow_colour : shadow_inactive_colour;
00310 }
00311
00312 bool Options::shadowWindowType(NET::WindowType t)
00313 {
00314 bool retval;
00315
00316 switch (t)
00317 {
00318 case NET::Dialog:
00319 case NET::Normal:
00320 retval = true;
00321 break;
00322 case NET::Desktop:
00323 case NET::Menu:
00324 case NET::Toolbar:
00325 retval = false;
00326 break;
00327 case NET::Dock:
00328 retval = shadow_docks;
00329 break;
00330 case NET::Override:
00331 retval = shadow_overrides;
00332 break;
00333 case NET::TopMenu:
00334 retval = shadow_topMenus;
00335 break;
00336 default:
00337 retval = false;
00338 break;
00339 }
00340
00341 return retval;
00342 }
00343
00344 bool Options::shadowEnabled(bool active)
00345 {
00346 return active ? shadow_enabled :
00347 (shadow_enabled && shadow_inactive_enabled);
00348 }
00349
00350 double Options::shadowOpacity(bool active)
00351 {
00352 return active ? shadow_opacity : shadow_inactive_opacity;
00353 }
00354
00355 int Options::shadowThickness(bool active)
00356 {
00357 return active ? shadow_thickness : shadow_inactive_thickness;
00358 }
00359
00360 int Options::shadowXOffset(bool active)
00361 {
00362 return active ? shadow_x_offset : shadow_inactive_x_offset;
00363 }
00364
00365 int Options::shadowYOffset(bool active)
00366 {
00367 return active ? shadow_y_offset : shadow_inactive_y_offset;
00368 }
00369
00370 int Options::electricBorders()
00371 {
00372 return electric_borders;
00373 }
00374
00375 int Options::electricBorderDelay()
00376 {
00377 return electric_border_delay;
00378 }
00379
00380 bool Options::checkIgnoreFocusStealing( const Client* c )
00381 {
00382 return ignoreFocusStealingClasses.contains(TQString::fromLatin1(c->resourceClass()));
00383 }
00384
00385 Options::MouseCommand Options::wheelToMouseCommand( MouseWheelCommand com, int delta )
00386 {
00387 switch( com )
00388 {
00389 case MouseWheelRaiseLower:
00390 return delta > 0 ? MouseRaise : MouseLower;
00391 case MouseWheelShadeUnshade:
00392 return delta > 0 ? MouseSetShade : MouseUnsetShade;
00393 case MouseWheelMaximizeRestore:
00394 return delta > 0 ? MouseMaximize : MouseRestore;
00395 case MouseWheelAboveBelow:
00396 return delta > 0 ? MouseAbove : MouseBelow;
00397 case MouseWheelPreviousNextDesktop:
00398 return delta > 0 ? MousePreviousDesktop : MouseNextDesktop;
00399 case MouseWheelChangeOpacity:
00400 return delta > 0 ? MouseOpacityMore : MouseOpacityLess;
00401 default:
00402 return MouseNothing;
00403 }
00404 }
00405 #endif
00406
00407 Options::MoveResizeMode Options::stringToMoveResizeMode( const TQString& s )
00408 {
00409 return s == "Opaque" ? Opaque : Transparent;
00410 }
00411
00412 const char* Options::moveResizeModeToString( MoveResizeMode mode )
00413 {
00414 return mode == Opaque ? "Opaque" : "Transparent";
00415 }
00416
00417 }