Enabling multithreaded compilation.
[debian/lxpanel.git] / include / lxpanel / plugin.h
CommitLineData
10862fa6
DB
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 LXPANEL_PLUGIN_H
20#define LXPANEL_PLUGIN_H
21
22#include <X11/Xlib.h>
23#include <gtk/gtk.h>
24#include <stdio.h>
25
26typedef FbEv;
27typedef FbBg;
28typedef pair;
29
30extern FbEv *fbev;
31extern pair bool_pair[];
32
33/* Panel */
34enum { ALLIGN_NONE, ALLIGN_LEFT, ALLIGN_CENTER, ALLIGN_RIGHT };
35enum { EDGE_NONE, EDGE_LEFT, EDGE_RIGHT, EDGE_TOP, EDGE_BOTTOM };
36enum { WIDTH_NONE, WIDTH_REQUEST, WIDTH_PIXEL, WIDTH_PERCENT };
37enum { HEIGHT_NONE, HEIGHT_PIXEL, HEIGHT_REQUEST };
38enum {
39 ORIENT_NONE = -1,
40 ORIENT_VERT = GTK_ORIENTATION_VERTICAL,
41 ORIENT_HORIZ = GTK_ORIENTATION_HORIZONTAL
42};
43enum { POS_NONE, POS_START, POS_END };
44
45typedef struct _Panel Panel;
1ea75322
DB
46/* Context of a panel on a given edge. */
47typedef struct _Panel {
10862fa6 48 char* name;
1ea75322
DB
49 GtkWidget * topgwin; /* Main panel window */
50 Window topxwin; /* Main panel's X window */
51 GdkDisplay * display; /* Main panel's GdkDisplay */
52 GtkStyle * defstyle;
53
54 GtkWidget * box; /* Top level widget */
10862fa6
DB
55
56 GtkRequisition requisition;
57 GtkWidget *(*my_box_new) (gboolean, gint);
58 GtkWidget *(*my_separator_new) ();
59
60 FbBg *bg;
61 int alpha;
62 guint32 tintcolor;
63 guint32 fontcolor;
64 GdkColor gtintcolor;
65 GdkColor gfontcolor;
66
1ea75322
DB
67 int ax, ay, aw, ah; /* prefferd allocation of a panel */
68 int cx, cy, cw, ch; /* current allocation (as reported by configure event) allocation */
10862fa6
DB
69 int allign, edge, margin;
70 int orientation;
71 int widthtype, width;
72 int heighttype, height;
1ea75322
DB
73 gulong strut_size; /* Values for WM_STRUT_PARTIAL */
74 gulong strut_lower;
75 gulong strut_upper;
76 int strut_edge;
10862fa6
DB
77
78 guint config_changed : 1;
79 guint self_destroy : 1;
80 guint setdocktype : 1;
81 guint setstrut : 1;
82 guint round_corners : 1;
83 guint usefontcolor : 1;
f8c25730
DB
84 guint usefontsize : 1;
85 guint fontsize;
10862fa6
DB
86 guint transparent : 1;
87 guint background : 1;
88 guint spacing;
89
1ea75322
DB
90 guint autohide : 1;
91 guint visible : 1;
92 int height_when_hidden;
93 guint hide_timeout;
94 int icon_size; /* Icon size */
95
10862fa6
DB
96 int desknum;
97 int curdesk;
98 guint32 *workarea;
99 int wa_len;
100
101 char* background_file;
102
1ea75322
DB
103 GList * plugins; /* List of all plugins */
104 GSList * system_menus; /* List of plugins having menus */
10862fa6 105
1ea75322
DB
106 GtkWidget* plugin_pref_dialog; /* Plugin preference dialog */
107 GtkWidget* pref_dialog; /* preference dialog */
108 GtkWidget* margin_control; /* Margin control in preference dialog */
109 GtkWidget* height_label; /* Label of height control */
110 GtkWidget* width_label; /* Label of width control */
111 GtkWidget* alignment_left_label; /* Label of alignment: left control */
112 GtkWidget* alignment_right_label; /* Label of alignment: right control */
113 GtkWidget* height_control; /* Height control in preference dialog */
114 GtkWidget* width_control; /* Width control in preference dialog */
115} Panel;
10862fa6 116
1ea75322
DB
117typedef struct {
118 char *name;
119 char *disp_name;
120 void (*cmd)(void);
121} Command;
122
123extern Command commands[];
10862fa6
DB
124
125/* Plugin */
126struct _Plugin;
1ea75322
DB
127
128/* Support for external plugin versioning.
129 * Plugins must invoke PLUGINCLASS_VERSIONING when they instantiate PluginClass. */
130#define PLUGINCLASS_VERSION 1
131#define PLUGINCLASS_VERSIONING \
132 structure_size : sizeof(PluginClass), \
133 structure_version : PLUGINCLASS_VERSION
134
135/* Representative of an available plugin. */
10862fa6 136typedef struct {
10862fa6 137
1ea75322
DB
138 /* Keep these first. Do not make unnecessary changes in structure layout. */
139 unsigned short structure_size; /* Structure size, for versioning support */
140 unsigned short structure_version; /* Structure version, for versioning support */
141
142 char * fname; /* Plugin file pathname */
143 int count; /* Reference count */
144 GModule * gmodule; /* Associated GModule structure */
145
146 int dynamic : 1; /* True if dynamically loaded */
147 int unused_invisible : 1; /* Unused; reserved bit */
148 int not_unloadable : 1; /* Not unloadable due to GModule restriction */
149 int one_per_system : 1; /* Special: only one possible per system, such as system tray */
150 int one_per_system_instantiated : 1; /* True if one instance exists */
151 int expand_available : 1; /* True if "stretch" option is available */
152 int expand_default : 1; /* True if "stretch" option is default */
153
154 /* These fields point within the plugin image. */
155 char * type; /* Internal name of plugin, to match external filename */
156 char * name; /* Display name of plugin for selection UI */
157 char * version; /* Version of plugin */
158 char * description; /* Brief textual description of plugin for selection UI */
159
160 int (*constructor)(struct _Plugin * plugin, char ** fp); /* Create an instance of the plugin */
161 void (*destructor)(struct _Plugin * plugin); /* Destroy an instance of the plugin */
162 void (*config)(struct _Plugin * plugin, GtkWindow * parent); /* Request the plugin to display its configuration dialog */
163 void (*save)(struct _Plugin * plugin, FILE * fp); /* Request the plugin to save its configuration to a file */
164 void (*panel_configuration_changed)(struct _Plugin * plugin); /* Request the plugin to do a full redraw after a panel configuration change */
10862fa6
DB
165} PluginClass;
166
1ea75322
DB
167/* Representative of a loaded and active plugin attached to a panel. */
168typedef struct _Plugin {
169 PluginClass * class; /* Back pointer to PluginClass */
170 Panel * panel; /* Back pointer to Panel */
171 GtkWidget * pwid; /* Top level widget; plugin allocates, but plugin mechanism, not plugin itself, destroys this */
172 int expand; /* Expand ("stretch") setting for container */
173 int padding; /* Padding setting for container */
174 int border; /* Border setting for container */
175 gpointer priv; /* Private context for plugin; plugin frees this in its destructor */
10862fa6
DB
176} Plugin;
177
178/* misc */
179enum {
180 CONF_TYPE_STR,
181 CONF_TYPE_INT,
182 CONF_TYPE_BOOL,
183 CONF_TYPE_FILE,
f8c25730
DB
184 CONF_TYPE_FILE_ENTRY,
185 CONF_TYPE_DIRECTORY_ENTRY,
186 CONF_TYPE_TRIM
10862fa6
DB
187};
188
189enum { LINE_NONE, LINE_BLOCK_START, LINE_BLOCK_END, LINE_VAR };
190
191typedef struct {
192 int num, len, type;
193 gchar str[256];
194 gchar *t[3];
195} line;
196
197/* Config Stuffs */
198int str2num(pair *p, gchar *str, int defval);
199gchar *num2str(pair *p, int num, gchar *defval);
200
201extern int lxpanel_get_line(char **fp, line *s);
202extern int lxpanel_put_line(FILE* fp, const char* format, ...);
203#define lxpanel_put_str(fp, name, val) (G_UNLIKELY( !(val) || !*(val) )) ? 0 : lxpanel_put_line(fp, "%s=%s", name, val)
204#define lxpanel_put_bool(fp, name, val) lxpanel_put_line(fp, "%s=%c", name, (val) ? '1' : '0')
205#define lxpanel_put_int(fp, name, val) lxpanel_put_line(fp, "%s=%d", name, val)
206
207
208/* For debuging */
209#define ERR(fmt, args...) fprintf(stderr, fmt, ## args)
210#define DBG2(fmt, args...) fprintf(stderr, "%s:%s:%-5d: " fmt, __FILE__, __FUNCTION__, __LINE__, ## args)
211#define ENTER2 do { fprintf(stderr, "%s:%s:%-5d: ENTER\n", __FILE__,__FUNCTION__, __LINE__); } while(0)
212#define RET2(args...) do { fprintf(stderr, "%s:%s:%-5d: RETURN\n", __FILE__,__FUNCTION__, __LINE__);\
213return args; } while(0)
214
215enum { LOG_NONE, LOG_ERR, LOG_WARN, LOG_INFO, LOG_ALL };
216#ifdef DEBUG
217
218#define ENTER do { fprintf(stderr, "%s:%s:%-5d: ENTER\n", __FILE__,__FUNCTION__, __LINE__); } while(0)
219#define RET(args...) do { fprintf(stderr, "%s:%s:%-5d: RETURN\n", __FILE__, __FUNCTION__, __LINE__);\
220return args; } while(0)
221#define DBG(fmt, args...) fprintf(stderr, "%s:%s:%-5d: " fmt, __FILE__,__FUNCTION__, __LINE__, ## args)
222#define LOG(level, fmt, args...) fprintf(stderr, fmt, ## args)
223
224#else
225
226extern int log_level;
227#define ENTER do { } while(0)
228#define RET(args...) return args
229#define DBG(fmt, args...) do { } while(0)
230#define LOG(level, fmt, args...) do { if (level <= log_level) fprintf(stderr, fmt, ## args); } while(0)
231
232#endif
233
234/* X11 */
235extern Atom a_UTF8_STRING;
236extern Atom a_XROOTPMAP_ID;
237
238extern Atom a_WM_STATE;
239extern Atom a_WM_CLASS;
240extern Atom a_WM_DELETE_WINDOW;
241extern Atom a_WM_PROTOCOLS;
242extern Atom a_NET_WORKAREA;
243extern Atom a_NET_CLIENT_LIST;
244extern Atom a_NET_CLIENT_LIST_STACKING;
245extern Atom a_NET_NUMBER_OF_DESKTOPS;
246extern Atom a_NET_CURRENT_DESKTOP;
247extern Atom a_NET_DESKTOP_VIEWPORT;
248extern Atom a_NET_DESKTOP_NAMES;
249extern Atom a_NET_ACTIVE_WINDOW;
250extern Atom a_NET_CLOSE_WINDOW;
251extern Atom a_NET_SUPPORTED;
252extern Atom a_NET_WM_STATE;
253extern Atom a_NET_WM_STATE_SKIP_TASKBAR;
254extern Atom a_NET_WM_STATE_SKIP_PAGER;
255extern Atom a_NET_WM_STATE_STICKY;
256extern Atom a_NET_WM_STATE_HIDDEN;
257extern Atom a_NET_WM_STATE_SHADED;
258
259#define a_NET_WM_STATE_REMOVE 0 /* remove/unset property */
260#define a_NET_WM_STATE_ADD 1 /* add/set property */
261#define a_NET_WM_STATE_TOGGLE 2 /* toggle property */
262
263extern Atom a_NET_WM_WINDOW_TYPE;
264extern Atom a_NET_WM_WINDOW_TYPE_DESKTOP;
265extern Atom a_NET_WM_WINDOW_TYPE_DOCK;
266extern Atom a_NET_WM_WINDOW_TYPE_TOOLBAR;
267extern Atom a_NET_WM_WINDOW_TYPE_MENU;
268extern Atom a_NET_WM_WINDOW_TYPE_UTILITY;
269extern Atom a_NET_WM_WINDOW_TYPE_SPLASH;
270extern Atom a_NET_WM_WINDOW_TYPE_DIALOG;
271extern Atom a_NET_WM_WINDOW_TYPE_NORMAL;
272
273extern Atom a_NET_WM_DESKTOP;
274extern Atom a_NET_WM_NAME;
275extern Atom a_NET_WM_VISIBLE_NAME;
276extern Atom a_NET_WM_STRUT;
277extern Atom a_NET_WM_STRUT_PARTIAL;
278extern Atom a_NET_WM_ICON;
279extern Atom a_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR;
280extern Atom a_LXPANEL_CMD; /* for private client message */
281
282/* glib-mem */
283#include <glib.h>
284
285#if ! GLIB_CHECK_VERSION(2, 10, 0)
286/* older versions of glib don't provde g_slice API */
287#define g_slice_alloc(size) g_malloc(size)
288#define g_slice_alloc0(size) g_malloc0(size)
289#define g_slice_new(type) g_new(type, 1)
290#define g_slice_new0(type) g_new0(type, 1)
291#define g_slice_free(type, mem) g_free(mem)
292#define g_slice_free1(size, mem) g_free(mem)
293#endif
294
295#endif