not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / utils.h
blob8e0cdd9a8e59d2157bd813439c31801370252777
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
22 #ifndef KWIN_UTILS_H
23 #define KWIN_UTILS_H
25 #include <config-workspace.h>
26 #include <config-X11.h>
27 #include <config-kwin.h>
29 #include <kwinconfig.h>
31 #include <X11/Xlib.h>
33 #include <fixx11h.h>
35 #include <QWidget>
36 #include <kmanagerselection.h>
37 #include <netwm_def.h>
38 #include <kkeysequencewidget.h>
39 #include <limits.h>
40 #include <QX11Info>
41 #include <kdialog.h>
43 #include <kwinglobals.h>
45 // needed by the DBUS interface
46 Q_DECLARE_METATYPE(QList<int>)
48 namespace KWin
51 #ifndef HAVE_XDAMAGE
52 typedef long Damage;
53 struct XDamageNotifyEvent
56 #endif
58 // window types that are supported as normal windows (i.e. KWin actually manages them)
59 const int SUPPORTED_MANAGED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
60 | NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
61 | NET::UtilityMask | NET::SplashMask;
62 // window types that are supported as unmanaged (mainly for compositing)
63 const int SUPPORTED_UNMANAGED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
64 | NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
65 | NET::UtilityMask | NET::SplashMask | NET::DropdownMenuMask | NET::PopupMenuMask
66 | NET::TooltipMask | NET::NotificationMask | NET::ComboBoxMask | NET::DNDIconMask;
68 const long ClientWinMask = KeyPressMask | KeyReleaseMask |
69 ButtonPressMask | ButtonReleaseMask |
70 KeymapStateMask |
71 ButtonMotionMask |
72 PointerMotionMask | // need this, too!
73 EnterWindowMask | LeaveWindowMask |
74 FocusChangeMask |
75 ExposureMask |
76 StructureNotifyMask |
77 SubstructureRedirectMask;
79 const QPoint invalidPoint( INT_MIN, INT_MIN );
81 class Toplevel;
82 class Client;
83 class Unmanaged;
84 class Deleted;
85 class Group;
86 class Options;
88 typedef QList< Toplevel* > ToplevelList;
89 typedef QList< const Toplevel* > ConstToplevelList;
90 typedef QList< Client* > ClientList;
91 typedef QList< const Client* > ConstClientList;
92 typedef QList< Unmanaged* > UnmanagedList;
93 typedef QList< const Unmanaged* > ConstUnmanagedList;
94 typedef QList< Deleted* > DeletedList;
95 typedef QList< const Deleted* > ConstDeletedList;
97 typedef QList< Group* > GroupList;
98 typedef QList< const Group* > ConstGroupList;
100 extern Options* options;
102 enum Layer
104 UnknownLayer = -1,
105 FirstLayer = 0,
106 DesktopLayer = FirstLayer,
107 BelowLayer,
108 NormalLayer,
109 DockLayer,
110 AboveLayer,
111 ActiveLayer, // active fullscreen, or active dialog
112 NumLayers // number of layers, must be last
115 // yes, I know this is not 100% like standard operator++
116 inline void operator++( Layer& lay )
118 lay = static_cast< Layer >( lay + 1 );
121 // for Client::takeActivity()
122 enum ActivityFlags
124 ActivityFocus = 1 << 0, // focus the window
125 ActivityFocusForce = 1 << 1, // focus even if Dock etc.
126 ActivityRaise = 1 << 2 // raise the window
129 // Some KWin classes, mainly Client and Workspace, are very tighly coupled,
130 // and some of the methods of one class may be called only from speficic places.
131 // Those methods have additional allowed_t argument. If you pass Allowed
132 // as an argument to any function, make sure you really know what you're doing.
133 enum allowed_t { Allowed };
135 // some enums to have more readable code, instead of using bools
136 enum ForceGeometry_t { NormalGeometrySet, ForceGeometrySet };
140 enum ShadeMode
142 ShadeNone, // not shaded
143 ShadeNormal, // normally shaded - isShade() is true only here
144 ShadeHover, // "shaded", but visible due to hover unshade
145 ShadeActivated // "shaded", but visible due to alt+tab to the window
148 // Whether to keep all windows mapped when compositing (i.e. whether to have
149 // actively updated window pixmaps).
150 enum HiddenPreviews
152 // The normal mode with regard to mapped windows. Hidden (minimized, etc.)
153 // and windows on inactive virtual desktops are not mapped, their pixmaps
154 // are only their icons.
155 HiddenPreviewsNever,
156 // Like normal mode, but shown windows (i.e. on inactive virtual desktops)
157 // are kept mapped, only hidden windows are unmapped.
158 HiddenPreviewsShown,
159 // All windows are kept mapped regardless of their state.
160 HiddenPreviewsAlways
163 // compile with XShape older than 1.0
164 #ifndef ShapeInput
165 const int ShapeInput = 2;
166 #endif
168 class Motif
170 public:
171 static void readFlags( WId w, bool& noborder, bool& resize, bool& move,
172 bool& minimize, bool& maximize, bool& close );
173 struct MwmHints
175 ulong flags;
176 ulong functions;
177 ulong decorations;
178 long input_mode;
179 ulong status;
181 enum {
182 MWM_HINTS_FUNCTIONS = (1L << 0),
183 MWM_HINTS_DECORATIONS = (1L << 1),
185 MWM_FUNC_ALL = (1L << 0),
186 MWM_FUNC_RESIZE = (1L << 1),
187 MWM_FUNC_MOVE = (1L << 2),
188 MWM_FUNC_MINIMIZE = (1L << 3),
189 MWM_FUNC_MAXIMIZE = (1L << 4),
190 MWM_FUNC_CLOSE = (1L << 5)
194 class KWinSelectionOwner
195 : public KSelectionOwner
197 Q_OBJECT
198 public:
199 KWinSelectionOwner( int screen );
200 protected:
201 virtual bool genericReply( Atom target, Atom property, Window requestor );
202 virtual void replyTargets( Atom property, Window requestor );
203 virtual void getAtoms();
204 private:
205 Atom make_selection_atom( int screen );
206 static Atom xa_version;
209 // Class which saves original value of the variable, assigns the new value
210 // to it, and in the destructor restores the value.
211 // Used in Client::isMaximizable() and so on.
212 // It also casts away contness and generally this looks like a hack.
213 template< typename T >
214 class TemporaryAssign
216 public:
217 TemporaryAssign( const T& var, const T& value )
218 : variable( var ), orig( var )
220 const_cast< T& >( variable ) = value;
222 ~TemporaryAssign()
224 const_cast< T& >( variable ) = orig;
226 private:
227 const T& variable;
228 T orig;
231 QByteArray getStringProperty(WId w, Atom prop, char separator=0);
232 void updateXTime();
233 void grabXServer();
234 void ungrabXServer();
235 bool grabbedXServer();
236 bool grabXKeyboard( Window w = rootWindow());
237 void ungrabXKeyboard();
239 class Scene;
240 extern Scene* scene;
241 inline bool compositing() { return scene != NULL; }
243 // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint
244 #ifndef UrgencyHint
245 #define UrgencyHint XUrgencyHint
246 #endif
248 // for STL-like algo's
249 #define KWIN_CHECK_PREDICATE( name, cls, check ) \
250 struct name \
252 inline bool operator()( const cls* cl ) { return check; } \
255 #define KWIN_COMPARE_PREDICATE( name, cls, type, check ) \
256 struct name \
258 typedef type type_helper; /* in order to work also with type being 'const Client*' etc. */ \
259 inline name( const type_helper& compare_value ) : value( compare_value ) {} \
260 inline bool operator()( const cls* cl ) { return check; } \
261 const type_helper& value; \
264 #define KWIN_PROCEDURE( name, cls, action ) \
265 struct name \
267 inline void operator()( cls* cl ) { action; } \
270 KWIN_CHECK_PREDICATE( TruePredicate, Client, cl == cl /*true, avoid warning about 'cl' */ );
272 template< typename T >
273 Client* findClientInList( const ClientList& list, T predicate )
275 for ( ClientList::ConstIterator it = list.begin(); it != list.end(); ++it)
277 if ( predicate( const_cast< const Client* >( *it)))
278 return *it;
280 return NULL;
283 template< typename T >
284 Unmanaged* findUnmanagedInList( const UnmanagedList& list, T predicate )
286 for ( UnmanagedList::ConstIterator it = list.begin(); it != list.end(); ++it)
288 if ( predicate( const_cast< const Unmanaged* >( *it)))
289 return *it;
291 return NULL;
294 inline
295 int timestampCompare( Time time1, Time time2 ) // like strcmp()
297 return NET::timestampCompare( time1, time2 );
300 inline
301 Time timestampDiff( Time time1, Time time2 ) // returns time2 - time1
303 return NET::timestampDiff( time1, time2 );
306 bool isLocalMachine( const QByteArray& host );
308 QPoint cursorPos();
310 // converting between X11 mouse/keyboard state mask and Qt button/keyboard states
311 int qtToX11Button( Qt::MouseButton button );
312 Qt::MouseButton x11ToQtMouseButton( int button );
313 int qtToX11State( Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers );
314 Qt::MouseButtons x11ToQtMouseButtons( int state );
315 Qt::KeyboardModifiers x11ToQtKeyboardModifiers( int state );
317 void checkNonExistentClients();
319 #ifndef KCMRULES
320 // Qt dialogs emit no signal when closed :(
321 class ShortcutDialog
322 : public KDialog
324 Q_OBJECT
325 public:
326 ShortcutDialog( const QKeySequence& cut );
327 virtual void accept();
328 QKeySequence shortcut() const;
329 public Q_SLOTS:
330 void keySequenceChanged(const QKeySequence &seq);
331 signals:
332 void dialogDone( bool ok );
333 protected:
334 virtual void done( int r );
335 private:
336 KKeySequenceWidget* widget;
337 QKeySequence _shortcut;
340 #endif //KCMRULES
342 } // namespace
344 #endif