]> Dogcows Code - chaz/openbox/blob - otk/property.hh
mode documentation updates
[chaz/openbox] / otk / property.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
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 #include <string>
18
19 #include "screeninfo.hh"
20
21 namespace otk {
22
23 //! Provides easy access to window properties.
24 class OBProperty {
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 #ifdef HAVE_GETPID
37 blackbox_pid,
38 #endif // HAVE_GETPID
39
40 // window hints
41 wm_colormap_windows,
42 wm_protocols,
43 wm_state,
44 wm_delete_window,
45 wm_take_focus,
46 wm_change_state,
47 wm_name,
48 wm_icon_name,
49 wm_class,
50 motif_wm_hints,
51 blackbox_attributes,
52 blackbox_change_attributes,
53 blackbox_hints,
54
55 // blackbox-protocol atoms (wm -> client)
56 blackbox_structure_messages,
57 blackbox_notify_startup,
58 blackbox_notify_window_add,
59 blackbox_notify_window_del,
60 blackbox_notify_window_focus,
61 blackbox_notify_current_workspace,
62 blackbox_notify_workspace_count,
63 blackbox_notify_window_raise,
64 blackbox_notify_window_lower,
65 // blackbox-protocol atoms (client -> wm)
66 blackbox_change_workspace,
67 blackbox_change_window_focus,
68 blackbox_cycle_window_focus,
69
70 openbox_show_root_menu,
71 openbox_show_workspace_menu,
72
73 // NETWM atoms
74 // root window properties
75 net_supported,
76 net_client_list,
77 net_client_list_stacking,
78 net_number_of_desktops,
79 net_desktop_geometry,
80 net_desktop_viewport,
81 net_current_desktop,
82 net_desktop_names,
83 net_active_window,
84 net_workarea,
85 net_supporting_wm_check,
86 // net_virtual_roots,
87 // root window messages
88 net_close_window,
89 net_wm_moveresize,
90 // application window properties
91 // net_properties,
92 net_wm_name,
93 net_wm_visible_name,
94 net_wm_icon_name,
95 net_wm_visible_icon_name,
96 net_wm_desktop,
97 net_wm_window_type,
98 net_wm_state,
99 net_wm_strut,
100 // net_wm_icon_geometry,
101 // net_wm_icon,
102 // net_wm_pid,
103 // net_wm_handled_icons,
104 net_wm_allowed_actions,
105 // application protocols
106 // net_wm_ping,
107
108 net_wm_window_type_desktop,
109 net_wm_window_type_dock,
110 net_wm_window_type_toolbar,
111 net_wm_window_type_menu,
112 net_wm_window_type_utility,
113 net_wm_window_type_splash,
114 net_wm_window_type_dialog,
115 net_wm_window_type_normal,
116
117 net_wm_moveresize_size_topleft,
118 net_wm_moveresize_size_topright,
119 net_wm_moveresize_size_bottomleft,
120 net_wm_moveresize_size_bottomright,
121 net_wm_moveresize_move,
122
123 net_wm_action_move,
124 net_wm_action_resize,
125 net_wm_action_shade,
126 net_wm_action_maximize_horz,
127 net_wm_action_maximize_vert,
128 net_wm_action_change_desktop,
129 net_wm_action_close,
130
131 net_wm_state_modal,
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
140 kde_net_system_tray_windows,
141 kde_net_wm_system_tray_window_for,
142 kde_net_wm_window_type_override,
143
144 // constant for how many atoms exist in the enumerator
145 NUM_ATOMS
146 };
147
148 //! The possible types/encodings of strings
149 enum StringType {
150 ascii, //!< Standard 8-bit ascii string
151 utf8, //!< Utf8-encoded string
152 NUM_STRING_TYPE
153 };
154
155 private:
156 //! The value of all atoms on the X server that exist in the
157 //! OBProperty::Atoms enum
158 Atom _atoms[NUM_ATOMS];
159
160 //! Gets the value of an Atom from the X server, creating it if nessesary
161 Atom create(const char *name) const;
162
163 //! Sets a property on a window
164 void set(Window win, Atom atom, Atom type, unsigned char *data,
165 int size, int nelements, bool append) const;
166 //! Gets a property's value from a window
167 bool get(Window win, Atom atom, Atom type,
168 unsigned long *nelements, unsigned char **value,
169 int size) const;
170
171 public:
172 //! A list of strings
173 typedef std::vector<std::string> StringVect;
174
175 //! Constructs a new OBAtom object
176 /*!
177 CAUTION: This constructor uses OBDisplay::display, so ensure that it is
178 initialized before initializing this class!
179 */
180 OBProperty();
181 //! Destroys the OBAtom object
182 virtual ~OBProperty();
183
184 //! Sets a single-value property on a window to a new value
185 /*!
186 @param win The window id of the window on which to set the property's value
187 @param atom A member of the OBProperty::Atoms enum that specifies which
188 property to set
189 @param type A member of the OBProperty::Atoms enum that specifies the type
190 of the property to set
191 @param value The value to set the property to
192 */
193 void set(Window win, Atoms atom, Atoms type, unsigned long value) const;
194 //! Sets an multiple-value property on a window to a new value
195 /*!
196 @param win The window id of the window on which to set the property's value
197 @param atom A member of the OBProperty::Atoms enum that specifies which
198 property to set
199 @param type A member of the OBProperty::Atoms enum that specifies the type
200 of the property to set
201 @param value Any array of values to set the property to. The array must
202 contain <i>elements</i> number of elements
203 @param elements The number of elements in the <i>value</i> array
204 */
205 void set(Window win, Atoms atom, Atoms type,
206 unsigned long value[], int elements) const;
207 //! Sets a string property on a window to a new value
208 /*!
209 @param win The window id of the window on which to set the property's value
210 @param atom A member of the OBProperty::Atoms enum that specifies which
211 property to set
212 @param type A member of the OBProperty::StringType enum that specifies the
213 type of the string the property is being set to
214 @param value The string to set the property to
215 */
216 void set(Window win, Atoms atom, StringType type,
217 const std::string &value) const;
218 //! Sets a string-array property on a window to a new value
219 /*!
220 @param win The window id of the window on which to set the property's value
221 @param atom A member of the OBProperty::Atoms enum that specifies which
222 property to set
223 @param type A member of the OBProperty::StringType enum that specifies the
224 type of the string the property is being set to
225 @param strings A list of strings to set the property to
226 */
227 void set(Window win, Atoms atom, StringType type,
228 const StringVect &strings) const;
229
230 //! Gets the value of a property on a window
231 /*!
232 @param win The window id of the window to get the property value from
233 @param atom A member of the OBProperty::Atoms enum that specifies which
234 property to retrieve
235 @param type A member of the OBProperty::Atoms enum that specifies the type
236 of the property to retrieve
237 @param nelements The maximum number of elements to retrieve from the
238 property (assuming it has more than 1 value in it). To
239 retrieve all possible elements, use "(unsigned) -1".<br>
240 When the function returns, if it returns true, this will
241 contain the actual number of elements retrieved.<br>
242 @param value If the function returns true, then this contains an array of
243 retrieved values for the property.<br>
244 The <i>value</i> is allocated inside the function and
245 <b>delete[]</b> value needs to be called when you are done
246 with it.<br>
247 The <i>value</i> array returned is null terminated, and has
248 <i>nelements</i> elements in it plus the terminating null.
249 @return true if retrieval of the specified property with the specified
250 type was successful; otherwise, false
251 */
252 bool get(Window win, Atoms atom, Atoms type,
253 unsigned long *nelements, unsigned long **value) const;
254 //! Gets a single element from the value of a property on a window
255 /*!
256 @param win The window id of the window to get the property value from
257 @param atom A member of the OBProperty::Atoms enum that specifies which
258 property to retrieve
259 @param type A member of the OBProperty::Atoms enum that specifies the type
260 of the property to retrieve
261 @param value If the function returns true, then this contains the first
262 (and possibly only) element in the value of the specified
263 property.
264 @return true if retrieval of the specified property with the specified
265 type was successful; otherwise, false
266 */
267 bool get(Window win, Atoms atom, Atoms type, unsigned long *value) const;
268 //! Gets a single string from the value of a property on a window
269 /*!
270 @param win The window id of the window to get the property value from
271 @param atom A member of the OBProperty::Atoms enum that specifies which
272 property to retrieve
273 @param type A member of the OBProperty::StringType enum that specifies the
274 type of the string property to retrieve
275 @param value If the function returns true, then this contains the first
276 (and possibly only) string in the value of the specified
277 property.
278 @return true if retrieval of the specified property with the specified
279 type was successful; otherwise, false
280 */
281 bool get(Window win, Atoms atom, StringType type, std::string *value) const;
282 //! Gets strings from the value of a property on a window
283 /*!
284 @param win The window id of the window to get the property value from
285 @param atom A member of the OBProperty::Atoms enum that specifies which
286 property to retrieve
287 @param type A member of the OBProperty::StringType enum that specifies the
288 type of the string property to retrieve
289 @param nelements The maximum number of strings to retrieve from the
290 property (assuming it has more than 1 string in it). To
291 retrieve all possible strings, use "(unsigned) -1".<br>
292 When the function returns, if it returns true, this will
293 contain the actual number of strings retrieved.<br>
294 @param strings If the function returns true, then this contains all of the
295 strings retrieved from the property's value.
296 @return true if retrieval of the specified property with the specified
297 type was successful; otherwise, false
298 */
299 bool get(Window win, Atoms atom, StringType type,
300 unsigned long *nelements, StringVect *strings) const;
301
302 //! Removes a property from a window
303 /*!
304 @param win The window id of the window to remove the property from
305 @param atom A member of the OBProperty::Atoms enum that specifies which
306 property to remove from the window
307 */
308 void erase(Window win, Atoms atom) const;
309
310 //! Gets the value of an atom on the X server
311 /*!
312 @param a A member of the OBProperty::Atoms enum that specifies which Atom's
313 value to return
314 @return The value of the specified Atom
315 */
316 inline Atom atom(Atoms a) {
317 assert(a >= 0 && a < NUM_ATOMS); Atom ret = _atoms[a]; assert(ret != 0);
318 return ret;
319 }
320 };
321
322 }
323
324 #endif // __atom_hh
This page took 0.050152 seconds and 5 git commands to generate.