~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/rules.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2004 Lubos Lunak <l.lunak@kde.org>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
 
 
21
#ifndef KWIN_RULES_H
 
22
#define KWIN_RULES_H
 
23
 
 
24
 
 
25
#include <netwm_def.h>
 
26
#include <QRect>
 
27
#include <kconfiggroup.h>
 
28
#include <kdebug.h>
 
29
 
 
30
#include "placement.h"
 
31
#include <kdecoration.h>
 
32
#include "options.h"
 
33
#include "utils.h"
 
34
 
 
35
class KConfig;
 
36
 
 
37
namespace KWin
 
38
{
 
39
 
 
40
class Client;
 
41
class Rules;
 
42
 
 
43
#ifndef KCMRULES // only for kwin core
 
44
 
 
45
class WindowRules
 
46
    : public KDecorationDefines
 
47
{
 
48
public:
 
49
    WindowRules(const QVector< Rules* >& rules);
 
50
    WindowRules();
 
51
    void update(Client*);
 
52
    void discardTemporary();
 
53
    bool contains(const Rules* rule) const;
 
54
    void remove(Rules* rule);
 
55
    Placement::Policy checkPlacement(Placement::Policy placement) const;
 
56
    QRect checkGeometry(QRect rect, bool init = false) const;
 
57
    // use 'invalidPoint' with checkPosition, unlike QSize() and QRect(), QPoint() is a valid point
 
58
    QPoint checkPosition(QPoint pos, bool init = false) const;
 
59
    QSize checkSize(QSize s, bool init = false) const;
 
60
    QSize checkMinSize(QSize s) const;
 
61
    QSize checkMaxSize(QSize s) const;
 
62
    int checkOpacityActive(int s) const;
 
63
    int checkOpacityInactive(int s) const;
 
64
    int checkTilingOption(int s) const;
 
65
    bool checkIgnoreGeometry(bool ignore) const;
 
66
    int checkDesktop(int desktop, bool init = false) const;
 
67
    NET::WindowType checkType(NET::WindowType type) const;
 
68
    MaximizeMode checkMaximize(MaximizeMode mode, bool init = false) const;
 
69
    bool checkMinimize(bool minimized, bool init = false) const;
 
70
    ShadeMode checkShade(ShadeMode shade, bool init = false) const;
 
71
    bool checkSkipTaskbar(bool skip, bool init = false) const;
 
72
    bool checkSkipPager(bool skip, bool init = false) const;
 
73
    bool checkSkipSwitcher(bool skip, bool init = false) const;
 
74
    bool checkKeepAbove(bool above, bool init = false) const;
 
75
    bool checkKeepBelow(bool below, bool init = false) const;
 
76
    bool checkFullScreen(bool fs, bool init = false) const;
 
77
    bool checkNoBorder(bool noborder, bool init = false) const;
 
78
    bool checkBlockCompositing(bool block) const;
 
79
    int checkFSP(int fsp) const;
 
80
    bool checkAcceptFocus(bool focus) const;
 
81
    Options::MoveResizeMode checkMoveResizeMode(Options::MoveResizeMode mode) const;
 
82
    bool checkCloseable(bool closeable) const;
 
83
    bool checkAutogrouping(bool autogroup) const;
 
84
    bool checkAutogroupInForeground(bool fg) const;
 
85
    QString checkAutogroupById(QString id) const;
 
86
    bool checkStrictGeometry(bool strict) const;
 
87
    QString checkShortcut(QString s, bool init = false) const;
 
88
    bool checkDisableGlobalShortcuts(bool disable) const;
 
89
    bool checkIgnorePosition(bool ignore) const;   // obsolete
 
90
private:
 
91
    MaximizeMode checkMaximizeVert(MaximizeMode mode, bool init) const;
 
92
    MaximizeMode checkMaximizeHoriz(MaximizeMode mode, bool init) const;
 
93
    QVector< Rules* > rules;
 
94
};
 
95
#endif
 
96
 
 
97
class Rules
 
98
    : public KDecorationDefines
 
99
{
 
100
public:
 
101
    Rules();
 
102
    Rules(const KConfigGroup&);
 
103
    Rules(const QString&, bool temporary);
 
104
    void write(KConfigGroup&) const;
 
105
    bool isEmpty() const;
 
106
#ifndef KCMRULES
 
107
    void discardUsed(bool withdrawn);
 
108
    bool match(const Client* c) const;
 
109
    bool update(Client*);
 
110
    bool isTemporary() const;
 
111
    bool discardTemporary(bool force);   // removes if temporary and forced or too old
 
112
    bool applyPlacement(Placement::Policy& placement) const;
 
113
    bool applyGeometry(QRect& rect, bool init) const;
 
114
    // use 'invalidPoint' with applyPosition, unlike QSize() and QRect(), QPoint() is a valid point
 
115
    bool applyPosition(QPoint& pos, bool init) const;
 
116
    bool applySize(QSize& s, bool init) const;
 
117
    bool applyMinSize(QSize& s) const;
 
118
    bool applyMaxSize(QSize& s) const;
 
119
    bool applyOpacityActive(int& s) const;
 
120
    bool applyOpacityInactive(int& s) const;
 
121
    bool applyTilingOption(int& s) const;
 
122
    bool applyIgnoreGeometry(bool& ignore) const;
 
123
    bool applyDesktop(int& desktop, bool init) const;
 
124
    bool applyType(NET::WindowType& type) const;
 
125
    bool applyMaximizeVert(MaximizeMode& mode, bool init) const;
 
126
    bool applyMaximizeHoriz(MaximizeMode& mode, bool init) const;
 
127
    bool applyMinimize(bool& minimized, bool init) const;
 
128
    bool applyShade(ShadeMode& shade, bool init) const;
 
129
    bool applySkipTaskbar(bool& skip, bool init) const;
 
130
    bool applySkipPager(bool& skip, bool init) const;
 
131
    bool applySkipSwitcher(bool& skip, bool init) const;
 
132
    bool applyKeepAbove(bool& above, bool init) const;
 
133
    bool applyKeepBelow(bool& below, bool init) const;
 
134
    bool applyFullScreen(bool& fs, bool init) const;
 
135
    bool applyNoBorder(bool& noborder, bool init) const;
 
136
    bool applyBlockCompositing(bool& block) const;
 
137
    bool applyFSP(int& fsp) const;
 
138
    bool applyAcceptFocus(bool& focus) const;
 
139
    bool applyMoveResizeMode(Options::MoveResizeMode& mode) const;
 
140
    bool applyCloseable(bool& closeable) const;
 
141
    bool applyAutogrouping(bool& autogroup) const;
 
142
    bool applyAutogroupInForeground(bool& fg) const;
 
143
    bool applyAutogroupById(QString& id) const;
 
144
    bool applyStrictGeometry(bool& strict) const;
 
145
    bool applyShortcut(QString& shortcut, bool init) const;
 
146
    bool applyDisableGlobalShortcuts(bool& disable) const;
 
147
    bool applyIgnorePosition(bool& ignore) const;   // obsolete
 
148
private:
 
149
#endif
 
150
    bool matchType(NET::WindowType match_type) const;
 
151
    bool matchWMClass(const QByteArray& match_class, const QByteArray& match_name) const;
 
152
    bool matchRole(const QByteArray& match_role) const;
 
153
    bool matchTitle(const QString& match_title) const;
 
154
    bool matchClientMachine(const QByteArray& match_machine) const;
 
155
    // All these values are saved to the cfg file, and are also used in kstart!
 
156
    enum {
 
157
        Unused = 0,
 
158
        DontAffect, // use the default value
 
159
        Force,      // force the given value
 
160
        Apply,      // apply only after initial mapping
 
161
        Remember,   // like apply, and remember the value when the window is withdrawn
 
162
        ApplyNow,   // apply immediatelly, then forget the setting
 
163
        ForceTemporarily // apply and force until the window is withdrawn
 
164
    };
 
165
    enum SetRule {
 
166
        UnusedSetRule = Unused,
 
167
        SetRuleDummy = 256   // so that it's at least short int
 
168
    };
 
169
    enum ForceRule {
 
170
        UnusedForceRule = Unused,
 
171
        ForceRuleDummy = 256   // so that it's at least short int
 
172
    };
 
173
    enum StringMatch {
 
174
        FirstStringMatch,
 
175
        UnimportantMatch = FirstStringMatch,
 
176
        ExactMatch,
 
177
        SubstringMatch,
 
178
        RegExpMatch,
 
179
        LastStringMatch = RegExpMatch
 
180
    };
 
181
    void readFromCfg(const KConfigGroup& cfg);
 
182
    static SetRule readSetRule(const KConfigGroup&, const QString& key);
 
183
    static ForceRule readForceRule(const KConfigGroup&, const QString& key);
 
184
    static NET::WindowType readType(const KConfigGroup&, const QString& key);
 
185
#ifndef KCMRULES
 
186
    static bool checkSetRule(SetRule rule, bool init);
 
187
    static bool checkForceRule(ForceRule rule);
 
188
    static bool checkSetStop(SetRule rule);
 
189
    static bool checkForceStop(ForceRule rule);
 
190
#endif
 
191
    int temporary_state; // e.g. for kstart
 
192
    QString description;
 
193
    QByteArray wmclass;
 
194
    StringMatch wmclassmatch;
 
195
    bool wmclasscomplete;
 
196
    QByteArray windowrole;
 
197
    StringMatch windowrolematch;
 
198
    QString title;
 
199
    StringMatch titlematch;
 
200
    QByteArray extrarole;
 
201
    StringMatch extrarolematch;
 
202
    QByteArray clientmachine;
 
203
    StringMatch clientmachinematch;
 
204
    unsigned long types; // types for matching
 
205
    Placement::Policy placement;
 
206
    ForceRule placementrule;
 
207
    QPoint position;
 
208
    SetRule positionrule;
 
209
    QSize size;
 
210
    SetRule sizerule;
 
211
    QSize minsize;
 
212
    ForceRule minsizerule;
 
213
    QSize maxsize;
 
214
    ForceRule maxsizerule;
 
215
    int opacityactive;
 
216
    ForceRule opacityactiverule;
 
217
    int opacityinactive;
 
218
    ForceRule opacityinactiverule;
 
219
    int tilingoption;
 
220
    ForceRule tilingoptionrule;
 
221
    bool ignoreposition;
 
222
    ForceRule ignorepositionrule;
 
223
    int desktop;
 
224
    SetRule desktoprule;
 
225
    NET::WindowType type; // type for setting
 
226
    ForceRule typerule;
 
227
    bool maximizevert;
 
228
    SetRule maximizevertrule;
 
229
    bool maximizehoriz;
 
230
    SetRule maximizehorizrule;
 
231
    bool minimize;
 
232
    SetRule minimizerule;
 
233
    bool shade;
 
234
    SetRule shaderule;
 
235
    bool skiptaskbar;
 
236
    SetRule skiptaskbarrule;
 
237
    bool skippager;
 
238
    SetRule skippagerrule;
 
239
    bool skipswitcher;
 
240
    SetRule skipswitcherrule;
 
241
    bool above;
 
242
    SetRule aboverule;
 
243
    bool below;
 
244
    SetRule belowrule;
 
245
    bool fullscreen;
 
246
    SetRule fullscreenrule;
 
247
    bool noborder;
 
248
    SetRule noborderrule;
 
249
    bool blockcompositing;
 
250
    ForceRule blockcompositingrule;
 
251
    int fsplevel;
 
252
    ForceRule fsplevelrule;
 
253
    bool acceptfocus;
 
254
    ForceRule acceptfocusrule;
 
255
    Options::MoveResizeMode moveresizemode;
 
256
    ForceRule moveresizemoderule;
 
257
    bool closeable;
 
258
    ForceRule closeablerule;
 
259
    bool autogroup;
 
260
    ForceRule autogrouprule;
 
261
    bool autogroupfg;
 
262
    ForceRule autogroupfgrule;
 
263
    QString autogroupid;
 
264
    ForceRule autogroupidrule;
 
265
    bool strictgeometry;
 
266
    ForceRule strictgeometryrule;
 
267
    QString shortcut;
 
268
    SetRule shortcutrule;
 
269
    bool disableglobalshortcuts;
 
270
    ForceRule disableglobalshortcutsrule;
 
271
    friend QDebug& operator<<(QDebug& stream, const Rules*);
 
272
};
 
273
 
 
274
#ifndef KCMRULES
 
275
inline
 
276
bool Rules::checkSetRule(SetRule rule, bool init)
 
277
{
 
278
    if (rule > (SetRule)DontAffect) {  // Unused or DontAffect
 
279
        if (rule == (SetRule)Force || rule == (SetRule) ApplyNow
 
280
                || rule == (SetRule) ForceTemporarily || init)
 
281
            return true;
 
282
    }
 
283
    return false;
 
284
}
 
285
 
 
286
inline
 
287
bool Rules::checkForceRule(ForceRule rule)
 
288
{
 
289
    return rule == (ForceRule)Force || rule == (ForceRule) ForceTemporarily;
 
290
}
 
291
 
 
292
inline
 
293
bool Rules::checkSetStop(SetRule rule)
 
294
{
 
295
    return rule != UnusedSetRule;
 
296
}
 
297
 
 
298
inline
 
299
bool Rules::checkForceStop(ForceRule rule)
 
300
{
 
301
    return rule != UnusedForceRule;
 
302
}
 
303
 
 
304
inline
 
305
WindowRules::WindowRules(const QVector< Rules* >& r)
 
306
    : rules(r)
 
307
{
 
308
}
 
309
 
 
310
inline
 
311
WindowRules::WindowRules()
 
312
{
 
313
}
 
314
 
 
315
inline
 
316
bool WindowRules::contains(const Rules* rule) const
 
317
{
 
318
    return qFind(rules.begin(), rules.end(), rule) != rules.end();
 
319
}
 
320
 
 
321
inline
 
322
void WindowRules::remove(Rules* rule)
 
323
{
 
324
    QVector< Rules* >::Iterator pos = qFind(rules.begin(), rules.end(), rule);
 
325
    if (pos != rules.end())
 
326
        rules.erase(pos);
 
327
}
 
328
 
 
329
#endif
 
330
 
 
331
QDebug& operator<<(QDebug& stream, const Rules*);
 
332
 
 
333
} // namespace
 
334
 
 
335
#endif