38479721e2b53990804af537f254a931fa365b19
[debian/lxpanel.git] / src / misc.h
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 MISC_H
20 #define MISC_H
21
22 #include <X11/Xatom.h>
23 #include <gtk/gtk.h>
24 #include <gdk/gdk.h>
25 #include <gdk/gdkx.h>
26 #include <stdio.h>
27
28 #include "panel.h"
29 #include "plugin.h"
30
31 enum _PluginConfType {
32 CONF_TYPE_STR,
33 CONF_TYPE_INT,
34 CONF_TYPE_BOOL,
35 CONF_TYPE_FILE,
36 CONF_TYPE_FILE_ENTRY,
37 CONF_TYPE_DIRECTORY_ENTRY,
38 CONF_TYPE_TRIM
39 };
40
41 enum { LINE_NONE, LINE_BLOCK_START, LINE_BLOCK_END, LINE_VAR };
42
43 typedef struct {
44 int num, len, type;
45 gchar str[256];
46 gchar *t[3];
47 } line;
48
49
50 typedef struct {
51 int num;
52 gchar *str;
53 } pair;
54
55 extern pair allign_pair[];
56 extern pair edge_pair[];
57 extern pair width_pair[];
58 extern pair height_pair[];
59 extern pair bool_pair[];
60 extern pair pos_pair[];
61
62 int str2num(pair *p, gchar *str, int defval);
63 gchar *num2str(pair *p, int num, gchar *defval);
64
65 extern int lxpanel_get_line(char **fp, line *s);
66 extern int lxpanel_put_line(FILE* fp, const char* format, ...);
67 #define lxpanel_put_str(fp, name, val) (G_UNLIKELY( !(val) || !*(val) )) ? 0 : lxpanel_put_line(fp, "%s=%s", name, val)
68 #define lxpanel_put_bool(fp, name, val) lxpanel_put_line(fp, "%s=%c", name, (val) ? '1' : '0')
69 #define lxpanel_put_int(fp, name, val) lxpanel_put_line(fp, "%s=%d", name, val)
70 //extern int lxpanel_put_str( FILE* fp, const char* name, const char* val );
71 //extern int lxpanel_put_bool( FILE* fp, const char* name, gboolean val );
72 //extern int lxpanel_put_int( FILE* fp, const char* name, int val );
73 int get_line_as_is(char **fp, line *s);
74
75 void Xclimsg(Window win, Atom type, long l0, long l1, long l2, long l3, long l4);
76 void Xclimsgwm(Window win, Atom type, Atom arg);
77 void *get_xaproperty (Window win, Atom prop, Atom type, int *nitems);
78 char *get_textproperty(Window win, Atom prop);
79 void *get_utf8_property(Window win, Atom atom);
80 char **get_utf8_property_list(Window win, Atom atom, int *count);
81
82 void resolve_atoms();
83 //Window Select_Window(Display *dpy);
84 int get_net_number_of_desktops();
85 int get_net_current_desktop ();
86 int get_net_wm_desktop(Window win);
87 int get_wm_state (Window win);
88 void get_net_wm_state(Window win, NetWMState *nws);
89 void get_net_wm_window_type(Window win, NetWMWindowType *nwwt);
90 GPid get_net_wm_pid(Window win);
91
92 void calculate_position(Panel *np);
93 gchar *expand_tilda(gchar *file);
94
95 GtkWidget *_gtk_image_new_from_file_scaled(const gchar *file, gint width,
96 gint height, gboolean keep_ratio);
97 void get_button_spacing(GtkRequisition *req, GtkContainer *parent, gchar *name);
98 guint32 gcolor2rgb24(GdkColor *color);
99 GtkWidget * fb_button_new_from_file(
100 gchar * image_file, int width, int height, gulong highlight_color, gboolean keep_ratio);
101 GtkWidget * fb_button_new_from_file_with_label(
102 gchar * image_file, int width, int height, gulong highlight_color, gboolean keep_ratio, Panel * panel, gchar * label);
103
104 char* translate_exec_to_cmd( const char* exec, const char* icon,
105 const char* title, const char* fpath );
106
107 /*
108 This function is used to re-create a new box with different
109 orientation from the old one, add all children of the old one to
110 the new one, and then destroy the old box.
111 It's mainly used when we need to change the orientation of the panel or
112 any plugin with a layout box. Since GtkHBox cannot be changed to GtkVBox,
113 recreating a new box to replace the old one is required.
114 */
115 GtkWidget* recreate_box( GtkBox* oldbox, GtkOrientation orientation );
116
117 void show_error( GtkWindow* parent_win, const char* msg );
118
119 /* Parameters: const char* name, gpointer ret_value, GType type, ....NULL */
120 GtkWidget* create_generic_config_dlg( const char* title, GtkWidget* parent,
121 GSourceFunc apply_func, Plugin * plugin,
122 const char* name, ... );
123
124
125 char* get_config_file( const char* profile, const char* file_name, gboolean is_global );
126
127 extern GtkMenu* lxpanel_get_panel_menu( Panel* panel, Plugin* plugin, gboolean use_sub_menu );
128
129 extern GdkPixbuf* lxpanel_load_icon( const char* name, int width, int height, gboolean use_fallback );
130
131 void fb_button_set_from_file(GtkWidget* btn, const char* img_file, gint width, gint height, gboolean keep_ratio);
132
133 gboolean lxpanel_launch_app(const char* exec, GList* files, gboolean in_terminal);
134
135 #endif