Simplify 'cpufreq' plugin using lxpanel_button_new_for_icon().
[lxde/lxpanel.git] / src / misc.h
CommitLineData
5d344669 1/**
b840f7cc 2 * Copyright (c) 2006-2014 LxDE Developers, see the file AUTHORS for details.
5d344669
AL
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
de7ff173
AG
19#ifndef __MISC_H__
20#define __MISC_H__ 1
a52c2257
HJYP
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>
911d5489 27#include <libfm/fm.h>
a52c2257
HJYP
28
29#include "panel.h"
a52c2257 30
de7ff173
AG
31G_BEGIN_DECLS
32
fd556052
AG
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
b31cb1d2 87/* Decoded value of WM_STATE property. */
a52c2257 88typedef struct {
b31cb1d2
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. */
a52c2257 103typedef struct {
b31cb1d2
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;
a52c2257 113
2918994e 114void Xclimsg(Window win, Atom type, long l0, long l1, long l2, long l3, long l4);
a52c2257
HJYP
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);
22242ed4
HJYP
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);
a52c2257 130
40a318c6
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
b8c2e0be 141gchar *expand_tilda(const gchar *file);
2918994e 142
a52c2257
HJYP
143void get_button_spacing(GtkRequisition *req, GtkContainer *parent, gchar *name);
144guint32 gcolor2rgb24(GdkColor *color);
8ec08843
AG
145
146/**
147 * lxpanel_button_new_for_icon
148 * @panel: panel instance
149 * @name: icon name or path
150 * @color: (allow-none): hilight color for icon
151 * @label: (allow-none): optional label for button
152 *
153 * Creates new #GtkEventBox button which will follow theme and icon size
154 * changes on @panel. If icon name is not found in theme then fallback
640871a1
AG
155 * name "application-x-executable" will be used. Button is flagged to be
156 * displayed.
04544a53
AG
157 *
158 * Returns: (transfer full): a new #GtkEventBox widget.
8ec08843 159 */
a3cf67bf
AG
160extern GtkWidget *lxpanel_button_new_for_icon(LXPanel *panel, const gchar *name, GdkColor *color, const gchar *label);
161extern GtkWidget *lxpanel_button_new_for_fm_icon(LXPanel *panel, FmIcon *icon, GdkColor *color, const gchar *label);
88f6fc06 162
8ec08843 163/**
88f6fc06
AG
164 * lxpanel_button_set_icon
165 * @btn: a button instance
166 * @name: icon name or path
167 * @size: new icon size
168 *
169 * Updates icon in the button created with lxpanel_button_new_for_icon()
170 * or lxpanel_button_new_for_fm_icon() before. If @size > 0 then stop
f7a4447c
AG
171 * following panel icon size and use this fixed size, if @size is 0 then
172 * do no changes on icons size.
8ec08843 173 */
a3cf67bf
AG
174extern void lxpanel_button_set_icon(GtkWidget* btn, const gchar *name, gint size);
175extern void lxpanel_button_update_icon(GtkWidget* btn, FmIcon *icon, gint size);
176
177/**
178 * lxpanel_button_compose
179 * @event_box: a widget to add image and label
180 * @image: an image widget
181 * @color: (allow-none): hilight color for icon
182 * @label: (allow-none): optional label for button
183 *
184 * Composes button similarly to lxpanel_button_new_for_icon() but using
185 * existing container @event_box and @image. The @image should be created
186 * using lxpanel_image_new_for_icon() or lxpanel_image_new_for_fm_icon(),
187 * and it can be updated later using lxpanel_button_set_icon() API.
188 *
189 * Returns: (transfer none): @event_box.
190 *
191 * Since: 0.8.0
192 */
193extern GtkWidget *lxpanel_button_compose(GtkWidget *event_box, GtkWidget *image,
194 GdkColor *color, const gchar *label);
8ec08843
AG
195
196/**
197 * lxpanel_image_new_for_icon
198 * @panel: (allow-none): panel instance
199 * @name: icon name or image path
200 * @height: image size
201 * @fallback: (allow-none): fallback image name or path
202 *
203 * Creates new #GtkImage which will follow theme if @name is a themed
204 * icon name. If @height is -1 then created image will also follow icon
205 * size changes on @panel. If icon not found in theme and @fallback is
206 * not %NULL then it will be used to load icon or image. Otherwise the
207 * "application-x-executable" will be used as fallback.
04544a53
AG
208 *
209 * Returns: (transfer full): a new #GtkImage widget.
210 *
211 * Since: 0.8.0
8ec08843 212 */
a3cf67bf
AG
213extern GtkWidget *lxpanel_image_new_for_icon(LXPanel *panel, const gchar *name,
214 gint height, const gchar *fallback);
215extern GtkWidget *lxpanel_image_new_for_fm_icon(LXPanel *panel, FmIcon *icon,
216 gint height, const gchar *fallback);
08ea5341 217
5272f2d4
AG
218/**
219 * lxpanel_image_change_icon
220 * @img: an image
221 * @name: icon name or image path
222 * @fallback: (allow-none): fallback image name or path
223 *
224 * Changes an image @img created by lxpanel_image_new_for_icon() to use
225 * new icon @name and @fallback.
04544a53
AG
226 *
227 * Returns: %TRUE.
228 *
229 * Since: 0.8.0
5272f2d4 230 */
a3cf67bf
AG
231extern gboolean lxpanel_image_change_icon(GtkWidget *img, const gchar *name,
232 const char *fallback);
5272f2d4 233
de7ff173
AG
234G_END_DECLS
235
a52c2257 236#endif