#include <property.hh>
Collaboration diagram for otk::Property:

Definition at line 133 of file property.hh.
Public Types | |
| typedef std::vector< ustring > | StringVect |
| A list of ustrings. | |
| enum | StringType { ascii, utf8 } |
| The possible types/encodings of strings. More... | |
Static Public Methods | |
| void | initialize () |
| Initializes the Property class. | |
| void | set (Window win, Atom atom, Atom type, unsigned long value) |
| Sets a single-value property on a window to a new value. | |
| void | set (Window win, Atom atom, Atom type, unsigned long value[], int elements) |
| Sets an multiple-value property on a window to a new value. | |
| void | set (Window win, Atom atom, StringType type, const ustring &value) |
| Sets a string property on a window to a new value. | |
| void | set (Window win, Atom atom, StringType type, const StringVect &strings) |
| Sets a string-array property on a window to a new value. | |
| bool | get (Window win, Atom atom, Atom type, unsigned long *nelements, unsigned long **value) |
| Gets the value of a property on a window. | |
| bool | get (Window win, Atom atom, Atom type, unsigned long *value) |
| Gets a single element from the value of a property on a window. | |
| bool | get (Window win, Atom atom, StringType type, ustring *value) |
| Gets a single string from the value of a property on a window. | |
| bool | get (Window win, Atom atom, StringType type, unsigned long *nelements, StringVect *strings) |
| Gets strings from the value of a property on a window. | |
| void | erase (Window win, Atom atom) |
| Removes a property from a window. | |
Static Public Attributes | |
| Atoms | atoms |
| The value of all atoms on the X server that exist in the Atoms struct. | |
Static Private Methods | |
| void | set (Window win, Atom atom, Atom type, unsigned char *data, int size, int nelements, bool append) |
| Sets a property on a window. | |
| bool | get (Window win, Atom atom, Atom type, unsigned long *nelements, unsigned char **value, int size) |
| Gets a property's value from a window. | |
|
|
A list of ustrings.
Definition at line 146 of file property.hh. Referenced by get(), ob::Screen::setDesktopName(), and ob::Client::updateClass(). |
|
|
The possible types/encodings of strings.
Definition at line 137 of file property.hh.
|
|
||||||||||||
|
Removes a property from a window.
Definition at line 331 of file property.cc. Referenced by ob::Client::maximize(), and ob::Client::~Client().
00332 {
00333 XDeleteProperty(**display, win, atom);
00334 }
|
|
||||||||||||||||||||||||
|
Gets strings from the value of a property on a window.
Definition at line 288 of file property.cc. References ascii, atoms, get(), otk::Atoms::string, otk::Atoms::utf8, and utf8.
00290 {
00291 assert(*nelements > 0);
00292
00293 Atom t;
00294 bool u; // utf8 encoded?
00295 switch (type) {
00296 case ascii: t = atoms.string; u = false; break;
00297 case utf8: t = atoms.utf8; u = true; break;
00298 default: assert(false); return false; // unhandled StringType
00299 }
00300
00301 unsigned char *value;
00302 unsigned long elements = (unsigned) -1;
00303 if (!get(win, atom, t, &elements, &value, 8) || elements < 1)
00304 return false;
00305
00306 std::string s((char*)value, elements);
00307 delete [] value;
00308
00309 std::string::const_iterator it = s.begin(), end = s.end();
00310 unsigned long num = 0;
00311 while(num < *nelements) {
00312 std::string::const_iterator tmp = it; // current string.begin()
00313 it = std::find(tmp, end, '\0'); // look for null between tmp and end
00314 strings->push_back(std::string(tmp, it)); // s[tmp:it)
00315 strings->back().setUtf8(u);
00316 ++num;
00317 if (it == end) break;
00318 ++it;
00319 if (it == end) break;
00320 }
00321
00322 *nelements = num;
00323
00324 return true;
00325 }
|
|
||||||||||||||||||||
|
Gets a single string from the value of a property on a window.
Definition at line 276 of file property.cc. References get(), and StringVect.
00277 {
00278 unsigned long n = 1;
00279 StringVect s;
00280
00281 if (get(win, atom, type, &n, &s)) {
00282 *value = s[0];
00283 return true;
00284 }
00285 return false;
00286 }
|
|
||||||||||||||||||||
|
Gets a single element from the value of a property on a window.
Definition at line 265 of file property.cc. References get().
00266 {
00267 unsigned long *temp;
00268 unsigned long num = 1;
00269 if (! get(win, atom, type, &num, (unsigned char **) &temp, 32))
00270 return false;
00271 *value = temp[0];
00272 delete [] temp;
00273 return true;
00274 }
|
|
||||||||||||||||||||||||
|
Gets the value of a property on a window.
Definition at line 259 of file property.cc. References get().
00261 {
00262 return get(win, atom, type, nelements, (unsigned char**) value, 32);
00263 }
|
|
||||||||||||||||||||||||||||
|
Gets a property's value from a window.
Definition at line 205 of file property.cc. Referenced by ob::Client::fullscreen(), get(), ob::Client::getDesktop(), ob::Client::getMwmHints(), ob::Client::getState(), ob::Client::getType(), ob::Client::maximize(), ob::Client::updateClass(), ob::Screen::updateDesktopNames(), ob::Client::updateIconTitle(), ob::Client::updateStrut(), and ob::Client::updateTitle().
00207 {
00208 assert(win != None); assert(atom != None); assert(type != None);
00209 assert(size == 8 || size == 16 || size == 32);
00210 assert(*nelements > 0);
00211 unsigned char *c_val = 0; // value alloc'd in Xlib, must be XFree()d
00212 Atom ret_type;
00213 int ret_size;
00214 unsigned long ret_bytes;
00215 int result;
00216 unsigned long maxread = *nelements;
00217 bool ret = false;
00218
00219 // try get the first element
00220 result = XGetWindowProperty(**display, win, atom, 0l, 1l,
00221 false, AnyPropertyType, &ret_type, &ret_size,
00222 nelements, &ret_bytes, &c_val);
00223 ret = (result == Success && ret_type == type && ret_size == size &&
00224 *nelements > 0);
00225 if (ret) {
00226 if (ret_bytes == 0 || maxread <= *nelements) {
00227 // we got the whole property's value
00228 *value = new unsigned char[*nelements * size/8 + 1];
00229 memcpy(*value, c_val, *nelements * size/8 + 1);
00230 } else {
00231 // get the entire property since it is larger than one long
00232 XFree(c_val);
00233 // the number of longs that need to be retreived to get the property's
00234 // entire value. The last + 1 is the first long that we retrieved above.
00235 int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1;
00236 if (remain > size/8 * (signed)maxread) // dont get more than the max
00237 remain = size/8 * (signed)maxread;
00238 result = XGetWindowProperty(**display, win, atom, 0l,
00239 remain, false, type, &ret_type, &ret_size,
00240 nelements, &ret_bytes, &c_val);
00241 ret = (result == Success && ret_type == type && ret_size == size &&
00242 ret_bytes == 0);
00243 /*
00244 If the property has changed type/size, or has grown since our first
00245 read of it, then stop here and try again. If it shrank, then this will
00246 still work.
00247 */
00248 if (! ret)
00249 return get(win, atom, type, &maxread, value, size);
00250
00251 *value = new unsigned char[*nelements * size/8 + 1];
00252 memcpy(*value, c_val, *nelements * size/8 + 1);
00253 }
00254 }
00255 if (c_val) XFree(c_val);
00256 return ret;
00257 }
|
|
|
Initializes the Property class. CAUTION: This function uses otk::Display, so ensure that otk::Display::initialize has been called before initializing this class! Definition at line 24 of file property.cc. References otk::Atoms::atom, atoms, otk::Atoms::cardinal, otk::create(), otk::Atoms::kde_net_system_tray_windows, otk::Atoms::kde_net_wm_system_tray_window_for, otk::Atoms::kde_net_wm_window_type_override, otk::Atoms::motif_wm_hints, otk::Atoms::net_active_window, otk::Atoms::net_client_list, otk::Atoms::net_client_list_stacking, otk::Atoms::net_close_window, otk::Atoms::net_current_desktop, otk::Atoms::net_desktop_geometry, otk::Atoms::net_desktop_names, otk::Atoms::net_desktop_viewport, otk::Atoms::net_number_of_desktops, otk::Atoms::net_supported, otk::Atoms::net_supporting_wm_check, otk::Atoms::net_wm_action_change_desktop, otk::Atoms::net_wm_action_close, otk::Atoms::net_wm_action_fullscreen, otk::Atoms::net_wm_action_maximize_horz, otk::Atoms::net_wm_action_maximize_vert, otk::Atoms::net_wm_action_minimize, otk::Atoms::net_wm_action_move, otk::Atoms::net_wm_action_resize, otk::Atoms::net_wm_action_shade, otk::Atoms::net_wm_action_stick, otk::Atoms::net_wm_allowed_actions, otk::Atoms::net_wm_desktop, otk::Atoms::net_wm_icon_name, otk::Atoms::net_wm_moveresize, otk::Atoms::net_wm_moveresize_move, otk::Atoms::net_wm_moveresize_size_bottomleft, otk::Atoms::net_wm_moveresize_size_bottomright, otk::Atoms::net_wm_moveresize_size_topleft, otk::Atoms::net_wm_moveresize_size_topright, otk::Atoms::net_wm_name, otk::Atoms::net_wm_state, otk::Atoms::net_wm_state_above, otk::Atoms::net_wm_state_below, otk::Atoms::net_wm_state_fullscreen, otk::Atoms::net_wm_state_hidden, otk::Atoms::net_wm_state_maximized_horz, otk::Atoms::net_wm_state_maximized_vert, otk::Atoms::net_wm_state_modal, otk::Atoms::net_wm_state_shaded, otk::Atoms::net_wm_state_skip_pager, otk::Atoms::net_wm_state_skip_taskbar, otk::Atoms::net_wm_state_sticky, otk::Atoms::net_wm_strut, otk::Atoms::net_wm_visible_icon_name, otk::Atoms::net_wm_visible_name, otk::Atoms::net_wm_window_type, otk::Atoms::net_wm_window_type_desktop, otk::Atoms::net_wm_window_type_dialog, otk::Atoms::net_wm_window_type_dock, otk::Atoms::net_wm_window_type_menu, otk::Atoms::net_wm_window_type_normal, otk::Atoms::net_wm_window_type_splash, otk::Atoms::net_wm_window_type_toolbar, otk::Atoms::net_wm_window_type_utility, otk::Atoms::net_workarea, otk::Atoms::openbox_active_window, otk::Atoms::openbox_pid, otk::Atoms::openbox_premax, otk::Atoms::openbox_show_root_menu, otk::Atoms::openbox_show_workspace_menu, otk::Atoms::pixmap, otk::Atoms::string, otk::Atoms::utf8, otk::Atoms::window, otk::Atoms::wm_change_state, otk::Atoms::wm_class, otk::Atoms::wm_colormap_windows, otk::Atoms::wm_delete_window, otk::Atoms::wm_icon_name, otk::Atoms::wm_name, otk::Atoms::wm_protocols, otk::Atoms::wm_state, otk::Atoms::wm_take_focus, and otk::Atoms::wm_window_role. Referenced by ob::Openbox::Openbox().
00025 {
00026 assert(display);
00027
00028 // make sure asserts fire if there is a problem
00029 memset(&atoms, 0, sizeof(Atoms));
00030
00031 atoms.cardinal = XA_CARDINAL;
00032 atoms.window = XA_WINDOW;
00033 atoms.pixmap = XA_PIXMAP;
00034 atoms.atom = XA_ATOM;
00035 atoms.string = XA_STRING;
00036 atoms.utf8 = create("UTF8_STRING");
00037
00038 atoms.openbox_pid = create("_OPENBOX_PID");
00039
00040 atoms.wm_colormap_windows = create("WM_COLORMAP_WINDOWS");
00041 atoms.wm_protocols = create("WM_PROTOCOLS");
00042 atoms.wm_state = create("WM_STATE");
00043 atoms.wm_change_state = create("WM_CHANGE_STATE");
00044 atoms.wm_delete_window = create("WM_DELETE_WINDOW");
00045 atoms.wm_take_focus = create("WM_TAKE_FOCUS");
00046 atoms.wm_name = create("WM_NAME");
00047 atoms.wm_icon_name = create("WM_ICON_NAME");
00048 atoms.wm_class = create("WM_CLASS");
00049 atoms.wm_window_role = create("WM_WINDOW_ROLE");
00050 atoms.motif_wm_hints = create("_MOTIF_WM_HINTS");
00051
00052 atoms.openbox_show_root_menu = create("_OPENBOX_SHOW_ROOT_MENU");
00053 atoms.openbox_show_workspace_menu = create("_OPENBOX_SHOW_WORKSPACE_MENU");
00054
00055 atoms.net_supported = create("_NET_SUPPORTED");
00056 atoms.net_client_list = create("_NET_CLIENT_LIST");
00057 atoms.net_client_list_stacking = create("_NET_CLIENT_LIST_STACKING");
00058 atoms.net_number_of_desktops = create("_NET_NUMBER_OF_DESKTOPS");
00059 atoms.net_desktop_geometry = create("_NET_DESKTOP_GEOMETRY");
00060 atoms.net_desktop_viewport = create("_NET_DESKTOP_VIEWPORT");
00061 atoms.net_current_desktop = create("_NET_CURRENT_DESKTOP");
00062 atoms.net_desktop_names = create("_NET_DESKTOP_NAMES");
00063 atoms.net_active_window = create("_NET_ACTIVE_WINDOW");
00064 atoms.net_workarea = create("_NET_WORKAREA");
00065 atoms.net_supporting_wm_check = create("_NET_SUPPORTING_WM_CHECK");
00066 // atoms.net_virtual_roots = create("_NET_VIRTUAL_ROOTS");
00067
00068 atoms.net_close_window = create("_NET_CLOSE_WINDOW");
00069 atoms.net_wm_moveresize = create("_NET_WM_MOVERESIZE");
00070
00071 // atoms.net_properties = create("_NET_PROPERTIES");
00072 atoms.net_wm_name = create("_NET_WM_NAME");
00073 atoms.net_wm_visible_name = create("_NET_WM_VISIBLE_NAME");
00074 atoms.net_wm_icon_name = create("_NET_WM_ICON_NAME");
00075 atoms.net_wm_visible_icon_name = create("_NET_WM_VISIBLE_ICON_NAME");
00076 atoms.net_wm_desktop = create("_NET_WM_DESKTOP");
00077 atoms.net_wm_window_type = create("_NET_WM_WINDOW_TYPE");
00078 atoms.net_wm_state = create("_NET_WM_STATE");
00079 atoms.net_wm_strut = create("_NET_WM_STRUT");
00080 // atoms.net_wm_icon_geometry = create("_NET_WM_ICON_GEOMETRY");
00081 // atoms.net_wm_icon = create("_NET_WM_ICON");
00082 // atoms.net_wm_pid = create("_NET_WM_PID");
00083 // atoms.net_wm_handled_icons = create("_NET_WM_HANDLED_ICONS");
00084 atoms.net_wm_allowed_actions = create("_NET_WM_ALLOWED_ACTIONS");
00085
00086 // atoms.net_wm_ping = create("_NET_WM_PING");
00087
00088 atoms.net_wm_window_type_desktop = create("_NET_WM_WINDOW_TYPE_DESKTOP");
00089 atoms.net_wm_window_type_dock = create("_NET_WM_WINDOW_TYPE_DOCK");
00090 atoms.net_wm_window_type_toolbar = create("_NET_WM_WINDOW_TYPE_TOOLBAR");
00091 atoms.net_wm_window_type_menu = create("_NET_WM_WINDOW_TYPE_MENU");
00092 atoms.net_wm_window_type_utility = create("_NET_WM_WINDOW_TYPE_UTILITY");
00093 atoms.net_wm_window_type_splash = create("_NET_WM_WINDOW_TYPE_SPLASH");
00094 atoms.net_wm_window_type_dialog = create("_NET_WM_WINDOW_TYPE_DIALOG");
00095 atoms.net_wm_window_type_normal = create("_NET_WM_WINDOW_TYPE_NORMAL");
00096
00097 atoms.net_wm_moveresize_size_topleft =
00098 create("_NET_WM_MOVERESIZE_SIZE_TOPLEFT");
00099 atoms.net_wm_moveresize_size_topright =
00100 create("_NET_WM_MOVERESIZE_SIZE_TOPRIGHT");
00101 atoms.net_wm_moveresize_size_bottomleft =
00102 create("_NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT");
00103 atoms.net_wm_moveresize_size_bottomright =
00104 create("_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT");
00105 atoms.net_wm_moveresize_move =
00106 create("_NET_WM_MOVERESIZE_MOVE");
00107
00108 atoms.net_wm_action_move = create("_NET_WM_ACTION_MOVE");
00109 atoms.net_wm_action_resize = create("_NET_WM_ACTION_RESIZE");
00110 atoms.net_wm_action_minimize = create("_NET_WM_ACTION_MINIMIZE");
00111 atoms.net_wm_action_shade = create("_NET_WM_ACTION_SHADE");
00112 atoms.net_wm_action_stick = create("_NET_WM_ACTION_STICK");
00113 atoms.net_wm_action_maximize_horz = create("_NET_WM_ACTION_MAXIMIZE_HORZ");
00114 atoms.net_wm_action_maximize_vert = create("_NET_WM_ACTION_MAXIMIZE_VERT");
00115 atoms.net_wm_action_fullscreen = create("_NET_WM_ACTION_FULLSCREEN");
00116 atoms.net_wm_action_change_desktop =
00117 create("_NET_WM_ACTION_CHANGE_DESKTOP");
00118 atoms.net_wm_action_close = create("_NET_WM_ACTION_CLOSE");
00119
00120 atoms.net_wm_state_modal = create("_NET_WM_STATE_MODAL");
00121 atoms.net_wm_state_sticky = create("_NET_WM_STATE_STICKY");
00122 atoms.net_wm_state_maximized_vert = create("_NET_WM_STATE_MAXIMIZED_VERT");
00123 atoms.net_wm_state_maximized_horz = create("_NET_WM_STATE_MAXIMIZED_HORZ");
00124 atoms.net_wm_state_shaded = create("_NET_WM_STATE_SHADED");
00125 atoms.net_wm_state_skip_taskbar = create("_NET_WM_STATE_SKIP_TASKBAR");
00126 atoms.net_wm_state_skip_pager = create("_NET_WM_STATE_SKIP_PAGER");
00127 atoms.net_wm_state_hidden = create("_NET_WM_STATE_HIDDEN");
00128 atoms.net_wm_state_fullscreen = create("_NET_WM_STATE_FULLSCREEN");
00129 atoms.net_wm_state_above = create("_NET_WM_STATE_ABOVE");
00130 atoms.net_wm_state_below = create("_NET_WM_STATE_BELOW");
00131
00132 atoms.kde_net_system_tray_windows = create("_KDE_NET_SYSTEM_TRAY_WINDOWS");
00133 atoms.kde_net_wm_system_tray_window_for =
00134 create("_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR");
00135 atoms.kde_net_wm_window_type_override =
00136 create("_KDE_NET_WM_WINDOW_TYPE_OVERRIDE");
00137
00138 atoms.openbox_premax = create("_OPENBOX_PREMAX");
00139 atoms.openbox_active_window = create("_OPENBOX_ACTIVE_WINDOW");
00140 }
|
|
||||||||||||||||||||
|
Sets a string-array property on a window to a new value.
Definition at line 179 of file property.cc. References ascii, atoms, otk::ustring::bytes(), otk::ustring::c_str(), set(), otk::Atoms::string, otk::Atoms::utf8, and utf8.
00181 {
00182 Atom t;
00183 bool u; // utf8 encoded?
00184 switch (type) {
00185 case ascii: t = atoms.string; u = false; break;
00186 case utf8: t = atoms.utf8; u = true; break;
00187 default: assert(false); return; // unhandled StringType
00188 }
00189
00190 ustring value(u);
00191
00192 StringVect::const_iterator it = strings.begin();
00193 const StringVect::const_iterator end = strings.end();
00194 for (; it != end; ++it) {
00195 assert(it->utf8() == u); // the ustring is encoded correctly?
00196 value += *it;
00197 value += '\0';
00198 }
00199
00200 // add 1 to the size to include the trailing null
00201 set(win, atom, t, (unsigned char*)value.c_str(), 8,
00202 value.bytes() + 1, false);
00203 }
|
|
||||||||||||||||||||
|
Sets a string property on a window to a new value.
Definition at line 164 of file property.cc. References ascii, atoms, otk::ustring::bytes(), otk::ustring::c_str(), set(), otk::Atoms::string, otk::Atoms::utf8, utf8, and otk::ustring::utf8().
00166 {
00167 Atom t;
00168 switch (type) {
00169 case ascii: t = atoms.string; assert(!value.utf8()); break;
00170 case utf8: t = atoms.utf8; assert(value.utf8()); break;
00171 default: assert(false); return; // unhandled StringType
00172 }
00173
00174 // add 1 to the size to include the trailing null
00175 set(win, atom, t, (unsigned char*) value.c_str(), 8, value.bytes() + 1,
00176 false);
00177 }
|
|
||||||||||||||||||||||||
|
Sets an multiple-value property on a window to a new value.
Definition at line 158 of file property.cc. References set().
00160 {
00161 set(win, atom, type, (unsigned char*) value, 32, elements, false);
00162 }
|
|
||||||||||||||||||||
|
Sets a single-value property on a window to a new value.
Definition at line 153 of file property.cc. References set().
00154 {
00155 set(win, atom, type, (unsigned char*) &value, 32, 1, false);
00156 }
|
|
||||||||||||||||||||||||||||||||
|
Sets a property on a window.
Definition at line 142 of file property.cc. Referenced by ob::Client::changeAllowedActions(), ob::Screen::changeClientList(), ob::Screen::changeDesktop(), ob::Screen::changeNumDesktops(), ob::Screen::changeStackingList(), ob::Client::changeState(), ob::Screen::changeSupportedAtoms(), ob::Screen::changeWorkArea(), ob::Client::Client(), ob::Client::fullscreen(), ob::Client::maximize(), ob::Screen::Screen(), set(), ob::Client::setDesktop(), ob::Screen::setDesktopName(), and ob::Openbox::setFocusedClient().
00144 {
00145 assert(win != None); assert(atom != None); assert(type != None);
00146 assert(nelements == 0 || (nelements > 0 && data != (unsigned char *) 0));
00147 assert(size == 8 || size == 16 || size == 32);
00148 XChangeProperty(**display, win, atom, type, size,
00149 (append ? PropModeAppend : PropModeReplace),
00150 data, nelements);
00151 }
|
|
|
The value of all atoms on the X server that exist in the Atoms struct.
Definition at line 20 of file property.cc. Referenced by ob::Client::changeAllowedActions(), ob::Screen::changeClientList(), ob::Screen::changeDesktop(), ob::Screen::changeNumDesktops(), ob::Screen::changeStackingList(), ob::Client::changeState(), ob::Screen::changeSupportedAtoms(), ob::Screen::changeWorkArea(), ob::Screen::clientMessageHandler(), ob::Client::clientMessageHandler(), ob::Client::close(), ob::Client::focus(), get(), ob::Client::getState(), ob::Client::getType(), initialize(), ob::Screen::propertyHandler(), ob::Client::propertyHandler(), ob::Screen::Screen(), set(), ob::Screen::setDesktopName(), ob::Client::setState(), ob::Screen::updateDesktopNames(), and ob::Client::updateProtocols(). |
1.3-rc2