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