• Skip to content
  • Skip to link menu
KDE 4.2 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 // Whether to keep all windows mapped when compositing (i.e. whether to have
00149 // actively updated window pixmaps).
00150 enum HiddenPreviews
00151     { 
00152     // The normal mode with regard to mapped windows. Hidden (minimized, etc.)
00153     // and windows on inactive virtual desktops are not mapped, their pixmaps
00154     // are only their icons.
00155     HiddenPreviewsNever,
00156     // Like normal mode, but shown windows (i.e. on inactive virtual desktops)
00157     // are kept mapped, only hidden windows are unmapped.
00158     HiddenPreviewsShown,
00159     // All windows are kept mapped regardless of their state.
00160     HiddenPreviewsAlways
00161     };
00162 
00163 // compile with XShape older than 1.0
00164 #ifndef ShapeInput
00165 const int ShapeInput = 2;
00166 #endif
00167 
00168 class Motif 
00169     {
00170     public:
00171         static void readFlags( WId w, bool& noborder, bool& resize, bool& move,
00172             bool& minimize, bool& maximize, bool& close );
00173         struct MwmHints 
00174             {
00175             ulong flags;
00176             ulong functions;
00177             ulong decorations;
00178             long input_mode;
00179             ulong status;
00180             };
00181         enum {
00182             MWM_HINTS_FUNCTIONS = (1L << 0),
00183             MWM_HINTS_DECORATIONS =  (1L << 1),
00184 
00185             MWM_FUNC_ALL = (1L << 0),
00186             MWM_FUNC_RESIZE = (1L << 1),
00187             MWM_FUNC_MOVE = (1L << 2),
00188             MWM_FUNC_MINIMIZE = (1L << 3),
00189             MWM_FUNC_MAXIMIZE = (1L << 4),
00190             MWM_FUNC_CLOSE = (1L << 5)
00191             };
00192     };
00193 
00194 class KWinSelectionOwner
00195     : public KSelectionOwner
00196     {
00197     Q_OBJECT
00198     public:
00199         KWinSelectionOwner( int screen );
00200     protected:
00201         virtual bool genericReply( Atom target, Atom property, Window requestor );
00202         virtual void replyTargets( Atom property, Window requestor );
00203         virtual void getAtoms();
00204     private:
00205         Atom make_selection_atom( int screen );
00206         static Atom xa_version;
00207     };
00208 
00209 // Class which saves original value of the variable, assigns the new value
00210 // to it, and in the destructor restores the value.
00211 // Used in Client::isMaximizable() and so on.
00212 // It also casts away contness and generally this looks like a hack.
00213 template< typename T >
00214 class TemporaryAssign
00215     {
00216     public:
00217         TemporaryAssign( const T& var, const T& value )
00218             : variable( var ), orig( var )
00219             {
00220             const_cast< T& >( variable ) = value;
00221             }
00222         ~TemporaryAssign()
00223             {
00224             const_cast< T& >( variable ) = orig;
00225             }
00226     private:
00227         const T& variable;
00228         T orig;
00229     };
00230 
00231 QByteArray getStringProperty(WId w, Atom prop, char separator=0);
00232 void updateXTime();
00233 void grabXServer();
00234 void ungrabXServer();
00235 bool grabbedXServer();
00236 bool grabXKeyboard( Window w = rootWindow());
00237 void ungrabXKeyboard();
00238 
00239 class Scene;
00240 extern Scene* scene;
00241 inline bool compositing() { return scene != NULL; }
00242 
00243 // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint
00244 #ifndef UrgencyHint
00245 #define UrgencyHint XUrgencyHint
00246 #endif
00247 
00248 // for STL-like algo's
00249 #define KWIN_CHECK_PREDICATE( name, cls, check ) \
00250 struct name \
00251     { \
00252     inline bool operator()( const cls* cl ) { return check; } \
00253     }
00254 
00255 #define KWIN_COMPARE_PREDICATE( name, cls, type, check ) \
00256 struct name \
00257     { \
00258     typedef type type_helper; /* in order to work also with type being 'const Client*' etc. */ \
00259     inline name( const type_helper& compare_value ) : value( compare_value ) {} \
00260     inline bool operator()( const cls* cl ) { return check; } \
00261     const type_helper& value; \
00262     }
00263 
00264 #define KWIN_PROCEDURE( name, cls, action ) \
00265 struct name \
00266     { \
00267     inline void operator()( cls* cl ) { action; } \
00268     }
00269 
00270 KWIN_CHECK_PREDICATE( TruePredicate, Client, cl == cl /*true, avoid warning about 'cl' */ );
00271 
00272 template< typename T >
00273 Client* findClientInList( const ClientList& list, T predicate )
00274     {
00275     for ( ClientList::ConstIterator it = list.begin(); it != list.end(); ++it) 
00276         {
00277         if ( predicate( const_cast< const Client* >( *it)))
00278             return *it;
00279         }
00280     return NULL;
00281     }
00282 
00283 template< typename T >
00284 Unmanaged* findUnmanagedInList( const UnmanagedList& list, T predicate )
00285     {
00286     for ( UnmanagedList::ConstIterator it = list.begin(); it != list.end(); ++it) 
00287         {
00288         if ( predicate( const_cast< const Unmanaged* >( *it)))
00289             return *it;
00290         }
00291     return NULL;
00292     }
00293 
00294 inline
00295 int timestampCompare( Time time1, Time time2 ) // like strcmp()
00296     {
00297     return NET::timestampCompare( time1, time2 );
00298     }
00299 
00300 inline
00301 Time timestampDiff( Time time1, Time time2 ) // returns time2 - time1
00302     {
00303     return NET::timestampDiff( time1, time2 );
00304     }
00305 
00306 bool isLocalMachine( const QByteArray& host );
00307 
00308 QPoint cursorPos();
00309 
00310 // converting between X11 mouse/keyboard state mask and Qt button/keyboard states
00311 int qtToX11Button( Qt::MouseButton button );
00312 Qt::MouseButton x11ToQtMouseButton( int button );
00313 int qtToX11State( Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers );
00314 Qt::MouseButtons x11ToQtMouseButtons( int state );
00315 Qt::KeyboardModifiers x11ToQtKeyboardModifiers( int state );
00316 
00317 void checkNonExistentClients();
00318 
00319 #ifndef KCMRULES
00320 // Qt dialogs emit no signal when closed :(
00321 class ShortcutDialog
00322     : public KDialog
00323     {
00324     Q_OBJECT
00325     public:
00326         ShortcutDialog( const QKeySequence& cut );
00327         virtual void accept();
00328         QKeySequence shortcut() const;
00329     public Q_SLOTS:
00330         void keySequenceChanged(const QKeySequence &seq);
00331     signals:
00332         void dialogDone( bool ok );
00333     protected:
00334         virtual void done( int r );
00335     private:
00336         KKeySequenceWidget* widget;
00337         QKeySequence _shortcut;
00338     };
00339 
00340 #endif //KCMRULES
00341 
00342 } // namespace
00343 
00344 #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
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
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