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