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