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
*********************************************************************/
27
#include <config-workspace.h>
28
#include <config-X11.h>
29
#include <config-kwin.h>
31
#include <kwinconfig.h>
38
#include <kmanagerselection.h>
39
#include <netwm_def.h>
40
#include <kkeysequencewidget.h>
45
#include <kwinglobals.h>
47
// needed by the DBUS interface
48
Q_DECLARE_METATYPE(QList<int>)
55
struct XDamageNotifyEvent {
59
// window types that are supported as normal windows (i.e. KWin actually manages them)
60
const int SUPPORTED_MANAGED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
61
| NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
62
| NET::UtilityMask | NET::SplashMask;
63
// window types that are supported as unmanaged (mainly for compositing)
64
const int SUPPORTED_UNMANAGED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
65
| NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
66
| NET::UtilityMask | NET::SplashMask | NET::DropdownMenuMask | NET::PopupMenuMask
67
| NET::TooltipMask | NET::NotificationMask | NET::ComboBoxMask | NET::DNDIconMask;
69
const long ClientWinMask = KeyPressMask | KeyReleaseMask |
70
ButtonPressMask | ButtonReleaseMask |
73
PointerMotionMask | // need this, too!
74
EnterWindowMask | LeaveWindowMask |
78
SubstructureRedirectMask;
80
const QPoint invalidPoint(INT_MIN, INT_MIN);
89
typedef QList< Toplevel* > ToplevelList;
90
typedef QList< const Toplevel* > ConstToplevelList;
91
typedef QList< Client* > ClientList;
92
typedef QList< const Client* > ConstClientList;
93
typedef QList< Unmanaged* > UnmanagedList;
94
typedef QList< const Unmanaged* > ConstUnmanagedList;
95
typedef QList< Deleted* > DeletedList;
96
typedef QList< const Deleted* > ConstDeletedList;
98
typedef QList< Group* > GroupList;
99
typedef QList< const Group* > ConstGroupList;
101
extern Options* options;
102
extern bool initting; // whether kwin is starting up
107
DesktopLayer = FirstLayer,
112
ActiveLayer, // active fullscreen, or active dialog
113
NumLayers // number of layers, must be last
116
// yes, I know this is not 100% like standard operator++
117
inline void operator++(Layer& lay)
119
lay = static_cast< Layer >(lay + 1);
122
// 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
130
StrutAreaInvalid = 0, // Null
131
StrutAreaTop = 1 << 0,
132
StrutAreaRight = 1 << 1,
133
StrutAreaBottom = 1 << 2,
134
StrutAreaLeft = 1 << 3,
135
StrutAreaAll = StrutAreaTop | StrutAreaRight | StrutAreaBottom | StrutAreaLeft
137
Q_DECLARE_FLAGS(StrutAreas, StrutArea)
139
class StrutRect : public QRect
142
explicit StrutRect(QRect rect = QRect(), StrutArea area = StrutAreaInvalid);
143
StrutRect(const StrutRect& other);
144
inline StrutArea area() const {
150
typedef QVector<StrutRect> StrutRects;
152
// Some KWin classes, mainly Client and Workspace, are very tighly coupled,
153
// and some of the methods of one class may be called only from speficic places.
154
// Those methods have additional allowed_t argument. If you pass Allowed
155
// as an argument to any function, make sure you really know what you're doing.
156
enum allowed_t { Allowed };
158
// some enums to have more readable code, instead of using bools
159
enum ForceGeometry_t { NormalGeometrySet, ForceGeometrySet };
164
ShadeNone, // not shaded
165
ShadeNormal, // normally shaded - isShade() is true only here
166
ShadeHover, // "shaded", but visible due to hover unshade
167
ShadeActivated // "shaded", but visible due to alt+tab to the window
170
// Whether to keep all windows mapped when compositing (i.e. whether to have
171
// actively updated window pixmaps).
172
enum HiddenPreviews {
173
// The normal mode with regard to mapped windows. Hidden (minimized, etc.)
174
// and windows on inactive virtual desktops are not mapped, their pixmaps
175
// are only their icons.
177
// Like normal mode, but shown windows (i.e. on inactive virtual desktops)
178
// are kept mapped, only hidden windows are unmapped.
180
// All windows are kept mapped regardless of their state.
184
// compile with XShape older than 1.0
186
const int ShapeInput = 2;
192
// Read a window's current settings from its _MOTIF_WM_HINTS
193
// property. If it explicitly requests that decorations be shown
194
// or hidden, 'got_noborder' is set to true and 'noborder' is set
196
static void readFlags(WId w, bool& got_noborder, bool& noborder,
197
bool& resize, bool& move, bool& minimize, bool& maximize,
207
MWM_HINTS_FUNCTIONS = (1L << 0),
208
MWM_HINTS_DECORATIONS = (1L << 1),
210
MWM_FUNC_ALL = (1L << 0),
211
MWM_FUNC_RESIZE = (1L << 1),
212
MWM_FUNC_MOVE = (1L << 2),
213
MWM_FUNC_MINIMIZE = (1L << 3),
214
MWM_FUNC_MAXIMIZE = (1L << 4),
215
MWM_FUNC_CLOSE = (1L << 5)
219
class KWinSelectionOwner
220
: public KSelectionOwner
224
KWinSelectionOwner(int screen);
226
virtual bool genericReply(Atom target, Atom property, Window requestor);
227
virtual void replyTargets(Atom property, Window requestor);
228
virtual void getAtoms();
230
Atom make_selection_atom(int screen);
231
static Atom xa_version;
234
// Class which saves original value of the variable, assigns the new value
235
// to it, and in the destructor restores the value.
236
// Used in Client::isMaximizable() and so on.
237
// It also casts away contness and generally this looks like a hack.
238
template< typename T >
239
class TemporaryAssign
242
TemporaryAssign(const T& var, const T& value)
243
: variable(var), orig(var) {
244
const_cast< T& >(variable) = value;
247
const_cast< T& >(variable) = orig;
254
QByteArray getStringProperty(WId w, Atom prop, char separator = 0);
257
void ungrabXServer();
258
bool grabbedXServer();
259
bool grabXKeyboard(Window w = rootWindow());
260
void ungrabXKeyboard();
264
inline bool compositing()
266
return scene != NULL;
269
// the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint
271
#define UrgencyHint XUrgencyHint
274
// for STL-like algo's
275
#define KWIN_CHECK_PREDICATE( name, cls, check ) \
278
inline bool operator()( const cls* cl ) { return check; } \
281
#define KWIN_COMPARE_PREDICATE( name, cls, type, check ) \
284
typedef type type_helper; /* in order to work also with type being 'const Client*' etc. */ \
285
inline name( const type_helper& compare_value ) : value( compare_value ) {} \
286
inline bool operator()( const cls* cl ) { return check; } \
287
const type_helper& value; \
290
#define KWIN_PROCEDURE( name, cls, action ) \
293
inline void operator()( cls* cl ) { action; } \
296
KWIN_CHECK_PREDICATE(TruePredicate, Client, cl == cl /*true, avoid warning about 'cl' */);
298
template< typename T >
299
Client* findClientInList(const ClientList& list, T predicate)
301
for (ClientList::ConstIterator it = list.begin(); it != list.end(); ++it) {
302
if (predicate(const_cast< const Client* >(*it)))
308
template< typename T >
309
Unmanaged* findUnmanagedInList(const UnmanagedList& list, T predicate)
311
for (UnmanagedList::ConstIterator it = list.begin(); it != list.end(); ++it) {
312
if (predicate(const_cast< const Unmanaged* >(*it)))
319
int timestampCompare(Time time1, Time time2) // like strcmp()
321
return NET::timestampCompare(time1, time2);
325
Time timestampDiff(Time time1, Time time2) // returns time2 - time1
327
return NET::timestampDiff(time1, time2);
330
bool isLocalMachine(const QByteArray& host);
334
// converting between X11 mouse/keyboard state mask and Qt button/keyboard states
335
int qtToX11Button(Qt::MouseButton button);
336
Qt::MouseButton x11ToQtMouseButton(int button);
337
int qtToX11State(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
338
Qt::MouseButtons x11ToQtMouseButtons(int state);
339
Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state);
341
void checkNonExistentClients();
344
// Qt dialogs emit no signal when closed :(
350
ShortcutDialog(const QKeySequence& cut);
351
virtual void accept();
352
QKeySequence shortcut() const;
354
void keySequenceChanged(const QKeySequence &seq);
356
void dialogDone(bool ok);
358
virtual void done(int r);
360
KKeySequenceWidget* widget;
361
QKeySequence _shortcut;
369
// Must be outside namespace
370
Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::StrutAreas)