Allow -Wl,-z,defs to work - create a liblxpanel.so.0.0.0
[lxde/lxpanel.git] / src / private.h
1 /**
2 * Copyright (c) 2006-2014 LxDE Developers, see the file AUTHORS for details.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #ifndef PRIVATE_H
20 #define PRIVATE_H
21
22 #include "plugin.h"
23 #include "conf.h"
24
25 #include <gmodule.h>
26
27 #include <gtk/gtk.h>
28 #include <gdk/gdk.h>
29 #include <stdio.h>
30 #include "panel.h"
31
32 #include <gdk/gdk.h>
33
34 #include "bg.h"
35 #include "ev.h"
36
37 #if !GLIB_CHECK_VERSION(2, 40, 0)
38 # define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
39 #endif
40
41 /* -----------------------------------------------------------------------------
42 * Definitions used by lxpanel main code internally */
43
44 /* Extracted from panel.h */
45 enum { ALLIGN_NONE, ALLIGN_LEFT, ALLIGN_CENTER, ALLIGN_RIGHT };
46 enum { EDGE_NONE=0, EDGE_LEFT, EDGE_RIGHT, EDGE_TOP, EDGE_BOTTOM };
47 enum { WIDTH_NONE, WIDTH_REQUEST, WIDTH_PIXEL, WIDTH_PERCENT };
48 enum { HEIGHT_NONE, HEIGHT_PIXEL, HEIGHT_REQUEST };
49
50 #define PANEL_ICON_SIZE 24 /* Default size of panel icons */
51 #define PANEL_HEIGHT_DEFAULT 26 /* Default height of horizontal panel */
52 #define PANEL_WIDTH_DEFAULT 150 /* Default "height" of vertical panel */
53 #define PANEL_HEIGHT_MAX 200 /* Maximum height of panel */
54 #define PANEL_HEIGHT_MIN 16 /* Minimum height of panel */
55 #define PANEL_ICON_HIGHLIGHT 0x202020 /* Constant to pass to icon loader */
56
57 /* to check if we are in LXDE */
58 extern gboolean is_in_lxde;
59
60 extern gchar *cprofile;
61
62 extern GSList* all_panels;
63
64 extern GtkWindowGroup* win_grp;
65
66 /* Context of a panel on a given edge. */
67 struct _Panel {
68 char* name;
69 LXPanel * topgwin; /* Main panel window */
70 Window topxwin; /* Main panel's X window */
71 GdkDisplay * display; /* Main panel's GdkDisplay */
72 GtkStyle * defstyle;
73 GtkIconTheme* icon_theme; /*Default icon theme*/
74
75 GtkWidget * box; /* Top level widget */
76
77 GtkRequisition requisition;
78 GtkWidget *(*my_box_new) (gboolean, gint);
79 GtkWidget *(*my_separator_new) ();
80
81 FbBg *bg;
82 int alpha;
83 guint32 tintcolor;
84 guint32 fontcolor;
85 GdkColor gtintcolor;
86 GdkColor gfontcolor;
87
88 int ax, ay, aw, ah; /* prefferd allocation of a panel */
89 int cx, cy, cw, ch; /* current allocation (as reported by configure event) allocation */
90 int allign, edge, margin;
91 guint orientation;
92 int widthtype, width;
93 int heighttype, height;
94 gint monitor;
95 gulong strut_size; /* Values for WM_STRUT_PARTIAL */
96 gulong strut_lower;
97 gulong strut_upper;
98 int strut_edge;
99
100 guint config_changed : 1;
101 guint self_destroy : 1;
102 guint setdocktype : 1;
103 guint setstrut : 1;
104 guint round_corners : 1;
105 guint usefontcolor : 1;
106 guint usefontsize : 1;
107 guint fontsize;
108 guint transparent : 1;
109 guint background : 1;
110 guint spacing;
111
112 guint autohide : 1;
113 guint visible : 1;
114 int height_when_hidden;
115 guint hide_timeout;
116 int icon_size; /* Icon size */
117
118 int desknum;
119 int curdesk;
120 gulong *workarea;
121 int wa_len;
122
123 char* background_file;
124
125 PanelConf * config; /* Panel configuration data */
126 GSList * system_menus; /* List of plugins having menus: deprecated */
127
128 GtkWidget* plugin_pref_dialog; /* Plugin preference dialog */
129 GtkWidget* pref_dialog; /* preference dialog */
130 GtkWidget* margin_control; /* Margin control in preference dialog */
131 GtkWidget* height_label; /* Label of height control */
132 GtkWidget* width_label; /* Label of width control */
133 GtkWidget* alignment_left_label; /* Label of alignment: left control */
134 GtkWidget* alignment_right_label; /* Label of alignment: right control */
135 GtkWidget* height_control; /* Height control in preference dialog */
136 GtkWidget* width_control; /* Width control in preference dialog */
137
138 guint initialized : 1; /* Should be grouped better later, */
139 guint ah_far : 1; /* placed here for binary compatibility */
140 guint ah_state : 3;
141 guint background_update_queued;
142 guint mouse_timeout;
143 //gint dyn_space; /* Space for expandable plugins */
144 //guint calculate_size_idle; /* The idle handler for dyn_space calc */
145 };
146
147 typedef struct {
148 char *name;
149 char *disp_name;
150 void (*cmd)(void);
151 } Command;
152
153 #define FBPANEL_WIN(win) gdk_window_lookup(win)
154
155 /* Extracted from misc.h */
156 typedef struct {
157 int num;
158 gchar *str;
159 } pair;
160
161 extern pair allign_pair[];
162 extern pair edge_pair[];
163 extern pair width_pair[];
164 extern pair height_pair[];
165 extern pair bool_pair[];
166
167 int str2num(pair *p, const gchar *str, int defval);
168 const gchar *num2str(pair *p, int num, const gchar *defval);
169
170 #ifdef __LXPANEL_INTERNALS__
171 static inline char *_system_config_file_name(const char *dir, const char *file_name)
172 {
173 return g_build_filename(dir, "lxpanel", cprofile, file_name, NULL);
174 }
175
176 static inline char *_old_system_config_file_name(const char *file_name)
177 {
178 return g_build_filename(PACKAGE_DATA_DIR "/profile", cprofile, file_name, NULL);
179 }
180
181 static inline char *_user_config_file_name(const char *name1, const char *name2)
182 {
183 return g_build_filename(g_get_user_config_dir(), "lxpanel", cprofile, name1,
184 name2, NULL);
185 }
186 #endif
187
188 //void _queue_panel_calculate_size(Panel *panel);
189
190 /* FIXME: optional definitions */
191 #define STATIC_SEPARATOR
192 #define STATIC_LAUNCHBAR
193 #define STATIC_LAUNCHTASKBAR
194 #define STATIC_DCLOCK
195 #define STATIC_WINCMD
196 #define STATIC_DIRMENU
197 #define STATIC_TASKBAR
198 #define STATIC_PAGER
199 #define STATIC_TRAY
200 #define STATIC_MENU
201 #define STATIC_SPACE
202 #define STATIC_ICONS
203
204 /* Plugins management - new style */
205 void _prepare_modules(void);
206 void _unload_modules(void);
207
208 GtkWidget *lxpanel_add_plugin(LXPanel *p, const char *name, config_setting_t *cfg, gint at);
209 GHashTable *lxpanel_get_all_types(void); /* transfer none */
210
211 extern GQuark lxpanel_plugin_qinit; /* access to LXPanelPluginInit data */
212 #define PLUGIN_CLASS(_i) ((LXPanelPluginInit*)g_object_get_qdata(G_OBJECT(_i),lxpanel_plugin_qinit))
213
214 extern GQuark lxpanel_plugin_qconf; /* access to congig_setting_t data */
215
216 #define PLUGIN_PANEL(_i) ((LXPanel*)gtk_widget_get_toplevel(_i))
217
218 gboolean _class_is_present(const LXPanelPluginInit *init);
219
220 LXPanel* panel_new(const char* config_file, const char* config_name);
221
222 void _panel_show_config_dialog(LXPanel *panel, GtkWidget *p, GtkWidget *dlg);
223
224 void _calculate_position(LXPanel *panel);
225
226 void _panel_determine_background_pixmap(LXPanel * p, GtkWidget * widget);
227 void _panel_establish_autohide(LXPanel *p);
228 void _panel_set_wm_strut(LXPanel *p);
229 void _panel_set_panel_configuration_changed(LXPanel *p);
230 void _panel_queue_update_background(LXPanel *p);
231
232 void panel_configure(LXPanel* p, int sel_page);
233 gboolean panel_edge_available(Panel* p, int edge, gint monitor);
234 void restart(void);
235 void logout(void);
236 void gtk_run(void);
237
238 /* -----------------------------------------------------------------------------
239 * Deprecated declarations. Kept for compatibility with old code plugins.
240 * Should be removed and appropriate code cleaned on some of next releases. */
241
242 extern Command commands[];
243
244 /* Extracted from panel.h */
245 extern int verbose;
246
247 extern void panel_destroy(Panel *p);
248 extern void panel_adjust_geometry_terminology(Panel *p);
249 extern void panel_determine_background_pixmap(Panel * p, GtkWidget * widget, GdkWindow * window);
250 extern void panel_draw_label_text(Panel * p, GtkWidget * label, const char * text,
251 gboolean bold, float custom_size_factor,
252 gboolean custom_color);
253 extern void panel_establish_autohide(Panel *p);
254 extern void panel_image_set_from_file(Panel * p, GtkWidget * image, const char * file);
255 extern gboolean panel_image_set_icon_theme(Panel * p, GtkWidget * image, const gchar * icon);
256 extern void panel_set_wm_strut(Panel *p);
257 extern void panel_set_dock_type(Panel *p);
258 extern void panel_set_panel_configuration_changed(Panel *p);
259 extern void panel_update_background( Panel* p );
260
261 /* if current window manager is EWMH conforming. */
262 extern gboolean is_ewmh_supported;
263
264 /*
265 This function is used to re-create a new box with different
266 orientation from the old one, add all children of the old one to
267 the new one, and then destroy the old box.
268 It's mainly used when we need to change the orientation of the panel or
269 any plugin with a layout box. Since GtkHBox cannot be changed to GtkVBox,
270 recreating a new box to replace the old one is required.
271 */
272 GtkWidget* recreate_box( GtkBox* oldbox, GtkOrientation orientation );
273
274 extern const char* lxpanel_get_file_manager();
275
276
277 /* Extracted from misc.h */
278 typedef struct _Plugin Plugin;
279
280 enum { LINE_NONE, LINE_BLOCK_START, LINE_BLOCK_END, LINE_VAR };
281
282 typedef struct {
283 int num, len, type;
284 gchar str[256];
285 gchar *t[3];
286 } line;
287
288 void calculate_position(Panel *np);
289
290 extern int lxpanel_get_line(char **fp, line *s);
291 extern int lxpanel_put_line(FILE* fp, const char* format, ...);
292 #define lxpanel_put_str(fp, name, val) (G_UNLIKELY( !(val) || !*(val) )) ? 0 : lxpanel_put_line(fp, "%s=%s", name, val)
293 #define lxpanel_put_bool(fp, name, val) lxpanel_put_line(fp, "%s=%c", name, (val) ? '1' : '0')
294 #define lxpanel_put_int(fp, name, val) lxpanel_put_line(fp, "%s=%d", name, val)
295
296 GtkWidget *_gtk_image_new_from_file_scaled(const gchar *file, gint width,
297 gint height, gboolean keep_ratio);
298
299 GtkWidget * fb_button_new_from_file(
300 const gchar * image_file, int width, int height, gulong highlight_color, gboolean keep_ratio);
301 GtkWidget * fb_button_new_from_file_with_label(
302 const gchar * image_file, int width, int height, gulong highlight_color, gboolean keep_ratio, Panel * panel, const gchar * label);
303
304 void fb_button_set_from_file(GtkWidget* btn, const char* img_file, gint width, gint height, gboolean keep_ratio);
305
306 char* translate_exec_to_cmd( const char* exec, const char* icon,
307 const char* title, const char* fpath );
308
309 void show_error( GtkWindow* parent_win, const char* msg );
310
311 gboolean spawn_command_async(GtkWindow *parent_window, gchar const* workdir,
312 gchar const* cmd);
313
314 /* Parameters: const char* name, gpointer ret_value, GType type, ....NULL */
315 GtkWidget* create_generic_config_dlg( const char* title, GtkWidget* parent,
316 GSourceFunc apply_func, Plugin * plugin,
317 const char* name, ... );
318
319 extern GtkMenu* lxpanel_get_panel_menu( Panel* panel, Plugin* plugin, gboolean use_sub_menu );
320
321 gboolean lxpanel_launch_app(const char* exec, GList* files, gboolean in_terminal, char const* in_workdir);
322
323 extern GdkPixbuf* lxpanel_load_icon( const char* name, int width, int height, gboolean use_fallback );
324
325
326 /* Extracted from plugin.h */
327 struct _Plugin;
328
329 /* Support for external plugin versioning.
330 * Plugins must invoke PLUGINCLASS_VERSIONING when they instantiate PluginClass. */
331 #define PLUGINCLASS_VERSION 1
332 #define PLUGINCLASS_VERSIONING \
333 .structure_size = sizeof(PluginClass), \
334 .structure_version = PLUGINCLASS_VERSION
335
336 /* Representative of an available plugin. */
337 typedef struct {
338
339 /* Keep these first. Do not make unnecessary changes in structure layout. */
340 unsigned short structure_size; /* Structure size, for versioning support */
341 unsigned short structure_version; /* Structure version, for versioning support */
342
343 char * fname; /* Plugin file pathname */
344 int count; /* Reference count */
345 GModule * gmodule; /* Associated GModule structure */
346
347 int dynamic : 1; /* True if dynamically loaded */
348 int unused_invisible : 1; /* Unused; reserved bit */
349 int not_unloadable : 1; /* Not unloadable due to GModule restriction */
350 int one_per_system : 1; /* Special: only one possible per system, such as system tray */
351 int one_per_system_instantiated : 1; /* True if one instance exists */
352 int expand_available : 1; /* True if "stretch" option is available */
353 int expand_default : 1; /* True if "stretch" option is default */
354
355 /* These fields point within the plugin image. */
356 char * type; /* Internal name of plugin, to match external filename */
357 char * name; /* Display name of plugin for selection UI */
358 char * version; /* Version of plugin */
359 char * description; /* Brief textual description of plugin for selection UI */
360
361 int (*constructor)(struct _Plugin * plugin, char ** fp); /* Create an instance of the plugin */
362 void (*destructor)(struct _Plugin * plugin); /* Destroy an instance of the plugin */
363 void (*config)(struct _Plugin * plugin, GtkWindow * parent); /* Request the plugin to display its configuration dialog */
364 void (*save)(struct _Plugin * plugin, FILE * fp); /* Request the plugin to save its configuration to a file */
365 void (*panel_configuration_changed)(struct _Plugin * plugin); /* Request the plugin to do a full redraw after a panel configuration change */
366 } PluginClass;
367
368 /* Representative of a loaded and active plugin attached to a panel. */
369 struct _Plugin {
370 PluginClass * class; /* Back pointer to PluginClass */
371 Panel * panel; /* Back pointer to Panel */
372 GtkWidget * pwid; /* Top level widget; plugin allocates, but plugin mechanism, not plugin itself, destroys this */
373 int expand; /* Expand ("stretch") setting for container */
374 int padding; /* Padding setting for container */
375 int border; /* Border setting for container */
376 gpointer priv; /* Private context for plugin; plugin frees this in its destructor */
377 };
378
379 /* Plugins management - deprecated style, for backward compatibility */
380 extern gboolean plugin_button_press_event(GtkWidget *widget, GdkEventButton *event, Plugin *plugin);
381 /* Handler for "button_press_event" signal with Plugin as parameter */
382 extern void plugin_adjust_popup_position(GtkWidget * popup, Plugin * plugin);
383 /* Helper to move popup windows away from the panel */
384 extern void plugin_popup_set_position_helper(Plugin * p, GtkWidget * near, GtkWidget * popup, GtkRequisition * popup_req, gint * px, gint * py);
385 /* Helper for position-calculation callback for popup menus */
386
387 #endif