Make lxpanel_plugin_button_press_event() static - plugins should never need it.
[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
17fab6e5
AG
22#include "plugin.h"
23#include "conf.h"
b31cb1d2
AG
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
908d9fdc
AG
37/* -----------------------------------------------------------------------------
38 * Definitions used by lxpanel main code internally */
39
b31cb1d2
AG
40/* Extracted from panel.h */
41enum { ALLIGN_NONE, ALLIGN_LEFT, ALLIGN_CENTER, ALLIGN_RIGHT };
42enum { EDGE_NONE=0, EDGE_LEFT, EDGE_RIGHT, EDGE_TOP, EDGE_BOTTOM };
43enum { WIDTH_NONE, WIDTH_REQUEST, WIDTH_PIXEL, WIDTH_PERCENT };
44enum { HEIGHT_NONE, HEIGHT_PIXEL, HEIGHT_REQUEST };
b31cb1d2
AG
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 */
54extern gboolean is_in_lxde;
55
56/* Context of a panel on a given edge. */
57struct _Panel {
58 char* name;
a7bd16a4 59 LXPanel * topgwin; /* Main panel window */
b31cb1d2
AG
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;
cfde283a 81 guint orientation;
b31cb1d2
AG
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;
0bcf9045 97 guint fontsize;
b31cb1d2
AG
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
17fab6e5 115 PanelConf * config; /* Panel configuration data */
dd731fde 116 GSList * system_menus; /* List of plugins having menus: deprecated */
b31cb1d2
AG
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 */
de5a8e6c 127
5eaabb1b
AG
128 guint initialized : 1; /* Should be grouped better later, */
129 guint ah_far : 1; /* placed here for binary compatibility */
130 guint ah_state : 3;
131 guint mouse_timeout;
de5a8e6c
AG
132 //gint dyn_space; /* Space for expandable plugins */
133 //guint calculate_size_idle; /* The idle handler for dyn_space calc */
b31cb1d2
AG
134};
135
136typedef struct {
137 char *name;
138 char *disp_name;
139 void (*cmd)(void);
140} Command;
141
142extern Command commands[];
143
b31cb1d2
AG
144#define FBPANEL_WIN(win) gdk_window_lookup(win)
145
b31cb1d2 146/* Extracted from misc.h */
b31cb1d2
AG
147typedef struct {
148 int num;
149 gchar *str;
150} pair;
151
152extern pair allign_pair[];
153extern pair edge_pair[];
154extern pair width_pair[];
155extern pair height_pair[];
156extern pair bool_pair[];
b31cb1d2 157
17fab6e5
AG
158int str2num(pair *p, const gchar *str, int defval);
159const gchar *num2str(pair *p, int num, const gchar *defval);
b31cb1d2 160
1f4bc3aa
AG
161#ifdef __LXPANEL_INTERNALS__
162static inline char *_system_config_file_name(const char *file_name)
163{
164 return g_build_filename(PACKAGE_SYSCONF_DIR, cprofile, file_name, NULL);
165}
166
167static inline char *_old_system_config_file_name(const char *file_name)
168{
169 return g_build_filename(PACKAGE_DATA_DIR "/profile", cprofile, file_name, NULL);
170}
171
172static inline char *_user_config_file_name(const char *name1, const char *name2)
173{
174 return g_build_filename(g_get_user_config_dir(), "lxpanel", cprofile, name1,
175 name2, NULL);
176}
177#endif
908d9fdc 178
de5a8e6c
AG
179//void _queue_panel_calculate_size(Panel *panel);
180
049061d8
AG
181/* FIXME: optional definitions */
182#define STATIC_SEPARATOR
183#define STATIC_LAUNCHBAR
89930ab6 184#define STATIC_LAUNCHTASKBAR
049061d8
AG
185#define STATIC_DCLOCK
186#define STATIC_WINCMD
187#define STATIC_DIRMENU
188#define STATIC_TASKBAR
189#define STATIC_PAGER
190#define STATIC_TRAY
191#define STATIC_MENU
192#define STATIC_SPACE
193#define STATIC_ICONS
194
195/* Plugins management - new style */
196void _prepare_modules(void);
197void _unload_modules(void);
198
a7bd16a4 199GtkWidget *lxpanel_add_plugin(LXPanel *p, const char *name, config_setting_t *cfg, gint at);
049061d8
AG
200GHashTable *lxpanel_get_all_types(void); /* transfer none */
201
202GQuark lxpanel_plugin_qinit; /* access to LXPanelPluginInit data */
203#define PLUGIN_CLASS(_i) ((LXPanelPluginInit*)g_object_get_qdata(G_OBJECT(_i),lxpanel_plugin_qinit))
204
205GQuark lxpanel_plugin_qconf; /* access to congig_setting_t data */
206
a7bd16a4 207#define PLUGIN_PANEL(_i) ((LXPanel*)gtk_widget_get_toplevel(_i))
908d9fdc 208
10d93053
AG
209gboolean _class_is_present(LXPanelPluginInit *init);
210
a7bd16a4
AG
211void _panel_show_config_dialog(LXPanel *panel, GtkWidget *p, GtkWidget *dlg);
212
213void _calculate_position(LXPanel *panel);
214
215void _panel_determine_background_pixmap(LXPanel * p, GtkWidget * widget);
216void _panel_establish_autohide(LXPanel *p);
217void _panel_set_wm_strut(LXPanel *p);
218void _panel_set_panel_configuration_changed(LXPanel *p);
219void _panel_update_background(LXPanel *p);
131514c9 220
908d9fdc
AG
221/* -----------------------------------------------------------------------------
222 * Deprecated declarations. Kept for compatibility with old code plugins.
223 * Should be removed and appropriate code cleaned on some of next releases. */
224
8dfa5918 225/* Extracted from panel.h */
f9e8104e
AG
226extern int verbose;
227
a7bd16a4
AG
228extern void panel_destroy(Panel *p);
229extern void panel_adjust_geometry_terminology(Panel *p);
230extern void panel_determine_background_pixmap(Panel * p, GtkWidget * widget, GdkWindow * window);
231extern void panel_draw_label_text(Panel * p, GtkWidget * label, const char * text,
232 gboolean bold, float custom_size_factor,
233 gboolean custom_color);
234extern void panel_establish_autohide(Panel *p);
235extern void panel_image_set_from_file(Panel * p, GtkWidget * image, const char * file);
236extern gboolean panel_image_set_icon_theme(Panel * p, GtkWidget * image, const gchar * icon);
237extern void panel_set_wm_strut(Panel *p);
238extern void panel_set_dock_type(Panel *p);
239extern void panel_set_panel_configuration_changed(Panel *p);
240extern void panel_update_background( Panel* p );
241
f9e8104e
AG
242/* if current window manager is EWMH conforming. */
243extern gboolean is_ewmh_supported;
244
245/*
246 This function is used to re-create a new box with different
247 orientation from the old one, add all children of the old one to
248 the new one, and then destroy the old box.
249 It's mainly used when we need to change the orientation of the panel or
250 any plugin with a layout box. Since GtkHBox cannot be changed to GtkVBox,
251 recreating a new box to replace the old one is required.
252*/
253GtkWidget* recreate_box( GtkBox* oldbox, GtkOrientation orientation );
254
8dfa5918
AG
255extern const char* lxpanel_get_file_manager();
256
257
908d9fdc
AG
258/* Extracted from misc.h */
259typedef struct _Plugin Plugin;
260
261enum { LINE_NONE, LINE_BLOCK_START, LINE_BLOCK_END, LINE_VAR };
262
263typedef struct {
264 int num, len, type;
265 gchar str[256];
266 gchar *t[3];
267} line;
268
a7bd16a4 269void calculate_position(Panel *np);
908d9fdc 270
b31cb1d2
AG
271extern int lxpanel_get_line(char **fp, line *s);
272extern int lxpanel_put_line(FILE* fp, const char* format, ...);
273#define lxpanel_put_str(fp, name, val) (G_UNLIKELY( !(val) || !*(val) )) ? 0 : lxpanel_put_line(fp, "%s=%s", name, val)
274#define lxpanel_put_bool(fp, name, val) lxpanel_put_line(fp, "%s=%c", name, (val) ? '1' : '0')
275#define lxpanel_put_int(fp, name, val) lxpanel_put_line(fp, "%s=%d", name, val)
b31cb1d2
AG
276
277GtkWidget *_gtk_image_new_from_file_scaled(const gchar *file, gint width,
278 gint height, gboolean keep_ratio);
279
c8e5ebb2
AG
280GtkWidget * fb_button_new_from_file(
281 const gchar * image_file, int width, int height, gulong highlight_color, gboolean keep_ratio);
282GtkWidget * fb_button_new_from_file_with_label(
dd731fde 283 const gchar * image_file, int width, int height, gulong highlight_color, gboolean keep_ratio, Panel * panel, const gchar * label);
c8e5ebb2
AG
284
285void fb_button_set_from_file(GtkWidget* btn, const char* img_file, gint width, gint height, gboolean keep_ratio);
286
b31cb1d2
AG
287char* translate_exec_to_cmd( const char* exec, const char* icon,
288 const char* title, const char* fpath );
289
290void show_error( GtkWindow* parent_win, const char* msg );
291
aaaef690
AG
292gboolean spawn_command_async(GtkWindow *parent_window, gchar const* workdir,
293 gchar const* cmd);
294
b31cb1d2
AG
295/* Parameters: const char* name, gpointer ret_value, GType type, ....NULL */
296GtkWidget* create_generic_config_dlg( const char* title, GtkWidget* parent,
297 GSourceFunc apply_func, Plugin * plugin,
298 const char* name, ... );
299
300extern GtkMenu* lxpanel_get_panel_menu( Panel* panel, Plugin* plugin, gboolean use_sub_menu );
301
302gboolean lxpanel_launch_app(const char* exec, GList* files, gboolean in_terminal, char const* in_workdir);
303
63e2d9e5
AG
304extern GdkPixbuf* lxpanel_load_icon( const char* name, int width, int height, gboolean use_fallback );
305
b31cb1d2
AG
306
307/* Extracted from plugin.h */
308struct _Plugin;
309
310/* Support for external plugin versioning.
311 * Plugins must invoke PLUGINCLASS_VERSIONING when they instantiate PluginClass. */
312#define PLUGINCLASS_VERSION 1
313#define PLUGINCLASS_VERSIONING \
314 .structure_size = sizeof(PluginClass), \
315 .structure_version = PLUGINCLASS_VERSION
316
317/* Representative of an available plugin. */
318typedef struct {
319
320 /* Keep these first. Do not make unnecessary changes in structure layout. */
321 unsigned short structure_size; /* Structure size, for versioning support */
322 unsigned short structure_version; /* Structure version, for versioning support */
323
324 char * fname; /* Plugin file pathname */
325 int count; /* Reference count */
326 GModule * gmodule; /* Associated GModule structure */
327
328 int dynamic : 1; /* True if dynamically loaded */
329 int unused_invisible : 1; /* Unused; reserved bit */
330 int not_unloadable : 1; /* Not unloadable due to GModule restriction */
331 int one_per_system : 1; /* Special: only one possible per system, such as system tray */
332 int one_per_system_instantiated : 1; /* True if one instance exists */
333 int expand_available : 1; /* True if "stretch" option is available */
334 int expand_default : 1; /* True if "stretch" option is default */
335
336 /* These fields point within the plugin image. */
337 char * type; /* Internal name of plugin, to match external filename */
338 char * name; /* Display name of plugin for selection UI */
339 char * version; /* Version of plugin */
340 char * description; /* Brief textual description of plugin for selection UI */
341
342 int (*constructor)(struct _Plugin * plugin, char ** fp); /* Create an instance of the plugin */
343 void (*destructor)(struct _Plugin * plugin); /* Destroy an instance of the plugin */
344 void (*config)(struct _Plugin * plugin, GtkWindow * parent); /* Request the plugin to display its configuration dialog */
345 void (*save)(struct _Plugin * plugin, FILE * fp); /* Request the plugin to save its configuration to a file */
346 void (*panel_configuration_changed)(struct _Plugin * plugin); /* Request the plugin to do a full redraw after a panel configuration change */
347} PluginClass;
348
349/* Representative of a loaded and active plugin attached to a panel. */
350struct _Plugin {
351 PluginClass * class; /* Back pointer to PluginClass */
352 Panel * panel; /* Back pointer to Panel */
353 GtkWidget * pwid; /* Top level widget; plugin allocates, but plugin mechanism, not plugin itself, destroys this */
354 int expand; /* Expand ("stretch") setting for container */
355 int padding; /* Padding setting for container */
356 int border; /* Border setting for container */
357 gpointer priv; /* Private context for plugin; plugin frees this in its destructor */
358};
359
360/* Plugins management - deprecated style, for backward compatibility */
b31cb1d2
AG
361extern gboolean plugin_button_press_event(GtkWidget *widget, GdkEventButton *event, Plugin *plugin);
362 /* Handler for "button_press_event" signal with Plugin as parameter */
363extern void plugin_adjust_popup_position(GtkWidget * popup, Plugin * plugin);
364 /* Helper to move popup windows away from the panel */
365extern void plugin_popup_set_position_helper(Plugin * p, GtkWidget * near, GtkWidget * popup, GtkRequisition * popup_req, gint * px, gint * py);
366 /* Helper for position-calculation callback for popup menus */
367
b31cb1d2 368#endif