Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
bryanh99
Posts: 43
Registered: ‎06-30-2012
My Device: Bold 9900
My Carrier: T-Mobile
Accepted Solution

Cascades QML and getting "SCREEN_IDLE_MODE_KEEP_AWAKE" to work

I have a QML driven application running just fine but after the usual timeout the screen turns off.  I need a way to keep it on.

 

I have tried adding a "ForeignWindow" to my QML and then use FindChild to find the window, attach it to a ForeignWindow pointer and using that.  I have no errors but the screen still turns off.

 

So if anyone has every gotten a Cascades QML driven UI app to actually keep the screen on, please share your secret.

 

Thank you

Bryan

 

 

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1154, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Cascades QML and getting "SCREEN_IDLE_MODE_KEEP_AWAKE" to work

Right now it does not seem possible to do this with Cascades:

http://supportforums.blackberry.com/t5/Native-Development/Cascades-way-of-keeping-the-display-awake/...

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Contributor
bryanh99
Posts: 43
Registered: ‎06-30-2012
My Device: Bold 9900
My Carrier: T-Mobile

Re: Cascades QML and getting "SCREEN_IDLE_MODE_KEEP_AWAKE" to work

Yes, I have read all those threads, but I am sure there MUST be a way to accomplish this.....

 

 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: Cascades QML and getting "SCREEN_IDLE_MODE_KEEP_AWAKE" to work

I confirmed a few things you already noted.

 

First, I note the documentation for screen_get_display_property_iv supports SCREEN_PROPERTY_KEEP_AWAKES

https://developer.blackberry.com/native/beta/reference/screen_libref/topic/screen_get_display_proper...

 

But the documentation for the corresponding screen_set_display_property_iv indicates this is not supported in R4:

https://developer.blackberry.com/native/beta/reference/screen_libref/topic/screen_set_display_proper...

 

I confirmed this by borrowing on http://supportforums.blackberry.com/t5/Cascades-Development/Display-Width-and-Height/td-p/1788393 (code below).   I get ENOTSUP when I attempt to set the value.

 

If you need this feature, please request a feature in Issue Tracker: http://supportforums.blackberry.com/t5/Java-Development/Developer-Issue-Tracker/td-p/271768

Please ensure the visibility is set to public, and post the link here so others can "vote" for it.

 

===============

 

In hellocascades I added to hellowcascades.pro:

LIBS += -lscreen

 

In HelloCascades constructor I added:

        screen_context_t m_screen_cxt;
        int count = 0;

        screen_create_context(&m_screen_cxt, SCREEN_APPLICATION_CONTEXT);
        screen_get_context_property_iv(m_screen_cxt, SCREEN_PROPERTY_DISPLAY_COUNT, &count);
        if (count >= 1)
        {
            screen_display_t* displays = (screen_display_t*)calloc(count, sizeof(screen_display_t));

            screen_get_context_property_pv(m_screen_cxt, SCREEN_PROPERTY_DISPLAYS, (void **)displays);

            int keepawake = -1; //SCREEN_IDLE_MODE_NORMAL; //SCREEN_IDLE_MODE_KEEP_AWAKE;
            int rv = screen_get_display_property_iv(displays[0], SCREEN_PROPERTY_KEEP_AWAKES, &keepawake);
            qDebug() << "Initial get: keepawake = " << keepawake;
            qDebug() << "Return code: " << rv;
            if (rv < 0) qDebug() << " errno: " << errno;

            keepawake = !keepawake;
            qDebug() << "Attempting to set keepawake = " << keepawake;
            rv = screen_set_display_property_iv(displays[0], SCREEN_PROPERTY_KEEP_AWAKES, &keepawake);
            qDebug() << "Set: Return code: " << rv;
            if (rv < 0) qDebug() << " errno: " << errno;

            rv = screen_get_display_property_iv(displays[0], SCREEN_PROPERTY_KEEP_AWAKES, &keepawake);
            qDebug() << "After set: keepawake = " << keepawake;
            qDebug() << "Return code: " << rv;
            if (rv < 0) qDebug() << " errno: " << errno;

            free(displays);
        }

 

This gives output:

 

Initial get: keepawake =  0
Return code:  0
Attempting to set keepawake =  1
Set: Return code:  -1
 errno:  48
After set: keepawake =  0
Return code:  0

Stuart

Please use plain text.
Contributor
bryanh99
Posts: 43
Registered: ‎06-30-2012
My Device: Bold 9900
My Carrier: T-Mobile

Re: Cascades QML and getting "SCREEN_IDLE_MODE_KEEP_AWAKE" to work

The issue with what you did is that SCREEN_IDLE_MODE_KEEP_AWAKE is a parameter for window using screen_set_window_property_iv not for the screen using screen_set_display_property_iv
Please use plain text.
Contributor
bryanh99
Posts: 43
Registered: ‎06-30-2012
My Device: Bold 9900
My Carrier: T-Mobile

Re: Cascades QML and getting "SCREEN_IDLE_MODE_KEEP_AWAKE" to work

[ Edited ]

I have now tried creating a seperate thread and create a screen context in said thread.  I can see the IDLE_TIMEOUT event, but cannot figure out a why to get a window ID to set the SCREEN_IDLE_MODE_KEEP_AWAKE.

 

I have considered a "screen_send_event" or "screen_inject_event"  but cannot find a good example of sending a real event.

 

 

 

Please use plain text.
Contributor
bryanh99
Posts: 43
Registered: ‎06-30-2012
My Device: Bold 9900
My Carrier: T-Mobile

Re: Cascades QML and getting "SCREEN_IDLE_MODE_KEEP_AWAKE" to work

Well, I am marking this as closed in that I have found a method to keep the screen awake (until it is actually fully supported in Cascades.

 

The method was built with input from two people and a lot of searching.  Here is the result

 

1) Create a new thread

2) In the thread create a screen context

3) request events for screen and navigator

4) when you get a message of screen idle, inject a touch event into the screen queue

 

Works great.  thank you all for your help

 

Please use plain text.
Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook
My Carrier: Rogers

Re: Cascades QML and getting "SCREEN_IDLE_MODE_KEEP_AWAKE" to work

Any chance you could post your actual code for this solution?  I'm having trouble tracking down how to inject a touch event into a screen queue.

---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.
Contributor
mnosov
Posts: 15
Registered: ‎10-25-2012
My Device: Dev Alpha B
My Carrier: Megafon

Re: Cascades QML and getting "SCREEN_IDLE_MODE_KEEP_AWAKE" to work

I see that Window class has now function setScreenIdleMode. So,

 

Application app(argc, argv);

app.mainWindow()->setScreenIdleMode(bb::cascades::smileyfrustrated:creenIdleMode::KeepAwake);

 

will prevent forcing idle mode after timeout. I've tried this and it works fine on my Dev Alpha device

Please use plain text.
Developer
smiley
Posts: 1,466
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: Cascades QML and getting "SCREEN_IDLE_MODE_KEEP_AWAKE" to work


mnosov wrote:

I see that Window class has now function setScreenIdleMode. So,

 

Application app(argc, argv);

app.mainWindow()->setScreenIdleMode(bb::cascades::smileyfrustrated:creenIdleMode::KeepAwake);

 

will prevent forcing idle mode after timeout. I've tried this and it works fine on my Dev Alpha device


doesn't work and can't compile the above code.

Please use plain text.