File indexing completed on 2024-04-28 05:32:14

0001 #ifndef oxygenshadowhelper_h
0002 #define oxygenshadowhelper_h
0003 /*
0004 * this file is part of the oxygen gtk engine
0005 * SPDX-FileCopyrightText: 2011 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0006 *
0007 * SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #include "oxygenapplicationname.h"
0011 #include "oxygencairosurface.h"
0012 #include "oxygenhook.h"
0013 #include "oxygensignal.h"
0014 #include "oxygentileset.h"
0015 #include "oxygenwindowshadow.h"
0016 
0017 #include <vector>
0018 #include <map>
0019 
0020 #ifdef GDK_WINDOWING_X11
0021 #include <X11/Xdefs.h>
0022 #include <X11/Xlib.h>
0023 #endif
0024 
0025 namespace Oxygen
0026 {
0027 
0028     //! handles X11 property passed to menu windows for window manager to draw proper shadows
0029     class ShadowHelper
0030     {
0031 
0032         public:
0033 
0034         //!@name property names
0035         //@{
0036         static const char* const netWMShadowAtomName;
0037         //@}
0038 
0039         //! constructor
0040         ShadowHelper( void );
0041 
0042         //! destructor
0043         virtual ~ShadowHelper( void );
0044 
0045         //! true is supported
0046         void setSupported( bool value )
0047         { _supported = value; }
0048 
0049         //! true if supported
0050         bool isSupported( void ) const
0051         { return _supported; }
0052 
0053         //! reset
0054         void reset( void );
0055 
0056         //! initialize hooks
0057         void initializeHooks( void );
0058 
0059         //! application name
0060         void setApplicationName( const ApplicationName& applicationName )
0061         { _applicationName = applicationName; }
0062 
0063         //! initialize
0064         void initialize( const ColorUtils::Rgba&, const WindowShadow& );
0065 
0066         //! register widget
0067         bool registerWidget( GtkWidget* );
0068 
0069         //! unregister widget
0070         void unregisterWidget( GtkWidget* );
0071 
0072         //! true if widget is menu
0073         bool isMenu( GtkWidget* ) const;
0074 
0075         //! true if widget is menu
0076         bool isToolTip( GtkWidget* ) const;
0077 
0078         //! true if shadow should be installed on widget
0079         bool acceptWidget( GtkWidget* ) const;
0080 
0081         //! create pixmaps
0082         void createPixmapHandles( void );
0083 
0084         //! create Pixmap for given surface
0085         #ifdef GDK_WINDOWING_X11
0086         Pixmap createPixmap( const Cairo::Surface&, int opacity = 255 ) const;
0087         #endif
0088 
0089         //! install shadow X11 property on given widget
0090         /*!
0091         shadow atom and property specification available at
0092         http://community.kde.org/KWin/Shadow
0093         */
0094         void installX11Shadows( GtkWidget* );
0095 
0096         //! uninstall shadow X11 property on given widget
0097         void uninstallX11Shadows( GtkWidget* ) const;
0098 
0099         //! map event hook
0100         static gboolean realizeHook( GSignalInvocationHint*, guint, const GValue*, gpointer );
0101 
0102         //! destruction callback
0103         static gboolean destroyNotifyEvent( GtkWidget*, gpointer );
0104 
0105         private:
0106 
0107         //! true if shadows are supported
0108         bool _supported;
0109 
0110         //! shadow size
0111         int _size;
0112 
0113         //! shadow tileset
0114         TileSet _roundTiles;
0115 
0116         //! shadow tileset
0117         TileSet _squareTiles;
0118 
0119         //! application name
0120         ApplicationName _applicationName;
0121 
0122         #ifdef GDK_WINDOWING_X11
0123         //! shadow atom
0124         Atom _atom;
0125         #endif
0126 
0127         //! number of pixmaps
0128         enum { numPixmaps = 8 };
0129 
0130         //! round shadows pixmap handles
0131         typedef std::vector<unsigned long> PixmapList;
0132         PixmapList _roundPixmaps;
0133 
0134         //! square shadows pixmap handles
0135         PixmapList _squarePixmaps;
0136 
0137         //! widget data
0138         class WidgetData
0139         {
0140 
0141             public:
0142 
0143             //! constructor
0144             WidgetData( void )
0145             {}
0146 
0147             //! destroy signal
0148             Signal _destroyId;
0149 
0150         };
0151 
0152         //! map widgets and window id
0153         typedef std::map<GtkWidget*, WidgetData> WidgetMap;
0154         WidgetMap _widgets;
0155 
0156         //! true if hooks are initialized
0157         bool _hooksInitialized;
0158 
0159         //! map-event hook
0160         Hook _realizeHook;
0161 
0162     };
0163 
0164 }
0165 
0166 #endif