]> Dogcows Code - chaz/openbox/blob - otk/property.hh
e942bfd2189978efc5d29707cd090be5c623da10
[chaz/openbox] / otk / property.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef __atom_hh
3 #define __atom_hh
4
5 /*! @file property.hh
6 @brief Provides access to window properties
7 */
8
9 extern "C" {
10 #include <X11/Xlib.h>
11 #include <X11/Xatom.h>
12
13 #include <assert.h>
14 }
15
16 #include <vector>
17
18 #include "userstring.hh"
19 #include "screeninfo.hh"
20
21 namespace otk {
22
23 //! Provides easy access to window properties.
24 class Property {
25 public:
26 //! The atoms on the X server which this class will cache
27 enum Atoms {
28 // types
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
35
36 openbox_pid,
37
38 // window hints
39 wm_colormap_windows,
40 wm_protocols,
41 wm_state,
42 wm_delete_window,
43 wm_take_focus,
44 wm_change_state,
45 wm_name,
46 wm_icon_name,
47 wm_class,
48 wm_window_role,
49 motif_wm_hints,
50 blackbox_attributes,
51 blackbox_change_attributes,
52 blackbox_hints,
53
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,
68
69 openbox_show_root_menu,
70 openbox_show_workspace_menu,
71
72 // NETWM atoms
73 // root window properties
74 net_supported,
75 net_client_list,
76 net_client_list_stacking,
77 net_number_of_desktops,
78 net_desktop_geometry,
79 net_desktop_viewport,
80 net_current_desktop,
81 net_desktop_names,
82 net_active_window,
83 net_workarea,
84 net_supporting_wm_check,
85 // net_virtual_roots,
86 // root window messages
87 net_close_window,
88 net_wm_moveresize,
89 // application window properties
90 // net_properties,
91 net_wm_name,
92 net_wm_visible_name,
93 net_wm_icon_name,
94 net_wm_visible_icon_name,
95 net_wm_desktop,
96 net_wm_window_type,
97 net_wm_state,
98 net_wm_strut,
99 // net_wm_icon_geometry,
100 // net_wm_icon,
101 // net_wm_pid,
102 // net_wm_handled_icons,
103 net_wm_allowed_actions,
104 // application protocols
105 // net_wm_ping,
106
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,
115
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,
121
122 net_wm_action_move,
123 net_wm_action_resize,
124 net_wm_action_shade,
125 net_wm_action_maximize_horz,
126 net_wm_action_maximize_vert,
127 net_wm_action_change_desktop,
128 net_wm_action_close,
129
130 net_wm_state_modal,
131 net_wm_state_sticky,
132 net_wm_state_maximized_vert,
133 net_wm_state_maximized_horz,
134 net_wm_state_shaded,
135 net_wm_state_skip_taskbar,
136 net_wm_state_skip_pager,
137 net_wm_state_hidden,
138 net_wm_state_fullscreen,
139 net_wm_state_above,
140 net_wm_state_below,
141
142 kde_net_system_tray_windows,
143 kde_net_wm_system_tray_window_for,
144 kde_net_wm_window_type_override,
145
146 #ifndef DOXYGEN_IGNORE
147 // constant for how many atoms exist in the enumerator
148 NUM_ATOMS
149 #endif
150 };
151
152 //! The possible types/encodings of strings
153 enum StringType {
154 ascii, //!< Standard 8-bit ascii string
155 utf8, //!< Utf8-encoded string
156 #ifndef DOXYGEN_IGNORE
157 NUM_STRING_TYPE
158 #endif
159 };
160
161 private:
162 //! The value of all atoms on the X server that exist in the
163 //! Property::Atoms enum
164 Atom _atoms[NUM_ATOMS];
165
166 //! Gets the value of an Atom from the X server, creating it if nessesary
167 Atom create(const char *name) const;
168
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,
175 int size) const;
176
177 public:
178 //! Constructs a new Atom object
179 /*!
180 CAUTION: This constructor uses Display::display, so ensure that it is
181 initialized before initializing this class!
182 */
183 Property();
184 //! Destroys the Atom object
185 virtual ~Property();
186
187 //! Sets a single-value property on a window to a new value
188 /*!
189 @param win The window id of the window on which to set the property's value
190 @param atom A member of the Property::Atoms enum that specifies which
191 property to set
192 @param type A member of the Property::Atoms enum that specifies the type
193 of the property to set
194 @param value The value to set the property to
195 */
196 void set(Window win, Atoms atom, Atoms type, unsigned long value) const;
197 //! Sets an multiple-value property on a window to a new value
198 /*!
199 @param win The window id of the window on which to set the property's value
200 @param atom A member of the Property::Atoms enum that specifies which
201 property to set
202 @param type A member of the Property::Atoms enum that specifies the type
203 of the property to set
204 @param value Any array of values to set the property to. The array must
205 contain <i>elements</i> number of elements
206 @param elements The number of elements in the <i>value</i> array
207 */
208 void set(Window win, Atoms atom, Atoms type,
209 unsigned long value[], int elements) const;
210 //! Sets a string property on a window to a new value
211 /*!
212 @param win The window id of the window on which to set the property's value
213 @param atom A member of the Property::Atoms enum that specifies which
214 property to set
215 @param type A member of the Property::StringType enum that specifies the
216 type of the string the property is being set to
217 @param value The string to set the property to
218 */
219 void set(Window win, Atoms atom, StringType type,
220 const userstring &value) const;
221 //! Sets a string-array property on a window to a new value
222 /*!
223 @param win The window id of the window on which to set the property's value
224 @param atom A member of the Property::Atoms enum that specifies which
225 property to set
226 @param type A member of the Property::StringType enum that specifies the
227 type of the string the property is being set to
228 @param strings A list of strings to set the property to
229 */
230 void set(Window win, Atoms atom, StringType type,
231 const userstring::vector &strings) const;
232
233 //! Gets the value of a property on a window
234 /*!
235 @param win The window id of the window to get the property value from
236 @param atom A member of the Property::Atoms enum that specifies which
237 property to retrieve
238 @param type A member of the Property::Atoms enum that specifies the type
239 of the property to retrieve
240 @param nelements The maximum number of elements to retrieve from the
241 property (assuming it has more than 1 value in it). To
242 retrieve all possible elements, use "(unsigned) -1".<br>
243 When the function returns, if it returns true, this will
244 contain the actual number of elements retrieved.<br>
245 @param value If the function returns true, then this contains an array of
246 retrieved values for the property.<br>
247 The <i>value</i> is allocated inside the function and
248 <b>delete[]</b> value needs to be called when you are done
249 with it.<br>
250 The <i>value</i> array returned is null terminated, and has
251 <i>nelements</i> elements in it plus the terminating null.
252 @return true if retrieval of the specified property with the specified
253 type was successful; otherwise, false
254 */
255 bool get(Window win, Atoms atom, Atoms type,
256 unsigned long *nelements, unsigned long **value) const;
257 //! Gets a single element from the value of a property on a window
258 /*!
259 @param win The window id of the window to get the property value from
260 @param atom A member of the Property::Atoms enum that specifies which
261 property to retrieve
262 @param type A member of the Property::Atoms enum that specifies the type
263 of the property to retrieve
264 @param value If the function returns true, then this contains the first
265 (and possibly only) element in the value of the specified
266 property.
267 @return true if retrieval of the specified property with the specified
268 type was successful; otherwise, false
269 */
270 bool get(Window win, Atoms atom, Atoms type, unsigned long *value) const;
271 //! Gets a single string from the value of a property on a window
272 /*!
273 @param win The window id of the window to get the property value from
274 @param atom A member of the Property::Atoms enum that specifies which
275 property to retrieve
276 @param type A member of the Property::StringType enum that specifies the
277 type of the string property to retrieve
278 @param value If the function returns true, then this contains the first
279 (and possibly only) string in the value of the specified
280 property.
281 @return true if retrieval of the specified property with the specified
282 type was successful; otherwise, false
283 */
284 bool get(Window win, Atoms atom, StringType type, userstring *value) const;
285 //! Gets strings from the value of a property on a window
286 /*!
287 @param win The window id of the window to get the property value from
288 @param atom A member of the Property::Atoms enum that specifies which
289 property to retrieve
290 @param type A member of the Property::StringType enum that specifies the
291 type of the string property to retrieve
292 @param nelements The maximum number of strings to retrieve from the
293 property (assuming it has more than 1 string in it). To
294 retrieve all possible strings, use "(unsigned) -1".<br>
295 When the function returns, if it returns true, this will
296 contain the actual number of strings retrieved.<br>
297 @param strings If the function returns true, then this contains all of the
298 strings retrieved from the property's value.
299 @return true if retrieval of the specified property with the specified
300 type was successful; otherwise, false
301 */
302 bool get(Window win, Atoms atom, StringType type,
303 unsigned long *nelements, userstring::vector *strings) const;
304
305 //! Removes a property from a window
306 /*!
307 @param win The window id of the window to remove the property from
308 @param atom A member of the Property::Atoms enum that specifies which
309 property to remove from the window
310 */
311 void erase(Window win, Atoms atom) const;
312
313 //! Gets the value of an atom on the X server
314 /*!
315 @param a A member of the Property::Atoms enum that specifies which Atom's
316 value to return
317 @return The value of the specified Atom
318 */
319 inline Atom atom(Atoms a) const {
320 assert(a >= 0 && a < NUM_ATOMS); Atom ret = _atoms[a]; assert(ret != 0);
321 return ret;
322 }
323 };
324
325 }
326
327 #endif // __atom_hh
This page took 0.046201 seconds and 4 git commands to generate.