SDL2: SDL_WINDOWEVENT is blocked ?

84 views
Skip to first unread message

BL

unread,
Oct 22, 2015, 8:21:40 PM10/22/15
to Native-Client-Discuss
Hi,

My Chrome App using libSDL2, In the SDL event handler (code below), 
I'm able to get all the keyboard and mouse events BUT NONE of the window event (SDL_WINDOWEVENT) was received.
The window events are blocked. Is there a way for the SDL event handler to receive SDL_WINDOWEVENT ?
Thanks

Below, the event handler loop, I got all SDL_KEY... and SDL_MOUSE... events 
but none for SDL_WINDOWEVENT when minimize, maximize, restore, resize, etc... the Chrome window.

    while (!done) {
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_QUIT:
                SDL_Log("%s(): SDL_QUIT", __func__);
                done = SDL_TRUE;
                break;

            case SDL_KEYDOWN:
                SDL_Log("%s(): SDL_KEYDOWN...", __func__);
                if (event.key.keysym.sym == SDLK_ESCAPE) {
                    SDL_Log("%s(): SDL_KEYDOWN=SDLK_ESCAPE", __func__);
                    done = SDL_TRUE;
                }
                break;
            case SDL_KEYUP:
                SDL_Log("%s(): SDL_KEYUP...\n",__func__);
                break;

            case SDL_MOUSEBUTTONDOWN:
            case SDL_MOUSEBUTTONUP:
            case SDL_MOUSEMOTION:
            case SDL_MOUSEWHEEL:
                SDL_Log("%s(): SDL_MOUSE events\n",__func__);
                break;

            case SDL_WINDOWEVENT:
                SDL_Log("%s(): SDL_WINDOWEVENT events\n",__func__);
                handle_window_event( &event );
                break;
            }
        }

//================================================
void handle_window_event( SDL_Event *    event )
{
    switch  ( event->window.event ) {
    case SDL_WINDOWEVENT_SHOWN:
        SDL_Log("%s(): Window %d shown", __func__, event->window.windowID);
        break;

    case SDL_WINDOWEVENT_HIDDEN:
        SDL_Log("%s():Window %d hidden", __func__, event->window.windowID);
        break;

    case SDL_WINDOWEVENT_EXPOSED:
        SDL_Log("%s(): Window %d exposed", __func__, event->window.windowID);
        break;

    case SDL_WINDOWEVENT_MOVED:
        SDL_Log("%s(): Window %d moved to %d,%d", __func__,
                event->window.windowID, event->window.data1,
                event->window.data2);
        break;

    case SDL_WINDOWEVENT_RESIZED:
        SDL_Log("%s(): Window %d resized to %dx%d", __func__,
                event->window.windowID, event->window.data1,
                event->window.data2);
        break;

    case SDL_WINDOWEVENT_SIZE_CHANGED:
        SDL_Log("%s(): Window %d size changed", __func__, event->window.windowID);
        break;

    case SDL_WINDOWEVENT_MINIMIZED:
        SDL_Log("%s(): Window %d minimized", __func__, event->window.windowID);
        break;

    case SDL_WINDOWEVENT_MAXIMIZED:
        SDL_Log("%s(): Window %d maximized", __func__, event->window.windowID);
        break;

    case SDL_WINDOWEVENT_RESTORED:
        SDL_Log("%s(): Window %d restored", __func__, event->window.windowID);
        break;

    case SDL_WINDOWEVENT_ENTER:
        SDL_Log("%s(): Mouse entered window %d", __func__, event->window.windowID);
        break;

    case SDL_WINDOWEVENT_LEAVE:
        SDL_Log("%s(): Mouse left window %d", __func__, event->window.windowID);
        break;

    case SDL_WINDOWEVENT_FOCUS_GAINED:
        SDL_Log("%s(): Window %d gained keyboard focus", __func__,
                event->window.windowID);
        break;

    case SDL_WINDOWEVENT_FOCUS_LOST:
        SDL_Log("%s(): Window %d lost keyboard focus", __func__,
                event->window.windowID);
        break;

    case SDL_WINDOWEVENT_CLOSE:
        SDL_Log("%s(): Window %d closed", __func__, event->window.windowID);
        break;

    default:
        SDL_Log( "%s(): Window %d got unknown event %d", __func__,
                 event->window.windowID,
                 event->window.event ) ;
        break ;
    }   //  Switch on event kind.
}   //  handle_window_event()

Sam Clegg

unread,
Oct 22, 2015, 8:57:35 PM10/22/15
to native-cli...@googlegroups.com
On Thu, Oct 22, 2015 at 5:21 PM, BL <mele...@gmail.com> wrote:
> Hi,
>
> My Chrome App using libSDL2, In the SDL event handler (code below),
> I'm able to get all the keyboard and mouse events BUT NONE of the window
> event (SDL_WINDOWEVENT) was received.
> The window events are blocked. Is there a way for the SDL event handler to
> receive SDL_WINDOWEVENT ?

Most likely the NaCl port of SDL2 is lacking support for these events.
Looking at the code in sdl2-2.0.3/src/video/nacl it looks like
SDL_WINDOWEVENT_RESIZED is generated (by NACL_SetScreenResolution) but
I don't see any of the other windows events ever being generated. If
you'd like to add support for these events it would be most welcome.

cheers,
sam
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to native-client-di...@googlegroups.com.
> To post to this group, send email to native-cli...@googlegroups.com.
> Visit this group at http://groups.google.com/group/native-client-discuss.
> For more options, visit https://groups.google.com/d/optout.

BL

unread,
Oct 26, 2015, 6:15:44 PM10/26/15
to Native-Client-Discuss
Thanks Sam for confirming the lack of supporting nacl SDL2 window events.
In order to add support, as you see, from the top level PS event which is only supported PSE_INSTANCE_DIDCHANGEVIEW
and PSE_INSTANCE_DIDCHANGEFOCUS before getting into SDL nacl code (sdl_naclvideo.c). We could
only bases on the width and the height to determine whether to generate other lacking SDL window events such as
(SDL_WINDOWEVENT_MINIMIZE, SDL_WINDOWEVENT_MINIMIZED, RESTORED, MOVED, MAXIMIZED, etc,...
Any suggestion ?

Sam Clegg

unread,
Oct 26, 2015, 11:45:26 PM10/26/15
to native-cli...@googlegroups.com
On Mon, Oct 26, 2015 at 3:15 PM, BL <mele...@gmail.com> wrote:
> Thanks Sam for confirming the lack of supporting nacl SDL2 window events.
> In order to add support, as you see, from the top level PS event which is
> only supported PSE_INSTANCE_DIDCHANGEVIEW
> and PSE_INSTANCE_DIDCHANGEFOCUS before getting into SDL nacl code
> (sdl_naclvideo.c). We could
> only bases on the width and the height to determine whether to generate
> other lacking SDL window events such as
> (SDL_WINDOWEVENT_MINIMIZE, SDL_WINDOWEVENT_MINIMIZED, RESTORED, MOVED,
> MAXIMIZED, etc,...
> Any suggestion ?

For some of these there may be no logical equivalent in NaCl. Are
there some in particular that you need/want for your application?
>> > email to native-client-di...@googlegroups.com.
>> > To post to this group, send email to native-cli...@googlegroups.com.
>> > Visit this group at
>> > http://groups.google.com/group/native-client-discuss.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to native-client-di...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages