• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KWin

utils.h

Go to the documentation of this file.
00001 /********************************************************************
00002  KWin - the KDE window manager
00003  This file is part of the KDE project.
00004 
00005 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
00006 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
00007 
00008 This program is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2 of the License, or
00011 (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 *********************************************************************/
00021 
00022 #ifndef KWIN_UTILS_H
00023 #define KWIN_UTILS_H
00024 
00025 #include <config-workspace.h>
00026 #include <config-X11.h>
00027 #include <config-kwin.h>
00028 
00029 #include <kwinconfig.h>
00030 
00031 #include <X11/Xlib.h>
00032 
00033 #include <fixx11h.h>
00034 
00035 #include <QWidget>
00036 #include <kmanagerselection.h>
00037 #include <netwm_def.h>
00038 #include <kkeysequencewidget.h>
00039 #include <limits.h>
00040 #include <QX11Info>
00041 #include <kdialog.h>
00042 
00043 #include <kwinglobals.h>
00044 
00045 // needed by the DBUS interface
00046 Q_DECLARE_METATYPE(QList<int>)
00047 
00048 namespace KWin
00049 {
00050 
00051 #ifndef HAVE_XDAMAGE
00052 typedef long Damage;
00053 struct XDamageNotifyEvent
00054     {
00055     };
00056 #endif
00057 
00058 // window types that are supported as normal windows (i.e. KWin actually manages them)
00059 const int SUPPORTED_MANAGED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
00060     | NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
00061     | NET::UtilityMask | NET::SplashMask;
00062 // window types that are supported as unmanaged (mainly for compositing)
00063 const int SUPPORTED_UNMANAGED_WINDOW_TYPES_MASK = NET::NormalMask | NET::DesktopMask | NET::DockMask
00064     | NET::ToolbarMask | NET::MenuMask | NET::DialogMask /*| NET::OverrideMask*/ | NET::TopMenuMask
00065     | NET::UtilityMask | NET::SplashMask | NET::DropdownMenuMask | NET::PopupMenuMask
00066     | NET::TooltipMask | NET::NotificationMask | NET::ComboBoxMask | NET::DNDIconMask;
00067 
00068 const long ClientWinMask = KeyPressMask | KeyReleaseMask |
00069                           ButtonPressMask | ButtonReleaseMask |
00070                   KeymapStateMask |
00071                   ButtonMotionMask |
00072                   PointerMotionMask | // need this, too!
00073                   EnterWindowMask | LeaveWindowMask |
00074                   FocusChangeMask |
00075                   ExposureMask |
00076                   StructureNotifyMask |
00077                   SubstructureRedirectMask;
00078 
00079 const QPoint invalidPoint( INT_MIN, INT_MIN );
00080 
00081 class Toplevel;
00082 class Client;
00083 class Unmanaged;
00084 class Deleted;
00085 class Group;
00086 class Options;
00087 
00088 typedef QList< Toplevel* > ToplevelList;
00089 typedef QList< const Toplevel* > ConstToplevelList;
00090 typedef QList< Client* > ClientList;
00091 typedef QList< const Client* > ConstClientList;
00092 typedef QList< Unmanaged* > UnmanagedList;
00093 typedef QList< const Unmanaged* > ConstUnmanagedList;
00094 typedef QList< Deleted* > DeletedList;
00095 typedef QList< const Deleted* > ConstDeletedList;
00096 
00097 typedef QList< Group* > GroupList;
00098 typedef QList< const Group* > ConstGroupList;
00099 
00100 extern Options* options;
00101 
00102 enum Layer
00103     {
00104     UnknownLayer = -1,
00105     FirstLayer = 0,
00106     DesktopLayer = FirstLayer,
00107     BelowLayer,
00108     NormalLayer,
00109     DockLayer,
00110     AboveLayer,
00111     ActiveLayer, // active fullscreen, or active dialog
00112     NumLayers // number of layers, must be last
00113     };
00114 
00115 // yes, I know this is not 100% like standard operator++
00116 inline void operator++( Layer& lay )
00117     {
00118     lay = static_cast< Layer >( lay + 1 );
00119     }
00120 
00121 // for Client::takeActivity()
00122 enum ActivityFlags
00123     {
00124     ActivityFocus = 1 << 0, // focus the window
00125     ActivityFocusForce = 1 << 1, // focus even if Dock etc.
00126     ActivityRaise = 1 << 2 // raise the window
00127     };
00128 
00129 // Some KWin classes, mainly Client and Workspace, are very tighly coupled,
00130 // and some of the methods of one class may be called only from speficic places.
00131 // Those methods have additional allowed_t argument. If you pass Allowed
00132 // as an argument to any function, make sure you really know what you're doing.
00133 enum allowed_t { Allowed };
00134 
00135 // some enums to have more readable code, instead of using bools
00136 enum ForceGeometry_t { NormalGeometrySet, ForceGeometrySet };
00137 
00138 
00139 
00140 enum ShadeMode
00141     {
00142     ShadeNone, // not shaded
00143     ShadeNormal, // normally shaded - isShade() is true only here
00144     ShadeHover, // "shaded", but visible due to hover unshade
00145     ShadeActivated // "shaded", but visible due to alt+tab to the window
00146     };
00147 
00148 enum HiddenPreviews // whether to keep all windows mapped when compositing
00149     { // do not reorder (config file)
00150     HiddenPreviewsNever, // don't keep pixmaps of unmapped windows at all
00151     HiddenPreviewsKeep, // only keep pixmaps, but unmap windows
00152     HiddenPreviewUpdate, // unmap, keep, but when needed map back and wait
00153     HiddenPreviewsActive // keep windows mapped
00154     };
00155 
00156 // compile with XShape older than 1.0
00157 #ifndef ShapeInput
00158 const int ShapeInput = 2;
00159 #endif
00160 
00161 class Motif 
00162     {
00163     public:
00164         static void readFlags( WId w, bool& noborder, bool& resize, bool& move,
00165             bool& minimize, bool& maximize, bool& close );
00166         struct MwmHints 
00167             {
00168             ulong flags;
00169             ulong functions;
00170             ulong decorations;
00171             long input_mode;
00172             ulong status;
00173             };
00174         enum {
00175             MWM_HINTS_FUNCTIONS = (1L << 0),
00176             MWM_HINTS_DECORATIONS =  (1L << 1),
00177 
00178             MWM_FUNC_ALL = (1L << 0),
00179             MWM_FUNC_RESIZE = (1L << 1),
00180             MWM_FUNC_MOVE = (1L << 2),
00181             MWM_FUNC_MINIMIZE = (1L << 3),
00182             MWM_FUNC_MAXIMIZE = (1L << 4),
00183             MWM_FUNC_CLOSE = (1L << 5)
00184             };
00185     };
00186 
00187 class KWinSelectionOwner
00188     : public KSelectionOwner
00189     {
00190     Q_OBJECT
00191     public:
00192         KWinSelectionOwner( int screen );
00193     protected:
00194         virtual bool genericReply( Atom target, Atom property, Window requestor );
00195         virtual void replyTargets( Atom property, Window requestor );
00196         virtual void getAtoms();
00197     private:
00198         Atom make_selection_atom( int screen );
00199         static Atom xa_version;
00200     };
00201 
00202 // Class which saves original value of the variable, assigns the new value
00203 // to it, and in the destructor restores the value.
00204 // Used in Client::isMaximizable() and so on.
00205 // It also casts away contness and generally this looks like a hack.
00206 template< typename T >
00207 class TemporaryAssign
00208     {
00209     public:
00210         TemporaryAssign( const T& var, const T& value )
00211             : variable( var ), orig( var )
00212             {
00213             const_cast< T& >( variable ) = value;
00214             }
00215         ~TemporaryAssign()
00216             {
00217             const_cast< T& >( variable ) = orig;
00218             }
00219     private:
00220         const T& variable;
00221         T orig;
00222     };
00223 
00224 QByteArray getStringProperty(WId w, Atom prop, char separator=0);
00225 void updateXTime();
00226 void grabXServer();
00227 void ungrabXServer();
00228 bool grabbedXServer();
00229 bool grabXKeyboard( Window w = rootWindow());
00230 void ungrabXKeyboard();
00231 
00232 class Scene;
00233 extern Scene* scene;
00234 inline bool compositing() { return scene != NULL; }
00235 
00236 // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint
00237 #ifndef UrgencyHint
00238 #define UrgencyHint XUrgencyHint
00239 #endif
00240 
00241 // for STL-like algo's
00242 #define KWIN_CHECK_PREDICATE( name, cls, check ) \
00243 struct name \
00244     { \
00245     inline bool operator()( const cls* cl ) { return check; } \
00246     }
00247 
00248 #define KWIN_COMPARE_PREDICATE( name, cls, type, check ) \
00249 struct name \
00250     { \
00251     typedef type type_helper; /* in order to work also with type being 'const Client*' etc. */ \
00252     inline name( const type_helper& compare_value ) : value( compare_value ) {} \
00253     inline bool operator()( const cls* cl ) { return check; } \
00254     const type_helper& value; \
00255     }
00256 
00257 #define KWIN_PROCEDURE( name, cls, action ) \
00258 struct name \
00259     { \
00260     inline void operator()( cls* cl ) { action; } \
00261     }
00262 
00263 KWIN_CHECK_PREDICATE( TruePredicate, Client, cl == cl /*true, avoid warning about 'cl' */ );
00264 
00265 template< typename T >
00266 Client* findClientInList( const ClientList& list, T predicate )
00267     {
00268     for ( ClientList::ConstIterator it = list.begin(); it != list.end(); ++it) 
00269         {
00270         if ( predicate( const_cast< const Client* >( *it)))
00271             return *it;
00272         }
00273     return NULL;
00274     }
00275 
00276 template< typename T >
00277 Unmanaged* findUnmanagedInList( const UnmanagedList& list, T predicate )
00278     {
00279     for ( UnmanagedList::ConstIterator it = list.begin(); it != list.end(); ++it) 
00280         {
00281         if ( predicate( const_cast< const Unmanaged* >( *it)))
00282             return *it;
00283         }
00284     return NULL;
00285     }
00286 
00287 inline
00288 int timestampCompare( Time time1, Time time2 ) // like strcmp()
00289     {
00290     return NET::timestampCompare( time1, time2 );
00291     }
00292 
00293 inline
00294 Time timestampDiff( Time time1, Time time2 ) // returns time2 - time1
00295     {
00296     return NET::timestampDiff( time1, time2 );
00297     }
00298 
00299 bool isLocalMachine( const QByteArray& host );
00300 
00301 QPoint cursorPos();
00302 
00303 // converting between X11 mouse/keyboard state mask and Qt button/keyboard states
00304 int qtToX11Button( Qt::MouseButton button );
00305 Qt::MouseButton x11ToQtMouseButton( int button );
00306 int qtToX11State( Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers );
00307 Qt::MouseButtons x11ToQtMouseButtons( int state );
00308 Qt::KeyboardModifiers x11ToQtKeyboardModifiers( int state );
00309 
00310 void checkNonExistentClients();
00311 
00312 #ifndef KCMRULES
00313 // Qt dialogs emit no signal when closed :(
00314 class ShortcutDialog
00315     : public KDialog
00316     {
00317     Q_OBJECT
00318     public:
00319         ShortcutDialog( const QKeySequence& cut );
00320         virtual void accept();
00321         QKeySequence shortcut() const;
00322     signals:
00323         void dialogDone( bool ok );
00324     protected:
00325         virtual void done( int r );
00326     private:
00327         KKeySequenceWidget* widget;
00328     };
00329 
00330 #endif //KCMRULES
00331 
00332 } // namespace
00333 
00334 #endif

KWin

Skip menu "KWin"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal