X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=otk%2Fproperty.cc;h=bda4ecea2ad6dc3a06383a2be4236574f2f9101b;hb=231f4dadabd532183317188c1a0e8ffe87dc579b;hp=ad9eacc90736ce6a7ec1cb96c2f6676f5f79562e;hpb=8f8acc24933830d4f5784616b9b0c5896bde0b93;p=chaz%2Fopenbox diff --git a/otk/property.cc b/otk/property.cc index ad9eacc9..bda4ecea 100644 --- a/otk/property.cc +++ b/otk/property.cc @@ -17,7 +17,7 @@ namespace otk { Property::Property() { - assert(Display::display); + assert(**display); // make sure asserts fire if there is a problem memset(_atoms, 0, sizeof(_atoms)); @@ -163,7 +163,7 @@ Property::~Property() */ Atom Property::create(const char *name) const { - Atom a = XInternAtom(Display::display, name, False); + Atom a = XInternAtom(**display, name, False); assert(a); return a; } @@ -181,7 +181,7 @@ void Property::set(Window win, Atom atom, Atom type, 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(Display::display, win, atom, type, size, + XChangeProperty(**display, win, atom, type, size, (append ? PropModeAppend : PropModeReplace), data, nelements); } @@ -217,17 +217,18 @@ void Property::set(Window win, Atoms atom, Atoms type, * Set an string property value on a window. */ void Property::set(Window win, Atoms atom, StringType type, - const std::string &value) const + 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 @@ -244,18 +245,23 @@ void Property::set(Window win, Atoms atom, StringType type, 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())), @@ -286,7 +292,7 @@ bool Property::get(Window win, Atom atom, Atom type, bool ret = False; // try get the first element - result = XGetWindowProperty(Display::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 && @@ -304,7 +310,7 @@ bool Property::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(Display::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 && @@ -363,10 +369,11 @@ bool Property::get(Window win, Atoms atom, Atoms type, * Gets an string property's value from a window. */ bool Property::get(Window win, Atoms atom, StringType type, - std::string *value) const + ustring *value) const { unsigned long n = 1; StringVect s; + if (get(win, atom, type, &n, &s)) { *value = s[0]; return True; @@ -376,7 +383,7 @@ bool Property::get(Window win, Atoms atom, StringType type, bool Property::get(Window win, Atoms atom, StringType type, - unsigned long *nelements, StringVect *strings) const + unsigned long *nelements, StringVect *strings) const { assert(atom >= 0 && atom < NUM_ATOMS); assert(type >= 0 && type < NUM_STRING_TYPE); @@ -384,9 +391,10 @@ bool Property::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 } @@ -404,6 +412,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); ++num; if (it == end) break; ++it; @@ -422,7 +431,7 @@ bool Property::get(Window win, Atoms atom, StringType type, void Property::erase(Window win, Atoms atom) const { assert(atom >= 0 && atom < NUM_ATOMS); - XDeleteProperty(Display::display, win, _atoms[atom]); + XDeleteProperty(**display, win, _atoms[atom]); } }