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 *********************************************************************/
25 #include <config-workspace.h>
26 #include <config-X11.h>
27 #include <config-kwin.h>
29 #include <kwinconfig.h>
36 #include <kmanagerselection.h>
37 #include <netwm_def.h>
38 #include <kkeysequencewidget.h>
43 #include <kwinglobals.h>
45 // needed by the DBUS interface
46 Q_DECLARE_METATYPE(QList
<int>)
53 struct XDamageNotifyEvent
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
|
72 PointerMotionMask
| // need this, too!
73 EnterWindowMask
| LeaveWindowMask
|
77 SubstructureRedirectMask
;
79 const QPoint
invalidPoint( INT_MIN
, INT_MIN
);
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
;
106 DesktopLayer
= FirstLayer
,
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()
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
};
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).
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.
156 // Like normal mode, but shown windows (i.e. on inactive virtual desktops)
157 // are kept mapped, only hidden windows are unmapped.
159 // All windows are kept mapped regardless of their state.
163 // compile with XShape older than 1.0
165 const int ShapeInput
= 2;
171 static void readFlags( WId w
, bool& noborder
, bool& resize
, bool& move
,
172 bool& minimize
, bool& maximize
, bool& close
);
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
199 KWinSelectionOwner( int screen
);
201 virtual bool genericReply( Atom target
, Atom property
, Window requestor
);
202 virtual void replyTargets( Atom property
, Window requestor
);
203 virtual void getAtoms();
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
217 TemporaryAssign( const T
& var
, const T
& value
)
218 : variable( var
), orig( var
)
220 const_cast< T
& >( variable
) = value
;
224 const_cast< T
& >( variable
) = orig
;
231 QByteArray
getStringProperty(WId w
, Atom prop
, char separator
=0);
234 void ungrabXServer();
235 bool grabbedXServer();
236 bool grabXKeyboard( Window w
= rootWindow());
237 void ungrabXKeyboard();
241 inline bool compositing() { return scene
!= NULL
; }
243 // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint
245 #define UrgencyHint XUrgencyHint
248 // for STL-like algo's
249 #define KWIN_CHECK_PREDICATE( name, cls, check ) \
252 inline bool operator()( const cls* cl ) { return check; } \
255 #define KWIN_COMPARE_PREDICATE( name, cls, type, check ) \
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 ) \
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
)))
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
)))
295 int timestampCompare( Time time1
, Time time2
) // like strcmp()
297 return NET::timestampCompare( time1
, time2
);
301 Time
timestampDiff( Time time1
, Time time2
) // returns time2 - time1
303 return NET::timestampDiff( time1
, time2
);
306 bool isLocalMachine( const QByteArray
& host
);
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();
320 // Qt dialogs emit no signal when closed :(
326 ShortcutDialog( const QKeySequence
& cut
);
327 virtual void accept();
328 QKeySequence
shortcut() const;
330 void keySequenceChanged(const QKeySequence
&seq
);
332 void dialogDone( bool ok
);
334 virtual void done( int r
);
336 KKeySequenceWidget
* widget
;
337 QKeySequence _shortcut
;