Move internal data into 'private.h' header for better new plugins design.
[lxde/lxpanel.git] / src / private.h
CommitLineData
b31cb1d2
AG
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
24#include <gmodule.h>
25
26#include <gtk/gtk.h>
27#include <gdk/gdk.h>
28#include <stdio.h>
29#include "panel.h"
30
31#include <gdk/gdk.h>
32
33#include "bg.h"
34#include "ev.h"
35
36/* Extracted from panel.h */
37enum { ALLIGN_NONE, ALLIGN_LEFT, ALLIGN_CENTER, ALLIGN_RIGHT };
38enum { EDGE_NONE=0, EDGE_LEFT, EDGE_RIGHT, EDGE_TOP, EDGE_BOTTOM };
39enum { WIDTH_NONE, WIDTH_REQUEST, WIDTH_PIXEL, WIDTH_PERCENT };
40enum { HEIGHT_NONE, HEIGHT_PIXEL, HEIGHT_REQUEST };
41enum {
42 ORIENT_NONE = -1,
43 ORIENT_VERT = GTK_ORIENTATION_VERTICAL,
44 ORIENT_HORIZ = GTK_ORIENTATION_HORIZONTAL
45};
46enum { POS_NONE, POS_START, POS_END };
47
48#define PANEL_ICON_SIZE 24 /* Default size of panel icons */
49#define PANEL_HEIGHT_DEFAULT 26 /* Default height of horizontal panel */
50#define PANEL_WIDTH_DEFAULT 150 /* Default "height" of vertical panel */
51#define PANEL_HEIGHT_MAX 200 /* Maximum height of panel */
52#define PANEL_HEIGHT_MIN 16 /* Minimum height of panel */
53#define PANEL_ICON_HIGHLIGHT 0x202020 /* Constant to pass to icon loader */
54
55/* to check if we are in LXDE */
56extern gboolean is_in_lxde;
57
58/* Context of a panel on a given edge. */
59struct _Panel {
60 char* name;
61 GtkWidget * topgwin; /* Main panel window */
62 Window topxwin; /* Main panel's X window */
63 GdkDisplay * display; /* Main panel's GdkDisplay */
64 GtkStyle * defstyle;
65 GtkIconTheme* icon_theme; /*Default icon theme*/
66
67 GtkWidget * box; /* Top level widget */
68
69 GtkRequisition requisition;
70 GtkWidget *(*my_box_new) (gboolean, gint);
71 GtkWidget *(*my_separator_new) ();
72
73 FbBg *bg;
74 int alpha;
75 guint32 tintcolor;
76 guint32 fontcolor;
77 GdkColor gtintcolor;
78 GdkColor gfontcolor;
79
80 int ax, ay, aw, ah; /* prefferd allocation of a panel */
81 int cx, cy, cw, ch; /* current allocation (as reported by configure event) allocation */
82 int allign, edge, margin;
83 int orientation;
84 int widthtype, width;
85 int heighttype, height;
86 gint monitor;
87 gulong strut_size; /* Values for WM_STRUT_PARTIAL */
88 gulong strut_lower;
89 gulong strut_upper;
90 int strut_edge;
91
92 guint config_changed : 1;
93 guint self_destroy : 1;
94 guint setdocktype : 1;
95 guint setstrut : 1;
96 guint round_corners : 1;
97 guint usefontcolor : 1;
98 guint usefontsize : 1;
99 guint fontsize;
100 guint transparent : 1;
101 guint background : 1;
102 guint spacing;
103
104 guint autohide : 1;
105 guint visible : 1;
106 int height_when_hidden;
107 guint hide_timeout;
108 int icon_size; /* Icon size */
109
110 int desknum;
111 int curdesk;
112 guint32 *workarea;
113 int wa_len;
114
115 char* background_file;
116
117 GList * plugins; /* List of all plugins */
118 GSList * system_menus; /* List of plugins having menus */
119
120 GtkWidget* plugin_pref_dialog; /* Plugin preference dialog */
121 GtkWidget* pref_dialog; /* preference dialog */
122 GtkWidget* margin_control; /* Margin control in preference dialog */
123 GtkWidget* height_label; /* Label of height control */
124 GtkWidget* width_label; /* Label of width control */
125 GtkWidget* alignment_left_label; /* Label of alignment: left control */
126 GtkWidget* alignment_right_label; /* Label of alignment: right control */
127 GtkWidget* height_control; /* Height control in preference dialog */
128 GtkWidget* width_control; /* Width control in preference dialog */
129};
130
131typedef struct {
132 char *name;
133 char *disp_name;
134 void (*cmd)(void);
135} Command;
136
137extern Command commands[];
138
139extern FbEv *fbev;
140
141#define FBPANEL_WIN(win) gdk_window_lookup(win)
142
143
144/* Extracted from misc.h */
145typedef struct _Plugin Plugin;
146
147enum _PluginConfType {
148 CONF_TYPE_STR,
149 CONF_TYPE_INT,
150 CONF_TYPE_BOOL,
151 CONF_TYPE_FILE,
152 CONF_TYPE_FILE_ENTRY,
153 CONF_TYPE_DIRECTORY_ENTRY,
154 CONF_TYPE_TRIM
155};
156
157enum { LINE_NONE, LINE_BLOCK_START, LINE_BLOCK_END, LINE_VAR };
158
159typedef struct {
160 int num, len, type;
161 gchar str[256];
162 gchar *t[3];
163} line;
164
165
166typedef struct {
167 int num;
168 gchar *str;
169} pair;
170
171extern pair allign_pair[];
172extern pair edge_pair[];
173extern pair width_pair[];
174extern pair height_pair[];
175extern pair bool_pair[];
176extern pair pos_pair[];
177
178int str2num(pair *p, gchar *str, int defval);
179gchar *num2str(pair *p, int num, gchar *defval);
180
181extern int lxpanel_get_line(char **fp, line *s);
182extern int lxpanel_put_line(FILE* fp, const char* format, ...);
183#define lxpanel_put_str(fp, name, val) (G_UNLIKELY( !(val) || !*(val) )) ? 0 : lxpanel_put_line(fp, "%s=%s", name, val)
184#define lxpanel_put_bool(fp, name, val) lxpanel_put_line(fp, "%s=%c", name, (val) ? '1' : '0')
185#define lxpanel_put_int(fp, name, val) lxpanel_put_line(fp, "%s=%d", name, val)
186//extern int lxpanel_put_str( FILE* fp, const char* name, const char* val );
187//extern int lxpanel_put_bool( FILE* fp, const char* name, gboolean val );
188//extern int lxpanel_put_int( FILE* fp, const char* name, int val );
189int get_line_as_is(char **fp, line *s);
190
191GtkWidget *_gtk_image_new_from_file_scaled(const gchar *file, gint width,
192 gint height, gboolean keep_ratio);
193
194char* translate_exec_to_cmd( const char* exec, const char* icon,
195 const char* title, const char* fpath );
196
197void show_error( GtkWindow* parent_win, const char* msg );
198
199/* Parameters: const char* name, gpointer ret_value, GType type, ....NULL */
200GtkWidget* create_generic_config_dlg( const char* title, GtkWidget* parent,
201 GSourceFunc apply_func, Plugin * plugin,
202 const char* name, ... );
203
204extern GtkMenu* lxpanel_get_panel_menu( Panel* panel, Plugin* plugin, gboolean use_sub_menu );
205
206gboolean lxpanel_launch_app(const char* exec, GList* files, gboolean in_terminal, char const* in_workdir);
207
208
209/* Extracted from plugin.h */
210struct _Plugin;
211
212/* Support for external plugin versioning.
213 * Plugins must invoke PLUGINCLASS_VERSIONING when they instantiate PluginClass. */
214#define PLUGINCLASS_VERSION 1
215#define PLUGINCLASS_VERSIONING \
216 .structure_size = sizeof(PluginClass), \
217 .structure_version = PLUGINCLASS_VERSION
218
219/* Representative of an available plugin. */
220typedef struct {
221
222 /* Keep these first. Do not make unnecessary changes in structure layout. */
223 unsigned short structure_size; /* Structure size, for versioning support */
224 unsigned short structure_version; /* Structure version, for versioning support */
225
226 char * fname; /* Plugin file pathname */
227 int count; /* Reference count */
228 GModule * gmodule; /* Associated GModule structure */
229
230 int dynamic : 1; /* True if dynamically loaded */
231 int unused_invisible : 1; /* Unused; reserved bit */
232 int not_unloadable : 1; /* Not unloadable due to GModule restriction */
233 int one_per_system : 1; /* Special: only one possible per system, such as system tray */
234 int one_per_system_instantiated : 1; /* True if one instance exists */
235 int expand_available : 1; /* True if "stretch" option is available */
236 int expand_default : 1; /* True if "stretch" option is default */
237
238 /* These fields point within the plugin image. */
239 char * type; /* Internal name of plugin, to match external filename */
240 char * name; /* Display name of plugin for selection UI */
241 char * version; /* Version of plugin */
242 char * description; /* Brief textual description of plugin for selection UI */
243
244 int (*constructor)(struct _Plugin * plugin, char ** fp); /* Create an instance of the plugin */
245 void (*destructor)(struct _Plugin * plugin); /* Destroy an instance of the plugin */
246 void (*config)(struct _Plugin * plugin, GtkWindow * parent); /* Request the plugin to display its configuration dialog */
247 void (*save)(struct _Plugin * plugin, FILE * fp); /* Request the plugin to save its configuration to a file */
248 void (*panel_configuration_changed)(struct _Plugin * plugin); /* Request the plugin to do a full redraw after a panel configuration change */
249} PluginClass;
250
251/* Representative of a loaded and active plugin attached to a panel. */
252struct _Plugin {
253 PluginClass * class; /* Back pointer to PluginClass */
254 Panel * panel; /* Back pointer to Panel */
255 GtkWidget * pwid; /* Top level widget; plugin allocates, but plugin mechanism, not plugin itself, destroys this */
256 int expand; /* Expand ("stretch") setting for container */
257 int padding; /* Padding setting for container */
258 int border; /* Border setting for container */
259 gpointer priv; /* Private context for plugin; plugin frees this in its destructor */
260};
261
262/* Plugins management - deprecated style, for backward compatibility */
263extern Plugin * plugin_load(char * type); /* Create an instance of a plugin, loading it if necessary */
264extern int plugin_start(Plugin * this, char ** fp); /* Configure and start a plugin by calling its constructor */
265extern void plugin_unload(Plugin * pl); /* Delete an instance of a plugin if initialization fails */
266extern void plugin_delete(Plugin * pl); /* Delete an instance of a plugin */
267extern GList * plugin_get_available_classes(void); /* Get a list of all plugin classes; free with plugin_class_list_free */
268extern void plugin_class_list_free(GList * list); /* Free the list allocated by plugin_get_available_classes */
269extern gboolean plugin_button_press_event(GtkWidget *widget, GdkEventButton *event, Plugin *plugin);
270 /* Handler for "button_press_event" signal with Plugin as parameter */
271extern void plugin_adjust_popup_position(GtkWidget * popup, Plugin * plugin);
272 /* Helper to move popup windows away from the panel */
273extern void plugin_popup_set_position_helper(Plugin * p, GtkWidget * near, GtkWidget * popup, GtkRequisition * popup_req, gint * px, gint * py);
274 /* Helper for position-calculation callback for popup menus */
275
276extern void plugin_widget_set_background(GtkWidget * w, Panel * p);
277 /* Recursively set the background of all widgets on a panel background configuration change */
278
279/* FIXME: optional definitions */
280#define STATIC_SEPARATOR
281#define STATIC_LAUNCHBAR
282#define STATIC_DCLOCK
283#define STATIC_WINCMD
284#define STATIC_DIRMENU
285#define STATIC_TASKBAR
286#define STATIC_PAGER
287#define STATIC_TRAY
288#define STATIC_MENU
289#define STATIC_SPACE
290#define STATIC_ICONS
291
292/* Plugins management - new style */
293gboolean lxpanel_add_plugin(Panel *p, const char *name, gint at);
294GList *lxpanel_get_all_types(void); /* transfer none */
295
296GQuark lxpanel_plugin_qinit; /* access to LXPanelPluginInit data */
297#define PLUGIN_CLASS(_i) (g_object_get_qdata(G_OBJECT(_i),lxpanel_plugin_qinit))
298
299GQuark lxpanel_plugin_qconf; /* access to congig_setting_t data */
300
301#endif