X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=otk%2Fproperty.cc;h=bda4ecea2ad6dc3a06383a2be4236574f2f9101b;hb=b989ec13f7774bdb4b2b8675a65da56cb2fe0ef4;hp=f76469d05e8e46dd0ba3657fdef93fb28dbc74aa;hpb=d3b7c84d4c640face48dfb54d70de2bff1551429;p=chaz%2Fopenbox diff --git a/otk/property.cc b/otk/property.cc index f76469d0..bda4ecea 100644 --- a/otk/property.cc +++ b/otk/property.cc @@ -15,9 +15,9 @@ extern "C" { namespace otk { -OBProperty::OBProperty() +Property::Property() { - assert(OBDisplay::display); + assert(**display); // make sure asserts fire if there is a problem memset(_atoms, 0, sizeof(_atoms)); @@ -29,9 +29,7 @@ OBProperty::OBProperty() _atoms[Atom_String] = XA_STRING; _atoms[Atom_Utf8] = create("UTF8_STRING"); -#ifdef HAVE_GETPID - _atoms[blackbox_pid] = create("_BLACKBOX_PID"); -#endif // HAVE_GETPID + _atoms[openbox_pid] = create("_OPENBOX_PID"); _atoms[wm_colormap_windows] = create("WM_COLORMAP_WINDOWS"); _atoms[wm_protocols] = create("WM_PROTOCOLS"); @@ -42,6 +40,7 @@ OBProperty::OBProperty() _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"); @@ -132,6 +131,7 @@ OBProperty::OBProperty() _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"); @@ -139,7 +139,8 @@ OBProperty::OBProperty() _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_floating] = create("_NET_WM_STATE_FLOATING"); + _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] = @@ -152,7 +153,7 @@ OBProperty::OBProperty() /* * clean up the class' members */ -OBProperty::~OBProperty() +Property::~Property() { } @@ -160,9 +161,11 @@ OBProperty::~OBProperty() /* * Returns an atom from the Xserver, creating it if necessary. */ -Atom OBProperty::create(const char *name) const +Atom Property::create(const char *name) const { - return XInternAtom(OBDisplay::display, name, False); + Atom a = XInternAtom(**display, name, False); + assert(a); + return a; } @@ -171,14 +174,14 @@ Atom OBProperty::create(const char *name) const * Sets a window property on a window, optionally appending to the existing * value. */ -void OBProperty::set(Window win, Atom atom, Atom type, +void Property::set(Window win, Atom atom, Atom type, unsigned char* data, int size, int nelements, bool append) const { assert(win != None); assert(atom != None); assert(type != None); assert(nelements == 0 || (nelements > 0 && data != (unsigned char *) 0)); assert(size == 8 || size == 16 || size == 32); - XChangeProperty(OBDisplay::display, win, atom, type, size, + XChangeProperty(**display, win, atom, type, size, (append ? PropModeAppend : PropModeReplace), data, nelements); } @@ -187,7 +190,7 @@ void OBProperty::set(Window win, Atom atom, Atom type, /* * Set a 32-bit property value on a window. */ -void OBProperty::set(Window win, Atoms atom, Atoms type, +void Property::set(Window win, Atoms atom, Atoms type, unsigned long value) const { assert(atom >= 0 && atom < NUM_ATOMS); @@ -200,7 +203,7 @@ void OBProperty::set(Window win, Atoms atom, Atoms type, /* * Set an array of 32-bit properties value on a window. */ -void OBProperty::set(Window win, Atoms atom, Atoms type, +void Property::set(Window win, Atoms atom, Atoms type, unsigned long value[], int elements) const { assert(atom >= 0 && atom < NUM_ATOMS); @@ -213,18 +216,19 @@ void OBProperty::set(Window win, Atoms atom, Atoms type, /* * Set an string property value on a window. */ -void OBProperty::set(Window win, Atoms atom, StringType type, - const std::string &value) const +void Property::set(Window win, Atoms atom, StringType type, + const ustring &value) const { assert(atom >= 0 && atom < NUM_ATOMS); assert(type >= 0 && type < NUM_STRING_TYPE); Atom t; switch (type) { - case ascii: t = _atoms[Atom_String]; break; - case utf8: t = _atoms[Atom_Utf8]; break; + 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 } + set(win, _atoms[atom], t, reinterpret_cast(const_cast(value.c_str())), 8, value.size() + 1, False); // add 1 to the size to include the null @@ -234,25 +238,30 @@ void OBProperty::set(Window win, Atoms atom, StringType type, /* * Set an array of string property values on a window. */ -void OBProperty::set(Window win, Atoms atom, StringType type, +void Property::set(Window win, Atoms atom, StringType type, const StringVect &strings) const { 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]; break; - case utf8: t = _atoms[Atom_Utf8]; break; + case ascii: t = _atoms[Atom_String]; u = false; break; + case utf8: t = _atoms[Atom_Utf8]; u = true; break; default: assert(False); return; // unhandled StringType } - std::string value; + ustring value; + value.setUtf8(u); StringVect::const_iterator it = strings.begin(); const StringVect::const_iterator end = strings.end(); - for (; it != end; ++it) - value += *it + '\0'; + for (; it != end; ++it) { + assert(it->utf8() == u); // the ustring is encoded correctly? + value += *it; + value += '\0'; + } set(win, _atoms[atom], t, reinterpret_cast(const_cast(value.c_str())), @@ -267,7 +276,7 @@ void OBProperty::set(Window win, Atoms atom, StringType type, * property did not exist on the window, or has a different type/size format * than the user tried to retrieve. */ -bool OBProperty::get(Window win, Atom atom, Atom type, +bool Property::get(Window win, Atom atom, Atom type, unsigned long *nelements, unsigned char **value, int size) const { @@ -283,7 +292,7 @@ bool OBProperty::get(Window win, Atom atom, Atom type, bool ret = False; // try get the first element - result = XGetWindowProperty(OBDisplay::display, win, atom, 0l, 1l, + result = XGetWindowProperty(**display, win, atom, 0l, 1l, False, AnyPropertyType, &ret_type, &ret_size, nelements, &ret_bytes, &c_val); ret = (result == Success && ret_type == type && ret_size == size && @@ -301,7 +310,7 @@ bool OBProperty::get(Window win, Atom atom, Atom type, int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1; if (remain > size/8 * (signed)maxread) // dont get more than the max remain = size/8 * (signed)maxread; - result = XGetWindowProperty(OBDisplay::display, win, atom, 0l, + result = XGetWindowProperty(**display, win, atom, 0l, remain, False, type, &ret_type, &ret_size, nelements, &ret_bytes, &c_val); ret = (result == Success && ret_type == type && ret_size == size && @@ -326,7 +335,7 @@ bool OBProperty::get(Window win, Atom atom, Atom type, /* * Gets a 32-bit property's value from a window. */ -bool OBProperty::get(Window win, Atoms atom, Atoms type, +bool Property::get(Window win, Atoms atom, Atoms type, unsigned long *nelements, unsigned long **value) const { @@ -340,7 +349,7 @@ bool OBProperty::get(Window win, Atoms atom, Atoms type, /* * Gets a single 32-bit property's value from a window. */ -bool OBProperty::get(Window win, Atoms atom, Atoms type, +bool Property::get(Window win, Atoms atom, Atoms type, unsigned long *value) const { assert(atom >= 0 && atom < NUM_ATOMS); @@ -359,11 +368,12 @@ bool OBProperty::get(Window win, Atoms atom, Atoms type, /* * Gets an string property's value from a window. */ -bool OBProperty::get(Window win, Atoms atom, StringType type, - std::string *value) const +bool Property::get(Window win, Atoms atom, StringType type, + ustring *value) const { unsigned long n = 1; StringVect s; + if (get(win, atom, type, &n, &s)) { *value = s[0]; return True; @@ -372,8 +382,8 @@ bool OBProperty::get(Window win, Atoms atom, StringType type, } -bool OBProperty::get(Window win, Atoms atom, StringType type, - unsigned long *nelements, StringVect *strings) const +bool Property::get(Window win, Atoms atom, StringType type, + unsigned long *nelements, StringVect *strings) const { assert(atom >= 0 && atom < NUM_ATOMS); assert(type >= 0 && type < NUM_STRING_TYPE); @@ -381,9 +391,10 @@ bool OBProperty::get(Window win, Atoms atom, StringType type, assert(*nelements > 0); Atom t; + bool u; // utf8 encoded? switch (type) { - case ascii: t = _atoms[Atom_String]; break; - case utf8: t = _atoms[Atom_Utf8]; break; + 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 } @@ -401,6 +412,7 @@ bool OBProperty::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); ++num; if (it == end) break; ++it; @@ -416,10 +428,10 @@ bool OBProperty::get(Window win, Atoms atom, StringType type, /* * Removes a property entirely from a window. */ -void OBProperty::erase(Window win, Atoms atom) const +void Property::erase(Window win, Atoms atom) const { assert(atom >= 0 && atom < NUM_ATOMS); - XDeleteProperty(OBDisplay::display, win, _atoms[atom]); + XDeleteProperty(**display, win, _atoms[atom]); } }