Skip to content
Browse files

[SDL2] Implemented modifier keys

Additionally, removed event watch callback in favor of calling
PollEvent() directly in ProcessEvents, which should be more efficient.
  • Loading branch information...
1 parent 221d466 commit 09f9bb3a1752dcc798adf4e525d052a677b6889b @thefiddler thefiddler committed
Showing with 10 additions and 11 deletions.
  1. +10 −11 Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs
View
21 Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs
@@ -72,9 +72,6 @@ class Sdl2NativeWindow : INativeWindow, IInputDriver
readonly IInputDriver input_driver;
- readonly EventFilter EventFilterDelegate_GCUnsafe = FilterEvents;
- readonly IntPtr EventFilterDelegate;
-
static readonly Dictionary<uint, Sdl2NativeWindow> windows =
new Dictionary<uint, Sdl2NativeWindow>();
@@ -105,17 +102,14 @@ class Sdl2NativeWindow : INativeWindow, IInputDriver
IntPtr handle;
lock (SDL.Sync)
{
- EventFilterDelegate = Marshal.GetFunctionPointerForDelegate(EventFilterDelegate_GCUnsafe);
handle = SDL.CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags);
- SDL.AddEventWatch(EventFilterDelegate, handle);
- SDL.PumpEvents();
+ exists = true;
}
+ ProcessEvents();
window = new Sdl2WindowInfo(handle, null);
window_id = SDL.GetWindowID(handle);
windows.Add(window_id, this);
window_title = title;
-
- exists = true;
}
}
@@ -152,14 +146,13 @@ static Key TranslateKey(Keycode key)
return TranslateKey(scan);
}
- unsafe static int FilterEvents(IntPtr user_data, IntPtr e)
+ int ProcessEvent(ref Event ev)
{
bool processed = false;
try
{
Sdl2NativeWindow window = null;
- Event ev = *(Event*)e;
switch (ev.Type)
{
@@ -245,6 +238,7 @@ static void ProcessKeyEvent(Sdl2NativeWindow window, Event ev)
var key = ev.Key.Keysym;
window.key_args.Key = TranslateKey(key.Scancode);
window.key_args.ScanCode = (uint)key.Scancode;
+ window.key_args.Modifiers = window.input_driver.Keyboard[0].GetModifiers();
if (key_pressed)
{
window.KeyDown(window, window.key_args);
@@ -396,7 +390,6 @@ void DestroyWindow()
CursorVisible = true;
lock (SDL.Sync)
{
- SDL.DelEventWatch(EventFilterDelegate, window.Handle);
if (windows.ContainsKey(window_id))
{
windows.Remove(window_id);
@@ -499,6 +492,12 @@ public void ProcessEvents()
if (Exists)
{
SDL.PumpEvents();
+ Event e;
+ while (SDL.PollEvent(out e) > 0)
+ {
+ ProcessEvent(ref e);
+ }
+
if (must_destroy)
{
DestroyWindow();

0 comments on commit 09f9bb3

Please sign in to comment.
Something went wrong with that request. Please try again.