wxwidgets and sdl/sdl2 (linux and windows) - no sdl events

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
arnoldemu
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Dec 29, 2014 12:59 pm

wxwidgets and sdl/sdl2 (linux and windows) - no sdl events

Post by arnoldemu » Mon Dec 29, 2014 1:18 pm

Hi,

I am trying to use wxwidgets and sdl (or sdl2) together. I am using sdl events. I poll the events during the idle time of my app and handle them (I am specificaly interested in keyboard and joystick input).

If the sdl/sdl2 window is created separately then all is good on Linux and windows. sdl or sdl2 window get events.
(Under Linux with sdl2, if I open a window I get a pthreads crash, I haven't investigated this yet).

(on a side note using sdl and wxwidgets on mac seems to have problems with key events too, but this happens even with a separate window).

Ideally I want to embed the window because I end up with:
- a separate menu bar (if using Ubuntu unity)
- a frame window which is empty
- a separate sdl window

It's a bit messy.

If I want to embed the sdl/sdl2 window the problems begin.

For sdl, I use the SDL_WINDOWID to give the HWND under windows and the XID under Linux. On both I get the window to embed. On windows all works fine I still see SDL events, under Linux they stop.

For sdl2, I use createwindowfrom and give it the HWND or XID. I see the window embedded. On Windows all is fine, on Linux again no events.

I have done some debugging on the Linux side. Both wxwidgets and sdl are using XEventsQueued underneath. Both are fighting each other and because wxwidgets is the parent it sees the events first. sdl then doesn't see any events so nothing happens.

I did try to use SDL_GetKeyState (sdl 1.2) but this didn't indicate any pressed keys probably (but not confirmed) that it's not seeing the key events so is not updating the internal array of key presses.

When sdl window is embedded I get wxwidgets key up/down and char events, so I could process these instead. But it does mean effectively I can't use sdl with wxwidgets.

I would be grateful if these questions could be answered to help me:

- does wxwidgets support xbox game pads?

- has anyone got sdl window to embed in wxwidgets under Linux and have the events work?

- when sdl window is embedded, Is it possible to stop events being processed for the wxwidgets window so that sdl sees them? Some kind of workaround to allow sdl to see them.

- is there a way that wxwidgets could look at the events and allow sdl to see them too, perhaps some kind of cooperative event sharing method?

- is there an example that shows how to change the video mode using wxwidgets and make it fullscreen?

thankyou for your help.


EDIT: I do see joystick events.
I think the events being filtered can't be worked around.

crashy
In need of some credit
In need of some credit
Posts: 2
Joined: Mon Aug 15, 2016 8:43 am

Re: wxwidgets and sdl/sdl2 (linux and windows) - no sdl events

Post by crashy » Mon Aug 15, 2016 8:46 am

Hi,

I know this post is 2 years old, but I have exactly the same issue here.
I have a sdl window created with SDL_CreateWindowFrom, and can succesfully grab inputs on windows, but not Linux. As arnoldemu, I suspect wxwidgets to grab all inputs before sdl can see them.
//Edit: and of course, I receive joystick events.

Is it even possible to do such a thing ?

Thanks.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3402
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxwidgets and sdl/sdl2 (linux and windows) - no sdl events

Post by ONEEYEMAN » Mon Aug 15, 2016 2:37 pm

Hi,
It would be nice to have some code to look at.
Especially how you handle the keyboard events.

Thank you.

crashy
In need of some credit
In need of some credit
Posts: 2
Joined: Mon Aug 15, 2016 8:43 am

Re: wxwidgets and sdl/sdl2 (linux and windows) - no sdl events

Post by crashy » Mon Aug 15, 2016 3:16 pm

Hi !
My whole codebase is quite big so I cannot post the whole thing. But if you want some precise parts I can post them.
This is how I handle the sdl key events:

Code: Select all

	SDL_Event events[OIS_SDL_KEY_BUFF];
	int count = SDL_PeepEvents(events, OIS_SDL_KEY_BUFF, SDL_GETEVENT,SDL_KEYDOWN , SDL_KEYUP);

	for( int i = 0; i < count; ++i )
	{
		[...]
	}
	
After a few trials without wxWidgets it seems I have no input either...so now I think this is a SDL2 problem only, thus I should post on their forum #-o

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3402
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxwidgets and sdl/sdl2 (linux and windows) - no sdl events

Post by ONEEYEMAN » Mon Aug 15, 2016 4:05 pm

Hi,
Do you call "event.Skip()" in you keyboard handler?
You need the keyboard event to be propagated up the chain and in the end let the system handle them.

Thank you.

arnoldemu
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Dec 29, 2014 12:59 pm

Re: wxwidgets and sdl/sdl2 (linux and windows) - no sdl events

Post by arnoldemu » Mon Oct 17, 2016 7:15 am

ONEEYEMAN wrote:Hi,
Do you call "event.Skip()" in you keyboard handler?
You need the keyboard event to be propagated up the chain and in the end let the system handle them.

Thank you.
No I don't. I will try that.

For embedding SDL on wxMac and wxLinux I currently use wxWidgets for keyboard and joystick events. They don't give me full control however (e.g. left and right shift give the same keyboard id).

All SDL ports have a message loop and on wxMac and wxLinux this doesn't get the input - wxWidgets gets it first.


I did think of a possible way:
- tell wxWidgets and SDL to not get events
- give wxWidgets and SDL an event handler function
- I process events and pass the events through

Another way could be to tell both to peek at the events and not collect them. I then do a collection task later to clear the list.

Another way would be wxWidgets collects the events and I put them into SDL's queue.

Manolo
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 695
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxwidgets and sdl/sdl2 (linux and windows) - no sdl events

Post by Manolo » Mon Oct 17, 2016 4:26 pm

(e.g. left and right shift give the same keyboard id)
Take a look at keyboard sample.

Post Reply