2003-09-16 19:28:03 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
Copyright (C) 2003 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_UTILS_H
|
|
|
|
#define KWIN_UTILS_H
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include <config-X11.h>
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
2006-11-07 22:44:39 +00:00
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
#ifdef HAVE_XCOMPOSITE
|
|
|
|
#include <X11/extensions/Xcomposite.h>
|
2006-11-07 22:44:39 +00:00
|
|
|
#if XCOMPOSITE_MAJOR > 0 || XCOMPOSITE_MINOR >= 3
|
|
|
|
#define HAVE_XCOMPOSITE_OVERLAY
|
|
|
|
#endif
|
2006-09-19 12:24:51 +00:00
|
|
|
#endif
|
2006-11-07 22:44:39 +00:00
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
#ifdef HAVE_XDAMAGE
|
|
|
|
#include <X11/extensions/Xdamage.h>
|
|
|
|
#endif
|
2006-11-07 22:44:39 +00:00
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
#ifdef HAVE_XFIXES
|
|
|
|
#include <X11/extensions/Xfixes.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <fixx11h.h>
|
|
|
|
|
2006-05-11 08:04:23 +00:00
|
|
|
#include <QWidget>
|
2003-09-16 19:28:03 +00:00
|
|
|
#include <kmanagerselection.h>
|
|
|
|
#include <netwm_def.h>
|
2005-01-10 09:56:21 +00:00
|
|
|
#include <kshortcutdialog.h>
|
2005-07-28 14:59:42 +00:00
|
|
|
#include <limits.h>
|
2006-08-10 17:00:14 +00:00
|
|
|
#include <QX11Info>
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
#ifndef HAVE_XDAMAGE
|
|
|
|
typedef long Damage;
|
|
|
|
struct XDamageNotifyEvent
|
|
|
|
{
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
const int SUPPORTED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
|
2005-05-11 14:20:54 +00:00
|
|
|
| NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
|
2003-09-16 19:28:03 +00:00
|
|
|
| NET::UtilityMask | NET::SplashMask;
|
|
|
|
|
|
|
|
const long ClientWinMask = KeyPressMask | KeyReleaseMask |
|
|
|
|
ButtonPressMask | ButtonReleaseMask |
|
|
|
|
KeymapStateMask |
|
|
|
|
ButtonMotionMask |
|
|
|
|
PointerMotionMask | // need this, too!
|
|
|
|
EnterWindowMask | LeaveWindowMask |
|
|
|
|
FocusChangeMask |
|
|
|
|
ExposureMask |
|
|
|
|
StructureNotifyMask |
|
|
|
|
SubstructureRedirectMask;
|
|
|
|
|
2004-05-31 14:25:25 +00:00
|
|
|
const QPoint invalidPoint( INT_MIN, INT_MIN );
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
class Toplevel;
|
2003-09-16 19:28:03 +00:00
|
|
|
class Client;
|
2006-09-19 12:24:51 +00:00
|
|
|
class Unmanaged;
|
2003-09-16 19:28:03 +00:00
|
|
|
class Group;
|
|
|
|
class Options;
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
typedef QList< Toplevel* > ToplevelList;
|
|
|
|
typedef QList< const Toplevel* > ConstToplevelList;
|
2005-07-28 14:59:42 +00:00
|
|
|
typedef QList< Client* > ClientList;
|
|
|
|
typedef QList< const Client* > ConstClientList;
|
2006-09-19 12:24:51 +00:00
|
|
|
typedef QList< Unmanaged* > UnmanagedList;
|
|
|
|
typedef QList< const Unmanaged* > ConstUnmanagedList;
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
typedef QList< Group* > GroupList;
|
|
|
|
typedef QList< const Group* > ConstGroupList;
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
extern Options* options;
|
|
|
|
|
|
|
|
enum Layer
|
|
|
|
{
|
|
|
|
UnknownLayer = -1,
|
|
|
|
FirstLayer = 0,
|
|
|
|
DesktopLayer = FirstLayer,
|
|
|
|
BelowLayer,
|
|
|
|
NormalLayer,
|
2004-10-21 15:26:44 +00:00
|
|
|
DockLayer,
|
2005-12-16 14:08:20 +00:00
|
|
|
AboveLayer,
|
2003-09-16 19:28:03 +00:00
|
|
|
ActiveLayer, // active fullscreen, or active dialog
|
|
|
|
NumLayers // number of layers, must be last
|
|
|
|
};
|
|
|
|
|
|
|
|
// yes, I know this is not 100% like standard operator++
|
|
|
|
inline void operator++( Layer& lay )
|
|
|
|
{
|
|
|
|
lay = static_cast< Layer >( lay + 1 );
|
|
|
|
}
|
|
|
|
|
2004-04-16 10:23:42 +00:00
|
|
|
// for Client::takeActivity()
|
|
|
|
enum ActivityFlags
|
|
|
|
{
|
|
|
|
ActivityFocus = 1 << 0, // focus the window
|
|
|
|
ActivityFocusForce = 1 << 1, // focus even if Dock etc.
|
|
|
|
ActivityRaise = 1 << 2 // raise the window
|
|
|
|
};
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
// Some KWin classes, mainly Client and Workspace, are very tighly coupled,
|
|
|
|
// and some of the methods of one class may be called only from speficic places.
|
|
|
|
// Those methods have additional allowed_t argument. If you pass Allowed
|
|
|
|
// as an argument to any function, make sure you really know what you're doing.
|
|
|
|
enum allowed_t { Allowed };
|
|
|
|
|
2003-10-01 12:10:22 +00:00
|
|
|
// some enums to have more readable code, instead of using bools
|
|
|
|
enum ForceGeometry_t { NormalGeometrySet, ForceGeometrySet };
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
|
2003-10-10 12:58:38 +00:00
|
|
|
// Areas, mostly related to Xinerama
|
|
|
|
enum clientAreaOption
|
|
|
|
{
|
|
|
|
PlacementArea, // geometry where a window will be initially placed after being mapped
|
2003-10-10 13:09:54 +00:00
|
|
|
MovementArea, // ??? window movement snapping area? ignore struts
|
2003-10-10 12:58:38 +00:00
|
|
|
MaximizeArea, // geometry to which a window will be maximized
|
2004-05-10 23:22:27 +00:00
|
|
|
MaximizeFullArea, // like MaximizeArea, but ignore struts - used e.g. for topmenu
|
|
|
|
FullScreenArea, // area for fullscreen windows
|
2004-02-18 17:57:57 +00:00
|
|
|
// these below don't depend on xinerama settings
|
2003-10-10 12:58:38 +00:00
|
|
|
WorkArea, // whole workarea (all screens together)
|
|
|
|
FullArea, // whole area (all screens together), ignore struts
|
2006-02-28 13:03:31 +00:00
|
|
|
ScreenArea // one whole screen, ignore struts
|
2003-10-10 12:58:38 +00:00
|
|
|
};
|
|
|
|
|
2004-06-18 08:57:42 +00:00
|
|
|
enum ShadeMode
|
|
|
|
{
|
|
|
|
ShadeNone, // not shaded
|
|
|
|
ShadeNormal, // normally shaded - isShade() is true only here
|
|
|
|
ShadeHover, // "shaded", but visible due to hover unshade
|
|
|
|
ShadeActivated // "shaded", but visible due to alt+tab to the window
|
|
|
|
};
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
class Extensions
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void init();
|
2006-09-19 12:24:51 +00:00
|
|
|
static bool shapeAvailable() { return has_shape; }
|
|
|
|
static int shapeNotifyEvent();
|
|
|
|
static bool damageAvailable() { return has_damage; }
|
|
|
|
static int damageNotifyEvent();
|
|
|
|
static bool compositeAvailable() { return has_composite; }
|
2006-11-07 22:44:39 +00:00
|
|
|
static bool compositeOverlayAvailable() { return has_composite && has_composite_overlay; }
|
2006-09-19 12:24:51 +00:00
|
|
|
static bool fixesAvailable() { return has_fixes; }
|
2006-09-30 17:28:27 +00:00
|
|
|
static bool hasShape( Window w );
|
2003-09-16 19:28:03 +00:00
|
|
|
private:
|
2006-09-19 12:24:51 +00:00
|
|
|
static bool has_shape;
|
|
|
|
static int shape_event_base;
|
|
|
|
static bool has_damage;
|
|
|
|
static int damage_event_base;
|
|
|
|
static bool has_composite;
|
2006-11-07 22:44:39 +00:00
|
|
|
static bool has_composite_overlay;
|
2006-09-19 12:24:51 +00:00
|
|
|
static bool has_fixes;
|
2003-09-16 19:28:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Motif
|
|
|
|
{
|
|
|
|
public:
|
2004-07-27 08:35:51 +00:00
|
|
|
static void readFlags( WId w, bool& noborder, bool& resize, bool& move,
|
|
|
|
bool& minimize, bool& maximize, bool& close );
|
2003-09-16 19:28:03 +00:00
|
|
|
struct MwmHints
|
|
|
|
{
|
|
|
|
ulong flags;
|
|
|
|
ulong functions;
|
|
|
|
ulong decorations;
|
|
|
|
long input_mode;
|
|
|
|
ulong status;
|
|
|
|
};
|
2004-07-27 08:35:51 +00:00
|
|
|
enum {
|
|
|
|
MWM_HINTS_FUNCTIONS = (1L << 0),
|
|
|
|
MWM_HINTS_DECORATIONS = (1L << 1),
|
|
|
|
|
|
|
|
MWM_FUNC_ALL = (1L << 0),
|
|
|
|
MWM_FUNC_RESIZE = (1L << 1),
|
|
|
|
MWM_FUNC_MOVE = (1L << 2),
|
|
|
|
MWM_FUNC_MINIMIZE = (1L << 3),
|
|
|
|
MWM_FUNC_MAXIMIZE = (1L << 4),
|
|
|
|
MWM_FUNC_CLOSE = (1L << 5)
|
2003-09-16 19:28:03 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
class KWinSelectionOwner
|
|
|
|
: public KSelectionOwner
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
KWinSelectionOwner( int screen );
|
|
|
|
protected:
|
|
|
|
virtual bool genericReply( Atom target, Atom property, Window requestor );
|
|
|
|
virtual void replyTargets( Atom property, Window requestor );
|
|
|
|
virtual void getAtoms();
|
|
|
|
private:
|
|
|
|
Atom make_selection_atom( int screen );
|
|
|
|
static Atom xa_version;
|
|
|
|
};
|
|
|
|
|
2004-08-26 10:34:10 +00:00
|
|
|
// Class which saves original value of the variable, assigns the new value
|
|
|
|
// to it, and in the destructor restores the value.
|
|
|
|
// Used in Client::isMaximizable() and so on.
|
|
|
|
// It also casts away contness and generally this looks like a hack.
|
|
|
|
template< typename T >
|
|
|
|
class TemporaryAssign
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TemporaryAssign( const T& var, const T& value )
|
|
|
|
: variable( var ), orig( var )
|
|
|
|
{
|
|
|
|
const_cast< T& >( variable ) = value;
|
|
|
|
}
|
|
|
|
~TemporaryAssign()
|
|
|
|
{
|
|
|
|
const_cast< T& >( variable ) = orig;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
const T& variable;
|
|
|
|
T orig;
|
|
|
|
};
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
QByteArray getStringProperty(WId w, Atom prop, char separator=0);
|
2003-10-10 12:48:09 +00:00
|
|
|
void updateXTime();
|
2003-12-04 13:54:10 +00:00
|
|
|
void grabXServer();
|
|
|
|
void ungrabXServer();
|
2005-10-07 12:00:29 +00:00
|
|
|
bool grabbedXServer();
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2006-08-10 17:00:14 +00:00
|
|
|
inline
|
|
|
|
Display* display()
|
|
|
|
{
|
|
|
|
return QX11Info::display();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
Window rootWindow()
|
|
|
|
{
|
|
|
|
return QX11Info::appRootWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
Window xTime()
|
|
|
|
{
|
|
|
|
return QX11Info::appTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int displayWidth()
|
|
|
|
{
|
|
|
|
return XDisplayWidth( display(), DefaultScreen( display()));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int displayHeight()
|
|
|
|
{
|
|
|
|
return XDisplayHeight( display(), DefaultScreen( display()));
|
|
|
|
}
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
class Scene;
|
|
|
|
extern Scene* scene;
|
|
|
|
inline bool compositing() { return scene != NULL; }
|
|
|
|
|
2003-10-10 11:23:42 +00:00
|
|
|
// the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint
|
|
|
|
#ifndef UrgencyHint
|
|
|
|
#define UrgencyHint XUrgencyHint
|
|
|
|
#endif
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
// for STL-like algo's
|
2006-09-19 12:24:51 +00:00
|
|
|
#define KWIN_CHECK_PREDICATE( name, cls, check ) \
|
2003-09-16 19:28:03 +00:00
|
|
|
struct name \
|
|
|
|
{ \
|
2006-09-19 12:24:51 +00:00
|
|
|
inline bool operator()( const cls* cl ) { return check; }; \
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
#define KWIN_COMPARE_PREDICATE( name, cls, type, check ) \
|
2003-09-16 19:28:03 +00:00
|
|
|
struct name \
|
|
|
|
{ \
|
|
|
|
typedef type type_helper; /* in order to work also with type being 'const Client*' etc. */ \
|
|
|
|
inline name( const type_helper& compare_value ) : value( compare_value ) {}; \
|
2006-09-19 12:24:51 +00:00
|
|
|
inline bool operator()( const cls* cl ) { return check; }; \
|
2003-09-16 19:28:03 +00:00
|
|
|
const type_helper& value; \
|
|
|
|
}
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
#define KWIN_PROCEDURE( name, cls, action ) \
|
2003-09-16 19:28:03 +00:00
|
|
|
struct name \
|
|
|
|
{ \
|
2006-09-19 12:24:51 +00:00
|
|
|
inline void operator()( cls* cl ) { action; }; \
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
KWIN_CHECK_PREDICATE( TruePredicate, Client, cl == cl /*true, avoid warning about 'cl' */ );
|
2003-09-16 19:28:03 +00:00
|
|
|
|
2004-01-08 16:18:07 +00:00
|
|
|
template< typename T >
|
|
|
|
Client* findClientInList( const ClientList& list, T predicate )
|
|
|
|
{
|
|
|
|
for ( ClientList::ConstIterator it = list.begin(); it != list.end(); ++it)
|
|
|
|
{
|
|
|
|
if ( predicate( const_cast< const Client* >( *it)))
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-09-19 12:24:51 +00:00
|
|
|
template< typename T >
|
|
|
|
Unmanaged* findUnmanagedInList( const UnmanagedList& list, T predicate )
|
|
|
|
{
|
|
|
|
for ( UnmanagedList::ConstIterator it = list.begin(); it != list.end(); ++it)
|
|
|
|
{
|
|
|
|
if ( predicate( const_cast< const Unmanaged* >( *it)))
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
inline
|
|
|
|
int timestampCompare( Time time1, Time time2 ) // like strcmp()
|
|
|
|
{
|
2006-04-11 12:55:49 +00:00
|
|
|
return NET::timestampCompare( time1, time2 );
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2003-10-10 12:48:09 +00:00
|
|
|
inline
|
|
|
|
Time timestampDiff( Time time1, Time time2 ) // returns time2 - time1
|
2006-04-11 12:55:49 +00:00
|
|
|
{
|
|
|
|
return NET::timestampDiff( time1, time2 );
|
2003-10-10 12:48:09 +00:00
|
|
|
}
|
2004-05-28 13:54:20 +00:00
|
|
|
|
2005-07-28 14:59:42 +00:00
|
|
|
bool isLocalMachine( const QByteArray& host );
|
2005-01-10 09:56:21 +00:00
|
|
|
|
|
|
|
#ifndef KCMRULES
|
|
|
|
// Qt dialogs emit no signal when closed :(
|
|
|
|
class ShortcutDialog
|
|
|
|
: public KShortcutDialog
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ShortcutDialog( const KShortcut& cut );
|
|
|
|
virtual void accept();
|
|
|
|
signals:
|
|
|
|
void dialogDone( bool ok );
|
|
|
|
protected:
|
|
|
|
virtual void done( int r ) { KShortcutDialog::done( r ); emit dialogDone( r == Accepted ); }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|