Port EffectWatcher to QAbstractNativeEventFilter

This commit is contained in:
David Faure 2012-11-23 20:09:15 +01:00
parent d332669af8
commit c28900a1c0
4 changed files with 45 additions and 47 deletions

View File

@ -122,7 +122,6 @@ set(plasma_LIB_SRCS
private/dataenginemanager.cpp private/dataenginemanager.cpp
private/dataengineservice.cpp private/dataengineservice.cpp
private/effects/halopainter.cpp private/effects/halopainter.cpp
private/effectwatcher.cpp
private/getsource.cpp private/getsource.cpp
private/packages.cpp private/packages.cpp
private/plasmoidservice.cpp private/plasmoidservice.cpp
@ -184,6 +183,10 @@ set(plasma_LIB_SRCS
corona.cpp corona.cpp
) )
if (QT5_BUILD)
set(plasma_LIB_SRCS ${plasma_LIB_SRCS} private/effectwatcher.cpp)
endif()
kconfig_add_kcfg_files(plasma_LIB_SRCS data/kconfigxt/libplasma-theme-global.kcfgc) kconfig_add_kcfg_files(plasma_LIB_SRCS data/kconfigxt/libplasma-theme-global.kcfgc)
kde4_add_ui_files(plasma_LIB_SRCS kde4_add_ui_files(plasma_LIB_SRCS

View File

@ -19,25 +19,23 @@
#include "effectwatcher_p.h" #include "effectwatcher_p.h"
#include <kdebug.h> #include <QCoreApplication>
#if 0 // Port to Qt5 native filters
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <QX11Info> #include <xcb/xcb.h>
#endif #include <qx11info_x11.h>
namespace Plasma namespace Plasma
{ {
EffectWatcher::EffectWatcher(const QString& property, QObject *parent)
EffectWatcher::EffectWatcher(QString property, QWidget *parent) : QObject(parent),
: QWidget(parent),
m_property(property) m_property(property)
{ {
m_effectActive = isEffectActive(); m_effectActive = isEffectActive();
#pragma message("Port to Qt5 native filter")
#if 0 QCoreApplication::instance()->installNativeEventFilter(this);
kapp->installX11EventFilter( this );
Display *dpy = QX11Info::display(); Display *dpy = QX11Info::display();
Window root = DefaultRootWindow(dpy); Window root = DefaultRootWindow(dpy);
XWindowAttributes attrs; XWindowAttributes attrs;
@ -45,33 +43,33 @@ EffectWatcher::EffectWatcher(QString property, QWidget *parent)
XGetWindowAttributes(dpy, root, &attrs); XGetWindowAttributes(dpy, root, &attrs);
attrs.your_event_mask |= PropertyChangeMask; attrs.your_event_mask |= PropertyChangeMask;
XSelectInput(dpy, root, attrs.your_event_mask); XSelectInput(dpy, root, attrs.your_event_mask);
#endif
} }
bool EffectWatcher::nativeEventFilter(const QByteArray& eventType, void *message, long *result)
#pragma message("Port to Qt5 native filter")
#if 0
bool EffectWatcher::x11Event(XEvent *event)
{ {
if (event->type == PropertyNotify) { Q_UNUSED(result);
Display *dpy = QX11Info::display(); if (eventType != "xcb_generic_event_t")
Atom testAtom = XInternAtom(dpy, m_property.toLatin1(), False); return false;
if (event->xproperty.atom == testAtom) { xcb_generic_event_t* event = reinterpret_cast<xcb_generic_event_t *>(message);
bool nowEffectActive = isEffectActive(); uint response_type = event->response_type & ~0x80;
if (m_effectActive != nowEffectActive) { if (response_type != XCB_PROPERTY_NOTIFY)
m_effectActive = nowEffectActive; return false;
emit effectChanged(m_effectActive);
} xcb_property_notify_event_t* prop_event = reinterpret_cast<xcb_property_notify_event_t *>(event);
Display *dpy = QX11Info::display();
Atom testAtom = XInternAtom(dpy, m_property.toLatin1(), False);
if (prop_event->atom == testAtom) {
bool nowEffectActive = isEffectActive();
if (m_effectActive != nowEffectActive) {
m_effectActive = nowEffectActive;
emit effectChanged(m_effectActive);
} }
} }
return QWidget::x11Event(event); return false;
} }
#endif
bool EffectWatcher::isEffectActive() const bool EffectWatcher::isEffectActive() const
{ {
#pragma message("Port to Qt5 native filter")
#if 0
Display *dpy = QX11Info::display(); Display *dpy = QX11Info::display();
Atom testAtom = XInternAtom(dpy, m_property.toLatin1(), False); Atom testAtom = XInternAtom(dpy, m_property.toLatin1(), False);
@ -83,11 +81,6 @@ bool EffectWatcher::isEffectActive() const
XFree(list); XFree(list);
} }
return nowEffectActive; return nowEffectActive;
#else
return false;
#endif
} }
} } // namespace Plasma
#include "moc_effectwatcher_p.cpp"

View File

@ -20,24 +20,24 @@
#ifndef BLURWATCHER_H #ifndef BLURWATCHER_H
#define BLURWATCHER_H #define BLURWATCHER_H
#include <QWidget> #include <QObject>
#include <QAbstractNativeEventFilter>
namespace Plasma namespace Plasma
{ {
class EffectWatcher: public QWidget class EffectWatcher: public QObject, public QAbstractNativeEventFilter
{ {
Q_OBJECT Q_OBJECT
public: public:
EffectWatcher(QString property, QWidget *parent = 0); EffectWatcher(const QString& property, QObject *parent = 0);
protected: protected:
bool isEffectActive() const; bool isEffectActive() const;
#pragma message("Port to Qt5 native filter")
#if 0 bool nativeEventFilter(const QByteArray& eventType, void *message, long *result) Q_DECL_OVERRIDE;
bool x11Event(XEvent *event);
#endif
Q_SIGNALS: Q_SIGNALS:
void effectChanged(bool on); void effectChanged(bool on);
@ -47,6 +47,6 @@ private:
bool m_effectActive; bool m_effectActive;
}; };
} } // namespace Plasma
#endif #endif

View File

@ -31,8 +31,10 @@
#if HAVE_X11 #if HAVE_X11
#include <QX11Info> #include <QX11Info>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include "private/effectwatcher_p.h" #include "private/effectwatcher_p.h"
#endif #endif
#endif
#include <kcolorscheme.h> #include <kcolorscheme.h>
#include <kcomponentdata.h> #include <kcomponentdata.h>
@ -113,7 +115,7 @@ public:
if (QPixmap::defaultDepth() > 8) { if (QPixmap::defaultDepth() > 8) {
QObject::connect(KWindowSystem::self(), SIGNAL(compositingChanged(bool)), q, SLOT(compositingChanged(bool))); QObject::connect(KWindowSystem::self(), SIGNAL(compositingChanged(bool)), q, SLOT(compositingChanged(bool)));
#if HAVE_X11 #if HAVE_X11 && QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
//watch for blur effect property changes as well //watch for blur effect property changes as well
if (!s_blurEffectWatcher) { if (!s_blurEffectWatcher) {
s_blurEffectWatcher = new EffectWatcher("_KDE_NET_WM_BLUR_BEHIND_REGION"); s_blurEffectWatcher = new EffectWatcher("_KDE_NET_WM_BLUR_BEHIND_REGION");
@ -170,7 +172,7 @@ public:
static const char *defaultTheme; static const char *defaultTheme;
static const char *systemColorsTheme; static const char *systemColorsTheme;
static const char *themeRcFile; static const char *themeRcFile;
#if HAVE_X11 #if HAVE_X11 && QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
static EffectWatcher *s_blurEffectWatcher; static EffectWatcher *s_blurEffectWatcher;
#endif #endif
@ -215,7 +217,7 @@ const char *ThemePrivate::themeRcFile = "plasmarc";
// the system colors theme is used to cache unthemed svgs with colorization needs // the system colors theme is used to cache unthemed svgs with colorization needs
// these svgs do not follow the theme's colors, but rather the system colors // these svgs do not follow the theme's colors, but rather the system colors
const char *ThemePrivate::systemColorsTheme = "internal-system-colors"; const char *ThemePrivate::systemColorsTheme = "internal-system-colors";
#if HAVE_X11 #if HAVE_X11 && QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
EffectWatcher *ThemePrivate::s_blurEffectWatcher = 0; EffectWatcher *ThemePrivate::s_blurEffectWatcher = 0;
#endif #endif