summaryrefslogtreecommitdiffstats
path: root/twin/rules.h
blob: 061f0ce802913a7f8afcc8900ac897ef1377ee68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*****************************************************************
 KWin - the KDE window manager
 This file is part of the KDE project.

Copyright (C) 2004 Lubos Lunak <l.lunak@kde.org>

You can Freely distribute this program under the GNU General Public
License. See the file "COPYING" for the exact licensing terms.
******************************************************************/

#ifndef KWIN_RULES_H
#define KWIN_RULES_H

#include <tqstring.h>
#include <netwm_def.h>
#include <tqrect.h>
#include <tqvaluevector.h>
#include <kdebug.h>

#include "placement.h"
#include "lib/kdecoration.h"
#include "options.h"
#include "utils.h"

class KConfig;

namespace KWinInternal
{

class Client;
class Rules;

#ifndef KCMRULES // only for twin core

class WindowRules
    : public KDecorationDefines
    {
    public:
        WindowRules( const TQValueVector< Rules* >& rules );
        WindowRules();
        void update( Client* );
        void discardTemporary();
        bool contains( const Rules* rule ) const;
        void remove( Rules* rule );
        Placement::Policy checkPlacement( Placement::Policy placement ) const;
        TQRect checkGeometry( TQRect rect, bool init = false ) const;
        // use 'invalidPoint' with checkPosition, unlike TQSize() and TQRect(), TQPoint() is a valid point
        TQPoint checkPosition( TQPoint pos, bool init = false ) const;
        TQSize checkSize( TQSize s, bool init = false ) const;
        TQSize checkMinSize( TQSize s ) const;
        TQSize checkMaxSize( TQSize s ) const;
        int checkOpacityActive(int s) const;
        int checkOpacityInactive(int s) const;
        bool checkIgnoreGeometry( bool ignore ) const;
        int checkDesktop( int desktop, bool init = false ) const;
        NET::WindowType checkType( NET::WindowType type ) const;
        MaximizeMode checkMaximize( MaximizeMode mode, bool init = false ) const;
        bool checkMinimize( bool minimized, bool init = false ) const;
        ShadeMode checkShade( ShadeMode shade, bool init = false ) const;
        bool checkSkipTaskbar( bool skip, bool init = false ) const;
        bool checkSkipPager( bool skip, bool init = false ) const;
        bool checkKeepAbove( bool above, bool init = false ) const;
        bool checkKeepBelow( bool below, bool init = false ) const;
        bool checkFullScreen( bool fs, bool init = false ) const;
        bool checkNoBorder( bool noborder, bool init = false ) const;
        int checkFSP( int fsp ) const;
        bool checkAcceptFocus( bool focus ) const;
        Options::MoveResizeMode checkMoveResizeMode( Options::MoveResizeMode mode ) const;
        bool checkCloseable( bool closeable ) const;
        bool checkStrictGeometry( bool strict ) const;
        TQString checkShortcut( TQString s, bool init = false ) const;
        bool checkDisableGlobalShortcuts( bool disable ) const;
        bool checkIgnorePosition( bool ignore ) const; // obsolete
    private:
        MaximizeMode checkMaximizeVert( MaximizeMode mode, bool init ) const;
        MaximizeMode checkMaximizeHoriz( MaximizeMode mode, bool init ) const;
        TQValueVector< Rules* > rules;
    };
#endif

class Rules
    : public KDecorationDefines
    {
    public:
        Rules();
        Rules( KConfig& );
        Rules( const TQString&, bool temporary );
        void write( KConfig& ) const;
        bool isEmpty() const;
#ifndef KCMRULES
        void discardUsed( bool withdrawn );
        bool match( const Client* c ) const;
        bool update( Client* );
        bool isTemporary() const;
        bool discardTemporary( bool force ); // removes if temporary and forced or too old
        bool applyPlacement( Placement::Policy& placement ) const;
        bool applyGeometry( TQRect& rect, bool init ) const;
        // use 'invalidPoint' with applyPosition, unlike TQSize() and TQRect(), TQPoint() is a valid point
        bool applyPosition( TQPoint& pos, bool init ) const;
        bool applySize( TQSize& s, bool init ) const;
        bool applyMinSize( TQSize& s ) const;
        bool applyMaxSize( TQSize& s ) const;
        bool applyOpacityActive(int& s) const;
        bool applyOpacityInactive(int& s) const;
        bool applyIgnoreGeometry( bool& ignore ) const;
        bool applyDesktop( int& desktop, bool init ) const;
        bool applyType( NET::WindowType& type ) const;
        bool applyMaximizeVert( MaximizeMode& mode, bool init ) const;
        bool applyMaximizeHoriz( MaximizeMode& mode, bool init ) const;
        bool applyMinimize( bool& minimized, bool init ) const;
        bool applyShade( ShadeMode& shade, bool init ) const;
        bool applySkipTaskbar( bool& skip, bool init ) const;
        bool applySkipPager( bool& skip, bool init ) const;
        bool applyKeepAbove( bool& above, bool init ) const;
        bool applyKeepBelow( bool& below, bool init ) const;
        bool applyFullScreen( bool& fs, bool init ) const;
        bool applyNoBorder( bool& noborder, bool init ) const;
        bool applyFSP( int& fsp ) const;
        bool applyAcceptFocus( bool& focus ) const;
        bool applyMoveResizeMode( Options::MoveResizeMode& mode ) const;
        bool applyCloseable( bool& closeable ) const;
        bool applyStrictGeometry( bool& strict ) const;
        bool applyShortcut( TQString& shortcut, bool init ) const;
        bool applyDisableGlobalShortcuts( bool& disable ) const;
        bool applyIgnorePosition( bool& ignore ) const; // obsolete
    private:
#endif
        bool matchType( NET::WindowType match_type ) const;
        bool matchWMClass( const TQCString& match_class, const TQCString& match_name ) const;
        bool matchRole( const TQCString& match_role ) const;
        bool matchTitle( const TQString& match_title ) const;
        bool matchClientMachine( const TQCString& match_machine ) const;
        // All these values are saved to the cfg file, and are also used in kstart!
        enum
            {
            Unused = 0,
            DontAffect, // use the default value
            Force,      // force the given value
            Apply,      // apply only after initial mapping
            Remember,   // like apply, and remember the value when the window is withdrawn
            ApplyNow,   // apply immediatelly, then forget the setting
            ForceTemporarily // apply and force until the window is withdrawn
            };
        enum SetRule
            {
            UnusedSetRule = Unused,
            SetRuleDummy = 256   // so that it's at least short int
            };
        enum ForceRule
            {
            UnusedForceRule = Unused,
            ForceRuleDummy = 256   // so that it's at least short int
            };
        enum StringMatch
            {
            FirstStringMatch,
            UnimportantMatch = FirstStringMatch,
            ExactMatch,
            SubstringMatch,
            RegExpMatch,
            LastStringMatch = RegExpMatch
            };
        void readFromCfg( KConfig& cfg );
        static SetRule readSetRule( KConfig&, const TQString& key );
        static ForceRule readForceRule( KConfig&, const TQString& key );
        static NET::WindowType readType( KConfig&, const TQString& key );
#ifndef KCMRULES
        static bool checkSetRule( SetRule rule, bool init );
        static bool checkForceRule( ForceRule rule );
        static bool checkSetStop( SetRule rule );
        static bool checkForceStop( ForceRule rule );
#endif
        int temporary_state; // e.g. for kstart
        TQString description;
        TQCString wmclass;
        StringMatch wmclassmatch;
        bool wmclasscomplete;
        TQCString windowrole;
        StringMatch windowrolematch;
        TQString title; // TODO "caption" ?
        StringMatch titlematch;
        TQCString extrarole;
        StringMatch extrarolematch;
        TQCString clientmachine;
        StringMatch clientmachinematch;
        unsigned long types; // types for matching
        Placement::Policy placement;
        ForceRule placementrule;
        TQPoint position;
        SetRule positionrule;
        TQSize size;
        SetRule sizerule;
        TQSize minsize;
        ForceRule minsizerule;
        TQSize maxsize;
        ForceRule maxsizerule;
        int opacityactive;
        ForceRule opacityactiverule;
        int opacityinactive;
        ForceRule opacityinactiverule;
        bool ignoreposition;
        ForceRule ignorepositionrule;
        int desktop;
        SetRule desktoprule;
        NET::WindowType type; // type for setting
        ForceRule typerule;
        bool maximizevert;
        SetRule maximizevertrule;
        bool maximizehoriz;
        SetRule maximizehorizrule;
        bool minimize;
        SetRule minimizerule;
        bool shade;
        SetRule shaderule;
        bool skiptaskbar;
        SetRule skiptaskbarrule;
        bool skippager;
        SetRule skippagerrule;
        bool above;
        SetRule aboverule;
        bool below;
        SetRule belowrule;
        bool fullscreen;
        SetRule fullscreenrule;
        bool noborder;
        SetRule noborderrule;
        int fsplevel;
        ForceRule fsplevelrule;
        bool acceptfocus;
        ForceRule acceptfocusrule;
        Options::MoveResizeMode moveresizemode;
        ForceRule moveresizemoderule;
        bool closeable;
        ForceRule closeablerule;
        bool strictgeometry;
        ForceRule strictgeometryrule;
        TQString shortcut;
        SetRule shortcutrule;
        bool disableglobalshortcuts;
        ForceRule disableglobalshortcutsrule;
        friend kdbgstream& operator<<( kdbgstream& stream, const Rules* );
    };

#ifndef KCMRULES
inline
bool Rules::checkSetRule( SetRule rule, bool init )
    {
    if( rule > ( SetRule )DontAffect) // Unused or DontAffect
        {
        if( rule == ( SetRule )Force || rule == ( SetRule ) ApplyNow
            || rule == ( SetRule ) ForceTemporarily || init )
            return true;
        }
    return false;
    }

inline
bool Rules::checkForceRule( ForceRule rule )
    {
    return rule == ( ForceRule )Force || rule == ( ForceRule ) ForceTemporarily;
    }

inline
bool Rules::checkSetStop( SetRule rule )
    {
    return rule != UnusedSetRule;
    }
    
inline
bool Rules::checkForceStop( ForceRule rule )
    {
    return rule != UnusedForceRule;
    }

inline
WindowRules::WindowRules( const TQValueVector< Rules* >& r )
    : rules( r )
    {
    }

inline
WindowRules::WindowRules()
    {
    }

inline
bool WindowRules::contains( const Rules* rule ) const
    {
    return tqFind( rules.begin(), rules.end(), rule ) != rules.end();
    }
    
inline
void WindowRules::remove( Rules* rule )
    {
    TQValueVector< Rules* >::Iterator pos = tqFind( rules.begin(), rules.end(), rule );
    if( pos != rules.end())
        rules.erase( pos );
    }

#endif

#ifdef NDEBUG
inline
kndbgstream& operator<<( kndbgstream& stream, const Rules* ) { return stream; }
#else
kdbgstream& operator<<( kdbgstream& stream, const Rules* );
#endif

} // namespace

#endif