File indexing completed on 2024-04-28 05:30:25

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 1999, 2000 Matthias Ettrich <ettrich@kde.org>
0006     SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org>
0007     SPDX-FileCopyrightText: 2012 Martin Gräßlin <m.graesslin@kde.org>
0008 
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #pragma once
0013 
0014 #include "core/renderloop.h"
0015 #include "main.h"
0016 
0017 #include <KConfigWatcher>
0018 
0019 namespace KWin
0020 {
0021 
0022 // Whether to keep all windows mapped when compositing (i.e. whether to have
0023 // actively updated window pixmaps).
0024 enum HiddenPreviews {
0025     // The normal mode with regard to mapped windows. Hidden (minimized, etc.)
0026     // and windows on inactive virtual desktops are not mapped, their pixmaps
0027     // are only their icons.
0028     HiddenPreviewsNever,
0029     // Like normal mode, but shown windows (i.e. on inactive virtual desktops)
0030     // are kept mapped, only hidden windows are unmapped.
0031     HiddenPreviewsShown,
0032     // All windows are kept mapped regardless of their state.
0033     HiddenPreviewsAlways
0034 };
0035 
0036 enum XwaylandEavesdropsMode {
0037     None,
0038     NonCharacterKeys,
0039     AllKeysWithModifier,
0040     All
0041 };
0042 
0043 /**
0044  * This enum type specifies whether the Xwayland server must be restarted after a crash.
0045  */
0046 enum XwaylandCrashPolicy {
0047     Stop,
0048     Restart,
0049 };
0050 
0051 /**
0052  * Placement policies. How workspace decides the way windows get positioned
0053  * on the screen. The better the policy, the heavier the resource use.
0054  * Normally you don't have to worry. What the WM adds to the startup time
0055  * is nil compared to the creation of the window itself in the memory
0056  */
0057 enum PlacementPolicy {
0058     PlacementNone, // not really a placement
0059     PlacementDefault, // special, means to use the global default
0060     PlacementUnknown, // special, means the function should use its default
0061     PlacementRandom,
0062     PlacementSmart,
0063     PlacementCentered,
0064     PlacementZeroCornered,
0065     PlacementUnderMouse, // special
0066     PlacementOnMainWindow, // special
0067     PlacementMaximizing,
0068 };
0069 
0070 class Settings;
0071 
0072 class KWIN_EXPORT Options : public QObject
0073 {
0074     Q_OBJECT
0075     Q_ENUM(XwaylandCrashPolicy)
0076     Q_ENUM(PlacementPolicy)
0077     Q_PROPERTY(FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy NOTIFY focusPolicyChanged)
0078     Q_PROPERTY(XwaylandCrashPolicy xwaylandCrashPolicy READ xwaylandCrashPolicy WRITE setXwaylandCrashPolicy NOTIFY xwaylandCrashPolicyChanged)
0079     Q_PROPERTY(int xwaylandMaxCrashCount READ xwaylandMaxCrashCount WRITE setXwaylandMaxCrashCount NOTIFY xwaylandMaxCrashCountChanged)
0080     Q_PROPERTY(bool nextFocusPrefersMouse READ isNextFocusPrefersMouse WRITE setNextFocusPrefersMouse NOTIFY nextFocusPrefersMouseChanged)
0081     /**
0082      * Whether clicking on a window raises it in FocusFollowsMouse
0083      * mode or not.
0084      */
0085     Q_PROPERTY(bool clickRaise READ isClickRaise WRITE setClickRaise NOTIFY clickRaiseChanged)
0086     /**
0087      * Whether autoraise is enabled FocusFollowsMouse mode or not.
0088      */
0089     Q_PROPERTY(bool autoRaise READ isAutoRaise WRITE setAutoRaise NOTIFY autoRaiseChanged)
0090     /**
0091      * Autoraise interval.
0092      */
0093     Q_PROPERTY(int autoRaiseInterval READ autoRaiseInterval WRITE setAutoRaiseInterval NOTIFY autoRaiseIntervalChanged)
0094     /**
0095      * Delayed focus interval.
0096      */
0097     Q_PROPERTY(int delayFocusInterval READ delayFocusInterval WRITE setDelayFocusInterval NOTIFY delayFocusIntervalChanged)
0098     /**
0099      * Whether shade hover is enabled or not.
0100      */
0101     Q_PROPERTY(bool shadeHover READ isShadeHover WRITE setShadeHover NOTIFY shadeHoverChanged)
0102     /**
0103      * Shade hover interval.
0104      */
0105     Q_PROPERTY(int shadeHoverInterval READ shadeHoverInterval WRITE setShadeHoverInterval NOTIFY shadeHoverIntervalChanged)
0106     /**
0107      * Whether to see Xinerama screens separately for focus (in Alt+Tab, when activating next client)
0108      */
0109     Q_PROPERTY(bool separateScreenFocus READ isSeparateScreenFocus WRITE setSeparateScreenFocus NOTIFY separateScreenFocusChanged)
0110     Q_PROPERTY(bool activeMouseScreen READ activeMouseScreen WRITE setActiveMouseScreen NOTIFY activeMouseScreenChanged)
0111     Q_PROPERTY(PlacementPolicy placement READ placement WRITE setPlacement NOTIFY placementChanged)
0112     Q_PROPERTY(ActivationDesktopPolicy activationDesktopPolicy READ activationDesktopPolicy WRITE setActivationDesktopPolicy NOTIFY activationDesktopPolicyChanged)
0113     Q_PROPERTY(bool focusPolicyIsReasonable READ focusPolicyIsReasonable NOTIFY focusPolicyIsResonableChanged)
0114     /**
0115      * The size of the zone that triggers snapping on desktop borders.
0116      */
0117     Q_PROPERTY(int borderSnapZone READ borderSnapZone WRITE setBorderSnapZone NOTIFY borderSnapZoneChanged)
0118     /**
0119      * The size of the zone that triggers snapping with other windows.
0120      */
0121     Q_PROPERTY(int windowSnapZone READ windowSnapZone WRITE setWindowSnapZone NOTIFY windowSnapZoneChanged)
0122     /**
0123      * The size of the zone that triggers snapping on the screen center.
0124      */
0125     Q_PROPERTY(int centerSnapZone READ centerSnapZone WRITE setCenterSnapZone NOTIFY centerSnapZoneChanged)
0126     /**
0127      * Snap only when windows will overlap.
0128      */
0129     Q_PROPERTY(bool snapOnlyWhenOverlapping READ isSnapOnlyWhenOverlapping WRITE setSnapOnlyWhenOverlapping NOTIFY snapOnlyWhenOverlappingChanged)
0130     /**
0131      * Whether or not we roll over to the other edge when switching desktops past the edge.
0132      */
0133     Q_PROPERTY(bool rollOverDesktops READ isRollOverDesktops WRITE setRollOverDesktops NOTIFY rollOverDesktopsChanged)
0134     /**
0135      * 0 - 4 , see Workspace::allowWindowActivation()
0136      */
0137     Q_PROPERTY(int focusStealingPreventionLevel READ focusStealingPreventionLevel WRITE setFocusStealingPreventionLevel NOTIFY focusStealingPreventionLevelChanged)
0138     Q_PROPERTY(KWin::Options::WindowOperation operationTitlebarDblClick READ operationTitlebarDblClick WRITE setOperationTitlebarDblClick NOTIFY operationTitlebarDblClickChanged)
0139     Q_PROPERTY(KWin::Options::WindowOperation operationMaxButtonLeftClick READ operationMaxButtonLeftClick WRITE setOperationMaxButtonLeftClick NOTIFY operationMaxButtonLeftClickChanged)
0140     Q_PROPERTY(KWin::Options::WindowOperation operationMaxButtonMiddleClick READ operationMaxButtonMiddleClick WRITE setOperationMaxButtonMiddleClick NOTIFY operationMaxButtonMiddleClickChanged)
0141     Q_PROPERTY(KWin::Options::WindowOperation operationMaxButtonRightClick READ operationMaxButtonRightClick WRITE setOperationMaxButtonRightClick NOTIFY operationMaxButtonRightClickChanged)
0142     Q_PROPERTY(MouseCommand commandActiveTitlebar1 READ commandActiveTitlebar1 WRITE setCommandActiveTitlebar1 NOTIFY commandActiveTitlebar1Changed)
0143     Q_PROPERTY(MouseCommand commandActiveTitlebar2 READ commandActiveTitlebar2 WRITE setCommandActiveTitlebar2 NOTIFY commandActiveTitlebar2Changed)
0144     Q_PROPERTY(MouseCommand commandActiveTitlebar3 READ commandActiveTitlebar3 WRITE setCommandActiveTitlebar3 NOTIFY commandActiveTitlebar3Changed)
0145     Q_PROPERTY(MouseCommand commandInactiveTitlebar1 READ commandInactiveTitlebar1 WRITE setCommandInactiveTitlebar1 NOTIFY commandInactiveTitlebar1Changed)
0146     Q_PROPERTY(MouseCommand commandInactiveTitlebar2 READ commandInactiveTitlebar2 WRITE setCommandInactiveTitlebar2 NOTIFY commandInactiveTitlebar2Changed)
0147     Q_PROPERTY(MouseCommand commandInactiveTitlebar3 READ commandInactiveTitlebar3 WRITE setCommandInactiveTitlebar3 NOTIFY commandInactiveTitlebar3Changed)
0148     Q_PROPERTY(MouseCommand commandWindow1 READ commandWindow1 WRITE setCommandWindow1 NOTIFY commandWindow1Changed)
0149     Q_PROPERTY(MouseCommand commandWindow2 READ commandWindow2 WRITE setCommandWindow2 NOTIFY commandWindow2Changed)
0150     Q_PROPERTY(MouseCommand commandWindow3 READ commandWindow3 WRITE setCommandWindow3 NOTIFY commandWindow3Changed)
0151     Q_PROPERTY(MouseCommand commandWindowWheel READ commandWindowWheel WRITE setCommandWindowWheel NOTIFY commandWindowWheelChanged)
0152     Q_PROPERTY(MouseCommand commandAll1 READ commandAll1 WRITE setCommandAll1 NOTIFY commandAll1Changed)
0153     Q_PROPERTY(MouseCommand commandAll2 READ commandAll2 WRITE setCommandAll2 NOTIFY commandAll2Changed)
0154     Q_PROPERTY(MouseCommand commandAll3 READ commandAll3 WRITE setCommandAll3 NOTIFY commandAll3Changed)
0155     Q_PROPERTY(uint keyCmdAllModKey READ keyCmdAllModKey WRITE setKeyCmdAllModKey NOTIFY keyCmdAllModKeyChanged)
0156     /**
0157      * Whether the visible name should be condensed.
0158      */
0159     Q_PROPERTY(bool condensedTitle READ condensedTitle WRITE setCondensedTitle NOTIFY condensedTitleChanged)
0160     /**
0161      * Whether a window gets maximized when it reaches top screen edge while being moved.
0162      */
0163     Q_PROPERTY(bool electricBorderMaximize READ electricBorderMaximize WRITE setElectricBorderMaximize NOTIFY electricBorderMaximizeChanged)
0164     /**
0165      * Whether a window is tiled to half screen when reaching left or right screen edge while been moved.
0166      */
0167     Q_PROPERTY(bool electricBorderTiling READ electricBorderTiling WRITE setElectricBorderTiling NOTIFY electricBorderTilingChanged)
0168     /**
0169      * Whether a window is tiled to half screen when reaching left or right screen edge while been moved.
0170      */
0171     Q_PROPERTY(float electricBorderCornerRatio READ electricBorderCornerRatio WRITE setElectricBorderCornerRatio NOTIFY electricBorderCornerRatioChanged)
0172     Q_PROPERTY(bool borderlessMaximizedWindows READ borderlessMaximizedWindows WRITE setBorderlessMaximizedWindows NOTIFY borderlessMaximizedWindowsChanged)
0173     /**
0174      * timeout before non-responding application will be killed after attempt to close.
0175      */
0176     Q_PROPERTY(int killPingTimeout READ killPingTimeout WRITE setKillPingTimeout NOTIFY killPingTimeoutChanged)
0177     /**
0178      * Whether to hide utility windows for inactive applications.
0179      */
0180     Q_PROPERTY(bool hideUtilityWindowsForInactive READ isHideUtilityWindowsForInactive WRITE setHideUtilityWindowsForInactive NOTIFY hideUtilityWindowsForInactiveChanged)
0181     Q_PROPERTY(int compositingMode READ compositingMode WRITE setCompositingMode NOTIFY compositingModeChanged)
0182     Q_PROPERTY(bool useCompositing READ isUseCompositing WRITE setUseCompositing NOTIFY useCompositingChanged)
0183     Q_PROPERTY(int hiddenPreviews READ hiddenPreviews WRITE setHiddenPreviews NOTIFY hiddenPreviewsChanged)
0184     /**
0185      * 0 = no, 1 = yes when transformed,
0186      * 2 = try trilinear when transformed; else 1,
0187      * -1 = auto
0188      */
0189     Q_PROPERTY(int glSmoothScale READ glSmoothScale WRITE setGlSmoothScale NOTIFY glSmoothScaleChanged)
0190     Q_PROPERTY(bool glStrictBinding READ isGlStrictBinding WRITE setGlStrictBinding NOTIFY glStrictBindingChanged)
0191     /**
0192      * Whether strict binding follows the driver or has been overwritten by a user defined config value.
0193      * If @c true glStrictBinding is set by the OpenGL Scene during initialization.
0194      * If @c false glStrictBinding is set from a config value and not updated during scene initialization.
0195      */
0196     Q_PROPERTY(bool glStrictBindingFollowsDriver READ isGlStrictBindingFollowsDriver WRITE setGlStrictBindingFollowsDriver NOTIFY glStrictBindingFollowsDriverChanged)
0197     Q_PROPERTY(GlSwapStrategy glPreferBufferSwap READ glPreferBufferSwap WRITE setGlPreferBufferSwap NOTIFY glPreferBufferSwapChanged)
0198     Q_PROPERTY(KWin::OpenGLPlatformInterface glPlatformInterface READ glPlatformInterface WRITE setGlPlatformInterface NOTIFY glPlatformInterfaceChanged)
0199     Q_PROPERTY(bool windowsBlockCompositing READ windowsBlockCompositing WRITE setWindowsBlockCompositing NOTIFY windowsBlockCompositingChanged)
0200     Q_PROPERTY(bool allowTearing READ allowTearing WRITE setAllowTearing NOTIFY allowTearingChanged)
0201 public:
0202     explicit Options(QObject *parent = nullptr);
0203     ~Options() override;
0204 
0205     void updateSettings();
0206 
0207     /**
0208      * This enum type is used to specify the focus policy.
0209      *
0210      * Note that FocusUnderMouse and FocusStrictlyUnderMouse are not
0211      * particulary useful. They are only provided for old-fashined
0212      * die-hard UNIX people ;-)
0213      */
0214     enum FocusPolicy {
0215         /**
0216          * Clicking into a window activates it. This is also the default.
0217          */
0218         ClickToFocus,
0219         /**
0220          * Moving the mouse pointer actively onto a normal window activates it.
0221          * For convenience, the desktop and windows on the dock are excluded.
0222          * They require clicking.
0223          */
0224         FocusFollowsMouse,
0225         /**
0226          * The window that happens to be under the mouse pointer becomes active.
0227          * The invariant is: no window can have focus that is not under the mouse.
0228          * This also means that Alt-Tab won't work properly and popup dialogs are
0229          * usually unsable with the keyboard. Note that the desktop and windows on
0230          * the dock are excluded for convenience. They get focus only when clicking
0231          * on it.
0232          */
0233         FocusUnderMouse,
0234         /**
0235          * This is even worse than FocusUnderMouse. Only the window under the mouse
0236          * pointer is active. If the mouse points nowhere, nothing has the focus. If
0237          * the mouse points onto the desktop, the desktop has focus. The same holds
0238          * for windows on the dock.
0239          */
0240         FocusStrictlyUnderMouse
0241     };
0242     Q_ENUM(FocusPolicy)
0243 
0244     FocusPolicy focusPolicy() const
0245     {
0246         return m_focusPolicy;
0247     }
0248     bool isNextFocusPrefersMouse() const
0249     {
0250         return m_nextFocusPrefersMouse;
0251     }
0252 
0253     XwaylandCrashPolicy xwaylandCrashPolicy() const
0254     {
0255         return m_xwaylandCrashPolicy;
0256     }
0257     int xwaylandMaxCrashCount() const
0258     {
0259         return m_xwaylandMaxCrashCount;
0260     }
0261     XwaylandEavesdropsMode xwaylandEavesdrops() const
0262     {
0263         return m_xwaylandEavesdrops;
0264     }
0265 
0266     /**
0267      * Whether clicking on a window raises it in FocusFollowsMouse
0268      * mode or not.
0269      */
0270     bool isClickRaise() const
0271     {
0272         return m_clickRaise;
0273     }
0274 
0275     /**
0276      * Whether autoraise is enabled FocusFollowsMouse mode or not.
0277      */
0278     bool isAutoRaise() const
0279     {
0280         return m_autoRaise;
0281     }
0282 
0283     /**
0284      * Autoraise interval
0285      */
0286     int autoRaiseInterval() const
0287     {
0288         return m_autoRaiseInterval;
0289     }
0290 
0291     /**
0292      * Delayed focus interval.
0293      */
0294     int delayFocusInterval() const
0295     {
0296         return m_delayFocusInterval;
0297     }
0298 
0299     /**
0300      * Whether shade hover is enabled or not.
0301      */
0302     bool isShadeHover() const
0303     {
0304         return m_shadeHover;
0305     }
0306 
0307     /**
0308      * Shade hover interval.
0309      */
0310     int shadeHoverInterval()
0311     {
0312         return m_shadeHoverInterval;
0313     }
0314 
0315     /**
0316      * Whether to see Xinerama screens separately for focus (in Alt+Tab, when activating next client)
0317      */
0318     bool isSeparateScreenFocus() const
0319     {
0320         return m_separateScreenFocus;
0321     }
0322 
0323     bool activeMouseScreen() const
0324     {
0325         return m_activeMouseScreen;
0326     }
0327 
0328     PlacementPolicy placement() const
0329     {
0330         return m_placement;
0331     }
0332 
0333     bool focusPolicyIsReasonable()
0334     {
0335         return m_focusPolicy == ClickToFocus || m_focusPolicy == FocusFollowsMouse;
0336     }
0337 
0338     enum ActivationDesktopPolicy {
0339         SwitchToOtherDesktop,
0340         BringToCurrentDesktop,
0341         DoNothing,
0342     };
0343     Q_ENUM(ActivationDesktopPolicy)
0344 
0345     ActivationDesktopPolicy activationDesktopPolicy() const
0346     {
0347         return m_activationDesktopPolicy;
0348     }
0349 
0350     /**
0351      * The size of the zone that triggers snapping on desktop borders.
0352      */
0353     int borderSnapZone() const
0354     {
0355         return m_borderSnapZone;
0356     }
0357 
0358     /**
0359      * The size of the zone that triggers snapping with other windows.
0360      */
0361     int windowSnapZone() const
0362     {
0363         return m_windowSnapZone;
0364     }
0365 
0366     /**
0367      * The size of the zone that triggers snapping on the screen center.
0368      */
0369     int centerSnapZone() const
0370     {
0371         return m_centerSnapZone;
0372     }
0373 
0374     /**
0375      * Snap only when windows will overlap.
0376      */
0377     bool isSnapOnlyWhenOverlapping() const
0378     {
0379         return m_snapOnlyWhenOverlapping;
0380     }
0381 
0382     /**
0383      * Whether or not we roll over to the other edge when switching desktops past the edge.
0384      */
0385     bool isRollOverDesktops() const
0386     {
0387         return m_rollOverDesktops;
0388     }
0389 
0390     /**
0391      * Returns the focus stealing prevention level.
0392      *
0393      * @see allowWindowActivation
0394      */
0395     int focusStealingPreventionLevel() const
0396     {
0397         return m_focusStealingPreventionLevel;
0398     }
0399 
0400     enum WindowOperation {
0401         MaximizeOp = 5000,
0402         RestoreOp,
0403         MinimizeOp,
0404         MoveOp,
0405         UnrestrictedMoveOp,
0406         ResizeOp,
0407         UnrestrictedResizeOp,
0408         CloseOp,
0409         OnAllDesktopsOp,
0410         ShadeOp,
0411         KeepAboveOp,
0412         KeepBelowOp,
0413         OperationsOp,
0414         WindowRulesOp,
0415         ToggleStoreSettingsOp = WindowRulesOp, ///< @obsolete
0416         HMaximizeOp,
0417         VMaximizeOp,
0418         LowerOp,
0419         FullScreenOp,
0420         NoBorderOp,
0421         NoOp,
0422         SetupWindowShortcutOp,
0423         ApplicationRulesOp,
0424     };
0425     Q_ENUM(WindowOperation)
0426 
0427     WindowOperation operationTitlebarDblClick() const
0428     {
0429         return OpTitlebarDblClick;
0430     }
0431     WindowOperation operationMaxButtonLeftClick() const
0432     {
0433         return opMaxButtonLeftClick;
0434     }
0435     WindowOperation operationMaxButtonRightClick() const
0436     {
0437         return opMaxButtonRightClick;
0438     }
0439     WindowOperation operationMaxButtonMiddleClick() const
0440     {
0441         return opMaxButtonMiddleClick;
0442     }
0443     WindowOperation operationMaxButtonClick(Qt::MouseButtons button) const;
0444 
0445     enum MouseCommand {
0446         MouseRaise,
0447         MouseLower,
0448         MouseOperationsMenu,
0449         MouseToggleRaiseAndLower,
0450         MouseActivateAndRaise,
0451         MouseActivateAndLower,
0452         MouseActivate,
0453         MouseActivateRaiseAndPassClick,
0454         MouseActivateAndPassClick,
0455         MouseMove,
0456         MouseUnrestrictedMove,
0457         MouseActivateRaiseAndMove,
0458         MouseActivateRaiseAndUnrestrictedMove,
0459         MouseResize,
0460         MouseUnrestrictedResize,
0461         MouseShade,
0462         MouseSetShade,
0463         MouseUnsetShade,
0464         MouseMaximize,
0465         MouseRestore,
0466         MouseMinimize,
0467         MouseNextDesktop,
0468         MousePreviousDesktop,
0469         MouseAbove,
0470         MouseBelow,
0471         MouseOpacityMore,
0472         MouseOpacityLess,
0473         MouseClose,
0474         MouseNothing
0475     };
0476     Q_ENUM(MouseCommand)
0477 
0478     enum MouseWheelCommand {
0479         MouseWheelRaiseLower,
0480         MouseWheelShadeUnshade,
0481         MouseWheelMaximizeRestore,
0482         MouseWheelAboveBelow,
0483         MouseWheelPreviousNextDesktop,
0484         MouseWheelChangeOpacity,
0485         MouseWheelNothing
0486     };
0487     Q_ENUM(MouseWheelCommand)
0488 
0489     MouseCommand operationTitlebarMouseWheel(int delta) const
0490     {
0491         return wheelToMouseCommand(CmdTitlebarWheel, delta);
0492     }
0493     MouseCommand operationWindowMouseWheel(int delta) const
0494     {
0495         return wheelToMouseCommand(CmdAllWheel, delta);
0496     }
0497 
0498     MouseCommand commandActiveTitlebar1() const
0499     {
0500         return CmdActiveTitlebar1;
0501     }
0502     MouseCommand commandActiveTitlebar2() const
0503     {
0504         return CmdActiveTitlebar2;
0505     }
0506     MouseCommand commandActiveTitlebar3() const
0507     {
0508         return CmdActiveTitlebar3;
0509     }
0510     MouseCommand commandInactiveTitlebar1() const
0511     {
0512         return CmdInactiveTitlebar1;
0513     }
0514     MouseCommand commandInactiveTitlebar2() const
0515     {
0516         return CmdInactiveTitlebar2;
0517     }
0518     MouseCommand commandInactiveTitlebar3() const
0519     {
0520         return CmdInactiveTitlebar3;
0521     }
0522     MouseCommand commandWindow1() const
0523     {
0524         return CmdWindow1;
0525     }
0526     MouseCommand commandWindow2() const
0527     {
0528         return CmdWindow2;
0529     }
0530     MouseCommand commandWindow3() const
0531     {
0532         return CmdWindow3;
0533     }
0534     MouseCommand commandWindowWheel() const
0535     {
0536         return CmdWindowWheel;
0537     }
0538     MouseCommand commandAll1() const
0539     {
0540         return CmdAll1;
0541     }
0542     MouseCommand commandAll2() const
0543     {
0544         return CmdAll2;
0545     }
0546     MouseCommand commandAll3() const
0547     {
0548         return CmdAll3;
0549     }
0550     MouseWheelCommand commandAllWheel() const
0551     {
0552         return CmdAllWheel;
0553     }
0554     uint keyCmdAllModKey() const
0555     {
0556         return CmdAllModKey;
0557     }
0558     Qt::KeyboardModifier commandAllModifier() const
0559     {
0560         switch (CmdAllModKey) {
0561         case Qt::Key_Alt:
0562             return Qt::AltModifier;
0563         case Qt::Key_Meta:
0564             return Qt::MetaModifier;
0565         default:
0566             Q_UNREACHABLE();
0567         }
0568     }
0569 
0570     static WindowOperation windowOperation(const QString &name, bool restricted);
0571     static MouseCommand mouseCommand(const QString &name, bool restricted);
0572     static MouseWheelCommand mouseWheelCommand(const QString &name);
0573 
0574     /**
0575      * Returns whether the user prefers his caption clean.
0576      */
0577     bool condensedTitle() const;
0578 
0579     /**
0580      * @returns true if a window gets maximized when it reaches top screen edge
0581      * while being moved.
0582      */
0583     bool electricBorderMaximize() const
0584     {
0585         return electric_border_maximize;
0586     }
0587     /**
0588      * @returns true if window is tiled to half screen when reaching left or
0589      * right screen edge while been moved.
0590      */
0591     bool electricBorderTiling() const
0592     {
0593         return electric_border_tiling;
0594     }
0595     /**
0596      * @returns the factor that determines the corner part of the edge (ie. 0.1 means tiny corner)
0597      */
0598     float electricBorderCornerRatio() const
0599     {
0600         return electric_border_corner_ratio;
0601     }
0602 
0603     bool borderlessMaximizedWindows() const
0604     {
0605         return borderless_maximized_windows;
0606     }
0607 
0608     /**
0609      * Timeout before non-responding application will be killed after attempt to close.
0610      */
0611     int killPingTimeout() const
0612     {
0613         return m_killPingTimeout;
0614     }
0615 
0616     /**
0617      * Whether to hide utility windows for inactive applications.
0618      */
0619     bool isHideUtilityWindowsForInactive() const
0620     {
0621         return m_hideUtilityWindowsForInactive;
0622     }
0623 
0624     /**
0625      * Returns the animation time factor for desktop effects.
0626      */
0627     double animationTimeFactor() const;
0628 
0629     //----------------------
0630     // Compositing settings
0631     CompositingType compositingMode() const
0632     {
0633         return m_compositingMode;
0634     }
0635     void setCompositingMode(CompositingType mode)
0636     {
0637         m_compositingMode = mode;
0638     }
0639     // Separate to mode so the user can toggle
0640     bool isUseCompositing() const;
0641 
0642     // General preferences
0643     HiddenPreviews hiddenPreviews() const
0644     {
0645         return m_hiddenPreviews;
0646     }
0647     // OpenGL
0648     // 1 = yes,
0649     // 2 = try trilinear when transformed; else 1,
0650     // -1 = auto
0651     int glSmoothScale() const
0652     {
0653         return m_glSmoothScale;
0654     }
0655 
0656     // Settings that should be auto-detected
0657     bool isGlStrictBinding() const
0658     {
0659         return m_glStrictBinding;
0660     }
0661     bool isGlStrictBindingFollowsDriver() const
0662     {
0663         return m_glStrictBindingFollowsDriver;
0664     }
0665     OpenGLPlatformInterface glPlatformInterface() const
0666     {
0667         return m_glPlatformInterface;
0668     }
0669 
0670     enum GlSwapStrategy {
0671         CopyFrontBuffer = 'c',
0672         PaintFullScreen = 'p',
0673         ExtendDamage = 'e',
0674         AutoSwapStrategy = 'a',
0675     };
0676     Q_ENUM(GlSwapStrategy)
0677     GlSwapStrategy glPreferBufferSwap() const
0678     {
0679         return m_glPreferBufferSwap;
0680     }
0681 
0682     bool windowsBlockCompositing() const
0683     {
0684         return m_windowsBlockCompositing;
0685     }
0686 
0687     QStringList modifierOnlyDBusShortcut(Qt::KeyboardModifier mod) const;
0688     bool allowTearing() const;
0689 
0690     // setters
0691     void setFocusPolicy(FocusPolicy focusPolicy);
0692     void setXwaylandCrashPolicy(XwaylandCrashPolicy crashPolicy);
0693     void setXwaylandMaxCrashCount(int maxCrashCount);
0694     void setXwaylandEavesdrops(XwaylandEavesdropsMode mode);
0695     void setNextFocusPrefersMouse(bool nextFocusPrefersMouse);
0696     void setClickRaise(bool clickRaise);
0697     void setAutoRaise(bool autoRaise);
0698     void setAutoRaiseInterval(int autoRaiseInterval);
0699     void setDelayFocusInterval(int delayFocusInterval);
0700     void setShadeHover(bool shadeHover);
0701     void setShadeHoverInterval(int shadeHoverInterval);
0702     void setSeparateScreenFocus(bool separateScreenFocus);
0703     void setActiveMouseScreen(bool activeMouseScreen);
0704     void setPlacement(PlacementPolicy placement);
0705     void setActivationDesktopPolicy(ActivationDesktopPolicy activationDesktopPolicy);
0706     void setBorderSnapZone(int borderSnapZone);
0707     void setWindowSnapZone(int windowSnapZone);
0708     void setCenterSnapZone(int centerSnapZone);
0709     void setSnapOnlyWhenOverlapping(bool snapOnlyWhenOverlapping);
0710     void setRollOverDesktops(bool rollOverDesktops);
0711     void setFocusStealingPreventionLevel(int focusStealingPreventionLevel);
0712     void setOperationTitlebarDblClick(WindowOperation operationTitlebarDblClick);
0713     void setOperationMaxButtonLeftClick(WindowOperation op);
0714     void setOperationMaxButtonRightClick(WindowOperation op);
0715     void setOperationMaxButtonMiddleClick(WindowOperation op);
0716     void setCommandActiveTitlebar1(MouseCommand commandActiveTitlebar1);
0717     void setCommandActiveTitlebar2(MouseCommand commandActiveTitlebar2);
0718     void setCommandActiveTitlebar3(MouseCommand commandActiveTitlebar3);
0719     void setCommandInactiveTitlebar1(MouseCommand commandInactiveTitlebar1);
0720     void setCommandInactiveTitlebar2(MouseCommand commandInactiveTitlebar2);
0721     void setCommandInactiveTitlebar3(MouseCommand commandInactiveTitlebar3);
0722     void setCommandWindow1(MouseCommand commandWindow1);
0723     void setCommandWindow2(MouseCommand commandWindow2);
0724     void setCommandWindow3(MouseCommand commandWindow3);
0725     void setCommandWindowWheel(MouseCommand commandWindowWheel);
0726     void setCommandAll1(MouseCommand commandAll1);
0727     void setCommandAll2(MouseCommand commandAll2);
0728     void setCommandAll3(MouseCommand commandAll3);
0729     void setKeyCmdAllModKey(uint keyCmdAllModKey);
0730     void setCondensedTitle(bool condensedTitle);
0731     void setElectricBorderMaximize(bool electricBorderMaximize);
0732     void setElectricBorderTiling(bool electricBorderTiling);
0733     void setElectricBorderCornerRatio(float electricBorderCornerRatio);
0734     void setBorderlessMaximizedWindows(bool borderlessMaximizedWindows);
0735     void setKillPingTimeout(int killPingTimeout);
0736     void setHideUtilityWindowsForInactive(bool hideUtilityWindowsForInactive);
0737     void setCompositingMode(int compositingMode);
0738     void setUseCompositing(bool useCompositing);
0739     void setHiddenPreviews(int hiddenPreviews);
0740     void setGlSmoothScale(int glSmoothScale);
0741     void setGlStrictBinding(bool glStrictBinding);
0742     void setGlStrictBindingFollowsDriver(bool glStrictBindingFollowsDriver);
0743     void setGlPreferBufferSwap(char glPreferBufferSwap);
0744     void setGlPlatformInterface(OpenGLPlatformInterface interface);
0745     void setWindowsBlockCompositing(bool set);
0746     void setAllowTearing(bool allow);
0747 
0748     // default values
0749     static WindowOperation defaultOperationTitlebarDblClick()
0750     {
0751         return MaximizeOp;
0752     }
0753     static WindowOperation defaultOperationMaxButtonLeftClick()
0754     {
0755         return MaximizeOp;
0756     }
0757     static WindowOperation defaultOperationMaxButtonRightClick()
0758     {
0759         return HMaximizeOp;
0760     }
0761     static WindowOperation defaultOperationMaxButtonMiddleClick()
0762     {
0763         return VMaximizeOp;
0764     }
0765     static MouseCommand defaultCommandActiveTitlebar1()
0766     {
0767         return MouseRaise;
0768     }
0769     static MouseCommand defaultCommandActiveTitlebar2()
0770     {
0771         return MouseNothing;
0772     }
0773     static MouseCommand defaultCommandActiveTitlebar3()
0774     {
0775         return MouseOperationsMenu;
0776     }
0777     static MouseCommand defaultCommandInactiveTitlebar1()
0778     {
0779         return MouseActivateAndRaise;
0780     }
0781     static MouseCommand defaultCommandInactiveTitlebar2()
0782     {
0783         return MouseNothing;
0784     }
0785     static MouseCommand defaultCommandInactiveTitlebar3()
0786     {
0787         return MouseOperationsMenu;
0788     }
0789     static MouseCommand defaultCommandWindow1()
0790     {
0791         return MouseActivateRaiseAndPassClick;
0792     }
0793     static MouseCommand defaultCommandWindow2()
0794     {
0795         return MouseActivateAndPassClick;
0796     }
0797     static MouseCommand defaultCommandWindow3()
0798     {
0799         return MouseActivateAndPassClick;
0800     }
0801     static MouseCommand defaultCommandWindowWheel()
0802     {
0803         return MouseNothing;
0804     }
0805     static MouseCommand defaultCommandAll1()
0806     {
0807         return MouseUnrestrictedMove;
0808     }
0809     static MouseCommand defaultCommandAll2()
0810     {
0811         return MouseToggleRaiseAndLower;
0812     }
0813     static MouseCommand defaultCommandAll3()
0814     {
0815         return MouseUnrestrictedResize;
0816     }
0817     static MouseWheelCommand defaultCommandTitlebarWheel()
0818     {
0819         return MouseWheelNothing;
0820     }
0821     static MouseWheelCommand defaultCommandAllWheel()
0822     {
0823         return MouseWheelNothing;
0824     }
0825     static uint defaultKeyCmdAllModKey()
0826     {
0827         return Qt::Key_Alt;
0828     }
0829     static CompositingType defaultCompositingMode()
0830     {
0831         return OpenGLCompositing;
0832     }
0833     static bool defaultUseCompositing()
0834     {
0835         return true;
0836     }
0837     static HiddenPreviews defaultHiddenPreviews()
0838     {
0839         return HiddenPreviewsShown;
0840     }
0841     static int defaultGlSmoothScale()
0842     {
0843         return 2;
0844     }
0845     static bool defaultGlStrictBinding()
0846     {
0847         return true;
0848     }
0849     static bool defaultGlStrictBindingFollowsDriver()
0850     {
0851         return true;
0852     }
0853     static GlSwapStrategy defaultGlPreferBufferSwap()
0854     {
0855         return AutoSwapStrategy;
0856     }
0857     static OpenGLPlatformInterface defaultGlPlatformInterface()
0858     {
0859         return kwinApp()->shouldUseWaylandForCompositing() ? EglPlatformInterface : GlxPlatformInterface;
0860     }
0861     static XwaylandCrashPolicy defaultXwaylandCrashPolicy()
0862     {
0863         return XwaylandCrashPolicy::Restart;
0864     }
0865     static int defaultXwaylandMaxCrashCount()
0866     {
0867         return 3;
0868     }
0869     static XwaylandEavesdropsMode defaultXwaylandEavesdrops()
0870     {
0871         return None;
0872     }
0873     static ActivationDesktopPolicy defaultActivationDesktopPolicy()
0874     {
0875         return ActivationDesktopPolicy::SwitchToOtherDesktop;
0876     }
0877     /**
0878      * Performs loading all settings except compositing related.
0879      */
0880     void loadConfig();
0881     void reparseConfiguration();
0882 
0883     //----------------------
0884 Q_SIGNALS:
0885     // for properties
0886     void focusPolicyChanged();
0887     void focusPolicyIsResonableChanged();
0888     void xwaylandCrashPolicyChanged();
0889     void xwaylandMaxCrashCountChanged();
0890     void xwaylandEavesdropsChanged();
0891     void nextFocusPrefersMouseChanged();
0892     void clickRaiseChanged();
0893     void autoRaiseChanged();
0894     void autoRaiseIntervalChanged();
0895     void delayFocusIntervalChanged();
0896     void shadeHoverChanged();
0897     void shadeHoverIntervalChanged();
0898     void separateScreenFocusChanged(bool);
0899     void activeMouseScreenChanged();
0900     void placementChanged();
0901     void activationDesktopPolicyChanged();
0902     void borderSnapZoneChanged();
0903     void windowSnapZoneChanged();
0904     void centerSnapZoneChanged();
0905     void snapOnlyWhenOverlappingChanged();
0906     void rollOverDesktopsChanged(bool enabled);
0907     void focusStealingPreventionLevelChanged();
0908     void operationTitlebarDblClickChanged();
0909     void operationMaxButtonLeftClickChanged();
0910     void operationMaxButtonRightClickChanged();
0911     void operationMaxButtonMiddleClickChanged();
0912     void commandActiveTitlebar1Changed();
0913     void commandActiveTitlebar2Changed();
0914     void commandActiveTitlebar3Changed();
0915     void commandInactiveTitlebar1Changed();
0916     void commandInactiveTitlebar2Changed();
0917     void commandInactiveTitlebar3Changed();
0918     void commandWindow1Changed();
0919     void commandWindow2Changed();
0920     void commandWindow3Changed();
0921     void commandWindowWheelChanged();
0922     void commandAll1Changed();
0923     void commandAll2Changed();
0924     void commandAll3Changed();
0925     void keyCmdAllModKeyChanged();
0926     void condensedTitleChanged();
0927     void electricBorderMaximizeChanged();
0928     void electricBorderTilingChanged();
0929     void electricBorderCornerRatioChanged();
0930     void borderlessMaximizedWindowsChanged();
0931     void killPingTimeoutChanged();
0932     void hideUtilityWindowsForInactiveChanged();
0933     void compositingModeChanged();
0934     void useCompositingChanged();
0935     void hiddenPreviewsChanged();
0936     void glSmoothScaleChanged();
0937     void glStrictBindingChanged();
0938     void glStrictBindingFollowsDriverChanged();
0939     void glPreferBufferSwapChanged();
0940     void glPlatformInterfaceChanged();
0941     void windowsBlockCompositingChanged();
0942     void animationSpeedChanged();
0943     void configChanged();
0944     void allowTearingChanged();
0945 
0946 private:
0947     void setElectricBorders(int borders);
0948     void syncFromKcfgc();
0949     std::unique_ptr<Settings> m_settings;
0950     KConfigWatcher::Ptr m_configWatcher;
0951 
0952     FocusPolicy m_focusPolicy;
0953     bool m_nextFocusPrefersMouse;
0954     bool m_clickRaise;
0955     bool m_autoRaise;
0956     int m_autoRaiseInterval;
0957     int m_delayFocusInterval;
0958     bool m_shadeHover;
0959     int m_shadeHoverInterval;
0960     bool m_separateScreenFocus;
0961     bool m_activeMouseScreen;
0962     PlacementPolicy m_placement;
0963     ActivationDesktopPolicy m_activationDesktopPolicy;
0964     int m_borderSnapZone;
0965     int m_windowSnapZone;
0966     int m_centerSnapZone;
0967     bool m_snapOnlyWhenOverlapping;
0968     bool m_rollOverDesktops;
0969     int m_focusStealingPreventionLevel;
0970     int m_killPingTimeout;
0971     bool m_hideUtilityWindowsForInactive;
0972     XwaylandCrashPolicy m_xwaylandCrashPolicy;
0973     int m_xwaylandMaxCrashCount;
0974     XwaylandEavesdropsMode m_xwaylandEavesdrops;
0975 
0976     CompositingType m_compositingMode;
0977     bool m_useCompositing;
0978     HiddenPreviews m_hiddenPreviews;
0979     int m_glSmoothScale;
0980     // Settings that should be auto-detected
0981     bool m_glStrictBinding;
0982     bool m_glStrictBindingFollowsDriver;
0983     GlSwapStrategy m_glPreferBufferSwap;
0984     OpenGLPlatformInterface m_glPlatformInterface;
0985     bool m_windowsBlockCompositing;
0986 
0987     WindowOperation OpTitlebarDblClick;
0988     WindowOperation opMaxButtonRightClick = defaultOperationMaxButtonRightClick();
0989     WindowOperation opMaxButtonMiddleClick = defaultOperationMaxButtonMiddleClick();
0990     WindowOperation opMaxButtonLeftClick = defaultOperationMaxButtonRightClick();
0991 
0992     // mouse bindings
0993     MouseCommand CmdActiveTitlebar1;
0994     MouseCommand CmdActiveTitlebar2;
0995     MouseCommand CmdActiveTitlebar3;
0996     MouseCommand CmdInactiveTitlebar1;
0997     MouseCommand CmdInactiveTitlebar2;
0998     MouseCommand CmdInactiveTitlebar3;
0999     MouseWheelCommand CmdTitlebarWheel;
1000     MouseCommand CmdWindow1;
1001     MouseCommand CmdWindow2;
1002     MouseCommand CmdWindow3;
1003     MouseCommand CmdWindowWheel;
1004     MouseCommand CmdAll1;
1005     MouseCommand CmdAll2;
1006     MouseCommand CmdAll3;
1007     MouseWheelCommand CmdAllWheel;
1008     uint CmdAllModKey;
1009 
1010     bool electric_border_maximize;
1011     bool electric_border_tiling;
1012     float electric_border_corner_ratio;
1013     bool borderless_maximized_windows;
1014     bool condensed_title;
1015 
1016     bool m_allowTearing = true;
1017 
1018     QHash<Qt::KeyboardModifier, QStringList> m_modifierOnlyShortcuts;
1019 
1020     MouseCommand wheelToMouseCommand(MouseWheelCommand com, int delta) const;
1021 };
1022 
1023 extern KWIN_EXPORT Options *options;
1024 
1025 } // namespace
1026 
1027 Q_DECLARE_METATYPE(KWin::Options::WindowOperation)
1028 Q_DECLARE_METATYPE(KWin::OpenGLPlatformInterface)