1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
6 @brief Provides access to window properties
10 #include "screeninfo.hh"
14 #include <X11/Xatom.h>
23 //! Provides easy access to window properties.
26 //! The atoms on the X server which this class will cache
29 Atom_Cardinal
, //!< The atom which represents the Cardinal data type
30 Atom_Window
, //!< The atom which represents window ids
31 Atom_Pixmap
, //!< The atom which represents pixmap ids
32 Atom_Atom
, //!< The atom which represents atom values
33 Atom_String
, //!< The atom which represents ascii strings
34 Atom_Utf8
, //!< The atom which represents utf8-encoded strings
51 blackbox_change_attributes
,
54 // blackbox-protocol atoms (wm -> client)
55 blackbox_structure_messages
,
56 blackbox_notify_startup
,
57 blackbox_notify_window_add
,
58 blackbox_notify_window_del
,
59 blackbox_notify_window_focus
,
60 blackbox_notify_current_workspace
,
61 blackbox_notify_workspace_count
,
62 blackbox_notify_window_raise
,
63 blackbox_notify_window_lower
,
64 // blackbox-protocol atoms (client -> wm)
65 blackbox_change_workspace
,
66 blackbox_change_window_focus
,
67 blackbox_cycle_window_focus
,
69 openbox_show_root_menu
,
70 openbox_show_workspace_menu
,
73 // root window properties
76 net_client_list_stacking
,
77 net_number_of_desktops
,
84 net_supporting_wm_check
,
86 // root window messages
89 // application window properties
94 net_wm_visible_icon_name
,
99 // net_wm_icon_geometry,
102 // net_wm_handled_icons,
103 net_wm_allowed_actions
,
104 // application protocols
107 net_wm_window_type_desktop
,
108 net_wm_window_type_dock
,
109 net_wm_window_type_toolbar
,
110 net_wm_window_type_menu
,
111 net_wm_window_type_utility
,
112 net_wm_window_type_splash
,
113 net_wm_window_type_dialog
,
114 net_wm_window_type_normal
,
116 net_wm_moveresize_size_topleft
,
117 net_wm_moveresize_size_topright
,
118 net_wm_moveresize_size_bottomleft
,
119 net_wm_moveresize_size_bottomright
,
120 net_wm_moveresize_move
,
123 net_wm_action_resize
,
125 net_wm_action_maximize_horz
,
126 net_wm_action_maximize_vert
,
127 net_wm_action_change_desktop
,
132 net_wm_state_maximized_vert
,
133 net_wm_state_maximized_horz
,
135 net_wm_state_skip_taskbar
,
136 net_wm_state_skip_pager
,
138 net_wm_state_fullscreen
,
142 kde_net_system_tray_windows
,
143 kde_net_wm_system_tray_window_for
,
144 kde_net_wm_window_type_override
,
146 #ifndef DOXYGEN_IGNORE
147 // constant for how many atoms exist in the enumerator
152 //! The possible types/encodings of strings
154 ascii
, //!< Standard 8-bit ascii string
155 utf8
, //!< Utf8-encoded string
156 #ifndef DOXYGEN_IGNORE
162 //! The value of all atoms on the X server that exist in the
163 //! Property::Atoms enum
164 Atom _atoms
[NUM_ATOMS
];
166 //! Gets the value of an Atom from the X server, creating it if nessesary
167 Atom
create(const char *name
) const;
169 //! Sets a property on a window
170 void set(Window win
, Atom atom
, Atom type
, unsigned char *data
,
171 int size
, int nelements
, bool append
) const;
172 //! Gets a property's value from a window
173 bool get(Window win
, Atom atom
, Atom type
,
174 unsigned long *nelements
, unsigned char **value
,
178 //! A list of strings
179 typedef std::vector
<ustring
> StringVect
;
181 //! Constructs a new Atom object
183 CAUTION: This constructor uses Display::display, so ensure that it is
184 initialized before initializing this class!
187 //! Destroys the Atom object
190 //! Sets a single-value property on a window to a new value
192 @param win The window id of the window on which to set the property's value
193 @param atom A member of the Property::Atoms enum that specifies which
195 @param type A member of the Property::Atoms enum that specifies the type
196 of the property to set
197 @param value The value to set the property to
199 void set(Window win
, Atoms atom
, Atoms type
, unsigned long value
) const;
200 //! Sets an multiple-value property on a window to a new value
202 @param win The window id of the window on which to set the property's value
203 @param atom A member of the Property::Atoms enum that specifies which
205 @param type A member of the Property::Atoms enum that specifies the type
206 of the property to set
207 @param value Any array of values to set the property to. The array must
208 contain <i>elements</i> number of elements
209 @param elements The number of elements in the <i>value</i> array
211 void set(Window win
, Atoms atom
, Atoms type
,
212 unsigned long value
[], int elements
) const;
213 //! Sets a string property on a window to a new value
215 @param win The window id of the window on which to set the property's value
216 @param atom A member of the Property::Atoms enum that specifies which
218 @param type A member of the Property::StringType enum that specifies the
219 type of the string the property is being set to
220 @param value The string to set the property to
222 void set(Window win
, Atoms atom
, StringType type
,
223 const ustring
&value
) const;
224 //! Sets a string-array property on a window to a new value
226 @param win The window id of the window on which to set the property's value
227 @param atom A member of the Property::Atoms enum that specifies which
229 @param type A member of the Property::StringType enum that specifies the
230 type of the string the property is being set to
231 @param strings A list of strings to set the property to
233 void set(Window win
, Atoms atom
, StringType type
,
234 const StringVect
&strings
) const;
236 //! Gets the value of a property on a window
238 @param win The window id of the window to get the property value from
239 @param atom A member of the Property::Atoms enum that specifies which
241 @param type A member of the Property::Atoms enum that specifies the type
242 of the property to retrieve
243 @param nelements The maximum number of elements to retrieve from the
244 property (assuming it has more than 1 value in it). To
245 retrieve all possible elements, use "(unsigned) -1".<br>
246 When the function returns, if it returns true, this will
247 contain the actual number of elements retrieved.<br>
248 @param value If the function returns true, then this contains an array of
249 retrieved values for the property.<br>
250 The <i>value</i> is allocated inside the function and
251 <b>delete[]</b> value needs to be called when you are done
253 The <i>value</i> array returned is null terminated, and has
254 <i>nelements</i> elements in it plus the terminating null.
255 @return true if retrieval of the specified property with the specified
256 type was successful; otherwise, false
258 bool get(Window win
, Atoms atom
, Atoms type
,
259 unsigned long *nelements
, unsigned long **value
) const;
260 //! Gets a single element from the value of a property on a window
262 @param win The window id of the window to get the property value from
263 @param atom A member of the Property::Atoms enum that specifies which
265 @param type A member of the Property::Atoms enum that specifies the type
266 of the property to retrieve
267 @param value If the function returns true, then this contains the first
268 (and possibly only) element in the value of the specified
270 @return true if retrieval of the specified property with the specified
271 type was successful; otherwise, false
273 bool get(Window win
, Atoms atom
, Atoms type
, unsigned long *value
) const;
274 //! Gets a single string from the value of a property on a window
276 @param win The window id of the window to get the property value from
277 @param atom A member of the Property::Atoms enum that specifies which
279 @param type A member of the Property::StringType enum that specifies the
280 type of the string property to retrieve
281 @param value If the function returns true, then this contains the first
282 (and possibly only) string in the value of the specified
284 @return true if retrieval of the specified property with the specified
285 type was successful; otherwise, false
287 bool get(Window win
, Atoms atom
, StringType type
, ustring
*value
) const;
288 //! Gets strings from the value of a property on a window
290 @param win The window id of the window to get the property value from
291 @param atom A member of the Property::Atoms enum that specifies which
293 @param type A member of the Property::StringType enum that specifies the
294 type of the string property to retrieve
295 @param nelements The maximum number of strings to retrieve from the
296 property (assuming it has more than 1 string in it). To
297 retrieve all possible strings, use "(unsigned) -1".<br>
298 When the function returns, if it returns true, this will
299 contain the actual number of strings retrieved.<br>
300 @param strings If the function returns true, then this contains all of the
301 strings retrieved from the property's value.
302 @return true if retrieval of the specified property with the specified
303 type was successful; otherwise, false
305 bool get(Window win
, Atoms atom
, StringType type
,
306 unsigned long *nelements
, StringVect
*strings
) const;
308 //! Removes a property from a window
310 @param win The window id of the window to remove the property from
311 @param atom A member of the Property::Atoms enum that specifies which
312 property to remove from the window
314 void erase(Window win
, Atoms atom
) const;
316 //! Gets the value of an atom on the X server
318 @param a A member of the Property::Atoms enum that specifies which Atom's
320 @return The value of the specified Atom
322 inline Atom
atom(Atoms a
) const {
323 assert(a
>= 0 && a
< NUM_ATOMS
); Atom ret
= _atoms
[a
]; assert(ret
!= 0);