Move get_button_spacing() into private.h - it should be deprecated.
[lxde/lxpanel.git] / src / misc.h
1 /**
2 * Copyright (c) 2006-2014 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__ 1
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 #include <libfm/fm.h>
28
29 #include "panel.h"
30
31 G_BEGIN_DECLS
32
33 extern Atom a_UTF8_STRING;
34 extern Atom a_XROOTPMAP_ID;
35
36 extern Atom a_WM_STATE;
37 extern Atom a_WM_CLASS;
38 extern Atom a_WM_DELETE_WINDOW;
39 extern Atom a_WM_PROTOCOLS;
40 extern Atom a_NET_WORKAREA;
41 extern Atom a_NET_CLIENT_LIST;
42 extern Atom a_NET_CLIENT_LIST_STACKING;
43 extern Atom a_NET_NUMBER_OF_DESKTOPS;
44 extern Atom a_NET_CURRENT_DESKTOP;
45 extern Atom a_NET_DESKTOP_VIEWPORT;
46 extern Atom a_NET_DESKTOP_NAMES;
47 extern Atom a_NET_ACTIVE_WINDOW;
48 extern Atom a_NET_CLOSE_WINDOW;
49 extern Atom a_NET_SHOWING_DESKTOP;
50 extern Atom a_NET_SUPPORTED;
51 extern Atom a_NET_WM_STATE;
52 extern Atom a_NET_WM_STATE_SKIP_TASKBAR;
53 extern Atom a_NET_WM_STATE_SKIP_PAGER;
54 extern Atom a_NET_WM_STATE_STICKY;
55 extern Atom a_NET_WM_STATE_HIDDEN;
56 extern Atom a_NET_WM_STATE_SHADED;
57
58 #define a_NET_WM_STATE_REMOVE 0 /* remove/unset property */
59 #define a_NET_WM_STATE_ADD 1 /* add/set property */
60 #define a_NET_WM_STATE_TOGGLE 2 /* toggle property */
61
62 extern Atom a_NET_WM_WINDOW_TYPE;
63 extern Atom a_NET_WM_WINDOW_TYPE_DESKTOP;
64 extern Atom a_NET_WM_WINDOW_TYPE_DOCK;
65 extern Atom a_NET_WM_WINDOW_TYPE_TOOLBAR;
66 extern Atom a_NET_WM_WINDOW_TYPE_MENU;
67 extern Atom a_NET_WM_WINDOW_TYPE_UTILITY;
68 extern Atom a_NET_WM_WINDOW_TYPE_SPLASH;
69 extern Atom a_NET_WM_WINDOW_TYPE_DIALOG;
70 extern Atom a_NET_WM_WINDOW_TYPE_NORMAL;
71
72 extern Atom a_NET_WM_DESKTOP;
73 extern Atom a_NET_WM_NAME;
74 extern Atom a_NET_WM_VISIBLE_NAME;
75 extern Atom a_NET_WM_STRUT;
76 extern Atom a_NET_WM_STRUT_PARTIAL;
77 extern Atom a_NET_WM_ICON;
78 extern Atom a_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR;
79
80 extern Atom a_NET_SYSTEM_TRAY_OPCODE;
81 extern Atom a_NET_SYSTEM_TRAY_MESSAGE_DATA;
82 extern Atom a_NET_SYSTEM_TRAY_ORIENTATION;
83 extern Atom a_MANAGER;
84
85 extern Atom a_LXPANEL_CMD; /* for private client message */
86
87 /* Decoded value of WM_STATE property. */
88 typedef struct {
89 unsigned int modal : 1;
90 unsigned int sticky : 1;
91 unsigned int maximized_vert : 1;
92 unsigned int maximized_horz : 1;
93 unsigned int shaded : 1;
94 unsigned int skip_taskbar : 1;
95 unsigned int skip_pager : 1;
96 unsigned int hidden : 1;
97 unsigned int fullscreen : 1;
98 unsigned int above : 1;
99 unsigned int below : 1;
100 } NetWMState;
101
102 /* Decoded value of _NET_WM_WINDOW_TYPE property. */
103 typedef struct {
104 unsigned int desktop : 1;
105 unsigned int dock : 1;
106 unsigned int toolbar : 1;
107 unsigned int menu : 1;
108 unsigned int utility : 1;
109 unsigned int splash : 1;
110 unsigned int dialog : 1;
111 unsigned int normal : 1;
112 } NetWMWindowType;
113
114 void Xclimsg(Window win, Atom type, long l0, long l1, long l2, long l3, long l4);
115 void Xclimsgwm(Window win, Atom type, Atom arg);
116 void *get_xaproperty (Window win, Atom prop, Atom type, int *nitems);
117 char *get_textproperty(Window win, Atom prop);
118 void *get_utf8_property(Window win, Atom atom);
119 char **get_utf8_property_list(Window win, Atom atom, int *count);
120
121 void resolve_atoms();
122 //Window Select_Window(Display *dpy);
123 int get_net_number_of_desktops();
124 int get_net_current_desktop ();
125 int get_net_wm_desktop(Window win);
126 int get_wm_state (Window win);
127 void get_net_wm_state(Window win, NetWMState *nws);
128 void get_net_wm_window_type(Window win, NetWMWindowType *nwwt);
129 GPid get_net_wm_pid(Window win);
130
131 /**
132 * panel_handle_x_error
133 * @d: X display
134 * @ev: X error event
135 *
136 * Prints X error message to stderr if logging was enabled.
137 */
138 extern int panel_handle_x_error(Display * d, XErrorEvent * ev);
139 extern int panel_handle_x_error_swallow_BadWindow_BadDrawable(Display * d, XErrorEvent * ev);
140
141 /**
142 * expand_tilda
143 * @file: file path
144 *
145 * If first char of @file is a tilda (~) then replaces it with content of
146 * environment variable HOME.
147 *
148 * Returns: (transfer full): new allocated path string.
149 */
150 gchar *expand_tilda(const gchar *file);
151
152 /**
153 * gcolor2rgb24
154 * @color: a color structure
155 *
156 * Creates integer @color representation which can be easily converted
157 * into string using printf conversion "#%06x".
158 *
159 * Returns: a 32-bit integer.
160 */
161 guint32 gcolor2rgb24(GdkColor *color);
162
163 /**
164 * lxpanel_button_new_for_icon
165 * @panel: panel instance
166 * @name: icon name or path
167 * @color: (allow-none): hilight color for icon
168 * @label: (allow-none): optional label for button
169 *
170 * Creates new #GtkEventBox button which will follow theme and icon size
171 * changes on @panel. If icon name is not found in theme then fallback
172 * name "application-x-executable" will be used. Button is flagged to be
173 * displayed.
174 *
175 * Returns: (transfer full): a new #GtkEventBox widget.
176 */
177 extern GtkWidget *lxpanel_button_new_for_icon(LXPanel *panel, const gchar *name, GdkColor *color, const gchar *label);
178 extern GtkWidget *lxpanel_button_new_for_fm_icon(LXPanel *panel, FmIcon *icon, GdkColor *color, const gchar *label);
179
180 /**
181 * lxpanel_button_set_icon
182 * @btn: a button instance
183 * @name: icon name or path
184 * @size: new icon size
185 *
186 * Updates icon in the button created with lxpanel_button_new_for_icon()
187 * or lxpanel_button_new_for_fm_icon() before. If @size > 0 then stop
188 * following panel icon size and use this fixed size, if @size is 0 then
189 * do no changes on icons size.
190 */
191 extern void lxpanel_button_set_icon(GtkWidget* btn, const gchar *name, gint size);
192 extern void lxpanel_button_update_icon(GtkWidget* btn, FmIcon *icon, gint size);
193
194 /**
195 * lxpanel_button_set_label
196 * @btn: a button instance
197 * @label: new label text
198 *
199 * Changes text of label created with lxpanel_button_new_for_icon(),
200 * lxpanel_button_new_for_fm_icon(), or lxpanel_button_compose(). Does
201 * nothing if those API were called with NULL passed as label.
202 *
203 * Returns: %TRUE in case of success.
204 *
205 * Since: 0.8.0
206 */
207 extern gboolean lxpanel_button_set_label(GtkWidget *btn, const char *label);
208
209 /**
210 * lxpanel_button_compose
211 * @event_box: a widget to add image and label
212 * @image: an image widget
213 * @color: (allow-none): hilight color for icon
214 * @label: (allow-none): optional label for button
215 *
216 * Composes button similarly to lxpanel_button_new_for_icon() but using
217 * existing container @event_box and @image. The @image should be created
218 * using lxpanel_image_new_for_icon() or lxpanel_image_new_for_fm_icon(),
219 * and it can be updated later using lxpanel_button_set_icon() API.
220 *
221 * Returns: (transfer none): @event_box.
222 *
223 * Since: 0.8.0
224 */
225 extern GtkWidget *lxpanel_button_compose(GtkWidget *event_box, GtkWidget *image,
226 GdkColor *color, const gchar *label);
227
228 /**
229 * lxpanel_image_new_for_icon
230 * @panel: (allow-none): panel instance
231 * @name: icon name or image path
232 * @height: image size
233 * @fallback: (allow-none): fallback image name or path
234 *
235 * Creates new #GtkImage which will follow theme if @name is a themed
236 * icon name. If @height is -1 then created image will also follow icon
237 * size changes on @panel. If icon not found in theme and @fallback is
238 * not %NULL then it will be used to load icon or image. Otherwise the
239 * "application-x-executable" will be used as fallback.
240 *
241 * Returns: (transfer full): a new #GtkImage widget.
242 *
243 * Since: 0.8.0
244 */
245 extern GtkWidget *lxpanel_image_new_for_icon(LXPanel *panel, const gchar *name,
246 gint height, const gchar *fallback);
247 extern GtkWidget *lxpanel_image_new_for_fm_icon(LXPanel *panel, FmIcon *icon,
248 gint height, const gchar *fallback);
249
250 /**
251 * lxpanel_image_change_icon
252 * @img: an image
253 * @name: icon name or image path
254 * @fallback: (allow-none): fallback image name or path
255 *
256 * Changes an image @img created by lxpanel_image_new_for_icon() to use
257 * new icon @name and @fallback.
258 *
259 * Returns: %TRUE.
260 *
261 * Since: 0.8.0
262 */
263 extern gboolean lxpanel_image_change_icon(GtkWidget *img, const gchar *name,
264 const char *fallback);
265
266 G_END_DECLS
267
268 #endif