add more spacing
[personal-kdebase.git] / workspace / khotkeys / libkhotkeysprivate / windows.h
blob5701b2cb34c856999a51d154c2501a4eaf523303
1 /****************************************************************************
3 KHotKeys
5 Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>
7 Distributed under the terms of the GNU General Public License version 2.
9 ****************************************************************************/
11 #ifndef _WINDOWS_H_
12 #define _WINDOWS_H_
14 #include <sys/types.h>
16 #include <QObject>
18 #include <Qt3Support/Q3PtrList>
19 #include <QtGui/QWidgetList>
21 #include <netwm_def.h>
23 #include "khotkeysglobal.h"
25 class KConfigGroup;
27 namespace KHotKeys
30 const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
31 | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | NET::OverrideMask | NET::TopMenuMask
32 | NET::UtilityMask | NET::SplashMask;
34 class Windowdef_list;
35 /*class ActionDataBase;*/
37 class KDE_EXPORT Windows
38 : public QObject
40 Q_OBJECT
41 public:
42 Windows( bool enable_signals_P, QObject* parent_P );
43 virtual ~Windows();
44 QString get_window_class( WId id_P );
45 QString get_window_role( WId id_P );
46 WId active_window();
47 void set_action_window( WId window );
48 WId action_window();
49 WId find_window( const Windowdef_list* window_P );
50 static WId window_at_position( int x, int y );
51 static void activate_window( WId id_P );
52 Q_SIGNALS:
53 void window_added( WId window_P );
54 void window_removed( WId window_P );
55 void active_window_changed( WId window_P );
56 void window_changed( WId window_P );
57 void window_changed( WId window_P, unsigned int flags_P );
58 protected Q_SLOTS:
59 void window_added_slot( WId window_P );
60 void window_removed_slot( WId window_P );
61 void active_window_changed_slot( WId window_P );
62 void window_changed_slot( WId window_P );
63 void window_changed_slot( WId window_P, unsigned int flags_P );
64 private:
65 bool signals_enabled;
66 WId _action_window;
69 struct KDE_EXPORT Window_data
71 Window_data( WId id_P );
72 QString title; // _NET_WM_NAME or WM_NAME
73 QString role; // WM_WINDOW_ROLE
74 QString wclass; // WM_CLASS
75 NET::WindowType type;
78 class KDE_EXPORT Windowdef
80 Q_DISABLE_COPY( Windowdef )
82 public:
83 Windowdef( const QString& comment_P );
84 Windowdef( KConfigGroup& cfg_P );
85 virtual ~Windowdef();
86 const QString& comment() const;
87 virtual bool match( const Window_data& window_P ) = 0;
88 static Windowdef* create_cfg_read( KConfigGroup& cfg_P/*, ActionDataBase* data_P*/ );
89 virtual void cfg_write( KConfigGroup& cfg_P ) const = 0;
90 virtual Windowdef* copy( /*ActionDataBase* data_P*/ ) const = 0;
91 virtual const QString description() const = 0;
92 private:
93 QString _comment;
96 class KDE_EXPORT Windowdef_list
97 : public Q3PtrList< Windowdef >
99 Q_DISABLE_COPY( Windowdef_list )
101 public:
102 Windowdef_list( const QString& comment_P );
103 Windowdef_list( KConfigGroup& cfg_P/*, ActionDataBase* data_P*/ );
104 void cfg_write( KConfigGroup& cfg_P ) const;
105 bool match( const Window_data& window_P ) const;
106 Windowdef_list* copy( /*ActionDataBase* data_P*/ ) const;
107 typedef Q3PtrListIterator< Windowdef > Iterator;
108 const QString& comment() const;
109 private:
110 QString _comment;
113 class KDE_EXPORT Windowdef_simple
114 : public Windowdef
116 typedef Windowdef base;
117 public:
118 enum substr_type_t
120 NOT_IMPORTANT,
121 CONTAINS,
123 REGEXP,
124 CONTAINS_NOT,
125 IS_NOT,
126 REGEXP_NOT
128 enum window_type_t
130 WINDOW_TYPE_NORMAL = ( 1 << NET::Normal ),
131 WINDOW_TYPE_DESKTOP = ( 1 << NET::Desktop ),
132 WINDOW_TYPE_DOCK = ( 1 << NET::Dock ),
133 // WINDOW_TYPE_TOOL = ( 1 << NET::Tool ),
134 // WINDOW_TYPE_MENU = ( 1 << NET::Menu ),
135 WINDOW_TYPE_DIALOG = ( 1 << NET::Dialog )
137 Windowdef_simple( const QString& comment_P, const QString& title_P,
138 substr_type_t title_type_P, const QString& wclass_P, substr_type_t wclass_type_P,
139 const QString& role_P, substr_type_t role_type_P, int window_types_P );
140 Windowdef_simple( KConfigGroup& cfg_P );
141 virtual bool match( const Window_data& window_P );
142 virtual void cfg_write( KConfigGroup& cfg_P ) const;
143 const QString& title() const;
144 substr_type_t title_match_type() const;
145 const QString& wclass() const;
146 substr_type_t wclass_match_type() const;
147 const QString& role() const;
148 substr_type_t role_match_type() const;
149 int window_types() const;
150 bool type_match( window_type_t type_P ) const;
151 bool type_match( NET::WindowType type_P ) const;
152 virtual Windowdef* copy( /*ActionDataBase* data_P*/ ) const;
153 virtual const QString description() const;
154 protected:
155 bool is_substr_match( const QString& str1_P, const QString& str2_P,
156 substr_type_t type_P );
157 private:
158 QString _title;
159 substr_type_t title_type;
160 QString _wclass;
161 substr_type_t wclass_type;
162 QString _role;
163 substr_type_t role_type;
164 int _window_types;
167 //***************************************************************************
168 // Inline
169 //***************************************************************************
171 // Windowdef
173 inline
174 Windowdef::Windowdef( const QString& comment_P )
175 : _comment( comment_P )
179 inline
180 const QString& Windowdef::comment() const
182 return _comment;
185 inline
186 Windowdef::~Windowdef()
190 // Windowdef_list
192 inline
193 Windowdef_list::Windowdef_list( const QString& comment_P )
194 : Q3PtrList< Windowdef >(), _comment( comment_P )
196 setAutoDelete( true );
199 inline
200 const QString& Windowdef_list::comment() const
202 return _comment;
205 // Windowdef_simple
207 inline
208 const QString& Windowdef_simple::title() const
210 return _title;
213 inline
214 Windowdef_simple::substr_type_t Windowdef_simple::title_match_type() const
216 return title_type;
219 inline
220 const QString& Windowdef_simple::wclass() const
222 return _wclass;
225 inline
226 Windowdef_simple::substr_type_t Windowdef_simple::wclass_match_type() const
228 return wclass_type;
231 inline
232 const QString& Windowdef_simple::role() const
234 return _role;
237 inline
238 Windowdef_simple::substr_type_t Windowdef_simple::role_match_type() const
240 return role_type;
243 inline
244 int Windowdef_simple::window_types() const
246 return _window_types;
249 inline
250 bool Windowdef_simple::type_match( window_type_t type_P ) const
252 return window_types() & type_P;
255 inline
256 bool Windowdef_simple::type_match( NET::WindowType type_P ) const
258 return ( window_types() & ( 1 << type_P ))
259 || ( type_P == NET::Unknown && ( window_types() & WINDOW_TYPE_NORMAL ));
260 // CHECKME HACK haaaack !
263 } // namespace KHotKeys
265 #endif