1 /*
2 * This file is a part of the Cairo-Dock project
3 *
4 * Copyright : (C) see the 'copyright' file.
5 * E-mail    : see the 'copyright' file.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef __GLDI_DESKTOP_MANAGER__
21 #define  __GLDI_DESKTOP_MANAGER__
22 
23 #include "cairo-dock-struct.h"
24 #include "cairo-dock-manager.h"
25 G_BEGIN_DECLS
26 
27 /**
28 *@file cairo-dock-desktop-manager.h This class manages the desktop: screen geometry, current desktop/viewport, etc, and notifies for any change on it.
29 */
30 
31 // manager
32 
33 #ifndef _MANAGER_DEF_
34 extern GldiManager myDesktopMgr;
35 extern GldiDesktopGeometry g_desktopGeometry;
36 #endif
37 
38 // no param
39 
40 
41 /// signals
42 typedef enum {
43 	/// notification called when the user switches to another desktop/viewport. data : NULL
44 	NOTIFICATION_DESKTOP_CHANGED = NB_NOTIFICATIONS_OBJECT,
45 	/// notification called when the geometry of the desktop has changed (number of viewports/desktops, dimensions). data: resolution-has-changed
46 	NOTIFICATION_DESKTOP_GEOMETRY_CHANGED,
47 	/// notification called when the desktop is shown/hidden. data: NULL
48 	NOTIFICATION_DESKTOP_VISIBILITY_CHANGED,
49 	/// notification called when the state of the keyboard has changed.
50 	NOTIFICATION_KBD_STATE_CHANGED,
51 	/// notification called when the names of the desktops have changed
52 	NOTIFICATION_DESKTOP_NAMES_CHANGED,
53 	/// notification called when the wallpaper has changed
54 	NOTIFICATION_DESKTOP_WALLPAPER_CHANGED,
55 	/// notification called when a shortkey that has been registered by the dock is pressed. data: keycode, modifiers
56 	NOTIFICATION_SHORTKEY_PRESSED,
57 	/// notification called when the keymap changed, before and after updating it. data: updated
58 	NOTIFICATION_KEYMAP_CHANGED,
59 	NB_NOTIFICATIONS_DESKTOP
60 	} CairoDesktopNotifications;
61 
62 // data
63 struct _GldiDesktopGeometry {
64 	int iNbScreens;
65 	GtkAllocation *pScreens;  // liste of all screen devices.
66 	GtkAllocation Xscreen;  // logical screen, possibly made of several screen devices.
67 	int iNbDesktops;
68 	int iNbViewportX, iNbViewportY;
69 	int iCurrentDesktop;
70 	int iCurrentViewportX, iCurrentViewportY;
71 	};
72 
73 /// Definition of the Desktop Manager backend.
74 struct _GldiDesktopManagerBackend {
75 	gboolean (*present_class) (const gchar *cClass);
76 	gboolean (*present_windows) (void);
77 	gboolean (*present_desktops) (void);
78 	gboolean (*show_widget_layer) (void);
79 	gboolean (*set_on_widget_layer) (GldiContainer *pContainer, gboolean bOnWidgetLayer);
80 	gboolean (*show_hide_desktop) (gboolean bShow);
81 	gboolean (*desktop_is_visible) (void);
82 	gchar** (*get_desktops_names) (void);
83 	gboolean (*set_desktops_names) (gchar **cNames);
84 	cairo_surface_t* (*get_desktop_bg_surface) (void);
85 	gboolean (*set_current_desktop) (int iDesktopNumber, int iViewportNumberX, int iViewportNumberY);
86 	gboolean (*set_nb_desktops) (int iNbDesktops, int iNbViewportX, int iNbViewportY);
87 	void (*refresh) (void);
88 	void (*notify_startup) (const gchar *cClass);
89 	gboolean (*grab_shortkey) (guint keycode, guint modifiers, gboolean grab);
90 	};
91 
92 /// Definition of a Desktop Background Buffer. It has a reference count so that it can be shared across all the lib.
93 struct _GldiDesktopBackground {
94 	cairo_surface_t *pSurface;
95 	GLuint iTexture;
96 	guint iSidDestroyBg;
97 	gint iRefCount;
98 	} ;
99 
100 
101   /////////////////////
102  // Desktop Backend //
103 /////////////////////
104 
105 /** Register a Desktop Manager backend. NULL functions do not overwrite existing ones.
106 *@param pBackend a Desktop Manager backend; can be freeed after.
107 */
108 void gldi_desktop_manager_register_backend (GldiDesktopManagerBackend *pBackend);
109 
110 /** Present all the windows of a given class.
111 *@param cClass the class.
112 *@return TRUE on success
113 */
114 gboolean gldi_desktop_present_class (const gchar *cClass);
115 
116 /** Present all the windows of the current desktop.
117 *@return TRUE on success
118 */
119 gboolean gldi_desktop_present_windows (void);
120 
121 /** Present all the desktops.
122 *@return TRUE on success
123 */
124 gboolean gldi_desktop_present_desktops (void);
125 
126 /** Show the Widget Layer.
127 *@return TRUE on success
128 */
129 gboolean gldi_desktop_show_widget_layer (void);
130 
131 /** Set a Container to be displayed on the Widget Layer.
132 *@param pContainer a container.
133 *@param bOnWidgetLayer whether to set or unset the option.
134 *@return TRUE on success
135 */
136 gboolean gldi_desktop_set_on_widget_layer (GldiContainer *pContainer, gboolean bOnWidgetLayer);
137 
138 gboolean gldi_desktop_can_present_class (void);
139 gboolean gldi_desktop_can_present_windows (void);
140 gboolean gldi_desktop_can_present_desktops (void);
141 gboolean gldi_desktop_can_show_widget_layer (void);
142 gboolean gldi_desktop_can_set_on_widget_layer (void);
143 
144 gboolean gldi_desktop_show_hide (gboolean bShow);
145 gboolean gldi_desktop_is_visible (void);
146 gchar** gldi_desktop_get_names (void);
147 gboolean gldi_desktop_set_names (gchar **cNames);
148 gboolean gldi_desktop_set_current (int iDesktopNumber, int iViewportNumberX, int iViewportNumberY);
149 gboolean gldi_desktop_set_nb_desktops (int iNbDesktops, int iNbViewportX, int iNbViewportY);
150 
151 void gldi_desktop_refresh (void);
152 
153 void gldi_desktop_notify_startup (const gchar *cClass);
154 
155 gboolean gldi_desktop_grab_shortkey (guint keycode, guint modifiers, gboolean grab);
156 
157   ////////////////////
158  // Desktop access //
159 ////////////////////
160 
161 /** Get the current workspace (desktop and viewport).
162 *@param iCurrentDesktop will be filled with the current desktop number
163 *@param iCurrentViewportX will be filled with the current horizontal viewport number
164 *@param iCurrentViewportY will be filled with the current vertical viewport number
165 */
166 void gldi_desktop_get_current (int *iCurrentDesktop, int *iCurrentViewportX, int *iCurrentViewportY);
167 
168 #define GLDI_DEFAULT_SCREEN 0 // it's the first screen. -1 = all screens
169 #define cairo_dock_get_screen_position_x(i) (i >= 0 && i < g_desktopGeometry.iNbScreens ? g_desktopGeometry.pScreens[i].x : 0)
170 #define cairo_dock_get_screen_position_y(i) (i >= 0 && i < g_desktopGeometry.iNbScreens ? g_desktopGeometry.pScreens[i].y : 0)
171 #define cairo_dock_get_screen_width(i) (i >= 0 && i < g_desktopGeometry.iNbScreens ? g_desktopGeometry.pScreens[i].width : g_desktopGeometry.Xscreen.width)
172 #define cairo_dock_get_screen_height(i) (i >= 0 && i < g_desktopGeometry.iNbScreens ? g_desktopGeometry.pScreens[i].height : g_desktopGeometry.Xscreen.height)
173 #define cairo_dock_get_nth_screen(i) (i >= 0 && i < g_desktopGeometry.iNbScreens ? &g_desktopGeometry.pScreens[i] : &g_desktopGeometry.Xscreen)
174 #define gldi_desktop_get_width() g_desktopGeometry.Xscreen.width
175 #define gldi_desktop_get_height() g_desktopGeometry.Xscreen.height
176 
177   ////////////////////////
178  // Desktop background //
179 ////////////////////////
180 
181 GldiDesktopBackground *gldi_desktop_background_get (gboolean bWithTextureToo);
182 
183 void gldi_desktop_background_destroy (GldiDesktopBackground *pDesktopBg);
184 
185 cairo_surface_t *gldi_desktop_background_get_surface (GldiDesktopBackground *pDesktopBg);
186 
187 GLuint gldi_desktop_background_get_texture (GldiDesktopBackground *pDesktopBg);
188 
189 
190 void gldi_register_desktop_manager (void);
191 
192 G_END_DECLS
193 #endif
194