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