Getting X11 (or windows) events when SDL_WINDOWID is set

Hi,
I am trying to write a simple wrapper that lets a generic SDL
application be used as a firefox plugin, but i am having
problem in receiving events in the SDL application.

In detail:

The wrapper is really straightforward (i am happy to post it
if people are interested): firefox tells the
plugins the WINDOWID of the area associated to the plugin,
so the wrapper can just set the SDL_WINDOWID environment variable,
and then fork the SDL application.

However, i see from the code in src/video/x11/SDL_x11video.c
that XSelectInput() is not called on this window, so the
application itself will not request X11 events.

Any idea on how to work around this limitation other than patching
the library ?

cheers
luigi

However, i see from the code in src/video/x11/SDL_x11video.c
that XSelectInput() is not called on this window, so the
application itself will not request X11 events.

Since this is already platform-specific and dealing with Window IDs,
you could just call XSelectInput yourself, before initializing SDL?On Mon, May 5, 2008 at 6:50 AM, Luigi Rizzo wrote:


http://pphaneuf.livejournal.com/

I tried that, both before and after sdl initialization, but
it does not seem to be effective. I get only
SDLEVENT: 1
SDLEVENT: 12
but probably these are not really X11 events but are generated
by SDL itself…

Note that while i am debugging this with X11, ideally I would
like this behaviour to work even on Windows (replacing X11 with
the specific window system and events)…

cheers
luigiOn Mon, May 05, 2008 at 09:02:15AM -0400, Pierre Phaneuf wrote:

On Mon, May 5, 2008 at 6:50 AM, Luigi Rizzo <@Luigi_Rizzo> wrote:

However, i see from the code in src/video/x11/SDL_x11video.c
that XSelectInput() is not called on this window, so the
application itself will not request X11 events.

Since this is already platform-specific and dealing with Window IDs,
you could just call XSelectInput yourself, before initializing SDL?

I tried that, both before and after sdl initialization, but
it does not seem to be effective. I get only
SDLEVENT: 1
SDLEVENT: 12
but probably these are not really X11 events but are generated
by SDL itself…

You could maybe probe a little bit with xev, using the -id option?

Note that while i am debugging this with X11, ideally I would
like this behaviour to work even on Windows (replacing X11 with
the specific window system and events)…

Whew, handing of windows like that is quite platform-specific, I don’t
know whether window handles are stable across processes on Windows!?!
Maybe they are, I wouldn’t know, just saying that coming up with a
cross-platform abstraction for that stuff might not be trivial. :-)On Mon, May 5, 2008 at 9:57 AM, Luigi Rizzo wrote:


http://pphaneuf.livejournal.com/

Followup and rephrase of the question:
As i said, i am using the ‘SDL_WINDOWID’ feature of SDL to
wrap an SDL application into another application who creates
the initial window to be used. It seems that, by design,
SDL does not request events (mouse, keyboard etc) when
SDL_WINDOWID is specified - at least this happens on both
X11 and Windows.

As the code is, at least on the 1.2 branch there seems no way
to override this behaviour - on X11 i would need to issue an
XSelectInput() on the same ‘SDL_Display’ descriptor used by SDL
itself to communicate with the X server, but the SDL_Display
is not available to the client code.

Maybe SDL 1.3 has this feature using SDL_GetDisplayFromWindow() ?

In any case, which approach could make sense to make this feature
(receiving events on an externally-managed window) configurable
by the user ?

  1. add some annotation to SDL_WINDOWID (which is a string), e.g.
    SDL_WINDOWID=123456_eventMask
    then the library code that handles the creation and opening of
    the library would just parse the string and decide whether or
    not receive mouse, keyboard and other events (according to the
    specific eventMask supplied) when using an externally supplied
    window. Examples:
    SDL_WINDOWID=123456 # same as now, uses the window and does not
    # receive external events
    SDL_WINDOWID=123456_keyboard # uses the window and
    # receive keyboard events
    SDL_WINDOWID=123456_mouse+keyboard # uses the window and
    # receive mouse and keyboard events
    The changes to the library code would be minimal, and this has
    the big advantage of enabling programs to use the feature without
    changes to the source code.

  2. add a new API call to SDL to access the low-level descriptor to
    talk directly with the graphic server (X11 or other).
    This is powerful in that it opens the way to all sort of manipulations
    of the graphic server, however it requires backend-specific code
    in the SDL application to do what one needs;

  3. add a new API call to SDL to configure the way events are reported,
    on either external or internally created windows.

I think #1 is quite convenient, but would this approach be acceptable for
inclusion in the library ?

cheers
luigi
  1. add a new API call to SDL to access the low-level descriptor to
    talk directly with the graphic server (X11 or other).
    This is powerful in that it opens the way to all sort of manipulations
    of the graphic server, however it requires backend-specific code
    in the SDL application to do what one needs;

SDL_GetWMInfo() can get you the Xlib Display* (have a look at what
else is there). Make sure to read the documentation about the
SDL_VERSION() bit, it’s quite important!

You’ll probably then have to enable SDL_SysWMEvent and handle them to
get at the X11 events, if I understand this correctly (I haven’t done
the specific thing you want, I get the Display* and hack other
things).On Thu, May 8, 2008 at 1:15 PM, Luigi Rizzo wrote:


http://pphaneuf.livejournal.com/

  1. add a new API call to SDL to access the low-level descriptor to
    talk directly with the graphic server (X11 or other).
    This is powerful in that it opens the way to all sort of manipulations
    of the graphic server, however it requires backend-specific code
    in the SDL application to do what one needs;

SDL_GetWMInfo() can get you the Xlib Display* (have a look at what
else is there). Make sure to read the documentation about the
SDL_VERSION() bit, it’s quite important!

many thanks, this did the job. I didn’t need to enable WM events,
as i only cared about mouse and keyboard events.

cheers
luigiOn Thu, May 08, 2008 at 01:58:02PM -0400, Pierre Phaneuf wrote:

On Thu, May 8, 2008 at 1:15 PM, Luigi Rizzo <@Luigi_Rizzo> wrote:

You’ll probably then have to enable SDL_SysWMEvent and handle them to
get at the X11 events, if I understand this correctly (I haven’t done
the specific thing you want, I get the Display* and hack other
things).


http://pphaneuf.livejournal.com/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Luigi Rizzo-5 wrote:

many thanks, this did the job. I didn’t need to enable WM events,
as i only cared about mouse and keyboard events.

Hi,

I’m trying to do the same here and currently keyboard presses and mouse
motion work fine but I’m getting a BadAccess (attempt to access private
resource denied) when trying to enable button presses too. Here’s what I’m
currently doing.

SDL_SysWMinfo info;
XSetWindowAttributes attributes;

SDL_VERSION(&info.version); // this is important!
SDL_GetWMInfo(&info);

info.info.x11.lock_func();
    
attributes.event_mask = KeyPressMask | KeyReleaseMask |

PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
XChangeWindowAttributes(info.info.x11.display, info.info.x11.window,
CWEventMask, &attributes);
info.info.x11.unlock_func();

I don’t know for sure if this is even the correct way to do it but does
anyone have an idea to get mouse clicks working too.

Cheers,
WP–
View this message in context: http://www.nabble.com/getting-X11-(or-windows)-events-when-SDL_WINDOWID-is-set-tp17059020p17476091.html
Sent from the SDL mailing list archive at Nabble.com.