Friday, February 1, 2013

Preventing display dimming in BB10 with Qt

Recently I was creating an application for BB10, where I need to disable display dimming. This same approach also works to avoid auto lock.

There is already API for this if you are using cascades API.

Following should do for Cascades Application
//for C++
Application::mainWindow->screenIdleMode = ScreenIdleMode::KeepAwake;

//for QML, we need to use constant as it seems required enum is not exported properly
Application.mainWindow.screenIdleMode = 1

But my application was pure Qt application. For this I required to use native API. Following is code which i used to achieve desired behavior.
        QScopedPointer view(new QDeclarativeView());
        view->setSource(QUrl("app/native/assets/main.qml"));
        view->showFullScreen();

 int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
 WId winId = view->winId();
 screen_set_window_property_iv(screen_window_t(winId), SCREEN_PROPERTY_IDLE_MODE,&idle_mode);
You will need to add following headers.
#include <bps/bps.h>
#include <bps/navigator.h>
#include <bps/screen.h>
And need to link screen library.
LIBS += -lscreen

1 comment:

  1. Hi. Thanks for this....the code i was using which wasnt working is almost the same as this, so i changed it to match this, and it still doesnt work. Screen idles after a short while. Anything else i could be doing wrong?

    viewer->showFullScreen();

    int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
    WId winId = viewer->winId();
    screen_set_window_property_iv(screen_window_t(winId), SCREEN_PROPERTY_IDLE_MODE, &idle_mode);

    Thx

    ReplyDelete