]> Dogcows Code - chaz/openbox/blob - otk/property.hh
use the c++ std cheaders
[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 #include "ustring.hh"
10 #include "screeninfo.hh"
11
12 extern "C" {
13 #include <X11/Xlib.h>
14 }
15
16 #include <vector>
17 #include <cassert>
18
19 namespace otk {
20
21 //! The atoms on the X server which this class will cache
22 struct Atoms {
23 // types
24 Atom cardinal; //!< The atom which represents the Cardinal data type
25 Atom window; //!< The atom which represents window ids
26 Atom pixmap; //!< The atom which represents pixmap ids
27 Atom atom; //!< The atom which represents atom values
28 Atom string; //!< The atom which represents ascii strings
29 Atom utf8; //!< The atom which represents utf8-encoded strings
30
31 Atom openbox_pid;
32
33 // window hints
34 Atom wm_colormap_windows;
35 Atom wm_protocols;
36 Atom wm_state;
37 Atom wm_delete_window;
38 Atom wm_take_focus;
39 Atom wm_change_state;
40 Atom wm_name;
41 Atom wm_icon_name;
42 Atom wm_class;
43 Atom wm_window_role;
44 Atom motif_wm_hints;
45
46 Atom openbox_show_root_menu;
47 Atom openbox_show_workspace_menu;
48
49 // NETWM atoms
50 // root window properties
51 Atom net_supported;
52 Atom net_client_list;
53 Atom net_client_list_stacking;
54 Atom net_number_of_desktops;
55 Atom net_desktop_geometry;
56 Atom net_desktop_viewport;
57 Atom net_current_desktop;
58 Atom net_desktop_names;
59 Atom net_active_window;
60 Atom net_workarea;
61 Atom net_supporting_wm_check;
62 // Atom net_virtual_roots;
63 // root window messages
64 Atom net_close_window;
65 Atom net_wm_moveresize;
66 // application window properties
67 // Atom net_properties;
68 Atom net_wm_name;
69 Atom net_wm_visible_name;
70 Atom net_wm_icon_name;
71 Atom net_wm_visible_icon_name;
72 Atom net_wm_desktop;
73 Atom net_wm_window_type;
74 Atom net_wm_state;
75 Atom net_wm_strut;
76 // Atom net_wm_icon_geometry;
77 // Atom net_wm_icon;
78 // Atom net_wm_pid;
79 // Atom net_wm_handled_icons;
80 Atom net_wm_allowed_actions;
81 // application protocols
82 // Atom Atom net_wm_ping;
83
84 Atom net_wm_window_type_desktop;
85 Atom net_wm_window_type_dock;
86 Atom net_wm_window_type_toolbar;
87 Atom net_wm_window_type_menu;
88 Atom net_wm_window_type_utility;
89 Atom net_wm_window_type_splash;
90 Atom net_wm_window_type_dialog;
91 Atom net_wm_window_type_normal;
92
93 Atom net_wm_moveresize_size_topleft;
94 Atom net_wm_moveresize_size_topright;
95 Atom net_wm_moveresize_size_bottomleft;
96 Atom net_wm_moveresize_size_bottomright;
97 Atom net_wm_moveresize_move;
98
99 Atom net_wm_action_move;
100 Atom net_wm_action_resize;
101 Atom net_wm_action_minimize;
102 Atom net_wm_action_shade;
103 Atom net_wm_action_stick;
104 Atom net_wm_action_maximize_horz;
105 Atom net_wm_action_maximize_vert;
106 Atom net_wm_action_fullscreen;
107 Atom net_wm_action_change_desktop;
108 Atom net_wm_action_close;
109
110 Atom net_wm_state_modal;
111 Atom net_wm_state_sticky;
112 Atom net_wm_state_maximized_vert;
113 Atom net_wm_state_maximized_horz;
114 Atom net_wm_state_shaded;
115 Atom net_wm_state_skip_taskbar;
116 Atom net_wm_state_skip_pager;
117 Atom net_wm_state_hidden;
118 Atom net_wm_state_fullscreen;
119 Atom net_wm_state_above;
120 Atom net_wm_state_below;
121
122 Atom kde_net_system_tray_windows;
123 Atom kde_net_wm_system_tray_window_for;
124 Atom kde_net_wm_window_type_override;
125
126 Atom openbox_premax;
127 Atom openbox_active_window;
128 };
129
130
131 //! Provides easy access to window properties.
132 class Property {
133 public:
134
135 //! The possible types/encodings of strings
136 enum StringType {
137 ascii, //!< Standard 8-bit ascii string
138 utf8, //!< Utf8-encoded string
139 #ifndef DOXYGEN_IGNORE
140 NUM_STRING_TYPE
141 #endif
142 };
143
144 //! A list of ustrings
145 typedef std::vector<ustring> StringVect;
146
147 //! The value of all atoms on the X server that exist in the
148 //! Atoms struct
149 static Atoms atoms;
150
151 private:
152 //! Sets a property on a window
153 static void set(Window win, Atom atom, Atom type, unsigned char *data,
154 int size, int nelements, bool append);
155 //! Gets a property's value from a window
156 static bool get(Window win, Atom atom, Atom type,
157 unsigned long *nelements, unsigned char **value,
158 int size);
159
160 public:
161 //! Initializes the Property class.
162 /*!
163 CAUTION: This function uses otk::Display, so ensure that
164 otk::Display::initialize has been called before initializing this class!
165 */
166 static void initialize();
167
168 //! Sets a single-value property on a window to a new value
169 /*!
170 @param win The window id of the window on which to set the property's value
171 @param atom The Atom value of the property to set. This can be found in the
172 struct returned by Property::atoms.
173 @param type The Atom value of the property type. This can be found in the
174 struct returned by Property::atoms.
175 @param value The value to set the property to
176 */
177 static void set(Window win, Atom atom, Atom type, unsigned long value);
178 //! Sets an multiple-value property on a window to a new value
179 /*!
180 @param win The window id of the window on which to set the property's value
181 @param atom The Atom value of the property to set. This can be found in the
182 struct returned by Property::atoms.
183 @param type The Atom value of the property type. This can be found in the
184 struct returned by Property::atoms.
185 @param value Any array of values to set the property to. The array must
186 contain <i>elements</i> number of elements
187 @param elements The number of elements in the <i>value</i> array
188 */
189 static void set(Window win, Atom atom, Atom type,
190 unsigned long value[], int elements);
191 //! Sets a string property on a window to a new value
192 /*!
193 @param win The window id of the window on which to set the property's value
194 @param atom The Atom value of the property to set. This can be found in the
195 struct returned by Property::atoms.
196 @param type A member of the Property::StringType enum that specifies the
197 type of the string the property is being set to
198 @param value The string to set the property to
199 */
200 static void set(Window win, Atom atom, StringType type,
201 const ustring &value);
202 //! Sets a string-array property on a window to a new value
203 /*!
204 @param win The window id of the window on which to set the property's value
205 @param atom The Atom value of the property to set. This can be found in the
206 struct returned by Property::atoms.
207 @param type A member of the Property::StringType enum that specifies the
208 type of the string the property is being set to
209 @param strings A list of strings to set the property to
210 */
211 static void set(Window win, Atom atom, StringType type,
212 const StringVect &strings);
213
214 //! Gets the value of a property on a window
215 /*!
216 @param win The window id of the window to get the property value from
217 @param atom The Atom value of the property to set. This can be found in the
218 struct returned by Property::atoms.
219 @param type The Atom value of the property type. This can be found in the
220 struct returned by Property::atoms.
221 @param nelements The maximum number of elements to retrieve from the
222 property (assuming it has more than 1 value in it). To
223 retrieve all possible elements, use "(unsigned) -1".<br>
224 When the function returns, if it returns true, this will
225 contain the actual number of elements retrieved.<br>
226 @param value If the function returns true, then this contains an array of
227 retrieved values for the property.<br>
228 The <i>value</i> is allocated inside the function and
229 <b>delete[]</b> value needs to be called when you are done
230 with it.<br>
231 The <i>value</i> array returned is null terminated, and has
232 <i>nelements</i> elements in it plus the terminating null.
233 @return true if retrieval of the specified property with the specified
234 type was successful; otherwise, false
235 */
236 static bool get(Window win, Atom atom, Atom type,
237 unsigned long *nelements, unsigned long **value);
238 //! Gets a single element from the value of a property on a window
239 /*!
240 @param win The window id of the window to get the property value from
241 @param atom The Atom value of the property to set. This can be found in the
242 struct returned by Property::atoms.
243 @param type The Atom value of the property type. This can be found in the
244 struct returned by Property::atoms.
245 @param value If the function returns true, then this contains the first
246 (and possibly only) element in the value of the specified
247 property.
248 @return true if retrieval of the specified property with the specified
249 type was successful; otherwise, false
250 */
251 static bool get(Window win, Atom atom, Atom type, unsigned long *value);
252 //! Gets a single string from the value of a property on a window
253 /*!
254 @param win The window id of the window to get the property value from
255 @param atom The Atom value of the property to set. This can be found in the
256 struct returned by Property::atoms.
257 @param type A member of the Property::StringType enum that specifies the
258 type of the string property to retrieve
259 @param value If the function returns true, then this contains the first
260 (and possibly only) string in the value of the specified
261 property.
262 @return true if retrieval of the specified property with the specified
263 type was successful; otherwise, false
264 */
265 static bool get(Window win, Atom atom, StringType type, ustring *value);
266 //! Gets strings from the value of a property on a window
267 /*!
268 @param win The window id of the window to get the property value from
269 @param atom The Atom value of the property to set. This can be found in the
270 struct returned by Property::atoms.
271 @param type A member of the Property::StringType enum that specifies the
272 type of the string property to retrieve
273 @param nelements The maximum number of strings to retrieve from the
274 property (assuming it has more than 1 string in it). To
275 retrieve all possible strings, use "(unsigned) -1".<br>
276 When the function returns, if it returns true, this will
277 contain the actual number of strings retrieved.<br>
278 @param strings If the function returns true, then this contains all of the
279 strings retrieved from the property's value.
280 @return true if retrieval of the specified property with the specified
281 type was successful; otherwise, false
282 */
283 static bool get(Window win, Atom atom, StringType type,
284 unsigned long *nelements, StringVect *strings);
285
286 //! Removes a property from a window
287 /*!
288 @param win The window id of the window to remove the property from
289 @param atom The Atom value of the property to set. This can be found in the
290 struct returned by Property::atoms.
291 */
292 static void erase(Window win, Atom atom);
293 };
294
295 }
296
297 #endif // __atom_hh
This page took 0.048238 seconds and 5 git commands to generate.