From dfec59c60e55ca2bb49295da0932560d424b8b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 2 May 2013 11:14:40 +0200 Subject: [PATCH] Port getStringProperty to XCB --- kcmkwin/kwinrules/CMakeLists.txt | 9 ++++++-- tests/test_client_machine.cpp | 2 +- utils.cpp | 36 +++++++++++++------------------- utils.h | 2 +- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/kcmkwin/kwinrules/CMakeLists.txt b/kcmkwin/kwinrules/CMakeLists.txt index 1d06cd3a31..a9b809c6b4 100644 --- a/kcmkwin/kwinrules/CMakeLists.txt +++ b/kcmkwin/kwinrules/CMakeLists.txt @@ -11,7 +11,12 @@ set(kwin_rules_dialog_KDEINIT_SRCS main.cpp ${kwinrules_SRCS}) kde4_add_kdeinit_executable( kwin_rules_dialog ${kwin_rules_dialog_KDEINIT_SRCS}) -target_link_libraries(kdeinit_kwin_rules_dialog ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${X11_LIBRARIES} ${KACTIVITIES_LIBRARY}) +set(kwin_kcm_rules_XCB_LIBS + ${XCB_XCB_LIBRARIES} + ${X11_XCB_LIBRARIES} +) + +target_link_libraries(kdeinit_kwin_rules_dialog ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${X11_LIBRARIES} ${KACTIVITIES_LIBRARY} ${kwin_kcm_rules_XCB_LIBS}) install(TARGETS kdeinit_kwin_rules_dialog ${INSTALL_TARGETS_DEFAULT_ARGS} ) install(TARGETS kwin_rules_dialog DESTINATION ${LIBEXEC_INSTALL_DIR} ) @@ -23,7 +28,7 @@ set(kcm_kwinrules_PART_SRCS kcm.cpp ${kwinrules_SRCS}) kde4_add_plugin(kcm_kwinrules ${kcm_kwinrules_PART_SRCS}) -target_link_libraries(kcm_kwinrules ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${X11_LIBRARIES} ${KACTIVITIES_LIBRARY}) +target_link_libraries(kcm_kwinrules ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${X11_LIBRARIES} ${KACTIVITIES_LIBRARY} ${kwin_kcm_rules_XCB_LIBS}) install(TARGETS kcm_kwinrules DESTINATION ${PLUGIN_INSTALL_DIR} ) diff --git a/tests/test_client_machine.cpp b/tests/test_client_machine.cpp index 1d4c56f7d6..3802ce4b34 100644 --- a/tests/test_client_machine.cpp +++ b/tests/test_client_machine.cpp @@ -36,7 +36,7 @@ along with this program. If not, see . namespace KWin { // mock required function from utils -QByteArray getStringProperty(WId w, Atom prop, char separator) +QByteArray getStringProperty(xcb_window_t w, xcb_atom_t prop, char separator) { Q_UNUSED(separator) ScopedCPointer property(xcb_get_property_reply(connection(), diff --git a/utils.cpp b/utils.cpp index 31e6953fbf..29b73f0f91 100644 --- a/utils.cpp +++ b/utils.cpp @@ -120,29 +120,23 @@ void Motif::readFlags(WId w, bool& got_noborder, bool& noborder, #endif -QByteArray getStringProperty(WId w, Atom prop, char separator) +QByteArray getStringProperty(xcb_window_t w, xcb_atom_t prop, char separator) { - Atom type; - int format, status; - unsigned long nitems = 0; - unsigned long extra = 0; - unsigned char *data = 0; - QByteArray result = ""; - KXErrorHandler handler; // ignore errors - status = XGetWindowProperty(display(), w, prop, 0, 10000, - false, XA_STRING, &type, &format, - &nitems, &extra, &data); - if (status == Success) { - if (data && separator) { - for (int i = 0; i < (int)nitems; i++) - if (!data[i] && i + 1 < (int)nitems) - data[i] = separator; - } - if (data) - result = (const char*) data; - XFree(data); + const xcb_get_property_cookie_t c = xcb_get_property_unchecked(connection(), false, w, prop, + XCB_ATOM_STRING, 0, 10000); + ScopedCPointer property(xcb_get_property_reply(connection(), c, NULL)); + if (property.isNull() || property->type == XCB_ATOM_NONE) { + return QByteArray(); } - return result; + char *data = static_cast(xcb_get_property_value(property.data())); + if (data && separator) { + for (uint32_t i = 0; i < property->value_len; ++i) { + if (!data[i] && i + 1 < property->value_len) { + data[i] = separator; + } + } + } + return QByteArray(data, property->value_len); } #ifndef KCMRULES diff --git a/utils.h b/utils.h index 070f319a15..620c2d0f23 100644 --- a/utils.h +++ b/utils.h @@ -216,7 +216,7 @@ public: ScopedCPointer(T *p = 0) : QScopedPointer(p) {} }; -QByteArray getStringProperty(Window w, Atom prop, char separator = 0); +QByteArray getStringProperty(xcb_window_t w, xcb_atom_t prop, char separator = 0); void updateXTime(); void grabXServer(); void ungrabXServer();