09-10-2012 07:12 AM
Hi,
in my Qt5 game I'm trying to get events from the Navigator through BPS. Basically I need to know the window state (fullscreen, thumbnail) to pause the game when not running fullscreen.
The problem is that I only receive a couple of events during startup. Later while the game is running no events are available from the event queue anymore. I know that Qt4 and Qt5 contain code to integrate BPS events into the Qt eventloop.
Still, after reading most of that code I'm still unsure what happens. Does Qt take the events out of the queue before I do? What happens to those events? Are they delivered through Qt somehow?
If anyone knows something about that I'd be grateful for all hints and pointer.
Thanks!
Conny
Solved! Go to Solution.
09-10-2012 07:37 AM
Right, BPS events are integrated into the Qt eventloop. When Qt is processing events, it also reads all BPS events and processes them. This also mean no one else should read BPS events (i.e. bps_get_event()), because otherwise these events are not available for Qt itself, and it might miss vital events needed to work properly.
Qt provides hooks to retrieve system events (BPS events in our case), see QAbstractEventDispatcher::installNativeEventFilter(). See https://qt.gitorious.org/qt/qtmultimedia/blobs/mas
In your specfic case, you don't even need to use BPS events in any way, since you'll get QEvent::ApplicationActivate and QEvent::ApplicationDeactivate events from Qt when the application goes into thumbnail state, IIRC.
09-11-2012 07:35 AM
Thanks a lot for the reply and sorry for the delay. Now I finally have some time...
I have now checked for events that are normally emitted. Unfortunately I only get QEvent::FocusIn and QEvent::FocusOut. I could use FocusIn to resume, but FocusOut is only called once I activate another application and not as soon as the task switcher is shown.
I'll now look at the QAbstractEventDispatcher. I'll report back once I know more.
09-11-2012 08:32 AM
In the Blackberry plugin for Qt, we use the navigator event NAVIGATOR_WINDOW_INACTIVE and NAVIGATOR_WINDOW_ACTIVE for activating/deactivating the application (which also translates into FocusOut/FocusIn events).
So I guess it is the navigator who doesn't send NAVIGATOR_WINDOW_INACTIVE when the app goes to thumbnail state, but only when the user switches to another application.
I suppose you can listen to NAVIGATOR_WINDOW_STATE events, that looks like it makes a difference between thumbnail and fullscreen.
09-11-2012 08:35 AM
Yes, it's exactly like that. Here is the code I'm using now. So far it seems to work great. Thanks again for the help!
#include <QDebug> #include <bps/navigator.h> #include "blackberryeventfilter.h" BlackberryEventFilter::BlackberryEventFilter(QObject *parent) : QObject(parent) { } bool BlackberryEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result) { Q_UNUSED(eventType); Q_UNUSED(result); bps_event_t * const event = static_cast<bps_event_t *>(message); // Check if it is a navigator event if (!event || (bps_event_get_domain(event) != navigator_get_domain())) { return false; } unsigned int code = bps_event_get_code(event); switch (code) { case NAVIGATOR_WINDOW_INACTIVE: qDebug() << "INFO: Window inactive"; break; case NAVIGATOR_WINDOW_ACTIVE: qDebug() << "INFO: Window active"; break; case NAVIGATOR_WINDOW_STATE: navigator_window_state_t state = navigator_event_get_window_state(event); if (state == NAVIGATOR_WINDOW_FULLSCREEN) { qDebug() << "INFO: Resume game"; } else { qDebug() << "INFO: Pause game"; } break; } // Don't stop event from beeing processed further return false; }
04-12-2013 11:19 AM
Hi Connyhald,
Thanks for sharing your code. I have a question. your "nativeEventFilter()" method require a set of parameter how to get those parameter?
04-12-2013 12:25 PM - edited 04-12-2013 12:26 PM
Simply register the filter with QGuiApplication like that:
BlackberryEventFilter *filter = new BlackberryEventFilter(); QGuiApplication::instance()->installNativeEventFilter(filter);
Hope that helps ![]()