Merge branch 'use-libfm'
[lxde/lxpanel.git] / src / private.h
1 /**
2 * Copyright (c) 2006 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 /* -----------------------------------------------------------------------------
38 * Definitions used by lxpanel main code internally */
39
40 /* Extracted from panel.h */
41 enum { ALLIGN_NONE, ALLIGN_LEFT, ALLIGN_CENTER, ALLIGN_RIGHT };
42 enum { EDGE_NONE=0, EDGE_LEFT, EDGE_RIGHT, EDGE_TOP, EDGE_BOTTOM };
43 enum { WIDTH_NONE, WIDTH_REQUEST, WIDTH_PIXEL, WIDTH_PERCENT };
44 enum { HEIGHT_NONE, HEIGHT_PIXEL, HEIGHT_REQUEST };
45
46 #define PANEL_ICON_SIZE 24 /* Default size of panel icons */
47 #define PANEL_HEIGHT_DEFAULT 26 /* Default height of horizontal panel */
48 #define PANEL_WIDTH_DEFAULT 150 /* Default "height" of vertical panel */
49 #define PANEL_HEIGHT_MAX 200 /* Maximum height of panel */
50 #define PANEL_HEIGHT_MIN 16 /* Minimum height of panel */
51 #define PANEL_ICON_HIGHLIGHT 0x202020 /* Constant to pass to icon loader */
52
53 /* to check if we are in LXDE */
54 extern gboolean is_in_lxde;
55
56 /* Context of a panel on a given edge. */
57 struct _Panel {
58 char* name;
59 GtkWidget * topgwin; /* Main panel window */
60 Window topxwin; /* Main panel's X window */
61 GdkDisplay * display; /* Main panel's GdkDisplay */
62 GtkStyle * defstyle;
63 GtkIconTheme* icon_theme; /*Default icon theme*/
64
65 GtkWidget * box; /* Top level widget */
66
67 GtkRequisition requisition;
68 GtkWidget *(*my_box_new) (gboolean, gint);
69 GtkWidget *(*my_separator_new) ();
70
71 FbBg *bg;
72 int alpha;
73 guint32 tintcolor;
74 guint32 fontcolor;
75 GdkColor gtintcolor;
76 GdkColor gfontcolor;
77
78 int ax, ay, aw, ah; /* prefferd allocation of a panel */
79 int cx, cy, cw, ch; /* current allocation (as reported by configure event) allocation */
80 int allign, edge, margin;
81 guint orientation;
82 int widthtype, width;
83 int heighttype, height;
84 gint monitor;
85 gulong strut_size; /* Values for WM_STRUT_PARTIAL */
86 gulong strut_lower;
87 gulong strut_upper;
88 int strut_edge;
89
90 guint config_changed : 1;
91 guint self_destroy : 1;
92 guint setdocktype : 1;
93 guint setstrut : 1;
94 guint round_corners : 1;
95 guint usefontcolor : 1;
96 guint usefontsize : 1;
97 guint fontsize;
98 guint transparent : 1;
99 guint background : 1;
100 guint spacing;
101
102 guint autohide : 1;
103 guint visible : 1;
104 int height_when_hidden;
105 guint hide_timeout;
106 int icon_size; /* Icon size */
107
108 int desknum;
109 int curdesk;
110 guint32 *workarea;
111 int wa_len;
112
113 char* background_file;
114
115 PanelConf * config; /* Panel configuration data */
116 GSList * system_menus; /* List of plugins having menus */
117
118 GtkWidget* plugin_pref_dialog; /* Plugin preference dialog */
119 GtkWidget* pref_dialog; /* preference dialog */
120 GtkWidget* margin_control; /* Margin control in preference dialog */
121 GtkWidget* height_label; /* Label of height control */
122 GtkWidget* width_label; /* Label of width control */
123 GtkWidget* alignment_left_label; /* Label of alignment: left control */
124 GtkWidget* alignment_right_label; /* Label of alignment: right control */
125 GtkWidget* height_control; /* Height control in preference dialog */
126 GtkWidget* width_control; /* Width control in preference dialog */
127
128 //gint dyn_space; /* Space for expandable plugins */
129 //guint calculate_size_idle; /* The idle handler for dyn_space calc */
130 };
131
132 typedef struct {
133 char *name;
134 char *disp_name;
135 void (*cmd)(void);
136 } Command;
137
138 extern Command commands[];
139
140 extern FbEv *fbev;
141
142 #define FBPANEL_WIN(win) gdk_window_lookup(win)
143
144 /* Extracted from misc.h */
145 typedef struct {
146 int num;
147 gchar *str;
148 } pair;
149
150 extern pair allign_pair[];
151 extern pair edge_pair[];
152 extern pair width_pair[];
153 extern pair height_pair[];
154 extern pair bool_pair[];
155
156 int str2num(pair *p, const gchar *str, int defval);
157 const gchar *num2str(pair *p, int num, const gchar *defval);
158
159 char* get_config_file( const char* profile, const char* file_name, gboolean is_global );
160
161 //void _queue_panel_calculate_size(Panel *panel);
162
163 /* FIXME: optional definitions */
164 #define STATIC_SEPARATOR
165 #define STATIC_LAUNCHBAR
166 #define STATIC_LAUNCHTASKBAR
167 #define STATIC_DCLOCK
168 #define STATIC_WINCMD
169 #define STATIC_DIRMENU
170 #define STATIC_TASKBAR
171 #define STATIC_PAGER
172 #define STATIC_TRAY
173 #define STATIC_MENU
174 #define STATIC_SPACE
175 #define STATIC_ICONS
176
177 /* Plugins management - new style */
178 void _prepare_modules(void);
179 void _unload_modules(void);
180
181 GtkWidget *lxpanel_add_plugin(Panel *p, const char *name, config_setting_t *cfg, gint at);
182 GHashTable *lxpanel_get_all_types(void); /* transfer none */
183
184 GQuark lxpanel_plugin_qinit; /* access to LXPanelPluginInit data */
185 #define PLUGIN_CLASS(_i) ((LXPanelPluginInit*)g_object_get_qdata(G_OBJECT(_i),lxpanel_plugin_qinit))
186
187 GQuark lxpanel_plugin_qconf; /* access to congig_setting_t data */
188
189 GQuark lxpanel_plugin_qpanel; /* access to Panel */
190 #define PLUGIN_PANEL(_i) ((Panel*)g_object_get_qdata(G_OBJECT(_i),lxpanel_plugin_qpanel))
191
192 gboolean _class_is_present(LXPanelPluginInit *init);
193
194 /* -----------------------------------------------------------------------------
195 * Deprecated declarations. Kept for compatibility with old code plugins.
196 * Should be removed and appropriate code cleaned on some of next releases. */
197
198 /* Extracted from panel.h */
199 extern int verbose;
200
201 /* if current window manager is EWMH conforming. */
202 extern gboolean is_ewmh_supported;
203
204 /*
205 This function is used to re-create a new box with different
206 orientation from the old one, add all children of the old one to
207 the new one, and then destroy the old box.
208 It's mainly used when we need to change the orientation of the panel or
209 any plugin with a layout box. Since GtkHBox cannot be changed to GtkVBox,
210 recreating a new box to replace the old one is required.
211 */
212 GtkWidget* recreate_box( GtkBox* oldbox, GtkOrientation orientation );
213
214 extern const char* lxpanel_get_file_manager();
215
216
217 /* Extracted from misc.h */
218 typedef struct _Plugin Plugin;
219
220 enum { LINE_NONE, LINE_BLOCK_START, LINE_BLOCK_END, LINE_VAR };
221
222 typedef struct {
223 int num, len, type;
224 gchar str[256];
225 gchar *t[3];
226 } line;
227
228
229 extern int lxpanel_get_line(char **fp, line *s);
230 extern int lxpanel_put_line(FILE* fp, const char* format, ...);
231 #define lxpanel_put_str(fp, name, val) (G_UNLIKELY( !(val) || !*(val) )) ? 0 : lxpanel_put_line(fp, "%s=%s", name, val)
232 #define lxpanel_put_bool(fp, name, val) lxpanel_put_line(fp, "%s=%c", name, (val) ? '1' : '0')
233 #define lxpanel_put_int(fp, name, val) lxpanel_put_line(fp, "%s=%d", name, val)
234
235 GtkWidget *_gtk_image_new_from_file_scaled(const gchar *file, gint width,
236 gint height, gboolean keep_ratio);
237
238 GtkWidget * fb_button_new_from_file(
239 const gchar * image_file, int width, int height, gulong highlight_color, gboolean keep_ratio);
240 GtkWidget * fb_button_new_from_file_with_label(
241 const gchar * image_file, int width, int height, gulong highlight_color, gboolean keep_ratio, Panel * panel, gchar * label);
242
243 void fb_button_set_from_file(GtkWidget* btn, const char* img_file, gint width, gint height, gboolean keep_ratio);
244
245 char* translate_exec_to_cmd( const char* exec, const char* icon,
246 const char* title, const char* fpath );
247
248 void show_error( GtkWindow* parent_win, const char* msg );
249
250 gboolean spawn_command_async(GtkWindow *parent_window, gchar const* workdir,
251 gchar const* cmd);
252
253 /* Parameters: const char* name, gpointer ret_value, GType type, ....NULL */
254 GtkWidget* create_generic_config_dlg( const char* title, GtkWidget* parent,
255 GSourceFunc apply_func, Plugin * plugin,
256 const char* name, ... );
257
258 extern GtkMenu* lxpanel_get_panel_menu( Panel* panel, Plugin* plugin, gboolean use_sub_menu );
259
260 gboolean lxpanel_launch_app(const char* exec, GList* files, gboolean in_terminal, char const* in_workdir);
261
262 extern GdkPixbuf* lxpanel_load_icon( const char* name, int width, int height, gboolean use_fallback );
263
264
265 /* Extracted from plugin.h */
266 struct _Plugin;
267
268 /* Support for external plugin versioning.
269 * Plugins must invoke PLUGINCLASS_VERSIONING when they instantiate PluginClass. */
270 #define PLUGINCLASS_VERSION 1
271 #define PLUGINCLASS_VERSIONING \
272 .structure_size = sizeof(PluginClass), \
273 .structure_version = PLUGINCLASS_VERSION
274
275 /* Representative of an available plugin. */
276 typedef struct {
277
278 /* Keep these first. Do not make unnecessary changes in structure layout. */
279 unsigned short structure_size; /* Structure size, for versioning support */
280 unsigned short structure_version; /* Structure version, for versioning support */
281
282 char * fname; /* Plugin file pathname */
283 int count; /* Reference count */
284 GModule * gmodule; /* Associated GModule structure */
285
286 int dynamic : 1; /* True if dynamically loaded */
287 int unused_invisible : 1; /* Unused; reserved bit */
288 int not_unloadable : 1; /* Not unloadable due to GModule restriction */
289 int one_per_system : 1; /* Special: only one possible per system, such as system tray */
290 int one_per_system_instantiated : 1; /* True if one instance exists */
291 int expand_available : 1; /* True if "stretch" option is available */
292 int expand_default : 1; /* True if "stretch" option is default */
293
294 /* These fields point within the plugin image. */
295 char * type; /* Internal name of plugin, to match external filename */
296 char * name; /* Display name of plugin for selection UI */
297 char * version; /* Version of plugin */
298 char * description; /* Brief textual description of plugin for selection UI */
299
300 int (*constructor)(struct _Plugin * plugin, char ** fp); /* Create an instance of the plugin */
301 void (*destructor)(struct _Plugin * plugin); /* Destroy an instance of the plugin */
302 void (*config)(struct _Plugin * plugin, GtkWindow * parent); /* Request the plugin to display its configuration dialog */
303 void (*save)(struct _Plugin * plugin, FILE * fp); /* Request the plugin to save its configuration to a file */
304 void (*panel_configuration_changed)(struct _Plugin * plugin); /* Request the plugin to do a full redraw after a panel configuration change */
305 } PluginClass;
306
307 /* Representative of a loaded and active plugin attached to a panel. */
308 struct _Plugin {
309 PluginClass * class; /* Back pointer to PluginClass */
310 Panel * panel; /* Back pointer to Panel */
311 GtkWidget * pwid; /* Top level widget; plugin allocates, but plugin mechanism, not plugin itself, destroys this */
312 int expand; /* Expand ("stretch") setting for container */
313 int padding; /* Padding setting for container */
314 int border; /* Border setting for container */
315 gpointer priv; /* Private context for plugin; plugin frees this in its destructor */
316 };
317
318 /* Plugins management - deprecated style, for backward compatibility */
319 extern gboolean plugin_button_press_event(GtkWidget *widget, GdkEventButton *event, Plugin *plugin);
320 /* Handler for "button_press_event" signal with Plugin as parameter */
321 extern void plugin_adjust_popup_position(GtkWidget * popup, Plugin * plugin);
322 /* Helper to move popup windows away from the panel */
323 extern void plugin_popup_set_position_helper(Plugin * p, GtkWidget * near, GtkWidget * popup, GtkRequisition * popup_req, gint * px, gint * py);
324 /* Helper for position-calculation callback for popup menus */
325
326 #endif