Skip to content
Next Next commit
Allow dropping events from HandleEventFromFilter
  • Loading branch information
Susko3 committed Apr 8, 2024
commit 5ab4f9368faaafa7d8c2c549a7b0fe7172be3929
20 changes: 17 additions & 3 deletions osu.Framework/Platform/SDL3Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,26 @@ protected void RunFrame()
Update?.Invoke();
}

/// <summary>
/// Drop event from SDL event queue.
/// </summary>
/// <remarks>Return value of <see cref="HandleEventFromFilter"/></remarks>
protected const int DROP_EVENT = 0;

/// <summary>
/// Keep event in SDL event queue (it'll get processed later in <see cref="pollSDLEvents"/>).
/// </summary>
/// <remarks>Return value of <see cref="HandleEventFromFilter"/></remarks>
protected const int KEEP_EVENT = 1;

/// <summary>
/// Handles <see cref="SDL_Event"/>s fired from the SDL event filter.
/// </summary>
/// <remarks>
/// As per SDL's recommendation, application events should always be handled via the event filter.
/// See: https://wiki.libsdl.org/SDL3/SDL_EventType#android_ios_and_winrt_events
/// </remarks>
protected virtual void HandleEventFromFilter(SDL_Event evt)
protected virtual int HandleEventFromFilter(SDL_Event evt)
{
switch (evt.type)
{
Expand All @@ -293,6 +305,8 @@ protected virtual void HandleEventFromFilter(SDL_Event evt)
LowOnMemory?.Invoke();
break;
}

return KEEP_EVENT;
}

protected void HandleEventFromWatch(SDL_Event evt)
Expand All @@ -313,9 +327,9 @@ private static int eventFilter(IntPtr userdata, SDL_Event* eventPtr)
{
var handle = new ObjectHandle<SDL3Window>(userdata);
if (handle.GetTarget(out SDL3Window window))
window.HandleEventFromFilter(*eventPtr);
return window.HandleEventFromFilter(*eventPtr);

return 1;
return KEEP_EVENT;
}

[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Platform/Windows/WindowsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private SDL_bool handleEventFromHook(MSG msg)
return SDL_bool.SDL_TRUE;
}

protected override void HandleEventFromFilter(SDL_Event evt)
protected override int HandleEventFromFilter(SDL_Event evt)
{
switch (evt.type)
{
Expand All @@ -100,7 +100,7 @@ protected override void HandleEventFromFilter(SDL_Event evt)
break;
}

base.HandleEventFromFilter(evt);
return base.HandleEventFromFilter(evt);
}

/// <summary>
Expand Down