The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
WinRT keep display on
hardcoredaniel
Guest

Hi David,

I'm trying to keep the screen programmatically on for some time, but I'm not doing it right. This is my simple code:

--------------------------

using namespace Windows::System::Display;

DisplayRequest ^ request = ref new DisplayRequest();

if (keepOn != 0)
{
request->RequestActive();
}
else
{
request->RequestRelease();
}

---------------------------

but there must be sth. fundamentally wrong with it, because when I call RequestRelease() I get an exception from WinRT about calling something at an unexpected time. I'm calling it from SDL's main thread, which is probably not the UI thread.

I saw in your code for the game bar that you are using something called a "dispatcher", I suppose this is to run sth. on the UI thread. Do I need to do the same for DisplayRequest()? Anything else I have missed?


Regards,

Daniel
WinRT keep display on
DLudwig


Joined: 09 Feb 2012
Posts: 179
I'm not sure why this call isn't working.  SDL's main thread on WinRT is, at present, typically the main thread.

Did the exception contain any more info?

I can plan on looking into this when I get a chance, hopefully in within the next few weeks, but make no guarantees.


-- David L.






On Sat, Aug 27, 2016 at 7:54 AM, hardcoredaniel wrote:
Quote:
Hi David,

I'm trying to keep the screen programmatically on for some time, but I'm not doing it right. This is my simple code:

--------------------------

    using namespace Windows::System::Display;

    DisplayRequest ^ request = ref new DisplayRequest();

    if (keepOn != 0)
    {
        request->RequestActive();
    }
    else
    {
        request->RequestRelease();
    }

---------------------------

but there must be sth. fundamentally wrong with it, because when I call RequestRelease() I get an exception from WinRT about calling something at an unexpected time. I'm calling it from SDL's main thread, which is probably not the UI thread.

I saw in your code for the game bar that you are using something called a "dispatcher", I suppose this is to run sth. on the UI thread. Do I need to do the same for DisplayRequest()? Anything else I have missed?


Regards,

Daniel



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

WinRT keep display on
hardcoredaniel
Guest

Hi David,

unfortunately that was the only message of the exception, "a function being called at an unexpected time".

I have googled a bit and found a suggestion to keep the DisplayRequest object that the requestActive() was called on for the corresponding requestRelease() call. This code does at least not crash immediately:


DisplayRequest ^ request = nullptr;

void SetKeepDisplayOn(int keepOn)
{

if (request == nullptr)
{
request = ref new DisplayRequest();
if (keepOn != 0)
{
request->RequestActive();
}
else
{
SDL_Log("Error: Trying to release display although not acquired!\n");
}
}
else
{
if (keepOn == 0)
{
request->RequestRelease();
request = nullptr;
}
else
{
SDL_Log("Error: Trying to acquire display although already acquired!\n");
}
}
}

but I can't say whether this is really correct and without side effects, esp. w.r.t. the lifetime of DisplayRequest objects. Can you please take a look at this code for obvious defects?

Regards,

Daniel




---------- Původní zpráva ----------
Od: David Ludwig
Komu: SDL Development List
Datum: 27. 8. 2016 15:29:14
Předmět: Re: [SDL] WinRT keep display on
Quote:
I'm not sure why this call isn't working. SDL's main thread on WinRT is, at present, typically the main thread.

Did the exception contain any more info?

I can plan on looking into this when I get a chance, hopefully in within the next few weeks, but make no guarantees.


-- David L.






On Sat, Aug 27, 2016 at 7:54 AM, hardcoredaniel wrote:
Quote:
Hi David,

I'm trying to keep the screen programmatically on for some time, but I'm not doing it right. This is my simple code:

--------------------------

using namespace Windows::System::Display;

DisplayRequest ^ request = ref new DisplayRequest();

if (keepOn != 0)
{
request->RequestActive();
}
else
{
request->RequestRelease();
}

---------------------------

but there must be sth. fundamentally wrong with it, because when I call RequestRelease() I get an exception from WinRT about calling something at an unexpected time. I'm calling it from SDL's main thread, which is probably not the UI thread.

I saw in your code for the game bar that you are using something called a "dispatcher", I suppose this is to run sth. on the UI thread. Do I need to do the same for DisplayRequest()? Anything else I have missed?


Regards,

Daniel



______________________________ _________________
SDL mailing list

http://lists.libsdl.org/ listinfo.cgi/sdl-libsdl.org





_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
WinRT keep display on
DLudwig


Joined: 09 Feb 2012
Posts: 179
I think that'll work.  If not, I went ahead and made SDL manage its own DisplayRequest, via calls to SDL_EnableScreenSaver() and SDL_DisableScreenSaver() (via https://hg.libsdl.org/SDL/rev/db77073d402d ).  To note, SDL2 will, by default, call SDL_EnableScreenSaver().

-- David L.





On Sat, Aug 27, 2016 at 12:11 PM, hardcoredaniel wrote:
Quote:
Hi David,

unfortunately that was the only message of the exception, "a function being called at an unexpected time".

I have googled a bit and found a suggestion to keep the DisplayRequest object that the requestActive() was called on for the corresponding requestRelease() call. This code does at least not crash immediately:


DisplayRequest ^ request = nullptr;

void SetKeepDisplayOn(int keepOn)
{

    if (request == nullptr)
    {
        request = ref new DisplayRequest();
        if (keepOn != 0)
        {
            request->RequestActive();
        }
        else
        {
            SDL_Log("Error: Trying to release display although not acquired!\n");
        }
    }
    else
    {
        if (keepOn == 0)
        {
            request->RequestRelease();
            request = nullptr;
        }
        else
        {
            SDL_Log("Error: Trying to acquire display although already acquired!\n");
        }
    }
}

but I can't say whether this is really correct and without side effects, esp. w.r.t. the lifetime of DisplayRequest objects. Can you please take a look at this code for obvious defects?

Regards,

Daniel




---------- Původní zpráva ----------
Od: David Ludwig
Komu: SDL Development List
Datum: 27. 8. 2016 15:29:14
Předmět: Re: [SDL] WinRT keep display on
Quote:
I'm not sure why this call isn't working.  SDL's main thread on WinRT is, at present, typically the main thread.

Did the exception contain any more info?

I can plan on looking into this when I get a chance, hopefully in within the next few weeks, but make no guarantees.


-- David L.






On Sat, Aug 27, 2016 at 7:54 AM, hardcoredaniel wrote:
Quote:
Hi David,

I'm trying to keep the screen programmatically on for some time, but I'm not doing it right. This is my simple code:

--------------------------

    using namespace Windows::System::Display;

    DisplayRequest ^ request = ref new DisplayRequest();

    if (keepOn != 0)
    {
        request->RequestActive();
    }
    else
    {
        request->RequestRelease();
    }

---------------------------

but there must be sth. fundamentally wrong with it, because when I call RequestRelease() I get an exception from WinRT about calling something at an unexpected time. I'm calling it from SDL's main thread, which is probably not the UI thread.

I saw in your code for the game bar that you are using something called a "dispatcher", I suppose this is to run sth. on the UI thread. Do I need to do the same for DisplayRequest()? Anything else I have missed?


Regards,

Daniel



______________________________ _________________
SDL mailing list

http://lists.libsdl.org/ listinfo.cgi/sdl-libsdl.org





_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org