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
|
|
|
|
|
2007-04-03 13:24:05 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include <config-X11.h>
|
|
|
|
#include <config-kwin.h>
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_XRANDR
|
|
|
|
#include <X11/extensions/Xrandr.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XCOMPOSITE
|
|
|
|
#include <X11/extensions/Xcomposite.h>
|
|
|
|
#if XCOMPOSITE_MAJOR > 0 || XCOMPOSITE_MINOR >= 3
|
|
|
|
#define HAVE_XCOMPOSITE_OVERLAY
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_XDAMAGE
|
|
|
|
#include <X11/extensions/Xdamage.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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>
|
2007-03-31 19:04:28 +00:00
|
|
|
//#include <kshortcutdialog.h> //you really want to use KKeySequenceWidget
|
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
|
|
|
|
{
|
|
|
|
|
2007-04-03 13:24:05 +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
|
2007-04-03 13:24:05 +00:00
|
|
|
| NET::UtilityMask | NET::SplashMask | NET::DropdownMenuMask | NET::PopupMenuMask
|
|
|
|
| NET::TooltipMask | NET::NotificationMask | NET::ComboBoxMask | NET::DNDIconMask;
|
2003-09-16 19:28:03 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2007-04-03 13:24:05 +00:00
|
|
|
class Toplevel;
|
2003-09-16 19:28:03 +00:00
|
|
|
class Client;
|
2007-04-03 13:24:05 +00:00
|
|
|
class Unmanaged;
|
|
|
|
class Deleted;
|
2003-09-16 19:28:03 +00:00
|
|
|
class Group;
|
|
|
|
class Options;
|
|
|
|
|
2007-04-03 13:24:05 +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;
|
2007-04-03 13:24:05 +00:00
|
|
|
typedef QList< Unmanaged* > UnmanagedList;
|
|
|
|
typedef QList< const Unmanaged* > ConstUnmanagedList;
|
|
|
|
typedef QList< Deleted* > DeletedList;
|
|
|
|
typedef QList< const Deleted* > ConstDeletedList;
|
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 };
|
|
|
|
|
2007-04-03 13:24:05 +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
|
|
|
|
};
|
|
|
|
|
2007-04-04 19:08:03 +00:00
|
|
|
enum ElectricBorder
|
|
|
|
{
|
|
|
|
ElectricTop,
|
|
|
|
ElectricTopRight,
|
|
|
|
ElectricRight,
|
|
|
|
ElectricBottomRight,
|
|
|
|
ElectricBottom,
|
|
|
|
ElectricBottomLeft,
|
|
|
|
ElectricLeft,
|
|
|
|
ElectricTopLeft,
|
|
|
|
ELECTRIC_COUNT,
|
|
|
|
ElectricNone
|
|
|
|
};
|
|
|
|
|
2007-04-03 13:24:05 +00:00
|
|
|
class Extensions
|
2003-09-16 19:28:03 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void init();
|
2007-04-03 13:24:05 +00:00
|
|
|
static bool shapeAvailable() { return has_shape; }
|
|
|
|
static int shapeNotifyEvent();
|
|
|
|
static bool randrAvailable() { return has_randr; }
|
|
|
|
static int randrNotifyEvent();
|
|
|
|
static bool damageAvailable() { return has_damage; }
|
|
|
|
static int damageNotifyEvent();
|
|
|
|
static bool compositeAvailable() { return has_composite; }
|
|
|
|
static bool compositeOverlayAvailable() { return has_composite && has_composite_overlay; }
|
|
|
|
static bool fixesAvailable() { return has_fixes; }
|
|
|
|
static bool hasShape( Window w );
|
2003-09-16 19:28:03 +00:00
|
|
|
private:
|
2007-04-03 13:24:05 +00:00
|
|
|
static bool has_shape;
|
|
|
|
static int shape_event_base;
|
|
|
|
static bool has_randr;
|
|
|
|
static int randr_event_base;
|
|
|
|
static bool has_damage;
|
|
|
|
static int damage_event_base;
|
|
|
|
static bool has_composite;
|
|
|
|
static bool has_composite_overlay;
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
2007-04-03 13:24:05 +00:00
|
|
|
QPoint cursorPos();
|
|
|
|
|
|
|
|
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
|
2007-04-03 13:24:05 +00:00
|
|
|
#define KWIN_CHECK_PREDICATE( name, cls, check ) \
|
2003-09-16 19:28:03 +00:00
|
|
|
struct name \
|
|
|
|
{ \
|
2007-04-03 13:24:05 +00:00
|
|
|
inline bool operator()( const cls* cl ) { return check; }; \
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 13:24:05 +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. */ \
|
2007-04-03 13:24:05 +00:00
|
|
|
inline name( const type_helper& compare_value ) : value( compare_value ) {}; \
|
|
|
|
inline bool operator()( const cls* cl ) { return check; }; \
|
2003-09-16 19:28:03 +00:00
|
|
|
const type_helper& value; \
|
|
|
|
}
|
|
|
|
|
2007-04-03 13:24:05 +00:00
|
|
|
#define KWIN_PROCEDURE( name, cls, action ) \
|
2003-09-16 19:28:03 +00:00
|
|
|
struct name \
|
|
|
|
{ \
|
2007-04-03 13:24:05 +00:00
|
|
|
inline void operator()( cls* cl ) { action; }; \
|
2003-09-16 19:28:03 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 13:24:05 +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;
|
|
|
|
}
|
|
|
|
|
2007-04-03 13:24:05 +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
|
|
|
|
2007-04-03 13:24:05 +00:00
|
|
|
// converting between X11 mouse/keyboard state mask and Qt button/keyboard states
|
|
|
|
int qtToX11Button( Qt::MouseButton button );
|
|
|
|
Qt::MouseButton x11ToQtMouseButton( int button );
|
|
|
|
int qtToX11State( Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers );
|
|
|
|
Qt::MouseButtons x11ToQtMouseButtons( int state );
|
|
|
|
Qt::KeyboardModifiers x11ToQtKeyboardModifiers( int state );
|
2006-12-14 16:32:55 +00:00
|
|
|
|
2005-01-10 09:56:21 +00:00
|
|
|
#ifndef KCMRULES
|
|
|
|
// Qt dialogs emit no signal when closed :(
|
2007-03-31 19:04:28 +00:00
|
|
|
|
|
|
|
// KShortcutDialog is gone, and K(Shortcut/KeySequence)Widget should replace it and be
|
|
|
|
// good enough to not need any further hacks here. If they aren't, CONTACT ME before
|
|
|
|
// you add hacks again. --ahartmetz
|
|
|
|
#if 0
|
2005-01-10 09:56:21 +00:00
|
|
|
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 ); }
|
|
|
|
};
|
2007-03-31 19:04:28 +00:00
|
|
|
#endif //0
|
|
|
|
#endif //KCMRULES
|
2005-01-10 09:56:21 +00:00
|
|
|
|
2003-09-16 19:28:03 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|