00001 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- 00002 #ifndef __atom_hh 00003 #define __atom_hh 00004 00005 /*! @file property.hh 00006 @brief Provides access to window properties 00007 */ 00008 00009 #include "ustring.hh" 00010 #include "screeninfo.hh" 00011 00012 extern "C" { 00013 #include <X11/Xlib.h> 00014 00015 #include <assert.h> 00016 } 00017 00018 #include <vector> 00019 00020 namespace otk { 00021 00022 //! The atoms on the X server which this class will cache 00023 struct Atoms { 00024 // types 00025 Atom cardinal; //!< The atom which represents the Cardinal data type 00026 Atom window; //!< The atom which represents window ids 00027 Atom pixmap; //!< The atom which represents pixmap ids 00028 Atom atom; //!< The atom which represents atom values 00029 Atom string; //!< The atom which represents ascii strings 00030 Atom utf8; //!< The atom which represents utf8-encoded strings 00031 00032 Atom openbox_pid; 00033 00034 // window hints 00035 Atom wm_colormap_windows; 00036 Atom wm_protocols; 00037 Atom wm_state; 00038 Atom wm_delete_window; 00039 Atom wm_take_focus; 00040 Atom wm_change_state; 00041 Atom wm_name; 00042 Atom wm_icon_name; 00043 Atom wm_class; 00044 Atom wm_window_role; 00045 Atom motif_wm_hints; 00046 00047 Atom openbox_show_root_menu; 00048 Atom openbox_show_workspace_menu; 00049 00050 // NETWM atoms 00051 // root window properties 00052 Atom net_supported; 00053 Atom net_client_list; 00054 Atom net_client_list_stacking; 00055 Atom net_number_of_desktops; 00056 Atom net_desktop_geometry; 00057 Atom net_desktop_viewport; 00058 Atom net_current_desktop; 00059 Atom net_desktop_names; 00060 Atom net_active_window; 00061 Atom net_workarea; 00062 Atom net_supporting_wm_check; 00063 // Atom net_virtual_roots; 00064 // root window messages 00065 Atom net_close_window; 00066 Atom net_wm_moveresize; 00067 // application window properties 00068 // Atom net_properties; 00069 Atom net_wm_name; 00070 Atom net_wm_visible_name; 00071 Atom net_wm_icon_name; 00072 Atom net_wm_visible_icon_name; 00073 Atom net_wm_desktop; 00074 Atom net_wm_window_type; 00075 Atom net_wm_state; 00076 Atom net_wm_strut; 00077 // Atom net_wm_icon_geometry; 00078 // Atom net_wm_icon; 00079 // Atom net_wm_pid; 00080 // Atom net_wm_handled_icons; 00081 Atom net_wm_allowed_actions; 00082 // application protocols 00083 // Atom Atom net_wm_ping; 00084 00085 Atom net_wm_window_type_desktop; 00086 Atom net_wm_window_type_dock; 00087 Atom net_wm_window_type_toolbar; 00088 Atom net_wm_window_type_menu; 00089 Atom net_wm_window_type_utility; 00090 Atom net_wm_window_type_splash; 00091 Atom net_wm_window_type_dialog; 00092 Atom net_wm_window_type_normal; 00093 00094 Atom net_wm_moveresize_size_topleft; 00095 Atom net_wm_moveresize_size_topright; 00096 Atom net_wm_moveresize_size_bottomleft; 00097 Atom net_wm_moveresize_size_bottomright; 00098 Atom net_wm_moveresize_move; 00099 00100 Atom net_wm_action_move; 00101 Atom net_wm_action_resize; 00102 Atom net_wm_action_minimize; 00103 Atom net_wm_action_shade; 00104 Atom net_wm_action_stick; 00105 Atom net_wm_action_maximize_horz; 00106 Atom net_wm_action_maximize_vert; 00107 Atom net_wm_action_fullscreen; 00108 Atom net_wm_action_change_desktop; 00109 Atom net_wm_action_close; 00110 00111 Atom net_wm_state_modal; 00112 Atom net_wm_state_sticky; 00113 Atom net_wm_state_maximized_vert; 00114 Atom net_wm_state_maximized_horz; 00115 Atom net_wm_state_shaded; 00116 Atom net_wm_state_skip_taskbar; 00117 Atom net_wm_state_skip_pager; 00118 Atom net_wm_state_hidden; 00119 Atom net_wm_state_fullscreen; 00120 Atom net_wm_state_above; 00121 Atom net_wm_state_below; 00122 00123 Atom kde_net_system_tray_windows; 00124 Atom kde_net_wm_system_tray_window_for; 00125 Atom kde_net_wm_window_type_override; 00126 00127 Atom openbox_premax; 00128 Atom openbox_active_window; 00129 }; 00130 00131 00132 //! Provides easy access to window properties. 00133 class Property { 00134 public: 00135 00136 //! The possible types/encodings of strings 00137 enum StringType { 00138 ascii, //!< Standard 8-bit ascii string 00139 utf8, //!< Utf8-encoded string 00140 #ifndef DOXYGEN_IGNORE 00141 NUM_STRING_TYPE 00142 #endif 00143 }; 00144 00145 //! A list of ustrings 00146 typedef std::vector<ustring> StringVect; 00147 00148 //! The value of all atoms on the X server that exist in the 00149 //! Atoms struct 00150 static Atoms atoms; 00151 00152 private: 00153 //! Sets a property on a window 00154 static void set(Window win, Atom atom, Atom type, unsigned char *data, 00155 int size, int nelements, bool append); 00156 //! Gets a property's value from a window 00157 static bool get(Window win, Atom atom, Atom type, 00158 unsigned long *nelements, unsigned char **value, 00159 int size); 00160 00161 public: 00162 //! Initializes the Property class. 00163 /*! 00164 CAUTION: This function uses otk::Display, so ensure that 00165 otk::Display::initialize has been called before initializing this class! 00166 */ 00167 static void initialize(); 00168 00169 //! Sets a single-value property on a window to a new value 00170 /*! 00171 @param win The window id of the window on which to set the property's value 00172 @param atom The Atom value of the property to set. This can be found in the 00173 struct returned by Property::atoms. 00174 @param type The Atom value of the property type. This can be found in the 00175 struct returned by Property::atoms. 00176 @param value The value to set the property to 00177 */ 00178 static void set(Window win, Atom atom, Atom type, unsigned long value); 00179 //! Sets an multiple-value property on a window to a new value 00180 /*! 00181 @param win The window id of the window on which to set the property's value 00182 @param atom The Atom value of the property to set. This can be found in the 00183 struct returned by Property::atoms. 00184 @param type The Atom value of the property type. This can be found in the 00185 struct returned by Property::atoms. 00186 @param value Any array of values to set the property to. The array must 00187 contain <i>elements</i> number of elements 00188 @param elements The number of elements in the <i>value</i> array 00189 */ 00190 static void set(Window win, Atom atom, Atom type, 00191 unsigned long value[], int elements); 00192 //! Sets a string property on a window to a new value 00193 /*! 00194 @param win The window id of the window on which to set the property's value 00195 @param atom The Atom value of the property to set. This can be found in the 00196 struct returned by Property::atoms. 00197 @param type A member of the Property::StringType enum that specifies the 00198 type of the string the property is being set to 00199 @param value The string to set the property to 00200 */ 00201 static void set(Window win, Atom atom, StringType type, 00202 const ustring &value); 00203 //! Sets a string-array property on a window to a new value 00204 /*! 00205 @param win The window id of the window on which to set the property's value 00206 @param atom The Atom value of the property to set. This can be found in the 00207 struct returned by Property::atoms. 00208 @param type A member of the Property::StringType enum that specifies the 00209 type of the string the property is being set to 00210 @param strings A list of strings to set the property to 00211 */ 00212 static void set(Window win, Atom atom, StringType type, 00213 const StringVect &strings); 00214 00215 //! Gets the value of a property on a window 00216 /*! 00217 @param win The window id of the window to get the property value from 00218 @param atom The Atom value of the property to set. This can be found in the 00219 struct returned by Property::atoms. 00220 @param type The Atom value of the property type. This can be found in the 00221 struct returned by Property::atoms. 00222 @param nelements The maximum number of elements to retrieve from the 00223 property (assuming it has more than 1 value in it). To 00224 retrieve all possible elements, use "(unsigned) -1".<br> 00225 When the function returns, if it returns true, this will 00226 contain the actual number of elements retrieved.<br> 00227 @param value If the function returns true, then this contains an array of 00228 retrieved values for the property.<br> 00229 The <i>value</i> is allocated inside the function and 00230 <b>delete[]</b> value needs to be called when you are done 00231 with it.<br> 00232 The <i>value</i> array returned is null terminated, and has 00233 <i>nelements</i> elements in it plus the terminating null. 00234 @return true if retrieval of the specified property with the specified 00235 type was successful; otherwise, false 00236 */ 00237 static bool get(Window win, Atom atom, Atom type, 00238 unsigned long *nelements, unsigned long **value); 00239 //! Gets a single element from the value of a property on a window 00240 /*! 00241 @param win The window id of the window to get the property value from 00242 @param atom The Atom value of the property to set. This can be found in the 00243 struct returned by Property::atoms. 00244 @param type The Atom value of the property type. This can be found in the 00245 struct returned by Property::atoms. 00246 @param value If the function returns true, then this contains the first 00247 (and possibly only) element in the value of the specified 00248 property. 00249 @return true if retrieval of the specified property with the specified 00250 type was successful; otherwise, false 00251 */ 00252 static bool get(Window win, Atom atom, Atom type, unsigned long *value); 00253 //! Gets a single string from the value of a property on a window 00254 /*! 00255 @param win The window id of the window to get the property value from 00256 @param atom The Atom value of the property to set. This can be found in the 00257 struct returned by Property::atoms. 00258 @param type A member of the Property::StringType enum that specifies the 00259 type of the string property to retrieve 00260 @param value If the function returns true, then this contains the first 00261 (and possibly only) string in the value of the specified 00262 property. 00263 @return true if retrieval of the specified property with the specified 00264 type was successful; otherwise, false 00265 */ 00266 static bool get(Window win, Atom atom, StringType type, ustring *value); 00267 //! Gets strings from the value of a property on a window 00268 /*! 00269 @param win The window id of the window to get the property value from 00270 @param atom The Atom value of the property to set. This can be found in the 00271 struct returned by Property::atoms. 00272 @param type A member of the Property::StringType enum that specifies the 00273 type of the string property to retrieve 00274 @param nelements The maximum number of strings to retrieve from the 00275 property (assuming it has more than 1 string in it). To 00276 retrieve all possible strings, use "(unsigned) -1".<br> 00277 When the function returns, if it returns true, this will 00278 contain the actual number of strings retrieved.<br> 00279 @param strings If the function returns true, then this contains all of the 00280 strings retrieved from the property's value. 00281 @return true if retrieval of the specified property with the specified 00282 type was successful; otherwise, false 00283 */ 00284 static bool get(Window win, Atom atom, StringType type, 00285 unsigned long *nelements, StringVect *strings); 00286 00287 //! Removes a property from a window 00288 /*! 00289 @param win The window id of the window to remove the property from 00290 @param atom The Atom value of the property to set. This can be found in the 00291 struct returned by Property::atoms. 00292 */ 00293 static void erase(Window win, Atom atom); 00294 }; 00295 00296 } 00297 00298 #endif // __atom_hh