From be3a0cf4ca5092347547715ae25ea5853cf29f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 25 Sep 2013 08:54:22 +0200 Subject: [PATCH] Fix reading of window properties from effects That's what you get for changing code you cannot properly test. The calculation was completely messed up. Now reads the correct byte size for the byte array. In addition the usages in the effects are improved to cast the data into the proper uint32_t values instead of the more generic long. After all if the format is 32, the length is 32 and not a long. --- effects.cpp | 5 ++--- effects/highlightwindow/highlightwindow.cpp | 2 +- effects/kscreen/kscreen.cpp | 2 +- effects/presentwindows/presentwindows.cpp | 4 ++-- effects/slidingpopups/slidingpopups.cpp | 6 +++--- effects/taskbarthumbnail/taskbarthumbnail.cpp | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/effects.cpp b/effects.cpp index e0d755e408..f945476f86 100644 --- a/effects.cpp +++ b/effects.cpp @@ -185,9 +185,8 @@ static QByteArray readWindowProperty(xcb_window_t win, xcb_atom_t atom, xcb_atom continue; } if (prop->type == type && prop->format == format) { - const int nitems = xcb_get_property_value_length(prop.data()); - int bytelen = format == 8 ? nitems : format == 16 ? nitems * sizeof(short) : nitems * sizeof(long); - return QByteArray(reinterpret_cast< const char* >(xcb_get_property_value(prop.data())), bytelen); + return QByteArray(reinterpret_cast< const char* >(xcb_get_property_value(prop.data())), + xcb_get_property_value_length(prop.data())); } else { return QByteArray(); } diff --git a/effects/highlightwindow/highlightwindow.cpp b/effects/highlightwindow/highlightwindow.cpp index b480c4618f..e29a739943 100644 --- a/effects/highlightwindow/highlightwindow.cpp +++ b/effects/highlightwindow/highlightwindow.cpp @@ -145,7 +145,7 @@ void HighlightWindowEffect::slotPropertyNotify(EffectWindow* w, long a, EffectWi finishHighlighting(); return; } - long* data = reinterpret_cast(byteData.data()); + auto* data = reinterpret_cast(byteData.data()); if (!data[0]) { // Purposely clearing highlight by issuing a NULL target diff --git a/effects/kscreen/kscreen.cpp b/effects/kscreen/kscreen.cpp index 6eb9aa3083..ccc9ee72d3 100644 --- a/effects/kscreen/kscreen.cpp +++ b/effects/kscreen/kscreen.cpp @@ -126,7 +126,7 @@ void KscreenEffect::propertyNotify(EffectWindow *window, long int atom) return; } QByteArray byteData = effects->readRootProperty(m_atom, XCB_ATOM_CARDINAL, 32); - long *data = reinterpret_cast(byteData.data()); + auto *data = reinterpret_cast(byteData.data()); if (!data[0]) { // Property was deleted if (m_state != StateNormal) { diff --git a/effects/presentwindows/presentwindows.cpp b/effects/presentwindows/presentwindows.cpp index e90a7d171f..326f6c8236 100755 --- a/effects/presentwindows/presentwindows.cpp +++ b/effects/presentwindows/presentwindows.cpp @@ -810,7 +810,7 @@ void PresentWindowsEffect::slotPropertyNotify(EffectWindow* w, long a) setActive(false); return; } - long* data = reinterpret_cast(byteData.data()); + auto* data = reinterpret_cast(byteData.data()); if (!data[0]) { // Purposely ending present windows by issuing a NULL target @@ -839,7 +839,7 @@ void PresentWindowsEffect::slotPropertyNotify(EffectWindow* w, long a) setActive(false); return; } - long* data = reinterpret_cast(byteData.data()); + auto* data = reinterpret_cast(byteData.data()); if (!data[0]) { // Purposely ending present windows by issuing a NULL target diff --git a/effects/slidingpopups/slidingpopups.cpp b/effects/slidingpopups/slidingpopups.cpp index 3d67558234..1f31a8517b 100644 --- a/effects/slidingpopups/slidingpopups.cpp +++ b/effects/slidingpopups/slidingpopups.cpp @@ -280,13 +280,13 @@ void SlidingPopupsEffect::slotPropertyNotify(EffectWindow* w, long a) return; } - long* d = reinterpret_cast< long* >(data.data()); + auto* d = reinterpret_cast< uint32_t* >(data.data()); Data animData; animData.start = d[ 0 ]; animData.from = (Position)d[ 1 ]; - if (data.length() >= (int)(sizeof(long) * 3)) { + if (data.length() >= (int)(sizeof(uint32_t) * 3)) { animData.fadeInDuration = d[2]; - if (data.length() >= (int)(sizeof(long) * 4)) + if (data.length() >= (int)(sizeof(uint32_t) * 4)) animData.fadeOutDuration = d[3]; else animData.fadeOutDuration = d[2]; diff --git a/effects/taskbarthumbnail/taskbarthumbnail.cpp b/effects/taskbarthumbnail/taskbarthumbnail.cpp index 22443d3ea1..31fcd5dd52 100644 --- a/effects/taskbarthumbnail/taskbarthumbnail.cpp +++ b/effects/taskbarthumbnail/taskbarthumbnail.cpp @@ -127,7 +127,7 @@ void TaskbarThumbnailEffect::slotPropertyNotify(EffectWindow* w, long a) QByteArray data = w->readProperty(atom, atom, 32); if (data.length() < 1) return; - long* d = reinterpret_cast< long* >(data.data()); + auto* d = reinterpret_cast< uint32_t* >(data.data()); int len = data.length() / sizeof(d[ 0 ]); int pos = 0; int cnt = d[ 0 ];