Bug with X11_CreateWindowFrom

Hey All,
Mako and Myself have been working with some hairy platform specific
issues with the way we create windows in our code. We have been making
Ogre windows and having SDL Create a windows from a platform specific
piece of data from Ogre. This worked great on windows, but was working
at all on Linux.

There are likely other things that still don’t work, but this patch
fixes at the user input part of using. I tried to copy just enough
functionality of X11_CreateWindow to make this work. However, I am not
certain what all the pre and post conditions of X11_CreateWindowFrom
are supposed to be.

Here is the patch:

--- SDLBuild/SDL/src/video/x11/SDL_x11window.c	2011-12-23
18:10:48.000000000 -0600
+++ SDLBuild.Working/SDL/src/video/x11/SDL_x11window.c	2011-12-23
17:54:01.345384675 -0600
@@ -576,10 +576,39 @@
 int
 X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
 {
-    Window w = (Window) data;-
+    Window w = (Window) data; //Window w = (Window) data;
     window->title = X11_GetWindowTitle(_this, w);

+    SDL_VideoData *vdata = (SDL_VideoData *) _this->driverdata;
+    Display *display = vdata->display;
+    XWMHints *wmhints;
+    Uint32 fevent = 0;
+
+#ifdef X_HAVE_UTF8_STRING
+    /*if (SDL_X11_HAVE_UTF8) {
+        pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
+                      XNFilterEvents, &fevent, NULL);
+    }*/
+#endif
+
+    /* Set the input hints so we get keyboard input */
+    wmhints = XAllocWMHints();
+    if (wmhints) {
+        wmhints->input = True;
+        wmhints->flags = InputHint;
+        XSetWMHints(display, w, wmhints);
+        XFree(wmhints);
+    }
+
+    XSelectInput(display, w,
+                 (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
+                 ExposureMask | ButtonPressMask | ButtonReleaseMask |
+                 PointerMotionMask | KeyPressMask | KeyReleaseMask |
+                 PropertyChangeMask | StructureNotifyMask |
+                 KeymapStateMask | fevent));
+
+    XFlush(display);
+
     if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
         return -1;
     }
@@ -862,7 +891,7 @@
     SDL_DisplayData *displaydata =
         (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
     Display *display = data->videodata->display;
-
+
     XIconifyWindow(display, data->xwindow, displaydata->screen);
     XFlush(display);
 }

Any word on if we did this correctly, or even if this might be
included in mercurial soon?On Fri, Dec 23, 2011 at 7:41 PM, Joseph Toppi wrote:

Hey All,
? Mako and Myself have been working with some hairy platform specific
issues with the way we create windows in our code. We have been making
Ogre windows and having SDL Create a windows from a platform specific
piece of data from Ogre. This worked great on windows, but was working
at all on Linux.

There are likely other things that still don’t work, but this patch
fixes at the user input part of using. I tried to copy just enough
functionality of X11_CreateWindow to make this work. However, I am not
certain what all the pre and post conditions of X11_CreateWindowFrom
are supposed to be.

Here is the patch:

--- SDLBuild/SDL/src/video/x11/SDL_x11window.c ?2011-12-23
> 18:10:48.000000000 -0600
> +++ SDLBuild.Working/SDL/src/video/x11/SDL_x11window.c ?2011-12-23
> 17:54:01.345384675 -0600
> @@ -576,10 +576,39 @@
> ?int
> ?X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
> ?{
> - ? ?Window w = (Window) data;
> -
> + ? ?Window w = (Window) data; //Window w = (Window) data;
> ? ? window->title = X11_GetWindowTitle(_this, w);
>
> + ? ?SDL_VideoData *vdata = (SDL_VideoData *) _this->driverdata;
> + ? ?Display *display = vdata->display;
> + ? ?XWMHints *wmhints;
> + ? ?Uint32 fevent = 0;
> +
> +#ifdef X_HAVE_UTF8_STRING
> + ? ?/*if (SDL_X11_HAVE_UTF8) {
> + ? ? ? ?pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
> + ? ? ? ? ? ? ? ? ? ? ?XNFilterEvents, &fevent, NULL);
> + ? ?}*/
> +#endif
> +
> + ? ?/* Set the input hints so we get keyboard input */
> + ? ?wmhints = XAllocWMHints();
> + ? ?if (wmhints) {
> + ? ? ? ?wmhints->input = True;
> + ? ? ? ?wmhints->flags = InputHint;
> + ? ? ? ?XSetWMHints(display, w, wmhints);
> + ? ? ? ?XFree(wmhints);
> + ? ?}
> +
> + ? ?XSelectInput(display, w,
> + ? ? ? ? ? ? ? ? (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
> + ? ? ? ? ? ? ? ? ExposureMask | ButtonPressMask | ButtonReleaseMask |
> + ? ? ? ? ? ? ? ? PointerMotionMask | KeyPressMask | KeyReleaseMask |
> + ? ? ? ? ? ? ? ? PropertyChangeMask | StructureNotifyMask |
> + ? ? ? ? ? ? ? ? KeymapStateMask | fevent));
> +
> + ? ?XFlush(display);
> +
> ? ? if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
> ? ? ? ? return -1;
> ? ? }
> @@ -862,7 +891,7 @@
> ? ? SDL_DisplayData *displaydata =
> ? ? ? ? (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
> ? ? Display *display = data->videodata->display;
> -
> +
> ? ? XIconifyWindow(display, data->xwindow, displaydata->screen);
> ? ? XFlush(display);
> ?}

  • Joe Toppi
    (402) 714-7539
    Toppij at gmail.com

  • Joe Toppi
    (402) 714-7539
    Toppij at gmail.com

The original use case for CreateWindowFrom() was to have a window that was
created in another widget toolkit work with SDL graphics output, so the
lack of input management was intentional.

On the TODO list for SDL 1.3 was to add flags to control that behavior.

Of course you’re welcome to use that patch and include the modified version
of SDL with your application.

See ya!On Fri, Dec 23, 2011 at 8:41 PM, Joseph Toppi wrote:

Hey All,
Mako and Myself have been working with some hairy platform specific
issues with the way we create windows in our code. We have been making
Ogre windows and having SDL Create a windows from a platform specific
piece of data from Ogre. This worked great on windows, but was working
at all on Linux.

There are likely other things that still don’t work, but this patch
fixes at the user input part of using. I tried to copy just enough
functionality of X11_CreateWindow to make this work. However, I am not
certain what all the pre and post conditions of X11_CreateWindowFrom
are supposed to be.

Here is the patch:

--- SDLBuild/SDL/src/video/x11/SDL_x11window.c  2011-12-23
> 18:10:48.000000000 -0600
> +++ SDLBuild.Working/SDL/src/video/x11/SDL_x11window.c  2011-12-23
> 17:54:01.345384675 -0600
> @@ -576,10 +576,39 @@
>  int
>  X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
>  {
> -    Window w = (Window) data;
> -
> +    Window w = (Window) data; //Window w = (Window) data;
>     window->title = X11_GetWindowTitle(_this, w);
>
> +    SDL_VideoData *vdata = (SDL_VideoData *) _this->driverdata;
> +    Display *display = vdata->display;
> +    XWMHints *wmhints;
> +    Uint32 fevent = 0;
> +
> +#ifdef X_HAVE_UTF8_STRING
> +    /*if (SDL_X11_HAVE_UTF8) {
> +        pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
> +                      XNFilterEvents, &fevent, NULL);
> +    }*/
> +#endif
> +
> +    /* Set the input hints so we get keyboard input */
> +    wmhints = XAllocWMHints();
> +    if (wmhints) {
> +        wmhints->input = True;
> +        wmhints->flags = InputHint;
> +        XSetWMHints(display, w, wmhints);
> +        XFree(wmhints);
> +    }
> +
> +    XSelectInput(display, w,
> +                 (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
> +                 ExposureMask | ButtonPressMask | ButtonReleaseMask |
> +                 PointerMotionMask | KeyPressMask | KeyReleaseMask |
> +                 PropertyChangeMask | StructureNotifyMask |
> +                 KeymapStateMask | fevent));
> +
> +    XFlush(display);
> +
>     if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
>         return -1;
>     }
> @@ -862,7 +891,7 @@
>     SDL_DisplayData *displaydata =
>         (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
>     Display *display = data->videodata->display;
> -
> +
>     XIconifyWindow(display, data->xwindow, displaydata->screen);
>     XFlush(display);
>  }

  • Joe Toppi
    (402) 714-7539
    Toppij at gmail.com

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

Sam,
That is similar to what we are doing. Rather than widgets, we want
a robust 3d architecture, we are creating a window with Ogre3d and
using SDL for user input. I will gladly add this functionality myself,
if it would be accepted in the end.

What did you have in mind? Specifically, where did you want the
flag to be stored at runtime? What enum or macro should be added?

Why does the Windows version work the way we needed? What will this
do on Mac OS X?On Wed, Dec 28, 2011 at 4:40 AM, Sam Lantinga wrote:

The original use case for CreateWindowFrom() was to have a window that was
created in another widget toolkit work with SDL graphics output, so the lack
of input management was intentional.

On the TODO list for SDL 1.3 was to add flags to control that behavior.

Of course you’re welcome to use that patch and include the modified version
of SDL with your application.

See ya!

On Fri, Dec 23, 2011 at 8:41 PM, Joseph Toppi wrote:

Hey All,
? Mako and Myself have been working with some hairy platform specific
issues with the way we create windows in our code. We have been making
Ogre windows and having SDL Create a windows from a platform specific
piece of data from Ogre. This worked great on windows, but was working
at all on Linux.

There are likely other things that still don’t work, but this patch
fixes at the user input part of using. I tried to copy just enough
functionality of X11_CreateWindow to make this work. However, I am not
certain what all the pre and post conditions of X11_CreateWindowFrom
are supposed to be.

Here is the patch:

--- SDLBuild/SDL/src/video/x11/SDL_x11window.c ?2011-12-23
>> 18:10:48.000000000 -0600
>> +++ SDLBuild.Working/SDL/src/video/x11/SDL_x11window.c ?2011-12-23
>> 17:54:01.345384675 -0600
>> @@ -576,10 +576,39 @@
>> ?int
>> ?X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
>> ?{
>> - ? ?Window w = (Window) data;
>> -
>> + ? ?Window w = (Window) data; //Window w = (Window) data;
>> ? ? window->title = X11_GetWindowTitle(_this, w);
>>
>> + ? ?SDL_VideoData *vdata = (SDL_VideoData *) _this->driverdata;
>> + ? ?Display *display = vdata->display;
>> + ? ?XWMHints *wmhints;
>> + ? ?Uint32 fevent = 0;
>> +
>> +#ifdef X_HAVE_UTF8_STRING
>> + ? ?/*if (SDL_X11_HAVE_UTF8) {
>> + ? ? ? ?pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
>> + ? ? ? ? ? ? ? ? ? ? ?XNFilterEvents, &fevent, NULL);
>> + ? ?}*/
>> +#endif
>> +
>> + ? ?/* Set the input hints so we get keyboard input */
>> + ? ?wmhints = XAllocWMHints();
>> + ? ?if (wmhints) {
>> + ? ? ? ?wmhints->input = True;
>> + ? ? ? ?wmhints->flags = InputHint;
>> + ? ? ? ?XSetWMHints(display, w, wmhints);
>> + ? ? ? ?XFree(wmhints);
>> + ? ?}
>> +
>> + ? ?XSelectInput(display, w,
>> + ? ? ? ? ? ? ? ? (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
>> + ? ? ? ? ? ? ? ? ExposureMask | ButtonPressMask | ButtonReleaseMask |
>> + ? ? ? ? ? ? ? ? PointerMotionMask | KeyPressMask | KeyReleaseMask |
>> + ? ? ? ? ? ? ? ? PropertyChangeMask | StructureNotifyMask |
>> + ? ? ? ? ? ? ? ? KeymapStateMask | fevent));
>> +
>> + ? ?XFlush(display);
>> +
>> ? ? if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
>> ? ? ? ? return -1;
>> ? ? }
>> @@ -862,7 +891,7 @@
>> ? ? SDL_DisplayData *displaydata =
>> ? ? ? ? (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
>> ? ? Display *display = data->videodata->display;
>> -
>> +
>> ? ? XIconifyWindow(display, data->xwindow, displaydata->screen);
>> ? ? XFlush(display);
>> ?}

  • Joe Toppi
    (402) 714-7539
    Toppij at gmail.com

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


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

  • Joe Toppi
    (402) 714-7539
    BlackTopp Studios Inc.
    Lead Software Developer
    Toppij at BlackToppStudios.com

For SDL 1.3 I was thinking that there would be a flags parameter
to SDL_CreateWindowFrom() that would be a bitmask of behavior flags. I
haven’t fully thought through what those flags would be, but there would at
least be an option to enable/disable graphics and an option to
enable/disable event handling on the window.

The underlying window management code is fairly similar in concept between
the different video drivers, so flag interpretation should be relatively
similar between them.On Fri, Dec 30, 2011 at 2:21 PM, Joseph Toppi wrote:

Sam,
That is similar to what we are doing. Rather than widgets, we want
a robust 3d architecture, we are creating a window with Ogre3d and
using SDL for user input. I will gladly add this functionality myself,
if it would be accepted in the end.

What did you have in mind? Specifically, where did you want the
flag to be stored at runtime? What enum or macro should be added?

Why does the Windows version work the way we needed? What will this
do on Mac OS X?

On Wed, Dec 28, 2011 at 4:40 AM, Sam Lantinga <@slouken> wrote:

The original use case for CreateWindowFrom() was to have a window that
was
created in another widget toolkit work with SDL graphics output, so the
lack
of input management was intentional.

On the TODO list for SDL 1.3 was to add flags to control that behavior.

Of course you’re welcome to use that patch and include the modified
version
of SDL with your application.

See ya!

On Fri, Dec 23, 2011 at 8:41 PM, Joseph Toppi wrote:

Hey All,
Mako and Myself have been working with some hairy platform specific
issues with the way we create windows in our code. We have been making
Ogre windows and having SDL Create a windows from a platform specific
piece of data from Ogre. This worked great on windows, but was working
at all on Linux.

There are likely other things that still don’t work, but this patch
fixes at the user input part of using. I tried to copy just enough
functionality of X11_CreateWindow to make this work. However, I am not
certain what all the pre and post conditions of X11_CreateWindowFrom
are supposed to be.

Here is the patch:

--- SDLBuild/SDL/src/video/x11/SDL_x11window.c  2011-12-23
> >> 18:10:48.000000000 -0600
> >> +++ SDLBuild.Working/SDL/src/video/x11/SDL_x11window.c  2011-12-23
> >> 17:54:01.345384675 -0600
> >> @@ -576,10 +576,39 @@
> >>  int
> >>  X11_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
> >>  {
> >> -    Window w = (Window) data;
> >> -
> >> +    Window w = (Window) data; //Window w = (Window) data;
> >>     window->title = X11_GetWindowTitle(_this, w);
> >>
> >> +    SDL_VideoData *vdata = (SDL_VideoData *) _this->driverdata;
> >> +    Display *display = vdata->display;
> >> +    XWMHints *wmhints;
> >> +    Uint32 fevent = 0;
> >> +
> >> +#ifdef X_HAVE_UTF8_STRING
> >> +    /*if (SDL_X11_HAVE_UTF8) {
> >> +        pXGetICValues(((SDL_WindowData *) window->driverdata)->ic,
> >> +                      XNFilterEvents, &fevent, NULL);
> >> +    }*/
> >> +#endif
> >> +
> >> +    /* Set the input hints so we get keyboard input */
> >> +    wmhints = XAllocWMHints();
> >> +    if (wmhints) {
> >> +        wmhints->input = True;
> >> +        wmhints->flags = InputHint;
> >> +        XSetWMHints(display, w, wmhints);
> >> +        XFree(wmhints);
> >> +    }
> >> +
> >> +    XSelectInput(display, w,
> >> +                 (FocusChangeMask | EnterWindowMask | LeaveWindowMask |
> >> +                 ExposureMask | ButtonPressMask | ButtonReleaseMask |
> >> +                 PointerMotionMask | KeyPressMask | KeyReleaseMask |
> >> +                 PropertyChangeMask | StructureNotifyMask |
> >> +                 KeymapStateMask | fevent));
> >> +
> >> +    XFlush(display);
> >> +
> >>     if (SetupWindowData(_this, window, w, SDL_FALSE) < 0) {
> >>         return -1;
> >>     }
> >> @@ -862,7 +891,7 @@
> >>     SDL_DisplayData *displaydata =
> >>         (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
> >>     Display *display = data->videodata->display;
> >> -
> >> +
> >>     XIconifyWindow(display, data->xwindow, displaydata->screen);
> >>     XFlush(display);
> >>  }

  • Joe Toppi
    (402) 714-7539
    Toppij at gmail.com

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


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

  • Joe Toppi
    (402) 714-7539
    BlackTopp Studios Inc.
    Lead Software Developer
    Toppij at BlackToppStudios.com

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

For SDL 1.3 I was thinking that there would be a flags parameter to SDL_CreateWindowFrom() that would be a bitmask of behavior flags. I haven’t fully thought through what those flags would be, but there would at least be an option to enable/disable graphics and an option to enable/disable event handling on the window.

The underlying window management code is fairly similar in concept between the different video drivers, so flag interpretation should be relatively similar between them.

Hi Sam, glad to see you’re still around. I have a few questions about this.

First, Why wasn’t it documented to lock out input by design? That alone would have saved us a substantial amount of time digging through SDL and X11 internals.

Second, Was there any special way you wanted to implement the flags for toggling the input? If it’s something simple we’ll do it ourselves and submit a patch. We’d like to see this functionality added to SDL(for as many platforms as possible that SDL supports).

Third, and lastly…Just out of curiosity, when we added this logic to windows it just worked without minimal intervention, no changing of the window manager or OS specific window handles at all. Does the Windows API just not support turning off the input or is this something more in SDL? Again, just a case of simple curiosity.