1 /** 2 * This file is a part of the Cairo-Dock project 3 * Login : <ctaf42@gmail.com> 4 * Started on Sun Jan 27 18:35:38 2008 Cedric GESTES 5 * $Id$ 6 * 7 * Author(s) 8 * - Cedric GESTES <ctaf42@gmail.com> 9 * - Fabrice REY 10 * 11 * Copyright : (C) 2008 Cedric GESTES 12 * E-mail : see the 'copyright' file. 13 * 14 * This program is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU General Public License 16 * as published by the Free Software Foundation; either version 3 17 * of the License, or (at your option) any later version. 18 * 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * You should have received a copy of the GNU General Public License 24 * along with this program. If not, see <http://www.gnu.org/licenses/>. 25 */ 26 27 #ifndef __CAIRO_DESKLET_FACTORY_H__ 28 #define __CAIRO_DESKLET_FACTORY_H__ 29 30 #include "cairo-dock-struct.h" 31 #include "cairo-dock-surface-factory.h" 32 #include "cairo-dock-image-buffer.h" 33 #include "cairo-dock-container.h" 34 G_BEGIN_DECLS 35 36 37 /** 38 *@file cairo-dock-desklet-factory.h This class defines the Desklets, that are Widgets placed directly on your desktop. 39 * A Desklet is a container that holds 1 applet's icon plus an optionnal list of other icons and an optionnal GTK widget, has a decoration, suports several accessibility types (like Compiz Widget Layer), and has a renderer. 40 * Desklets can be resized or moved directly with the mouse, and can be rotated in the 3 directions of space. 41 * To actually create or destroy a Desklet, use the Desklet Manager's functoins in \ref cairo-dock-desklet-manager.h. 42 */ 43 44 /// Type of accessibility of a Desklet. 45 typedef enum { 46 /// Normal, like normal window 47 CAIRO_DESKLET_NORMAL = 0, 48 /// always above 49 CAIRO_DESKLET_KEEP_ABOVE, 50 /// always below 51 CAIRO_DESKLET_KEEP_BELOW, 52 /// on the Compiz widget layer 53 CAIRO_DESKLET_ON_WIDGET_LAYER, 54 /// prevent other windows form overlapping it 55 CAIRO_DESKLET_RESERVE_SPACE 56 } CairoDeskletVisibility; 57 58 /// Decoration of a Desklet. 59 struct _CairoDeskletDecoration { 60 const gchar *cDisplayedName; 61 gchar *cBackGroundImagePath; 62 gchar *cForeGroundImagePath; 63 CairoDockLoadImageModifier iLoadingModifier; 64 gdouble fBackGroundAlpha; 65 gdouble fForeGroundAlpha; 66 gint iLeftMargin; 67 gint iTopMargin; 68 gint iRightMargin; 69 gint iBottomMargin; 70 }; 71 72 typedef struct _CairoDeskletAttr CairoDeskletAttr; 73 74 /// Configuration attributes of a Desklet. 75 struct _CairoDeskletAttr { 76 // parent attributes 77 GldiContainerAttr cattr; 78 gboolean bDeskletUseSize; 79 gint iDeskletWidth; 80 gint iDeskletHeight; 81 gint iDeskletPositionX; 82 gint iDeskletPositionY; 83 gboolean bPositionLocked; 84 gint iRotation; 85 gint iDepthRotationY; 86 gint iDepthRotationX; 87 gchar *cDecorationTheme; 88 CairoDeskletDecoration *pUserDecoration; 89 CairoDeskletVisibility iVisibility; 90 gboolean bOnAllDesktops; 91 gint iNumDesktop; 92 gboolean bNoInput; 93 Icon *pIcon; 94 } ; 95 96 typedef gpointer CairoDeskletRendererDataParameter; 97 typedef CairoDeskletRendererDataParameter* CairoDeskletRendererDataPtr; 98 typedef gpointer CairoDeskletRendererConfigParameter; 99 typedef CairoDeskletRendererConfigParameter* CairoDeskletRendererConfigPtr; 100 typedef struct { 101 gchar *cName; 102 CairoDeskletRendererConfigPtr pConfig; 103 } CairoDeskletRendererPreDefinedConfig; 104 typedef void (* CairoDeskletRenderFunc) (cairo_t *pCairoContext, CairoDesklet *pDesklet); 105 typedef void (*CairoDeskletGLRenderFunc) (CairoDesklet *pDesklet); 106 typedef gpointer (* CairoDeskletConfigureRendererFunc) (CairoDesklet *pDesklet, CairoDeskletRendererConfigPtr pConfig); 107 typedef void (* CairoDeskletLoadRendererDataFunc) (CairoDesklet *pDesklet); 108 typedef void (* CairoDeskletUpdateRendererDataFunc) (CairoDesklet *pDesklet, CairoDeskletRendererDataPtr pNewData); 109 typedef void (* CairoDeskletFreeRendererDataFunc) (CairoDesklet *pDesklet); 110 typedef void (* CairoDeskletCalculateIconsFunc) (CairoDesklet *pDesklet); 111 /// Definition of a Desklet's renderer. 112 struct _CairoDeskletRenderer { 113 /// rendering function with libcairo. 114 CairoDeskletRenderFunc render; 115 /// rendering function with OpenGL. 116 CairoDeskletGLRenderFunc render_opengl; 117 /// get the configuration of the renderer from a set of config attributes. 118 CairoDeskletConfigureRendererFunc configure; 119 /// load the internal data of the renderer. 120 CairoDeskletLoadRendererDataFunc load_data; 121 /// free all internal data of the renderer. 122 CairoDeskletFreeRendererDataFunc free_data; 123 /// define the icons' size and load them. 124 CairoDeskletCalculateIconsFunc calculate_icons; 125 /// function called on each iteration of the rendering loop. 126 CairoDeskletUpdateRendererDataFunc update; 127 /// optionnal rendering function with OpenGL that only draws the bounding boxes of the icons (for picking). 128 CairoDeskletGLRenderFunc render_bounding_box; 129 /// An optionnal list of preset configs. 130 GList *pPreDefinedConfigList; 131 }; 132 133 134 /// Definition of a Desklet, which derives from a Container. 135 struct _CairoDesklet { 136 //\________________ Core 137 // container 138 GldiContainer container; 139 // Main icon (usually an applet) 140 Icon *pIcon; 141 // List of sub-icons (possibly NULL) 142 GList *icons; 143 // Renderer used to draw the desklet 144 CairoDeskletRenderer *pRenderer; 145 // data used by the renderer 146 gpointer pRendererData; 147 // The following function outclasses the corresponding function of the renderer. This is useful if you don't want to pick icons but some elements that you draw yourself on the desklet. 148 CairoDeskletGLRenderFunc render_bounding_box; 149 // ID of the object that was picked in case the previous function is not null. 150 GLuint iPickedObject; 151 152 //\________________ decorations 153 gchar *cDecorationTheme; 154 CairoDeskletDecoration *pUserDecoration; 155 gint iLeftSurfaceOffset; 156 gint iTopSurfaceOffset; 157 gint iRightSurfaceOffset; 158 gint iBottomSurfaceOffset; 159 CairoDockImageBuffer backGroundImageBuffer; 160 CairoDockImageBuffer foreGroundImageBuffer; 161 gboolean bUseDefaultColors; // use default colors instead of the bg/fg images 162 163 //\________________ properties. 164 gdouble fRotation; // rotation. 165 gdouble fDepthRotationY; 166 gdouble fDepthRotationX; 167 gboolean bFixedAttitude; 168 gboolean bAllowNoClickable; 169 gboolean bNoInput; 170 GtkWidget *pInteractiveWidget; 171 gboolean bPositionLocked; // TRUE ssi on ne peut pas deplacer le widget a l'aide du simple clic gauche. 172 173 //\________________ internal 174 gint iSidWritePosition; // un timer pour retarder l'ecriture dans le fichier lors des deplacements. 175 gint iSidWriteSize; // un timer pour retarder l'ecriture dans le fichier lors des redimensionnements. 176 gint iDesiredWidth, iDesiredHeight; // taille a atteindre (fixee par l'utilisateur dans le.conf) 177 gint iKnownWidth, iKnownHeight; // taille connue par l'applet associee. 178 gboolean bSpaceReserved; // l'espace est actuellement reserve. 179 gboolean bAllowMinimize; // TRUE to allow the desklet to be minimized once. The flag is reseted to FALSE after the desklet has minimized. 180 gint iMouseX2d; // X position of the pointer taking into account the 2D transformations on the desklet (for an opengl renderer, you'll have to use the picking). 181 gint iMouseY2d; // Y position of the pointer taking into account the 2D transformations on the desklet (for an opengl renderer, you'll have to use the picking). 182 GTimer *pUnmapTimer; 183 gdouble fButtonsAlpha; // pour le fondu des boutons lors de l'entree dans le desklet. 184 gboolean bButtonsApparition; // si les boutons sont en train d'apparaitre ou de disparaitre. 185 gboolean bGrowingUp; // pour le zoom initial. 186 187 //\________________ current state 188 gboolean rotatingY; 189 gboolean rotatingX; 190 gboolean rotating; 191 gboolean retaching; // rattachement au dock. 192 gboolean making_transparent; // no input. 193 gboolean moving; // pour le deplacement manuel de la fenetre. 194 gboolean bClicked; 195 guint time; // date du clic. 196 197 CairoDeskletVisibility iVisibility; 198 gpointer reserved[4]; 199 }; 200 201 /** Say if an object is a Desklet. 202 *@param obj the object. 203 *@return TRUE if the object is a Desklet. 204 */ 205 #define GLDI_OBJECT_IS_DESKLET(obj) gldi_object_is_manager_child (GLDI_OBJECT(obj), &myDeskletObjectMgr) 206 #define CAIRO_DOCK_IS_DESKLET GLDI_OBJECT_IS_DESKLET 207 208 /** Cast a Container into a Desklet. 209 *@param pContainer the container. 210 *@return the desklet. 211 */ 212 #define CAIRO_DESKLET(pContainer) ((CairoDesklet *)pContainer) 213 214 #define cairo_dock_desklet_is_free(pDesklet) (! (pDesklet->bPositionLocked || pDesklet->bFixedAttitude)) 215 216 /** Create a new desklet. 217 *@param attr the attributes of the desklet 218 *@return the desklet. 219 */ 220 CairoDesklet *gldi_desklet_new (CairoDeskletAttr *attr); 221 222 void gldi_desklet_init_internals (CairoDesklet *pDesklet); 223 224 /* Apply its settings on a desklet: 225 * it places it, resizes it, sets up its accessibility, locks its position, and sets up its decorations. 226 *@param pDesklet the desklet. 227 *@param pAttribute the attributes to configure the desklet. 228 */ 229 void gldi_desklet_configure (CairoDesklet *pDesklet, CairoDeskletAttr *pAttribute); 230 231 #define gldi_desklet_set_static(pDesklet) (pDesklet)->bFixedAttitude = TRUE 232 233 #define gldi_desklet_allow_no_clickable(pDesklet) (pDesklet)->bAllowNoClickable = TRUE 234 235 void gldi_desklet_load_desklet_decorations (CairoDesklet *pDesklet); 236 237 void gldi_desklet_decoration_free (CairoDeskletDecoration *pDecoration); 238 239 240 /** Add a GtkWidget to a desklet. Only 1 widget is allowed per desklet, if you need more, you can just use a GtkContainer, and place as many widget as you want inside. 241 *@param pInteractiveWidget the widget to add. 242 *@param pDesklet the desklet. 243 *@param iRightMargin right margin, in pixels, useful to keep a clickable zone on the desklet, or 0 if you don't want a margin. 244 */ 245 void gldi_desklet_add_interactive_widget_with_margin (CairoDesklet *pDesklet, GtkWidget *pInteractiveWidget, int iRightMargin); 246 /** Add a GtkWidget to a desklet. Only 1 widget is allowed per desklet, if you need more, you can just use a GtkContainer, and place as many widget as you want inside. 247 *@param pInteractiveWidget the widget to add. 248 *@param pDesklet the desklet. 249 */ 250 #define gldi_desklet_add_interactive_widget(pDesklet, pInteractiveWidget) gldi_desklet_add_interactive_widget_with_margin (pDesklet, pInteractiveWidget, 0) 251 /** Set the right margin of a desklet. This is useful to keep a clickable zone on the desklet when you put a GTK widget inside. 252 *@param pDesklet the desklet. 253 *@param iRightMargin right margin, in pixels. 254 */ 255 void gldi_desklet_set_margin (CairoDesklet *pDesklet, int iRightMargin); 256 /** Detach the interactive widget from a desklet. The widget can then be placed anywhere after that. You have to unref it after you placed it into a container, or to destroy it. 257 *@param pDesklet the desklet with an interactive widget. 258 *@return the widget. 259 */ 260 GtkWidget *gldi_desklet_steal_interactive_widget (CairoDesklet *pDesklet); 261 262 263 /** Hide a desklet. 264 *@param pDesklet the desklet. 265 */ 266 void gldi_desklet_hide (CairoDesklet *pDesklet); 267 /** Show a desklet, and give it the focus. 268 *@param pDesklet the desklet. 269 */ 270 void gldi_desklet_show (CairoDesklet *pDesklet); 271 272 /** Set a desklet's accessibility. For Widget Layer, the WM must support it and the correct rule must be set up in the WM (for instance for Compiz : class=Cairo-dock & type=utility). The function automatically sets up the rule for Compiz (if Dbus is activated). 273 *@param pDesklet the desklet. 274 *@param iVisibility the new accessibility. 275 *@param bSaveState whether to save the new state in the conf file. 276 */ 277 void gldi_desklet_set_accessibility (CairoDesklet *pDesklet, CairoDeskletVisibility iVisibility, gboolean bSaveState); 278 279 /** Set a desklet sticky (i.e. visible on all desktops), or not. In case the desklet is set unsticky, its current desktop/viewport is saved. 280 *@param pDesklet the desklet. 281 *@param bSticky whether the desklet should be sticky or not. 282 */ 283 void gldi_desklet_set_sticky (CairoDesklet *pDesklet, gboolean bSticky); 284 285 gboolean gldi_desklet_is_sticky (CairoDesklet *pDesklet); 286 287 /** Lock the position of a desklet. This makes the desklet impossible to rotate, drag with the mouse, or retach to the dock. The new state is saved in conf. 288 *@param pDesklet the desklet. 289 *@param bPositionLocked whether the position should be locked or not. 290 */ 291 void gldi_desklet_lock_position (CairoDesklet *pDesklet, gboolean bPositionLocked); 292 293 294 void gldi_desklet_insert_icon (Icon *icon, CairoDesklet *pDesklet); 295 296 gboolean gldi_desklet_detach_icon (Icon *icon, CairoDesklet *pDesklet); 297 298 G_END_DECLS 299 300 #endif 301