File indexing completed on 2025-03-23 05:02:59
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2004 Lubos Lunak <l.lunak@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #pragma once 0011 0012 #include <QList> 0013 #include <QRectF> 0014 #include <netwm_def.h> 0015 0016 #include "options.h" 0017 #include "utils/common.h" 0018 0019 class QDebug; 0020 class KConfig; 0021 0022 namespace KWin 0023 { 0024 0025 class Window; 0026 class Output; 0027 class Rules; 0028 class RuleSettings; 0029 class VirtualDesktop; 0030 0031 #ifndef KCMRULES // only for kwin core 0032 0033 class WindowRules 0034 { 0035 public: 0036 explicit WindowRules(const QList<Rules *> &rules); 0037 WindowRules(); 0038 void update(Window *, int selection); 0039 bool contains(const Rules *rule) const; 0040 void remove(Rules *rule); 0041 PlacementPolicy checkPlacement(PlacementPolicy placement) const; 0042 QRectF checkGeometry(QRectF rect, bool init = false) const; 0043 QRectF checkGeometrySafe(QRectF rect, bool init = false) const; 0044 // use 'invalidPoint' with checkPosition, unlike QSize() and QRect(), QPoint() is a valid point 0045 QPointF checkPositionSafe(QPointF pos, bool init = false) const; 0046 QPointF checkPosition(QPointF pos, bool init = false) const; 0047 QSizeF checkSize(QSizeF s, bool init = false) const; 0048 QSizeF checkMinSize(QSizeF s) const; 0049 QSizeF checkMaxSize(QSizeF s) const; 0050 int checkOpacityActive(int s) const; 0051 int checkOpacityInactive(int s) const; 0052 bool checkIgnoreGeometry(bool ignore, bool init = false) const; 0053 QList<VirtualDesktop *> checkDesktops(QList<VirtualDesktop *> desktops, bool init = false) const; 0054 Output *checkOutput(Output *output, bool init = false) const; 0055 QStringList checkActivity(QStringList activity, bool init = false) const; 0056 MaximizeMode checkMaximize(MaximizeMode mode, bool init = false) const; 0057 bool checkMinimize(bool minimized, bool init = false) const; 0058 ShadeMode checkShade(ShadeMode shade, bool init = false) const; 0059 bool checkSkipTaskbar(bool skip, bool init = false) const; 0060 bool checkSkipPager(bool skip, bool init = false) const; 0061 bool checkSkipSwitcher(bool skip, bool init = false) const; 0062 bool checkKeepAbove(bool above, bool init = false) const; 0063 bool checkKeepBelow(bool below, bool init = false) const; 0064 bool checkFullScreen(bool fs, bool init = false) const; 0065 bool checkNoBorder(bool noborder, bool init = false) const; 0066 QString checkDecoColor(QString schemeFile) const; 0067 bool checkBlockCompositing(bool block) const; 0068 int checkFSP(int fsp) const; 0069 int checkFPP(int fpp) const; 0070 bool checkAcceptFocus(bool focus) const; 0071 bool checkCloseable(bool closeable) const; 0072 bool checkAutogrouping(bool autogroup) const; 0073 bool checkAutogroupInForeground(bool fg) const; 0074 QString checkAutogroupById(QString id) const; 0075 bool checkStrictGeometry(bool strict) const; 0076 QString checkShortcut(QString s, bool init = false) const; 0077 bool checkDisableGlobalShortcuts(bool disable) const; 0078 QString checkDesktopFile(QString desktopFile, bool init = false) const; 0079 Layer checkLayer(Layer layer) const; 0080 0081 private: 0082 MaximizeMode checkMaximizeVert(MaximizeMode mode, bool init) const; 0083 MaximizeMode checkMaximizeHoriz(MaximizeMode mode, bool init) const; 0084 QList<Rules *> rules; 0085 }; 0086 0087 #endif 0088 0089 class Rules 0090 { 0091 public: 0092 Rules(); 0093 explicit Rules(const RuleSettings *); 0094 enum Type { 0095 Position = 1 << 0, 0096 Size = 1 << 1, 0097 Desktops = 1 << 2, 0098 MaximizeVert = 1 << 3, 0099 MaximizeHoriz = 1 << 4, 0100 Minimize = 1 << 5, 0101 Shade = 1 << 6, 0102 SkipTaskbar = 1 << 7, 0103 SkipPager = 1 << 8, 0104 SkipSwitcher = 1 << 9, 0105 Above = 1 << 10, 0106 Below = 1 << 11, 0107 Fullscreen = 1 << 12, 0108 NoBorder = 1 << 13, 0109 OpacityActive = 1 << 14, 0110 OpacityInactive = 1 << 15, 0111 Activity = 1 << 16, 0112 Screen = 1 << 17, 0113 DesktopFile = 1 << 18, 0114 Layer = 1 << 19, 0115 All = 0xffffffff 0116 }; 0117 Q_DECLARE_FLAGS(Types, Type) 0118 // All these values are saved to the cfg file, and are also used in kstart! 0119 enum { 0120 Unused = 0, 0121 DontAffect, // use the default value 0122 Force, // force the given value 0123 Apply, // apply only after initial mapping 0124 Remember, // like apply, and remember the value when the window is withdrawn 0125 ApplyNow, // apply immediatelly, then forget the setting 0126 ForceTemporarily // apply and force until the window is withdrawn 0127 }; 0128 enum StringMatch { 0129 FirstStringMatch, 0130 UnimportantMatch = FirstStringMatch, 0131 ExactMatch, 0132 SubstringMatch, 0133 RegExpMatch, 0134 LastStringMatch = RegExpMatch 0135 }; 0136 enum SetRule { 0137 UnusedSetRule = Unused, 0138 SetRuleDummy = 256 // so that it's at least short int 0139 }; 0140 enum ForceRule { 0141 UnusedForceRule = Unused, 0142 ForceRuleDummy = 256 // so that it's at least short int 0143 }; 0144 void write(RuleSettings *) const; 0145 bool isEmpty() const; 0146 #ifndef KCMRULES 0147 bool discardUsed(bool withdrawn); 0148 bool match(const Window *c) const; 0149 bool update(Window *, int selection); 0150 bool applyPlacement(PlacementPolicy &placement) const; 0151 bool applyGeometry(QRectF &rect, bool init) const; 0152 // use 'invalidPoint' with applyPosition, unlike QSize() and QRect(), QPoint() is a valid point 0153 bool applyPosition(QPointF &pos, bool init) const; 0154 bool applySize(QSizeF &s, bool init) const; 0155 bool applyMinSize(QSizeF &s) const; 0156 bool applyMaxSize(QSizeF &s) const; 0157 bool applyOpacityActive(int &s) const; 0158 bool applyOpacityInactive(int &s) const; 0159 bool applyIgnoreGeometry(bool &ignore, bool init) const; 0160 bool applyDesktops(QList<VirtualDesktop *> &desktops, bool init) const; 0161 bool applyScreen(int &desktop, bool init) const; 0162 bool applyActivity(QStringList &activity, bool init) const; 0163 bool applyMaximizeVert(MaximizeMode &mode, bool init) const; 0164 bool applyMaximizeHoriz(MaximizeMode &mode, bool init) const; 0165 bool applyMinimize(bool &minimized, bool init) const; 0166 bool applyShade(ShadeMode &shade, bool init) const; 0167 bool applySkipTaskbar(bool &skip, bool init) const; 0168 bool applySkipPager(bool &skip, bool init) const; 0169 bool applySkipSwitcher(bool &skip, bool init) const; 0170 bool applyKeepAbove(bool &above, bool init) const; 0171 bool applyKeepBelow(bool &below, bool init) const; 0172 bool applyFullScreen(bool &fs, bool init) const; 0173 bool applyNoBorder(bool &noborder, bool init) const; 0174 bool applyDecoColor(QString &schemeFile) const; 0175 bool applyBlockCompositing(bool &block) const; 0176 bool applyFSP(int &fsp) const; 0177 bool applyFPP(int &fpp) const; 0178 bool applyAcceptFocus(bool &focus) const; 0179 bool applyCloseable(bool &closeable) const; 0180 bool applyAutogrouping(bool &autogroup) const; 0181 bool applyAutogroupInForeground(bool &fg) const; 0182 bool applyAutogroupById(QString &id) const; 0183 bool applyStrictGeometry(bool &strict) const; 0184 bool applyShortcut(QString &shortcut, bool init) const; 0185 bool applyDisableGlobalShortcuts(bool &disable) const; 0186 bool applyDesktopFile(QString &desktopFile, bool init) const; 0187 bool applyLayer(enum Layer &layer) const; 0188 0189 private: 0190 #endif 0191 bool matchType(NET::WindowType match_type) const; 0192 bool matchWMClass(const QString &match_class, const QString &match_name) const; 0193 bool matchRole(const QString &match_role) const; 0194 bool matchTitle(const QString &match_title) const; 0195 bool matchClientMachine(const QString &match_machine, bool local) const; 0196 #ifdef KCMRULES 0197 private: 0198 #endif 0199 void readFromSettings(const RuleSettings *settings); 0200 static ForceRule convertForceRule(int v); 0201 static QString getDecoColor(const QString &themeName); 0202 #ifndef KCMRULES 0203 static bool checkSetRule(SetRule rule, bool init); 0204 static bool checkForceRule(ForceRule rule); 0205 static bool checkSetStop(SetRule rule); 0206 static bool checkForceStop(ForceRule rule); 0207 #endif 0208 enum Layer layer; 0209 ForceRule layerrule; 0210 QString description; 0211 QString wmclass; 0212 StringMatch wmclassmatch; 0213 bool wmclasscomplete; 0214 QString windowrole; 0215 StringMatch windowrolematch; 0216 QString title; 0217 StringMatch titlematch; 0218 QString clientmachine; 0219 StringMatch clientmachinematch; 0220 NET::WindowTypes types; // types for matching 0221 PlacementPolicy placement; 0222 ForceRule placementrule; 0223 QPoint position; 0224 SetRule positionrule; 0225 QSize size; 0226 SetRule sizerule; 0227 QSize minsize; 0228 ForceRule minsizerule; 0229 QSize maxsize; 0230 ForceRule maxsizerule; 0231 int opacityactive; 0232 ForceRule opacityactiverule; 0233 int opacityinactive; 0234 ForceRule opacityinactiverule; 0235 bool ignoregeometry; 0236 SetRule ignoregeometryrule; 0237 QStringList desktops; 0238 SetRule desktopsrule; 0239 int screen; 0240 SetRule screenrule; 0241 QStringList activity; 0242 SetRule activityrule; 0243 bool maximizevert; 0244 SetRule maximizevertrule; 0245 bool maximizehoriz; 0246 SetRule maximizehorizrule; 0247 bool minimize; 0248 SetRule minimizerule; 0249 bool shade; 0250 SetRule shaderule; 0251 bool skiptaskbar; 0252 SetRule skiptaskbarrule; 0253 bool skippager; 0254 SetRule skippagerrule; 0255 bool skipswitcher; 0256 SetRule skipswitcherrule; 0257 bool above; 0258 SetRule aboverule; 0259 bool below; 0260 SetRule belowrule; 0261 bool fullscreen; 0262 SetRule fullscreenrule; 0263 bool noborder; 0264 SetRule noborderrule; 0265 QString decocolor; 0266 ForceRule decocolorrule; 0267 bool blockcompositing; 0268 ForceRule blockcompositingrule; 0269 int fsplevel; 0270 int fpplevel; 0271 ForceRule fsplevelrule; 0272 ForceRule fpplevelrule; 0273 bool acceptfocus; 0274 ForceRule acceptfocusrule; 0275 bool closeable; 0276 ForceRule closeablerule; 0277 bool autogroup; 0278 ForceRule autogrouprule; 0279 bool autogroupfg; 0280 ForceRule autogroupfgrule; 0281 QString autogroupid; 0282 ForceRule autogroupidrule; 0283 bool strictgeometry; 0284 ForceRule strictgeometryrule; 0285 QString shortcut; 0286 SetRule shortcutrule; 0287 bool disableglobalshortcuts; 0288 ForceRule disableglobalshortcutsrule; 0289 QString desktopfile; 0290 SetRule desktopfilerule; 0291 friend QDebug &operator<<(QDebug &stream, const Rules *); 0292 }; 0293 0294 #ifndef KCMRULES 0295 class KWIN_EXPORT RuleBook : public QObject 0296 { 0297 Q_OBJECT 0298 public: 0299 explicit RuleBook(); 0300 ~RuleBook() override; 0301 WindowRules find(const Window *window) const; 0302 void discardUsed(Window *c, bool withdraw); 0303 void setUpdatesDisabled(bool disable); 0304 bool areUpdatesDisabled() const; 0305 void load(); 0306 void edit(Window *c, bool whole_app); 0307 void requestDiskStorage(); 0308 0309 void setConfig(const KSharedConfig::Ptr &config) 0310 { 0311 m_config = config; 0312 } 0313 0314 private Q_SLOTS: 0315 void save(); 0316 0317 private: 0318 void deleteAll(); 0319 QTimer *m_updateTimer; 0320 bool m_updatesDisabled; 0321 QList<Rules *> m_rules; 0322 KSharedConfig::Ptr m_config; 0323 }; 0324 0325 inline bool RuleBook::areUpdatesDisabled() const 0326 { 0327 return m_updatesDisabled; 0328 } 0329 0330 inline bool Rules::checkSetRule(SetRule rule, bool init) 0331 { 0332 if (rule > (SetRule)DontAffect) { // Unused or DontAffect 0333 if (rule == (SetRule)Force || rule == (SetRule)ApplyNow 0334 || rule == (SetRule)ForceTemporarily || init) { 0335 return true; 0336 } 0337 } 0338 return false; 0339 } 0340 0341 inline bool Rules::checkForceRule(ForceRule rule) 0342 { 0343 return rule == (ForceRule)Force || rule == (ForceRule)ForceTemporarily; 0344 } 0345 0346 inline bool Rules::checkSetStop(SetRule rule) 0347 { 0348 return rule != UnusedSetRule; 0349 } 0350 0351 inline bool Rules::checkForceStop(ForceRule rule) 0352 { 0353 return rule != UnusedForceRule; 0354 } 0355 0356 inline WindowRules::WindowRules(const QList<Rules *> &r) 0357 : rules(r) 0358 { 0359 } 0360 0361 inline WindowRules::WindowRules() 0362 { 0363 } 0364 0365 inline bool WindowRules::contains(const Rules *rule) const 0366 { 0367 return rules.contains(rule); 0368 } 0369 0370 inline void WindowRules::remove(Rules *rule) 0371 { 0372 rules.removeOne(rule); 0373 } 0374 0375 #endif 0376 0377 QDebug &operator<<(QDebug &stream, const Rules *); 0378 0379 } // namespace 0380 0381 Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::Rules::Types)