Merging upstream version 0.8.0 (Closes: #639729, #761971).
[debian/lxpanel.git] / src / misc.h
CommitLineData
6cc5e1a6 1/**
00916e98 2 * Copyright (c) 2006-2014 LxDE Developers, see the file AUTHORS for details.
6cc5e1a6
DB
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
00916e98
AG
19#ifndef __MISC_H__
20#define __MISC_H__ 1
6cc5e1a6
DB
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>
00916e98 27#include <libfm/fm.h>
6cc5e1a6
DB
28
29#include "panel.h"
6cc5e1a6 30
00916e98
AG
31G_BEGIN_DECLS
32
33extern Atom a_UTF8_STRING;
34extern Atom a_XROOTPMAP_ID;
35
36extern Atom a_WM_STATE;
37extern Atom a_WM_CLASS;
38extern Atom a_WM_DELETE_WINDOW;
39extern Atom a_WM_PROTOCOLS;
40extern Atom a_NET_WORKAREA;
41extern Atom a_NET_CLIENT_LIST;
42extern Atom a_NET_CLIENT_LIST_STACKING;
43extern Atom a_NET_NUMBER_OF_DESKTOPS;
44extern Atom a_NET_CURRENT_DESKTOP;
45extern Atom a_NET_DESKTOP_VIEWPORT;
46extern Atom a_NET_DESKTOP_NAMES;
47extern Atom a_NET_ACTIVE_WINDOW;
48extern Atom a_NET_CLOSE_WINDOW;
49extern Atom a_NET_SHOWING_DESKTOP;
50extern Atom a_NET_SUPPORTED;
51extern Atom a_NET_WM_STATE;
52extern Atom a_NET_WM_STATE_SKIP_TASKBAR;
53extern Atom a_NET_WM_STATE_SKIP_PAGER;
54extern Atom a_NET_WM_STATE_STICKY;
55extern Atom a_NET_WM_STATE_HIDDEN;
56extern 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
62extern Atom a_NET_WM_WINDOW_TYPE;
63extern Atom a_NET_WM_WINDOW_TYPE_DESKTOP;
64extern Atom a_NET_WM_WINDOW_TYPE_DOCK;
65extern Atom a_NET_WM_WINDOW_TYPE_TOOLBAR;
66extern Atom a_NET_WM_WINDOW_TYPE_MENU;
67extern Atom a_NET_WM_WINDOW_TYPE_UTILITY;
68extern Atom a_NET_WM_WINDOW_TYPE_SPLASH;
69extern Atom a_NET_WM_WINDOW_TYPE_DIALOG;
70extern Atom a_NET_WM_WINDOW_TYPE_NORMAL;
71
72extern Atom a_NET_WM_DESKTOP;
73extern Atom a_NET_WM_NAME;
74extern Atom a_NET_WM_VISIBLE_NAME;
75extern Atom a_NET_WM_STRUT;
76extern Atom a_NET_WM_STRUT_PARTIAL;
77extern Atom a_NET_WM_ICON;
78extern Atom a_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR;
79
80extern Atom a_NET_SYSTEM_TRAY_OPCODE;
81extern Atom a_NET_SYSTEM_TRAY_MESSAGE_DATA;
82extern Atom a_NET_SYSTEM_TRAY_ORIENTATION;
83extern Atom a_MANAGER;
84
85extern Atom a_LXPANEL_CMD; /* for private client message */
86
87/* Decoded value of WM_STATE property. */
6cc5e1a6 88typedef struct {
00916e98
AG
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. */
6cc5e1a6 103typedef struct {
00916e98
AG
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;
6cc5e1a6 113
1ea75322 114void Xclimsg(Window win, Atom type, long l0, long l1, long l2, long l3, long l4);
6cc5e1a6
DB
115void Xclimsgwm(Window win, Atom type, Atom arg);
116void *get_xaproperty (Window win, Atom prop, Atom type, int *nitems);
117char *get_textproperty(Window win, Atom prop);
118void *get_utf8_property(Window win, Atom atom);
119char **get_utf8_property_list(Window win, Atom atom, int *count);
120
121void resolve_atoms();
122//Window Select_Window(Display *dpy);
123int get_net_number_of_desktops();
124int get_net_current_desktop ();
125int get_net_wm_desktop(Window win);
126int get_wm_state (Window win);
127void get_net_wm_state(Window win, NetWMState *nws);
128void get_net_wm_window_type(Window win, NetWMWindowType *nwwt);
129GPid get_net_wm_pid(Window win);
130
00916e98
AG
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 */
138extern int panel_handle_x_error(Display * d, XErrorEvent * ev);
139extern int panel_handle_x_error_swallow_BadWindow_BadDrawable(Display * d, XErrorEvent * ev);
140
89173f95
AG
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 */
00916e98 150gchar *expand_tilda(const gchar *file);
1ea75322 151
89173f95
AG
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 */
6cc5e1a6 161guint32 gcolor2rgb24(GdkColor *color);
89173f95
AG
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 */
177extern GtkWidget *lxpanel_button_new_for_icon(LXPanel *panel, const gchar *name, GdkColor *color, const gchar *label);
178extern 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 */
191extern void lxpanel_button_set_icon(GtkWidget* btn, const gchar *name, gint size);
192extern 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 */
207extern 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 */
225extern 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 */
245extern GtkWidget *lxpanel_image_new_for_icon(LXPanel *panel, const gchar *name,
246 gint height, const gchar *fallback);
247extern 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 */
263extern gboolean lxpanel_image_change_icon(GtkWidget *img, const gchar *name,
264 const char *fallback);
10862fa6 265
00916e98 266G_END_DECLS
6cc5e1a6
DB
267
268#endif