KWin
Loading...
Searching...
No Matches
rules.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2004 Lubos Lunak <l.lunak@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#pragma once
11
12#include <QList>
13#include <QRectF>
14#include <netwm_def.h>
15
16#include "options.h"
17#include "utils/common.h"
18
19class QDebug;
20class KConfig;
21
22namespace KWin
23{
24
25class Window;
26class Output;
27class Rules;
28class RuleSettings;
29class VirtualDesktop;
30
31#ifndef KCMRULES // only for kwin core
32
34{
35public:
36 explicit WindowRules(const QList<Rules *> &rules);
38 void update(Window *, int selection);
39 bool contains(const Rules *rule) const;
40 void remove(Rules *rule);
42 QRectF checkGeometry(QRectF rect, bool init = false) const;
43 QRectF checkGeometrySafe(QRectF rect, bool init = false) const;
44 // use 'invalidPoint' with checkPosition, unlike QSize() and QRect(), QPoint() is a valid point
45 QPointF checkPositionSafe(QPointF pos, bool init = false) const;
46 QPointF checkPosition(QPointF pos, bool init = false) const;
47 QSizeF checkSize(QSizeF s, bool init = false) const;
48 QSizeF checkMinSize(QSizeF s) const;
49 QSizeF checkMaxSize(QSizeF s) const;
50 int checkOpacityActive(int s) const;
51 int checkOpacityInactive(int s) const;
52 bool checkIgnoreGeometry(bool ignore, bool init = false) const;
53 QList<VirtualDesktop *> checkDesktops(QList<VirtualDesktop *> desktops, bool init = false) const;
54 Output *checkOutput(Output *output, bool init = false) const;
55 QStringList checkActivity(QStringList activity, bool init = false) const;
56 MaximizeMode checkMaximize(MaximizeMode mode, bool init = false) const;
57 bool checkMinimize(bool minimized, bool init = false) const;
58 ShadeMode checkShade(ShadeMode shade, bool init = false) const;
59 bool checkSkipTaskbar(bool skip, bool init = false) const;
60 bool checkSkipPager(bool skip, bool init = false) const;
61 bool checkSkipSwitcher(bool skip, bool init = false) const;
62 bool checkKeepAbove(bool above, bool init = false) const;
63 bool checkKeepBelow(bool below, bool init = false) const;
64 bool checkFullScreen(bool fs, bool init = false) const;
65 bool checkNoBorder(bool noborder, bool init = false) const;
66 QString checkDecoColor(QString schemeFile) const;
67 bool checkBlockCompositing(bool block) const;
68 int checkFSP(int fsp) const;
69 int checkFPP(int fpp) const;
70 bool checkAcceptFocus(bool focus) const;
71 bool checkCloseable(bool closeable) const;
72 bool checkAutogrouping(bool autogroup) const;
73 bool checkAutogroupInForeground(bool fg) const;
74 QString checkAutogroupById(QString id) const;
75 bool checkStrictGeometry(bool strict) const;
76 QString checkShortcut(QString s, bool init = false) const;
77 bool checkDisableGlobalShortcuts(bool disable) const;
78 QString checkDesktopFile(QString desktopFile, bool init = false) const;
79 Layer checkLayer(Layer layer) const;
80 bool checkAdaptiveSync(bool adaptivesync) const;
81
82private:
83 MaximizeMode checkMaximizeVert(MaximizeMode mode, bool init) const;
84 MaximizeMode checkMaximizeHoriz(MaximizeMode mode, bool init) const;
85 QList<Rules *> rules;
86};
87
88#endif
89
90class Rules
91{
92public:
93 Rules();
94 explicit Rules(const RuleSettings *);
95 enum Type {
96 Position = 1 << 0,
97 Size = 1 << 1,
98 Desktops = 1 << 2,
99 MaximizeVert = 1 << 3,
101 Minimize = 1 << 5,
102 Shade = 1 << 6,
103 SkipTaskbar = 1 << 7,
104 SkipPager = 1 << 8,
105 SkipSwitcher = 1 << 9,
106 Above = 1 << 10,
107 Below = 1 << 11,
108 Fullscreen = 1 << 12,
109 NoBorder = 1 << 13,
110 OpacityActive = 1 << 14,
112 Activity = 1 << 16,
113 Screen = 1 << 17,
114 DesktopFile = 1 << 18,
115 Layer = 1 << 19,
116 All = 0xffffffff
117 };
118 Q_DECLARE_FLAGS(Types, Type)
119 // All these values are saved to the cfg file, and are also used in kstart!
120 enum {
122 DontAffect, // use the default value
123 Force, // force the given value
124 Apply, // apply only after initial mapping
125 Remember, // like apply, and remember the value when the window is withdrawn
126 ApplyNow, // apply immediatelly, then forget the setting
127 ForceTemporarily // apply and force until the window is withdrawn
128 };
137 enum SetRule {
139 SetRuleDummy = 256 // so that it's at least short int
140 };
143 ForceRuleDummy = 256 // so that it's at least short int
144 };
145 void write(RuleSettings *) const;
146 bool isEmpty() const;
147#ifndef KCMRULES
148 bool discardUsed(bool withdrawn);
149 bool match(const Window *c) const;
150 bool update(Window *, int selection);
151 bool applyPlacement(PlacementPolicy &placement) const;
152 bool applyGeometry(QRectF &rect, bool init) const;
153 // use 'invalidPoint' with applyPosition, unlike QSize() and QRect(), QPoint() is a valid point
154 bool applyPosition(QPointF &pos, bool init) const;
155 bool applySize(QSizeF &s, bool init) const;
156 bool applyMinSize(QSizeF &s) const;
157 bool applyMaxSize(QSizeF &s) const;
158 bool applyOpacityActive(int &s) const;
159 bool applyOpacityInactive(int &s) const;
160 bool applyIgnoreGeometry(bool &ignore, bool init) const;
161 bool applyDesktops(QList<VirtualDesktop *> &desktops, bool init) const;
162 bool applyScreen(int &desktop, bool init) const;
163 bool applyActivity(QStringList &activity, bool init) const;
164 bool applyMaximizeVert(MaximizeMode &mode, bool init) const;
165 bool applyMaximizeHoriz(MaximizeMode &mode, bool init) const;
166 bool applyMinimize(bool &minimized, bool init) const;
167 bool applyShade(ShadeMode &shade, bool init) const;
168 bool applySkipTaskbar(bool &skip, bool init) const;
169 bool applySkipPager(bool &skip, bool init) const;
170 bool applySkipSwitcher(bool &skip, bool init) const;
171 bool applyKeepAbove(bool &above, bool init) const;
172 bool applyKeepBelow(bool &below, bool init) const;
173 bool applyFullScreen(bool &fs, bool init) const;
174 bool applyNoBorder(bool &noborder, bool init) const;
175 bool applyDecoColor(QString &schemeFile) const;
176 bool applyBlockCompositing(bool &block) const;
177 bool applyFSP(int &fsp) const;
178 bool applyFPP(int &fpp) const;
179 bool applyAcceptFocus(bool &focus) const;
180 bool applyCloseable(bool &closeable) const;
181 bool applyAutogrouping(bool &autogroup) const;
182 bool applyAutogroupInForeground(bool &fg) const;
183 bool applyAutogroupById(QString &id) const;
184 bool applyStrictGeometry(bool &strict) const;
185 bool applyShortcut(QString &shortcut, bool init) const;
186 bool applyDisableGlobalShortcuts(bool &disable) const;
187 bool applyDesktopFile(QString &desktopFile, bool init) const;
188 bool applyLayer(enum Layer &layer) const;
189 bool applyAdaptiveSync(bool &adaptivesync) const;
190
191private:
192#endif
193 bool matchType(NET::WindowType match_type) const;
194 bool matchWMClass(const QString &match_class, const QString &match_name) const;
195 bool matchRole(const QString &match_role) const;
196 bool matchTitle(const QString &match_title) const;
197 bool matchClientMachine(const QString &match_machine, bool local) const;
198#ifdef KCMRULES
199private:
200#endif
201 void readFromSettings(const RuleSettings *settings);
202 static ForceRule convertForceRule(int v);
203 static QString getDecoColor(const QString &themeName);
204#ifndef KCMRULES
205 static bool checkSetRule(SetRule rule, bool init);
206 static bool checkForceRule(ForceRule rule);
207 static bool checkSetStop(SetRule rule);
208 static bool checkForceStop(ForceRule rule);
209#endif
210 enum Layer layer;
211 ForceRule layerrule;
212 QString description;
213 QString wmclass;
214 StringMatch wmclassmatch;
215 bool wmclasscomplete;
216 QString windowrole;
217 StringMatch windowrolematch;
218 QString title;
219 StringMatch titlematch;
220 QString clientmachine;
221 StringMatch clientmachinematch;
222 NET::WindowTypes types; // types for matching
223 PlacementPolicy placement;
224 ForceRule placementrule;
225 QPoint position;
226 SetRule positionrule;
227 QSize size;
228 SetRule sizerule;
229 QSize minsize;
230 ForceRule minsizerule;
231 QSize maxsize;
232 ForceRule maxsizerule;
233 int opacityactive;
234 ForceRule opacityactiverule;
235 int opacityinactive;
236 ForceRule opacityinactiverule;
237 bool ignoregeometry;
238 SetRule ignoregeometryrule;
239 QStringList desktops;
240 SetRule desktopsrule;
241 int screen;
242 SetRule screenrule;
243 QStringList activity;
244 SetRule activityrule;
245 bool maximizevert;
246 SetRule maximizevertrule;
247 bool maximizehoriz;
248 SetRule maximizehorizrule;
249 bool minimize;
250 SetRule minimizerule;
251 bool shade;
252 SetRule shaderule;
253 bool skiptaskbar;
254 SetRule skiptaskbarrule;
255 bool skippager;
256 SetRule skippagerrule;
257 bool skipswitcher;
258 SetRule skipswitcherrule;
259 bool above;
260 SetRule aboverule;
261 bool below;
262 SetRule belowrule;
263 bool fullscreen;
264 SetRule fullscreenrule;
265 bool noborder;
266 SetRule noborderrule;
267 QString decocolor;
268 ForceRule decocolorrule;
269 bool blockcompositing;
270 ForceRule blockcompositingrule;
271 int fsplevel;
272 int fpplevel;
273 ForceRule fsplevelrule;
274 ForceRule fpplevelrule;
275 bool acceptfocus;
276 ForceRule acceptfocusrule;
277 bool closeable;
278 ForceRule closeablerule;
279 bool autogroup;
280 ForceRule autogrouprule;
281 bool autogroupfg;
282 ForceRule autogroupfgrule;
283 QString autogroupid;
284 ForceRule autogroupidrule;
285 bool strictgeometry;
286 ForceRule strictgeometryrule;
287 QString shortcut;
288 SetRule shortcutrule;
289 bool disableglobalshortcuts;
290 ForceRule disableglobalshortcutsrule;
291 QString desktopfile;
292 SetRule desktopfilerule;
293 bool adaptivesync;
294 ForceRule adaptivesyncrule;
295 friend QDebug &operator<<(QDebug &stream, const Rules *);
296};
297
298#ifndef KCMRULES
299class KWIN_EXPORT RuleBook : public QObject
300{
301 Q_OBJECT
302public:
303 explicit RuleBook();
304 ~RuleBook() override;
305 WindowRules find(const Window *window) const;
306 void discardUsed(Window *c, bool withdraw);
307 void setUpdatesDisabled(bool disable);
308 bool areUpdatesDisabled() const;
309 void load();
310 void edit(Window *c, bool whole_app);
311 void requestDiskStorage();
312
313 void setConfig(const KSharedConfig::Ptr &config)
314 {
315 m_config = config;
316 }
317
318private Q_SLOTS:
319 void save();
320
321private:
322 void deleteAll();
323 QTimer *m_updateTimer;
324 bool m_updatesDisabled;
325 QList<Rules *> m_rules;
326 KSharedConfig::Ptr m_config;
327};
328
330{
331 return m_updatesDisabled;
332}
333
334inline bool Rules::checkSetRule(SetRule rule, bool init)
335{
336 if (rule > (SetRule)DontAffect) { // Unused or DontAffect
337 if (rule == (SetRule)Force || rule == (SetRule)ApplyNow
338 || rule == (SetRule)ForceTemporarily || init) {
339 return true;
340 }
341 }
342 return false;
343}
344
345inline bool Rules::checkForceRule(ForceRule rule)
346{
347 return rule == (ForceRule)Force || rule == (ForceRule)ForceTemporarily;
348}
349
350inline bool Rules::checkSetStop(SetRule rule)
351{
352 return rule != UnusedSetRule;
353}
354
355inline bool Rules::checkForceStop(ForceRule rule)
356{
357 return rule != UnusedForceRule;
358}
359
360inline WindowRules::WindowRules(const QList<Rules *> &r)
361 : rules(r)
362{
363}
364
366{
367}
368
369inline bool WindowRules::contains(const Rules *rule) const
370{
371 return rules.contains(rule);
372}
373
374inline void WindowRules::remove(Rules *rule)
375{
376 rules.removeOne(rule);
377}
378
379#endif
380
381QDebug &operator<<(QDebug &stream, const Rules *);
382
383} // namespace
384
385Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::Rules::Types)
bool areUpdatesDisabled() const
Definition rules.h:329
void setConfig(const KSharedConfig::Ptr &config)
Definition rules.h:313
bool applyMaximizeVert(MaximizeMode &mode, bool init) const
Definition rules.cpp:601
bool applyKeepBelow(bool &below, bool init) const
bool applyCloseable(bool &closeable) const
bool applyScreen(int &desktop, bool init) const
bool applyLayer(enum Layer &layer) const
bool applyMaximizeHoriz(MaximizeMode &mode, bool init) const
Definition rules.cpp:593
bool applyGeometry(QRectF &rect, bool init) const
Definition rules.cpp:538
bool applySkipSwitcher(bool &skip, bool init) const
bool applyFPP(int &fpp) const
bool applySkipTaskbar(bool &skip, bool init) const
@ ForceTemporarily
Definition rules.h:127
@ DontAffect
Definition rules.h:122
bool applyPosition(QPointF &pos, bool init) const
Definition rules.cpp:554
bool applyAdaptiveSync(bool &adaptivesync) const
bool applyNoBorder(bool &noborder, bool init) const
bool applyDesktops(QList< VirtualDesktop * > &desktops, bool init) const
Definition rules.cpp:580
bool applyOpacityInactive(int &s) const
bool applyAutogrouping(bool &autogroup) const
bool applyFullScreen(bool &fs, bool init) const
bool applyStrictGeometry(bool &strict) const
void write(RuleSettings *) const
Definition rules.cpp:187
bool applyIgnoreGeometry(bool &ignore, bool init) const
bool applyMaxSize(QSizeF &s) const
bool applyFSP(int &fsp) const
bool applyMinSize(QSizeF &s) const
bool applyAutogroupInForeground(bool &fg) const
bool applyOpacityActive(int &s) const
bool applyActivity(QStringList &activity, bool init) const
@ UnusedSetRule
Definition rules.h:138
@ SetRuleDummy
Definition rules.h:139
bool applyPlacement(PlacementPolicy &placement) const
bool applyDecoColor(QString &schemeFile) const
bool applySkipPager(bool &skip, bool init) const
bool update(Window *, int selection)
Definition rules.cpp:422
bool applyMinimize(bool &minimized, bool init) const
bool applyDesktopFile(QString &desktopFile, bool init) const
bool applyKeepAbove(bool &above, bool init) const
bool applyDisableGlobalShortcuts(bool &disable) const
bool applyShortcut(QString &shortcut, bool init) const
@ FirstStringMatch
Definition rules.h:130
@ SubstringMatch
Definition rules.h:133
@ LastStringMatch
Definition rules.h:135
@ RegExpMatch
Definition rules.h:134
@ UnimportantMatch
Definition rules.h:131
@ ExactMatch
Definition rules.h:132
bool applyShade(ShadeMode &shade, bool init) const
Definition rules.cpp:611
@ UnusedForceRule
Definition rules.h:142
@ ForceRuleDummy
Definition rules.h:143
bool applyAutogroupById(QString &id) const
bool discardUsed(bool withdrawn)
Definition rules.cpp:664
bool applyAcceptFocus(bool &focus) const
bool applySize(QSizeF &s, bool init) const
Definition rules.cpp:562
friend QDebug & operator<<(QDebug &stream, const Rules *)
Definition rules.cpp:712
bool isEmpty() const
Definition rules.cpp:248
@ SkipTaskbar
Definition rules.h:103
@ SkipPager
Definition rules.h:104
@ OpacityInactive
Definition rules.h:111
@ MaximizeHoriz
Definition rules.h:100
@ OpacityActive
Definition rules.h:110
@ DesktopFile
Definition rules.h:114
@ Desktops
Definition rules.h:98
@ Fullscreen
Definition rules.h:108
@ MaximizeVert
Definition rules.h:99
@ Position
Definition rules.h:96
@ SkipSwitcher
Definition rules.h:105
bool match(const Window *c) const
Definition rules.cpp:397
bool applyBlockCompositing(bool &block) const
PlacementPolicy checkPlacement(PlacementPolicy placement) const
QPointF checkPositionSafe(QPointF pos, bool init=false) const
Definition rules.cpp:776
QSizeF checkMaxSize(QSizeF s) const
QString checkDesktopFile(QString desktopFile, bool init=false) const
QString checkShortcut(QString s, bool init=false) const
Layer checkLayer(Layer layer) const
bool checkDisableGlobalShortcuts(bool disable) const
bool checkNoBorder(bool noborder, bool init=false) const
int checkOpacityInactive(int s) const
bool checkCloseable(bool closeable) const
bool contains(const Rules *rule) const
Definition rules.h:369
bool checkStrictGeometry(bool strict) const
Output * checkOutput(Output *output, bool init=false) const
Definition rules.cpp:813
bool checkFullScreen(bool fs, bool init=false) const
bool checkKeepBelow(bool below, bool init=false) const
bool checkSkipSwitcher(bool skip, bool init=false) const
QString checkDecoColor(QString schemeFile) const
bool checkSkipPager(bool skip, bool init=false) const
int checkFSP(int fsp) const
bool checkIgnoreGeometry(bool ignore, bool init=false) const
bool checkAutogroupInForeground(bool fg) const
bool checkBlockCompositing(bool block) const
int checkFPP(int fpp) const
void update(Window *, int selection)
Definition rules.cpp:719
bool checkAutogrouping(bool autogroup) const
QList< VirtualDesktop * > checkDesktops(QList< VirtualDesktop * > desktops, bool init=false) const
QStringList checkActivity(QStringList activity, bool init=false) const
void remove(Rules *rule)
Definition rules.h:374
ShadeMode checkShade(ShadeMode shade, bool init=false) const
MaximizeMode checkMaximize(MaximizeMode mode, bool init=false) const
Definition rules.cpp:806
QString checkAutogroupById(QString id) const
bool checkMinimize(bool minimized, bool init=false) const
QSizeF checkSize(QSizeF s, bool init=false) const
bool checkAcceptFocus(bool focus) const
int checkOpacityActive(int s) const
bool checkSkipTaskbar(bool skip, bool init=false) const
QRectF checkGeometrySafe(QRectF rect, bool init=false) const
Definition rules.cpp:771
QSizeF checkMinSize(QSizeF s) const
bool checkAdaptiveSync(bool adaptivesync) const
QPointF checkPosition(QPointF pos, bool init=false) const
bool checkKeepAbove(bool above, bool init=false) const
QRectF checkGeometry(QRectF rect, bool init=false) const
Definition rules.cpp:766
ShadeMode
Definition common.h:62
QDebug & operator<<(QDebug &s, const KWin::DrmConnector *obj)
MaximizeMode
Definition common.h:74
PlacementPolicy
Definition options.h:57
Layer
Definition globals.h:162