diff options
author | Ralf Engels <ralf.engels@nokia.com> | 2010-04-19 14:22:12 +0200 |
---|---|---|
committer | Ralf Engels <ralf.engels@nokia.com> | 2010-04-19 14:22:12 +0200 |
commit | 2440777e575c348fa3336515ff07dc0e6f51faf1 (patch) | |
tree | e83f63233ac0cd7376137dd2cda8f592d5bfd69f | |
parent | 1472fda35eb2a3585f24d3a8109bb03e985ab2ea (diff) |
Fix Homescreen focus problem
-rw-r--r-- | qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.cpp | 51 | ||||
-rw-r--r-- | qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.h | 1 |
2 files changed, 51 insertions, 1 deletions
diff --git a/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.cpp b/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.cpp index b473fea..ddd962d 100644 --- a/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.cpp +++ b/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.cpp @@ -42,13 +42,16 @@ #include "qmaemo5homescreenadaptor.h" #include <QtCore/qsocketnotifier.h> +#include <QtCore/qpointer.h> #include <QtGui/qapplication.h> #include <QtGui/qx11info_x11.h> #include <QtGui/qwidget.h> +#include <QtGui/qevent.h> #include <X11/Xlib.h> #include <X11/Xatom.h> +#include <X11/Xutil.h> static QCoreApplication::EventFilter oldEventFilter; static QList<QMaemo5HomescreenAdaptor *> allDesktopItems; @@ -212,6 +215,22 @@ QMaemo5HomescreenAdaptor::QMaemo5HomescreenAdaptor(QWidget *widget) oldEventFilter = QCoreApplication::instance()->setEventFilter(applicationEventFilter); allDesktopItems.append(this); + + // --- set WM input hints indicating that we don't want focus events + XWMHints *h = XGetWMHints(display, widget->winId()); + XWMHints wm_hints; + if (!h) { + memset(&wm_hints, 0, sizeof(wm_hints)); // make valgrind happy + h = &wm_hints; + } + h->flags |= InputHint; + h->input = False; + + XSetWMHints(display, widget->winId(), h); + if (h != &wm_hints) + XFree(h); + + widget->setMouseTracking(true); } } @@ -248,9 +267,17 @@ void QMaemo5HomescreenAdaptor::socketException() appletWidget()->close(); } +bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event) +{ + return QCoreApplication::sendSpontaneousEvent(receiver, event); +} + + + /*! \internal */ bool QMaemo5HomescreenAdaptor::applicationEventFilter(void *message, long *result) { + static QPointer<QWidget> lastMouseWidget; bool retval = false; if (oldEventFilter) @@ -261,7 +288,29 @@ bool QMaemo5HomescreenAdaptor::applicationEventFilter(void *message, long *resul XEvent *ev = reinterpret_cast<XEvent *>(message); - if (ev->type == ClientMessage) { + // Generate a mouse release for a leave Notify (as we don't get the mouse release from X11) + if (ev->type == ButtonPress) { + QPoint globalPos( ev->xbutton.x_root, ev->xbutton.y_root); + QWidget *widget = QWidget::find((WId)ev->xany.window); + if (widget) { + lastMouseWidget = widget->childAt(widget->mapFromGlobal(globalPos)); + if (!lastMouseWidget) + lastMouseWidget = widget; + } + + } else if (ev->type == ButtonRelease) { + lastMouseWidget = 0; + + } else if (ev->type == LeaveNotify) { + if (lastMouseWidget) { + // create a mouse up event that lies in Nirvana. + QPoint pos(-1000, -1000); + QMouseEvent e(QEvent::MouseButtonRelease, pos, pos, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); + qt_sendSpontaneousEvent(lastMouseWidget, &e); + lastMouseWidget = 0; + } + + } else if (ev->type == ClientMessage) { XClientMessageEvent *cm = (XClientMessageEvent *)message; if (cm->message_type == hsAtoms[HildonAppletShowSettings]) { for (int i = 0; i < allDesktopItems.count(); ++i) { diff --git a/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.h b/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.h index 68c4d5b..9270649 100644 --- a/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.h +++ b/qmaemo5homescreenadaptor/qmaemo5homescreenadaptor.h @@ -43,6 +43,7 @@ #define QMAEMO5HOMESCREENADAPTOR_H #include <QtCore/qobject.h> +#include <QtCore/qpointer.h> #include <QtGui/qwidget.h> class QWidget; |