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