1 /* 2 * Copyright (C) 2006-2010 Hong Jen Yee (PCMan) <pcman.tw@gmail.com> 3 * 2006-2008 Jim Huang <jserv.tw@gmail.com> 4 * 2008-2009 Fred Chien <fred@lxde.org> 5 * 2009 Marty Jack <martyj19@comcast.net> 6 * 2011-2013 Henry Gebhardt <hsggebhardt@gmail.com> 7 * 2014-2016 Andriy Grytsenko <andrej@rep.kiev.ua> 8 * 9 * This file is a part of LXPanel project. 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software Foundation, 23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 */ 25 26 #ifndef __MISC_H__ 27 #define __MISC_H__ 1 28 29 #include <X11/Xatom.h> 30 #include <gtk/gtk.h> 31 #include <gdk/gdk.h> 32 #include <gdk/gdkx.h> 33 #include <stdio.h> 34 #include <libfm/fm.h> 35 36 #include "panel.h" 37 38 G_BEGIN_DECLS 39 40 extern Atom a_UTF8_STRING; 41 extern Atom a_XROOTPMAP_ID; 42 43 extern Atom a_WM_STATE; 44 extern Atom a_WM_DELETE_WINDOW; 45 extern Atom a_WM_PROTOCOLS; 46 extern Atom a_NET_WORKAREA; 47 extern Atom a_NET_CLIENT_LIST; 48 extern Atom a_NET_CLIENT_LIST_STACKING; 49 extern Atom a_NET_NUMBER_OF_DESKTOPS; 50 extern Atom a_NET_CURRENT_DESKTOP; 51 extern Atom a_NET_DESKTOP_VIEWPORT; 52 extern Atom a_NET_DESKTOP_NAMES; 53 extern Atom a_NET_ACTIVE_WINDOW; 54 extern Atom a_NET_CLOSE_WINDOW; 55 extern Atom a_NET_SHOWING_DESKTOP; 56 extern Atom a_NET_SUPPORTED; 57 extern Atom a_NET_WM_STATE; 58 extern Atom a_NET_WM_STATE_SKIP_TASKBAR; 59 extern Atom a_NET_WM_STATE_SKIP_PAGER; 60 extern Atom a_NET_WM_STATE_STICKY; 61 extern Atom a_NET_WM_STATE_HIDDEN; 62 extern Atom a_NET_WM_STATE_SHADED; 63 64 #define a_NET_WM_STATE_REMOVE 0 /* remove/unset property */ 65 #define a_NET_WM_STATE_ADD 1 /* add/set property */ 66 #define a_NET_WM_STATE_TOGGLE 2 /* toggle property */ 67 68 extern Atom a_NET_WM_WINDOW_TYPE; 69 extern Atom a_NET_WM_WINDOW_TYPE_DESKTOP; 70 extern Atom a_NET_WM_WINDOW_TYPE_DOCK; 71 extern Atom a_NET_WM_WINDOW_TYPE_TOOLBAR; 72 extern Atom a_NET_WM_WINDOW_TYPE_MENU; 73 extern Atom a_NET_WM_WINDOW_TYPE_UTILITY; 74 extern Atom a_NET_WM_WINDOW_TYPE_SPLASH; 75 extern Atom a_NET_WM_WINDOW_TYPE_DIALOG; 76 extern Atom a_NET_WM_WINDOW_TYPE_NORMAL; 77 78 extern Atom a_NET_WM_DESKTOP; 79 extern Atom a_NET_WM_NAME; 80 extern Atom a_NET_WM_VISIBLE_NAME; 81 extern Atom a_NET_WM_STRUT; 82 extern Atom a_NET_WM_STRUT_PARTIAL; 83 extern Atom a_NET_WM_ICON; 84 extern Atom a_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR; 85 86 extern Atom a_NET_SYSTEM_TRAY_OPCODE; 87 extern Atom a_NET_SYSTEM_TRAY_MESSAGE_DATA; 88 extern Atom a_NET_SYSTEM_TRAY_ORIENTATION; 89 extern Atom a_MANAGER; 90 91 extern Atom a_LXPANEL_CMD; /* for private client message */ 92 93 /* Decoded value of WM_STATE property. */ 94 typedef struct { 95 unsigned int modal : 1; 96 unsigned int sticky : 1; 97 unsigned int maximized_vert : 1; 98 unsigned int maximized_horz : 1; 99 unsigned int shaded : 1; 100 unsigned int skip_taskbar : 1; 101 unsigned int skip_pager : 1; 102 unsigned int hidden : 1; 103 unsigned int fullscreen : 1; 104 unsigned int above : 1; 105 unsigned int below : 1; 106 } NetWMState; 107 108 /* Decoded value of _NET_WM_WINDOW_TYPE property. */ 109 typedef struct { 110 unsigned int desktop : 1; 111 unsigned int dock : 1; 112 unsigned int toolbar : 1; 113 unsigned int menu : 1; 114 unsigned int utility : 1; 115 unsigned int splash : 1; 116 unsigned int dialog : 1; 117 unsigned int normal : 1; 118 } NetWMWindowType; 119 120 void Xclimsgx(Screen *screen, Window win, Atom type, long l0, long l1, long l2, long l3, long l4); 121 void Xclimsgwm(Window win, Atom type, Atom arg); 122 void *get_xaproperty (Window win, Atom prop, Atom type, int *nitems); 123 char *get_textproperty(Window win, Atom prop); 124 void *get_utf8_property(Window win, Atom atom); 125 char **get_utf8_property_list(Window win, Atom atom, int *count); 126 127 void resolve_atoms(); 128 //Window Select_Window(Display *dpy); 129 int get_net_number_of_desktops(); 130 int get_net_current_desktop (); 131 int get_net_wm_desktop(Window win); 132 int get_wm_state (Window win); 133 void get_net_wm_state(Window win, NetWMState *nws); 134 void get_net_wm_window_type(Window win, NetWMWindowType *nwwt); 135 GPid get_net_wm_pid(Window win); 136 137 /** 138 * panel_handle_x_error 139 * @d: X display 140 * @ev: X error event 141 * 142 * Prints X error message to stderr if logging was enabled. 143 */ 144 extern int panel_handle_x_error(Display * d, XErrorEvent * ev); 145 extern int panel_handle_x_error_swallow_BadWindow_BadDrawable(Display * d, XErrorEvent * ev); 146 147 /** 148 * expand_tilda 149 * @file: file path 150 * 151 * If first char of @file is a tilda (~) then replaces it with content of 152 * environment variable HOME. 153 * 154 * Returns: (transfer full): new allocated path string. 155 */ 156 gchar *expand_tilda(const gchar *file); 157 158 /** 159 * gcolor2rgb24 160 * @color: a color structure 161 * 162 * Creates integer @color representation which can be easily converted 163 * into string using printf conversion "#%06x". 164 * 165 * Returns: a 32-bit integer. 166 */ 167 guint32 gcolor2rgb24(GdkColor *color); 168 169 /** 170 * lxpanel_button_new_for_icon 171 * @panel: panel instance 172 * @name: icon name or path 173 * @color: (allow-none): hilight color for icon 174 * @label: (allow-none): optional label for button 175 * 176 * Creates new #GtkEventBox button which will follow theme and icon size 177 * changes on @panel. If icon name is not found in theme then fallback 178 * name "application-x-executable" will be used. Button is flagged to be 179 * displayed. 180 * 181 * Returns: (transfer full): a new #GtkEventBox widget. 182 */ 183 extern GtkWidget *lxpanel_button_new_for_icon(LXPanel *panel, const gchar *name, GdkColor *color, const gchar *label); 184 extern GtkWidget *lxpanel_button_new_for_fm_icon(LXPanel *panel, FmIcon *icon, GdkColor *color, const gchar *label); 185 186 /** 187 * lxpanel_button_set_icon 188 * @btn: a button instance 189 * @name: icon name or path 190 * @size: new icon size 191 * 192 * Updates icon in the button created with lxpanel_button_new_for_icon() 193 * or lxpanel_button_new_for_fm_icon() before. If @size > 0 then stop 194 * following panel icon size and use this fixed size, if @size is 0 then 195 * do no changes on icons size. 196 */ 197 extern void lxpanel_button_set_icon(GtkWidget* btn, const gchar *name, gint size); 198 extern void lxpanel_button_update_icon(GtkWidget* btn, FmIcon *icon, gint size); 199 200 /** 201 * lxpanel_button_set_label 202 * @btn: a button instance 203 * @label: new label text 204 * 205 * Changes text of label created with lxpanel_button_new_for_icon(), 206 * lxpanel_button_new_for_fm_icon(), or lxpanel_button_compose(). Does 207 * nothing if those API were called with NULL passed as label. 208 * 209 * Returns: %TRUE in case of success. 210 * 211 * Since: 0.8.0 212 */ 213 extern gboolean lxpanel_button_set_label(GtkWidget *btn, const char *label); 214 215 /** 216 * lxpanel_button_compose 217 * @event_box: a widget to add image and label 218 * @image: an image widget 219 * @color: (allow-none): hilight color for icon 220 * @label: (allow-none): optional label for button 221 * 222 * Composes button similarly to lxpanel_button_new_for_icon() but using 223 * existing container @event_box and @image. The @image should be created 224 * using lxpanel_image_new_for_icon() or lxpanel_image_new_for_fm_icon(), 225 * and it can be updated later using lxpanel_button_set_icon() API. 226 * 227 * Returns: (transfer none): @event_box. 228 * 229 * Since: 0.8.0 230 */ 231 extern GtkWidget *lxpanel_button_compose(GtkWidget *event_box, GtkWidget *image, 232 GdkColor *color, const gchar *label); 233 234 /** 235 * lxpanel_image_new_for_icon 236 * @panel: (allow-none): panel instance 237 * @name: icon name or image path 238 * @height: image size 239 * @fallback: (allow-none): fallback image name or path 240 * 241 * Creates new #GtkImage which will follow theme if @name is a themed 242 * icon name. If @height is -1 then created image will also follow icon 243 * size changes on @panel. If icon not found in theme and @fallback is 244 * not %NULL then it will be used to load icon or image. Otherwise the 245 * "application-x-executable" will be used as fallback. 246 * 247 * Returns: (transfer full): a new #GtkImage widget. 248 * 249 * Since: 0.8.0 250 */ 251 extern GtkWidget *lxpanel_image_new_for_icon(LXPanel *panel, const gchar *name, 252 gint height, const gchar *fallback); 253 extern GtkWidget *lxpanel_image_new_for_fm_icon(LXPanel *panel, FmIcon *icon, 254 gint height, const gchar *fallback); 255 256 /** 257 * lxpanel_image_change_icon 258 * @img: an image 259 * @name: icon name or image path 260 * @fallback: (allow-none): fallback image name or path 261 * 262 * Changes an image @img created by lxpanel_image_new_for_icon() to use 263 * new icon @name and @fallback. 264 * 265 * Returns: %TRUE. 266 * 267 * Since: 0.8.0 268 */ 269 extern gboolean lxpanel_image_change_icon(GtkWidget *img, const gchar *name, 270 const char *fallback); 271 272 G_END_DECLS 273 274 #endif 275