summaryrefslogtreecommitdiff
path: root/otk
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-01-16 08:44:52 +0000
committerDana Jansens <danakj@orodu.net>2003-01-16 08:44:52 +0000
commitd8aff44a6a639de83ba8f0957f9f9f17f2a05532 (patch)
tree43ebc733819c4337599a55eaed7b701a3401d2a7 /otk
parent8b0daa912e72085994cfd804a60ba4113ba27148 (diff)
redo otk::Property. make it static.
Diffstat (limited to 'otk')
-rw-r--r--otk/property.cc411
-rw-r--r--otk/property.hh344
2 files changed, 305 insertions, 450 deletions
diff --git a/otk/property.cc b/otk/property.cc
index bda4ecea..a51a2353 100644
--- a/otk/property.cc
+++ b/otk/property.cc
@@ -8,6 +8,8 @@
#include "display.hh"
extern "C" {
+#include <X11/Xatom.h>
+
#include <assert.h>
}
@@ -15,168 +17,124 @@ extern "C" {
namespace otk {
-Property::Property()
+Atoms Property::atoms;
+
+static Atom create(char *name) { return XInternAtom(**display, name, false); }
+
+void Property::initialize()
{
- assert(**display);
+ assert(display);
// make sure asserts fire if there is a problem
- memset(_atoms, 0, sizeof(_atoms));
-
- _atoms[Atom_Cardinal] = XA_CARDINAL;
- _atoms[Atom_Window] = XA_WINDOW;
- _atoms[Atom_Pixmap] = XA_PIXMAP;
- _atoms[Atom_Atom] = XA_ATOM;
- _atoms[Atom_String] = XA_STRING;
- _atoms[Atom_Utf8] = create("UTF8_STRING");
+ memset(&atoms, 0, sizeof(Atoms));
+
+ atoms.cardinal = XA_CARDINAL;
+ atoms.window = XA_WINDOW;
+ atoms.pixmap = XA_PIXMAP;
+ atoms.atom = XA_ATOM;
+ atoms.string = XA_STRING;
+ atoms.utf8 = create("UTF8_STRING");
- _atoms[openbox_pid] = create("_OPENBOX_PID");
-
- _atoms[wm_colormap_windows] = create("WM_COLORMAP_WINDOWS");
- _atoms[wm_protocols] = create("WM_PROTOCOLS");
- _atoms[wm_state] = create("WM_STATE");
- _atoms[wm_change_state] = create("WM_CHANGE_STATE");
- _atoms[wm_delete_window] = create("WM_DELETE_WINDOW");
- _atoms[wm_take_focus] = create("WM_TAKE_FOCUS");
- _atoms[wm_name] = create("WM_NAME");
- _atoms[wm_icon_name] = create("WM_ICON_NAME");
- _atoms[wm_class] = create("WM_CLASS");
- _atoms[wm_window_role] = create("WM_WINDOW_ROLE");
- _atoms[motif_wm_hints] = create("_MOTIF_WM_HINTS");
- _atoms[blackbox_hints] = create("_BLACKBOX_HINTS");
- _atoms[blackbox_attributes] = create("_BLACKBOX_ATTRIBUTES");
- _atoms[blackbox_change_attributes] = create("_BLACKBOX_CHANGE_ATTRIBUTES");
- _atoms[blackbox_structure_messages] = create("_BLACKBOX_STRUCTURE_MESSAGES");
- _atoms[blackbox_notify_startup] = create("_BLACKBOX_NOTIFY_STARTUP");
- _atoms[blackbox_notify_window_add] = create("_BLACKBOX_NOTIFY_WINDOW_ADD");
- _atoms[blackbox_notify_window_del] = create("_BLACKBOX_NOTIFY_WINDOW_DEL");
- _atoms[blackbox_notify_current_workspace] =
- create("_BLACKBOX_NOTIFY_CURRENT_WORKSPACE");
- _atoms[blackbox_notify_workspace_count] =
- create("_BLACKBOX_NOTIFY_WORKSPACE_COUNT");
- _atoms[blackbox_notify_window_focus] =
- create("_BLACKBOX_NOTIFY_WINDOW_FOCUS");
- _atoms[blackbox_notify_window_raise] =
- create("_BLACKBOX_NOTIFY_WINDOW_RAISE");
- _atoms[blackbox_notify_window_lower] =
- create("_BLACKBOX_NOTIFY_WINDOW_LOWER");
+ atoms.openbox_pid = create("_OPENBOX_PID");
+
+ atoms.wm_colormap_windows = create("WM_COLORMAP_WINDOWS");
+ atoms.wm_protocols = create("WM_PROTOCOLS");
+ atoms.wm_state = create("WM_STATE");
+ atoms.wm_change_state = create("WM_CHANGE_STATE");
+ atoms.wm_delete_window = create("WM_DELETE_WINDOW");
+ atoms.wm_take_focus = create("WM_TAKE_FOCUS");
+ atoms.wm_name = create("WM_NAME");
+ atoms.wm_icon_name = create("WM_ICON_NAME");
+ atoms.wm_class = create("WM_CLASS");
+ atoms.wm_window_role = create("WM_WINDOW_ROLE");
+ atoms.motif_wm_hints = create("_MOTIF_WM_HINTS");
+
+ atoms.openbox_show_root_menu = create("_OPENBOX_SHOW_ROOT_MENU");
+ atoms.openbox_show_workspace_menu = create("_OPENBOX_SHOW_WORKSPACE_MENU");
+
+ atoms.net_supported = create("_NET_SUPPORTED");
+ atoms.net_client_list = create("_NET_CLIENT_LIST");
+ atoms.net_client_list_stacking = create("_NET_CLIENT_LIST_STACKING");
+ atoms.net_number_of_desktops = create("_NET_NUMBER_OF_DESKTOPS");
+ atoms.net_desktop_geometry = create("_NET_DESKTOP_GEOMETRY");
+ atoms.net_desktop_viewport = create("_NET_DESKTOP_VIEWPORT");
+ atoms.net_current_desktop = create("_NET_CURRENT_DESKTOP");
+ atoms.net_desktop_names = create("_NET_DESKTOP_NAMES");
+ atoms.net_active_window = create("_NET_ACTIVE_WINDOW");
+ atoms.net_workarea = create("_NET_WORKAREA");
+ atoms.net_supporting_wm_check = create("_NET_SUPPORTING_WM_CHECK");
+// atoms.net_virtual_roots = create("_NET_VIRTUAL_ROOTS");
+
+ atoms.net_close_window = create("_NET_CLOSE_WINDOW");
+ atoms.net_wm_moveresize = create("_NET_WM_MOVERESIZE");
+
+// atoms.net_properties = create("_NET_PROPERTIES");
+ atoms.net_wm_name = create("_NET_WM_NAME");
+ atoms.net_wm_visible_name = create("_NET_WM_VISIBLE_NAME");
+ atoms.net_wm_icon_name = create("_NET_WM_ICON_NAME");
+ atoms.net_wm_visible_icon_name = create("_NET_WM_VISIBLE_ICON_NAME");
+ atoms.net_wm_desktop = create("_NET_WM_DESKTOP");
+ atoms.net_wm_window_type = create("_NET_WM_WINDOW_TYPE");
+ atoms.net_wm_state = create("_NET_WM_STATE");
+ atoms.net_wm_strut = create("_NET_WM_STRUT");
+// atoms.net_wm_icon_geometry = create("_NET_WM_ICON_GEOMETRY");
+// atoms.net_wm_icon = create("_NET_WM_ICON");
+// atoms.net_wm_pid = create("_NET_WM_PID");
+// atoms.net_wm_handled_icons = create("_NET_WM_HANDLED_ICONS");
+ atoms.net_wm_allowed_actions = create("_NET_WM_ALLOWED_ACTIONS");
+
+// atoms.net_wm_ping = create("_NET_WM_PING");
- _atoms[blackbox_change_workspace] = create("_BLACKBOX_CHANGE_WORKSPACE");
- _atoms[blackbox_change_window_focus] =
- create("_BLACKBOX_CHANGE_WINDOW_FOCUS");
- _atoms[blackbox_cycle_window_focus] = create("_BLACKBOX_CYCLE_WINDOW_FOCUS");
-
- _atoms[openbox_show_root_menu] = create("_OPENBOX_SHOW_ROOT_MENU");
- _atoms[openbox_show_workspace_menu] = create("_OPENBOX_SHOW_WORKSPACE_MENU");
-
- _atoms[net_supported] = create("_NET_SUPPORTED");
- _atoms[net_client_list] = create("_NET_CLIENT_LIST");
- _atoms[net_client_list_stacking] = create("_NET_CLIENT_LIST_STACKING");
- _atoms[net_number_of_desktops] = create("_NET_NUMBER_OF_DESKTOPS");
- _atoms[net_desktop_geometry] = create("_NET_DESKTOP_GEOMETRY");
- _atoms[net_desktop_viewport] = create("_NET_DESKTOP_VIEWPORT");
- _atoms[net_current_desktop] = create("_NET_CURRENT_DESKTOP");
- _atoms[net_desktop_names] = create("_NET_DESKTOP_NAMES");
- _atoms[net_active_window] = create("_NET_ACTIVE_WINDOW");
- _atoms[net_workarea] = create("_NET_WORKAREA");
- _atoms[net_supporting_wm_check] = create("_NET_SUPPORTING_WM_CHECK");
-// _atoms[net_virtual_roots] = create("_NET_VIRTUAL_ROOTS");
-
- _atoms[net_close_window] = create("_NET_CLOSE_WINDOW");
- _atoms[net_wm_moveresize] = create("_NET_WM_MOVERESIZE");
-
-// _atoms[net_properties] = create("_NET_PROPERTIES");
- _atoms[net_wm_name] = create("_NET_WM_NAME");
- _atoms[net_wm_visible_name] = create("_NET_WM_VISIBLE_NAME");
- _atoms[net_wm_icon_name] = create("_NET_WM_ICON_NAME");
- _atoms[net_wm_visible_icon_name] = create("_NET_WM_VISIBLE_ICON_NAME");
- _atoms[net_wm_desktop] = create("_NET_WM_DESKTOP");
- _atoms[net_wm_window_type] = create("_NET_WM_WINDOW_TYPE");
- _atoms[net_wm_state] = create("_NET_WM_STATE");
- _atoms[net_wm_strut] = create("_NET_WM_STRUT");
-// _atoms[net_wm_icon_geometry] = create("_NET_WM_ICON_GEOMETRY");
-// _atoms[net_wm_icon] = create("_NET_WM_ICON");
-// _atoms[net_wm_pid] = create("_NET_WM_PID");
-// _atoms[net_wm_handled_icons] = create("_NET_WM_HANDLED_ICONS");
- _atoms[net_wm_allowed_actions] = create("_NET_WM_ALLOWED_ACTIONS");
-
-// _atoms[net_wm_ping] = create("_NET_WM_PING");
-
- _atoms[net_wm_window_type_desktop] = create("_NET_WM_WINDOW_TYPE_DESKTOP");
- _atoms[net_wm_window_type_dock] = create("_NET_WM_WINDOW_TYPE_DOCK");
- _atoms[net_wm_window_type_toolbar] = create("_NET_WM_WINDOW_TYPE_TOOLBAR");
- _atoms[net_wm_window_type_menu] = create("_NET_WM_WINDOW_TYPE_MENU");
- _atoms[net_wm_window_type_utility] = create("_NET_WM_WINDOW_TYPE_UTILITY");
- _atoms[net_wm_window_type_splash] = create("_NET_WM_WINDOW_TYPE_SPLASH");
- _atoms[net_wm_window_type_dialog] = create("_NET_WM_WINDOW_TYPE_DIALOG");
- _atoms[net_wm_window_type_normal] = create("_NET_WM_WINDOW_TYPE_NORMAL");
-
- _atoms[net_wm_moveresize_size_topleft] =
+ atoms.net_wm_window_type_desktop = create("_NET_WM_WINDOW_TYPE_DESKTOP");
+ atoms.net_wm_window_type_dock = create("_NET_WM_WINDOW_TYPE_DOCK");
+ atoms.net_wm_window_type_toolbar = create("_NET_WM_WINDOW_TYPE_TOOLBAR");
+ atoms.net_wm_window_type_menu = create("_NET_WM_WINDOW_TYPE_MENU");
+ atoms.net_wm_window_type_utility = create("_NET_WM_WINDOW_TYPE_UTILITY");
+ atoms.net_wm_window_type_splash = create("_NET_WM_WINDOW_TYPE_SPLASH");
+ atoms.net_wm_window_type_dialog = create("_NET_WM_WINDOW_TYPE_DIALOG");
+ atoms.net_wm_window_type_normal = create("_NET_WM_WINDOW_TYPE_NORMAL");
+
+ atoms.net_wm_moveresize_size_topleft =
create("_NET_WM_MOVERESIZE_SIZE_TOPLEFT");
- _atoms[net_wm_moveresize_size_topright] =
+ atoms.net_wm_moveresize_size_topright =
create("_NET_WM_MOVERESIZE_SIZE_TOPRIGHT");
- _atoms[net_wm_moveresize_size_bottomleft] =
+ atoms.net_wm_moveresize_size_bottomleft =
create("_NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT");
- _atoms[net_wm_moveresize_size_bottomright] =
+ atoms.net_wm_moveresize_size_bottomright =
create("_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT");
- _atoms[net_wm_moveresize_move] =
+ atoms.net_wm_moveresize_move =
create("_NET_WM_MOVERESIZE_MOVE");
- _atoms[net_wm_action_move] = create("_NET_WM_ACTION_MOVE");
- _atoms[net_wm_action_resize] = create("_NET_WM_ACTION_RESIZE");
- _atoms[net_wm_action_shade] = create("_NET_WM_ACTION_SHADE");
- _atoms[net_wm_action_maximize_horz] = create("_NET_WM_ACTION_MAXIMIZE_HORZ");
- _atoms[net_wm_action_maximize_vert] = create("_NET_WM_ACTION_MAXIMIZE_VERT");
- _atoms[net_wm_action_change_desktop] =
+ atoms.net_wm_action_move = create("_NET_WM_ACTION_MOVE");
+ atoms.net_wm_action_resize = create("_NET_WM_ACTION_RESIZE");
+ atoms.net_wm_action_shade = create("_NET_WM_ACTION_SHADE");
+ atoms.net_wm_action_maximize_horz = create("_NET_WM_ACTION_MAXIMIZE_HORZ");
+ atoms.net_wm_action_maximize_vert = create("_NET_WM_ACTION_MAXIMIZE_VERT");
+ atoms.net_wm_action_change_desktop =
create("_NET_WM_ACTION_CHANGE_DESKTOP");
- _atoms[net_wm_action_close] = create("_NET_WM_ACTION_CLOSE");
+ atoms.net_wm_action_close = create("_NET_WM_ACTION_CLOSE");
- _atoms[net_wm_state_modal] = create("_NET_WM_STATE_MODAL");
- _atoms[net_wm_state_sticky] = create("_NET_WM_STATE_STICKY");
- _atoms[net_wm_state_maximized_vert] = create("_NET_WM_STATE_MAXIMIZED_VERT");
- _atoms[net_wm_state_maximized_horz] = create("_NET_WM_STATE_MAXIMIZED_HORZ");
- _atoms[net_wm_state_shaded] = create("_NET_WM_STATE_SHADED");
- _atoms[net_wm_state_skip_taskbar] = create("_NET_WM_STATE_SKIP_TASKBAR");
- _atoms[net_wm_state_skip_pager] = create("_NET_WM_STATE_SKIP_PAGER");
- _atoms[net_wm_state_hidden] = create("_NET_WM_STATE_HIDDEN");
- _atoms[net_wm_state_fullscreen] = create("_NET_WM_STATE_FULLSCREEN");
- _atoms[net_wm_state_above] = create("_NET_WM_STATE_ABOVE");
- _atoms[net_wm_state_below] = create("_NET_WM_STATE_BELOW");
+ atoms.net_wm_state_modal = create("_NET_WM_STATE_MODAL");
+ atoms.net_wm_state_sticky = create("_NET_WM_STATE_STICKY");
+ atoms.net_wm_state_maximized_vert = create("_NET_WM_STATE_MAXIMIZED_VERT");
+ atoms.net_wm_state_maximized_horz = create("_NET_WM_STATE_MAXIMIZED_HORZ");
+ atoms.net_wm_state_shaded = create("_NET_WM_STATE_SHADED");
+ atoms.net_wm_state_skip_taskbar = create("_NET_WM_STATE_SKIP_TASKBAR");
+ atoms.net_wm_state_skip_pager = create("_NET_WM_STATE_SKIP_PAGER");
+ atoms.net_wm_state_hidden = create("_NET_WM_STATE_HIDDEN");
+ atoms.net_wm_state_fullscreen = create("_NET_WM_STATE_FULLSCREEN");
+ atoms.net_wm_state_above = create("_NET_WM_STATE_ABOVE");
+ atoms.net_wm_state_below = create("_NET_WM_STATE_BELOW");
- _atoms[kde_net_system_tray_windows] = create("_KDE_NET_SYSTEM_TRAY_WINDOWS");
- _atoms[kde_net_wm_system_tray_window_for] =
+ atoms.kde_net_system_tray_windows = create("_KDE_NET_SYSTEM_TRAY_WINDOWS");
+ atoms.kde_net_wm_system_tray_window_for =
create("_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR");
- _atoms[kde_net_wm_window_type_override] =
+ atoms.kde_net_wm_window_type_override =
create("_KDE_NET_WM_WINDOW_TYPE_OVERRIDE");
}
-
-/*
- * clean up the class' members
- */
-Property::~Property()
-{
-}
-
-
-/*
- * Returns an atom from the Xserver, creating it if necessary.
- */
-Atom Property::create(const char *name) const
-{
- Atom a = XInternAtom(**display, name, False);
- assert(a);
- return a;
-}
-
-
-/*
- * Internal set.
- * Sets a window property on a window, optionally appending to the existing
- * value.
- */
-void Property::set(Window win, Atom atom, Atom type,
- unsigned char* data, int size, int nelements,
- bool append) const
+void Property::set(Window win, Atom atom, Atom type, unsigned char* data,
+ int size, int nelements, bool append)
{
assert(win != None); assert(atom != None); assert(type != None);
assert(nelements == 0 || (nelements > 0 && data != (unsigned char *) 0));
@@ -186,74 +144,44 @@ void Property::set(Window win, Atom atom, Atom type,
data, nelements);
}
-
-/*
- * Set a 32-bit property value on a window.
- */
-void Property::set(Window win, Atoms atom, Atoms type,
- unsigned long value) const
+void Property::set(Window win, Atom atom, Atom type, unsigned long value)
{
- assert(atom >= 0 && atom < NUM_ATOMS);
- assert(type >= 0 && type < NUM_ATOMS);
- set(win, _atoms[atom], _atoms[type],
- reinterpret_cast<unsigned char*>(&value), 32, 1, False);
+ set(win, atom, type, (unsigned char*) &value, 32, 1, false);
}
-
-/*
- * Set an array of 32-bit properties value on a window.
- */
-void Property::set(Window win, Atoms atom, Atoms type,
- unsigned long value[], int elements) const
+void Property::set(Window win, Atom atom, Atom type, unsigned long value[],
+ int elements)
{
- assert(atom >= 0 && atom < NUM_ATOMS);
- assert(type >= 0 && type < NUM_ATOMS);
- set(win, _atoms[atom], _atoms[type],
- reinterpret_cast<unsigned char*>(value), 32, elements, False);
+ set(win, atom, type, (unsigned char*) value, 32, elements, false);
}
-
-/*
- * Set an string property value on a window.
- */
-void Property::set(Window win, Atoms atom, StringType type,
- const ustring &value) const
+void Property::set(Window win, Atom atom, StringType type,
+ const ustring &value)
{
- assert(atom >= 0 && atom < NUM_ATOMS);
- assert(type >= 0 && type < NUM_STRING_TYPE);
-
Atom t;
switch (type) {
- case ascii: t = _atoms[Atom_String]; assert(!value.utf8()); break;
- case utf8: t = _atoms[Atom_Utf8]; assert(value.utf8()); break;
- default: assert(False); return; // unhandled StringType
+ case ascii: t = atoms.string; assert(!value.utf8()); break;
+ case utf8: t = atoms.utf8; assert(value.utf8()); break;
+ default: assert(false); return; // unhandled StringType
}
-
- set(win, _atoms[atom], t,
- reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
- 8, value.size() + 1, False); // add 1 to the size to include the null
-}
+ // add 1 to the size to include the trailing null
+ set(win, atom, t, (unsigned char*) value.c_str(), 8, value.bytes() + 1,
+ false);
+}
-/*
- * Set an array of string property values on a window.
- */
-void Property::set(Window win, Atoms atom, StringType type,
- const StringVect &strings) const
+void Property::set(Window win, Atom atom, StringType type,
+ const StringVect &strings)
{
- assert(atom >= 0 && atom < NUM_ATOMS);
- assert(type >= 0 && type < NUM_STRING_TYPE);
-
Atom t;
bool u; // utf8 encoded?
switch (type) {
- case ascii: t = _atoms[Atom_String]; u = false; break;
- case utf8: t = _atoms[Atom_Utf8]; u = true; break;
- default: assert(False); return; // unhandled StringType
+ case ascii: t = atoms.string; u = false; break;
+ case utf8: t = atoms.utf8; u = true; break;
+ default: assert(false); return; // unhandled StringType
}
- ustring value;
- value.setUtf8(u);
+ ustring value(u);
StringVect::const_iterator it = strings.begin();
const StringVect::const_iterator end = strings.end();
@@ -263,22 +191,13 @@ void Property::set(Window win, Atoms atom, StringType type,
value += '\0';
}
- set(win, _atoms[atom], t,
- reinterpret_cast<unsigned char *>(const_cast<char *>(value.c_str())),
- 8, value.size(), False);
+ // add 1 to the size to include the trailing null
+ set(win, atom, t, (unsigned char*)value.c_str(), 8,
+ value.bytes() + 1, false);
}
-
-/*
- * Internal get function used by all of the typed get functions.
- * Gets an property's value from a window.
- * Returns True if the property was successfully retrieved; False if the
- * property did not exist on the window, or has a different type/size format
- * than the user tried to retrieve.
- */
-bool Property::get(Window win, Atom atom, Atom type,
- unsigned long *nelements, unsigned char **value,
- int size) const
+bool Property::get(Window win, Atom atom, Atom type, unsigned long *nelements,
+ unsigned char **value, int size)
{
assert(win != None); assert(atom != None); assert(type != None);
assert(size == 8 || size == 16 || size == 32);
@@ -289,11 +208,11 @@ bool Property::get(Window win, Atom atom, Atom type,
unsigned long ret_bytes;
int result;
unsigned long maxread = *nelements;
- bool ret = False;
+ bool ret = false;
// try get the first element
result = XGetWindowProperty(**display, win, atom, 0l, 1l,
- False, AnyPropertyType, &ret_type, &ret_size,
+ false, AnyPropertyType, &ret_type, &ret_size,
nelements, &ret_bytes, &c_val);
ret = (result == Success && ret_type == type && ret_size == size &&
*nelements > 0);
@@ -311,7 +230,7 @@ bool Property::get(Window win, Atom atom, Atom type,
if (remain > size/8 * (signed)maxread) // dont get more than the max
remain = size/8 * (signed)maxread;
result = XGetWindowProperty(**display, win, atom, 0l,
- remain, False, type, &ret_type, &ret_size,
+ remain, false, type, &ret_type, &ret_size,
nelements, &ret_bytes, &c_val);
ret = (result == Success && ret_type == type && ret_size == size &&
ret_bytes == 0);
@@ -331,79 +250,54 @@ bool Property::get(Window win, Atom atom, Atom type,
return ret;
}
-
-/*
- * Gets a 32-bit property's value from a window.
- */
-bool Property::get(Window win, Atoms atom, Atoms type,
- unsigned long *nelements,
- unsigned long **value) const
+bool Property::get(Window win, Atom atom, Atom type, unsigned long *nelements,
+ unsigned long **value)
{
- assert(atom >= 0 && atom < NUM_ATOMS);
- assert(type >= 0 && type < NUM_ATOMS);
- return get(win, _atoms[atom], _atoms[type], nelements,
- reinterpret_cast<unsigned char **>(value), 32);
+ return get(win, atom, type, nelements, (unsigned char**) value, 32);
}
-
-/*
- * Gets a single 32-bit property's value from a window.
- */
-bool Property::get(Window win, Atoms atom, Atoms type,
- unsigned long *value) const
+bool Property::get(Window win, Atom atom, Atom type, unsigned long *value)
{
- assert(atom >= 0 && atom < NUM_ATOMS);
- assert(type >= 0 && type < NUM_ATOMS);
unsigned long *temp;
unsigned long num = 1;
- if (! get(win, _atoms[atom], _atoms[type], &num,
- reinterpret_cast<unsigned char **>(&temp), 32))
- return False;
+ if (! get(win, atom, type, &num, (unsigned char **) &temp, 32))
+ return false;
*value = temp[0];
delete [] temp;
- return True;
+ return true;
}
-
-/*
- * Gets an string property's value from a window.
- */
-bool Property::get(Window win, Atoms atom, StringType type,
- ustring *value) const
+bool Property::get(Window win, Atom atom, StringType type, ustring *value)
{
unsigned long n = 1;
StringVect s;
if (get(win, atom, type, &n, &s)) {
*value = s[0];
- return True;
+ return true;
}
- return False;
+ return false;
}
-
-bool Property::get(Window win, Atoms atom, StringType type,
- unsigned long *nelements, StringVect *strings) const
+bool Property::get(Window win, Atom atom, StringType type,
+ unsigned long *nelements, StringVect *strings)
{
- assert(atom >= 0 && atom < NUM_ATOMS);
- assert(type >= 0 && type < NUM_STRING_TYPE);
- assert(win != None); assert(_atoms[atom] != None);
assert(*nelements > 0);
Atom t;
bool u; // utf8 encoded?
switch (type) {
- case ascii: t = _atoms[Atom_String]; u = false; break;
- case utf8: t = _atoms[Atom_Utf8]; u = true; break;
- default: assert(False); return False; // unhandled StringType
+ case ascii: t = atoms.string; u = false; break;
+ case utf8: t = atoms.utf8; u = true; break;
+ default: assert(false); return false; // unhandled StringType
}
unsigned char *value;
unsigned long elements = (unsigned) -1;
- if (!get(win, _atoms[atom], t, &elements, &value, 8) || elements < 1)
- return False;
+ if (!get(win, atom, t, &elements, &value, 8) || elements < 1)
+ return false;
- std::string s(reinterpret_cast<char *>(value), elements);
+ std::string s((char*)value, elements);
delete [] value;
std::string::const_iterator it = s.begin(), end = s.end();
@@ -412,7 +306,7 @@ bool Property::get(Window win, Atoms atom, StringType type,
std::string::const_iterator tmp = it; // current string.begin()
it = std::find(tmp, end, '\0'); // look for null between tmp and end
strings->push_back(std::string(tmp, it)); // s[tmp:it)
- if (!u) strings->back().setUtf8(false);
+ strings->back().setUtf8(u);
++num;
if (it == end) break;
++it;
@@ -421,17 +315,16 @@ bool Property::get(Window win, Atoms atom, StringType type,
*nelements = num;
- return True;
+ return true;
}
/*
* Removes a property entirely from a window.
*/
-void Property::erase(Window win, Atoms atom) const
+void Property::erase(Window win, Atom atom)
{
- assert(atom >= 0 && atom < NUM_ATOMS);
- XDeleteProperty(**display, win, _atoms[atom]);
+ XDeleteProperty(**display, win, atom);
}
}
diff --git a/otk/property.hh b/otk/property.hh
index 9681b9c3..1e379448 100644
--- a/otk/property.hh
+++ b/otk/property.hh
@@ -11,7 +11,6 @@
extern "C" {
#include <X11/Xlib.h>
-#include <X11/Xatom.h>
#include <assert.h>
}
@@ -20,135 +19,114 @@ extern "C" {
namespace otk {
-//! Provides easy access to window properties.
-class Property {
-public:
- //! The atoms on the X server which this class will cache
- enum Atoms {
- // types
- Atom_Cardinal, //!< The atom which represents the Cardinal data type
- Atom_Window, //!< The atom which represents window ids
- Atom_Pixmap, //!< The atom which represents pixmap ids
- Atom_Atom, //!< The atom which represents atom values
- Atom_String, //!< The atom which represents ascii strings
- Atom_Utf8, //!< The atom which represents utf8-encoded strings
-
- openbox_pid,
+//! The atoms on the X server which this class will cache
+struct Atoms {
+ // types
+ Atom cardinal; //!< The atom which represents the Cardinal data type
+ Atom window; //!< The atom which represents window ids
+ Atom pixmap; //!< The atom which represents pixmap ids
+ Atom atom; //!< The atom which represents atom values
+ Atom string; //!< The atom which represents ascii strings
+ Atom utf8; //!< The atom which represents utf8-encoded strings
- // window hints
- wm_colormap_windows,
- wm_protocols,
- wm_state,
- wm_delete_window,
- wm_take_focus,
- wm_change_state,
- wm_name,
- wm_icon_name,
- wm_class,
- wm_window_role,
- motif_wm_hints,
- blackbox_attributes,
- blackbox_change_attributes,
- blackbox_hints,
+ Atom openbox_pid;
- // blackbox-protocol atoms (wm -> client)
- blackbox_structure_messages,
- blackbox_notify_startup,
- blackbox_notify_window_add,
- blackbox_notify_window_del,
- blackbox_notify_window_focus,
- blackbox_notify_current_workspace,
- blackbox_notify_workspace_count,
- blackbox_notify_window_raise,
- blackbox_notify_window_lower,
- // blackbox-protocol atoms (client -> wm)
- blackbox_change_workspace,
- blackbox_change_window_focus,
- blackbox_cycle_window_focus,
+ // window hints
+ Atom wm_colormap_windows;
+ Atom wm_protocols;
+ Atom wm_state;
+ Atom wm_delete_window;
+ Atom wm_take_focus;
+ Atom wm_change_state;
+ Atom wm_name;
+ Atom wm_icon_name;
+ Atom wm_class;
+ Atom wm_window_role;
+ Atom motif_wm_hints;
- openbox_show_root_menu,
- openbox_show_workspace_menu,
+ Atom openbox_show_root_menu;
+ Atom openbox_show_workspace_menu;
- // NETWM atoms
- // root window properties
- net_supported,
- net_client_list,
- net_client_list_stacking,
- net_number_of_desktops,
- net_desktop_geometry,
- net_desktop_viewport,
- net_current_desktop,
- net_desktop_names,
- net_active_window,
- net_workarea,
- net_supporting_wm_check,
-// net_virtual_roots,
- // root window messages
- net_close_window,
- net_wm_moveresize,
- // application window properties
-// net_properties,
- net_wm_name,
- net_wm_visible_name,
- net_wm_icon_name,
- net_wm_visible_icon_name,
- net_wm_desktop,
- net_wm_window_type,
- net_wm_state,
- net_wm_strut,
-// net_wm_icon_geometry,
-// net_wm_icon,
-// net_wm_pid,
-// net_wm_handled_icons,
- net_wm_allowed_actions,
- // application protocols
-// net_wm_ping,
+ // NETWM atoms
+ // root window properties
+ Atom net_supported;
+ Atom net_client_list;
+ Atom net_client_list_stacking;
+ Atom net_number_of_desktops;
+ Atom net_desktop_geometry;
+ Atom net_desktop_viewport;
+ Atom net_current_desktop;
+ Atom net_desktop_names;
+ Atom net_active_window;
+ Atom net_workarea;
+ Atom net_supporting_wm_check;
+// Atom net_virtual_roots;
+ // root window messages
+ Atom net_close_window;
+ Atom net_wm_moveresize;
+ // application window properties
+// Atom net_properties;
+ Atom net_wm_name;
+ Atom net_wm_visible_name;
+ Atom net_wm_icon_name;
+ Atom net_wm_visible_icon_name;
+ Atom net_wm_desktop;
+ Atom net_wm_window_type;
+ Atom net_wm_state;
+ Atom net_wm_strut;
+// Atom net_wm_icon_geometry;
+// Atom net_wm_icon;
+// Atom net_wm_pid;
+// Atom net_wm_handled_icons;
+ Atom net_wm_allowed_actions;
+ // application protocols
+// Atom Atom net_wm_ping;
- net_wm_window_type_desktop,
- net_wm_window_type_dock,
- net_wm_window_type_toolbar,
- net_wm_window_type_menu,
- net_wm_window_type_utility,
- net_wm_window_type_splash,
- net_wm_window_type_dialog,
- net_wm_window_type_normal,
+ Atom net_wm_window_type_desktop;
+ Atom net_wm_window_type_dock;
+ Atom net_wm_window_type_toolbar;
+ Atom net_wm_window_type_menu;
+ Atom net_wm_window_type_utility;
+ Atom net_wm_window_type_splash;
+ Atom net_wm_window_type_dialog;
+ Atom net_wm_window_type_normal;
- net_wm_moveresize_size_topleft,
- net_wm_moveresize_size_topright,
- net_wm_moveresize_size_bottomleft,
- net_wm_moveresize_size_bottomright,
- net_wm_moveresize_move,
+ Atom net_wm_moveresize_size_topleft;
+ Atom net_wm_moveresize_size_topright;
+ Atom net_wm_moveresize_size_bottomleft;
+ Atom net_wm_moveresize_size_bottomright;
+ Atom net_wm_moveresize_move;
- net_wm_action_move,
- net_wm_action_resize,
- net_wm_action_shade,
- net_wm_action_maximize_horz,
- net_wm_action_maximize_vert,
- net_wm_action_change_desktop,
- net_wm_action_close,
+ Atom net_wm_action_move;
+ Atom net_wm_action_resize;
+ Atom net_wm_action_shade;
+ Atom net_wm_action_maximize_horz;
+ Atom net_wm_action_maximize_vert;
+ Atom net_wm_action_change_desktop;
+ Atom net_wm_action_close;
- net_wm_state_modal,
- net_wm_state_sticky,
- net_wm_state_maximized_vert,
- net_wm_state_maximized_horz,
- net_wm_state_shaded,
- net_wm_state_skip_taskbar,
- net_wm_state_skip_pager,
- net_wm_state_hidden,
- net_wm_state_fullscreen,
- net_wm_state_above,
- net_wm_state_below,
+ Atom net_wm_state_modal;
+ Atom net_wm_state_sticky;
+ Atom net_wm_state_maximized_vert;
+ Atom net_wm_state_maximized_horz;
+ Atom net_wm_state_shaded;
+ Atom net_wm_state_skip_taskbar;
+ Atom net_wm_state_skip_pager;
+ Atom net_wm_state_hidden;
+ Atom net_wm_state_fullscreen;
+ Atom net_wm_state_above;
+ Atom net_wm_state_below;
+
+ Atom kde_net_system_tray_windows;
+ Atom kde_net_wm_system_tray_window_for;
+ Atom kde_net_wm_window_type_override;
+};
- kde_net_system_tray_windows,
- kde_net_wm_system_tray_window_for,
- kde_net_wm_window_type_override,
-
-#ifndef DOXYGEN_IGNORE
- // constant for how many atoms exist in the enumerator
- NUM_ATOMS
-#endif
- };
+//! Provides easy access to window properties.
+class Property {
+public:
+
//! The possible types/encodings of strings
enum StringType {
ascii, //!< Standard 8-bit ascii string
@@ -158,88 +136,83 @@ public:
#endif
};
-private:
- //! The value of all atoms on the X server that exist in the
- //! Property::Atoms enum
- Atom _atoms[NUM_ATOMS];
+ //! A list of ustrings
+ typedef std::vector<ustring> StringVect;
- //! Gets the value of an Atom from the X server, creating it if nessesary
- Atom create(const char *name) const;
+ //! The value of all atoms on the X server that exist in the
+ //! Atoms struct
+ static Atoms atoms;
+private:
//! Sets a property on a window
- void set(Window win, Atom atom, Atom type, unsigned char *data,
- int size, int nelements, bool append) const;
+ static void set(Window win, Atom atom, Atom type, unsigned char *data,
+ int size, int nelements, bool append);
//! Gets a property's value from a window
- bool get(Window win, Atom atom, Atom type,
- unsigned long *nelements, unsigned char **value,
- int size) const;
+ static bool get(Window win, Atom atom, Atom type,
+ unsigned long *nelements, unsigned char **value,
+ int size);
public:
- //! A list of strings
- typedef std::vector<ustring> StringVect;
-
- //! Constructs a new Atom object
+ //! Initializes the Property class.
/*!
- CAUTION: This constructor uses Display::display, so ensure that it is
- initialized before initializing this class!
+ CAUTION: This function uses otk::Display, so ensure that
+ otk::Display::initialize has been called before initializing this class!
*/
- Property();
- //! Destroys the Atom object
- virtual ~Property();
+ static void initialize();
//! Sets a single-value property on a window to a new value
/*!
@param win The window id of the window on which to set the property's value
- @param atom A member of the Property::Atoms enum that specifies which
- property to set
- @param type A member of the Property::Atoms enum that specifies the type
- of the property to set
+ @param atom The Atom value of the property to set. This can be found in the
+ struct returned by Property::atoms.
+ @param type The Atom value of the property type. This can be found in the
+ struct returned by Property::atoms.
@param value The value to set the property to
*/
- void set(Window win, Atoms atom, Atoms type, unsigned long value) const;
+ static void set(Window win, Atom atom, Atom type, unsigned long value);
//! Sets an multiple-value property on a window to a new value
/*!
@param win The window id of the window on which to set the property's value
- @param atom A member of the Property::Atoms enum that specifies which
- property to set
- @param type A member of the Property::Atoms enum that specifies the type
- of the property to set
+ @param atom The Atom value of the property to set. This can be found in the
+ struct returned by Property::atoms.
+ @param type The Atom value of the property type. This can be found in the
+ struct returned by Property::atoms.
@param value Any array of values to set the property to. The array must
contain <i>elements</i> number of elements
@param elements The number of elements in the <i>value</i> array
*/
- void set(Window win, Atoms atom, Atoms type,
- unsigned long value[], int elements) const;
+ static void set(Window win, Atom atom, Atom type,
+ unsigned long value[], int elements);
//! Sets a string property on a window to a new value
/*!
@param win The window id of the window on which to set the property's value
- @param atom A member of the Property::Atoms enum that specifies which
- property to set
+ @param atom The Atom value of the property to set. This can be found in the
+ struct returned by Property::atoms.
@param type A member of the Property::StringType enum that specifies the
type of the string the property is being set to
@param value The string to set the property to
*/
- void set(Window win, Atoms atom, StringType type,
- const ustring &value) const;
+ static void set(Window win, Atom atom, StringType type,
+ const ustring &value);
//! Sets a string-array property on a window to a new value
/*!
@param win The window id of the window on which to set the property's value
- @param atom A member of the Property::Atoms enum that specifies which
- property to set
+ @param atom The Atom value of the property to set. This can be found in the
+ struct returned by Property::atoms.
@param type A member of the Property::StringType enum that specifies the
type of the string the property is being set to
@param strings A list of strings to set the property to
*/
- void set(Window win, Atoms atom, StringType type,
- const StringVect &strings) const;
+ static void set(Window win, Atom atom, StringType type,
+ const StringVect &strings);
//! Gets the value of a property on a window
/*!
@param win The window id of the window to get the property value from
- @param atom A member of the Property::Atoms enum that specifies which
- property to retrieve
- @param type A member of the Property::Atoms enum that specifies the type
- of the property to retrieve
+ @param atom The Atom value of the property to set. This can be found in the
+ struct returned by Property::atoms.
+ @param type The Atom value of the property type. This can be found in the
+ struct returned by Property::atoms.
@param nelements The maximum number of elements to retrieve from the
property (assuming it has more than 1 value in it). To
retrieve all possible elements, use "(unsigned) -1".<br>
@@ -255,27 +228,27 @@ public:
@return true if retrieval of the specified property with the specified
type was successful; otherwise, false
*/
- bool get(Window win, Atoms atom, Atoms type,
- unsigned long *nelements, unsigned long **value) const;
+ static bool get(Window win, Atom atom, Atom type,
+ unsigned long *nelements, unsigned long **value);
//! Gets a single element from the value of a property on a window
/*!
@param win The window id of the window to get the property value from
- @param atom A member of the Property::Atoms enum that specifies which
- property to retrieve
- @param type A member of the Property::Atoms enum that specifies the type
- of the property to retrieve
+ @param atom The Atom value of the property to set. This can be found in the
+ struct returned by Property::atoms.
+ @param type The Atom value of the property type. This can be found in the
+ struct returned by Property::atoms.
@param value If the function returns true, then this contains the first
(and possibly only) element in the value of the specified
property.
@return true if retrieval of the specified property with the specified
type was successful; otherwise, false
*/
- bool get(Window win, Atoms atom, Atoms type, unsigned long *value) const;
+ static bool get(Window win, Atom atom, Atom type, unsigned long *value);
//! Gets a single string from the value of a property on a window
/*!
@param win The window id of the window to get the property value from
- @param atom A member of the Property::Atoms enum that specifies which
- property to retrieve
+ @param atom The Atom value of the property to set. This can be found in the
+ struct returned by Property::atoms.
@param type A member of the Property::StringType enum that specifies the
type of the string property to retrieve
@param value If the function returns true, then this contains the first
@@ -284,12 +257,12 @@ public:
@return true if retrieval of the specified property with the specified
type was successful; otherwise, false
*/
- bool get(Window win, Atoms atom, StringType type, ustring *value) const;
+ static bool get(Window win, Atom atom, StringType type, ustring *value);
//! Gets strings from the value of a property on a window
/*!
@param win The window id of the window to get the property value from
- @param atom A member of the Property::Atoms enum that specifies which
- property to retrieve
+ @param atom The Atom value of the property to set. This can be found in the
+ struct returned by Property::atoms.
@param type A member of the Property::StringType enum that specifies the
type of the string property to retrieve
@param nelements The maximum number of strings to retrieve from the
@@ -302,27 +275,16 @@ public:
@return true if retrieval of the specified property with the specified
type was successful; otherwise, false
*/
- bool get(Window win, Atoms atom, StringType type,
- unsigned long *nelements, StringVect *strings) const;
+ static bool get(Window win, Atom atom, StringType type,
+ unsigned long *nelements, StringVect *strings);
//! Removes a property from a window
/*!
@param win The window id of the window to remove the property from
- @param atom A member of the Property::Atoms enum that specifies which
- property to remove from the window
- */
- void erase(Window win, Atoms atom) const;
-
- //! Gets the value of an atom on the X server
- /*!
- @param a A member of the Property::Atoms enum that specifies which Atom's
- value to return
- @return The value of the specified Atom
+ @param atom The Atom value of the property to set. This can be found in the
+ struct returned by Property::atoms.
*/
- inline Atom atom(Atoms a) const {
- assert(a >= 0 && a < NUM_ATOMS); Atom ret = _atoms[a]; assert(ret != 0);
- return ret;
- }
+ static void erase(Window win, Atom atom);
};
}