Skip to content

Commit

Permalink
Add code path for handling window messages
Browse files Browse the repository at this point in the history
Some IME messages didn't get sent trough `SDL_SetWindowsMessageHook`, so this alternative is required.
  • Loading branch information
Susko3 committed Dec 17, 2021
1 parent 7d8e6d0 commit eb44a5c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
31 changes: 31 additions & 0 deletions osu.Framework/Platform/SDL2/SDL2Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,5 +1011,36 @@ public static unsafe bool TryGetStringFromBytePointer(byte* bytePointer, out str
str = Marshal.PtrToStringUTF8(ptr) ?? string.Empty;
return true;
}

// ReSharper disable InconsistentNaming (mimics SDL and SDL2-CS naming)
// ReSharper disable IdentifierTypo

[StructLayout(LayoutKind.Sequential)]
internal struct INTERNAL_windows_wmmsg
{
public IntPtr hwnd;
public uint msg;
public ulong wParam;
public long lParam;
}

[StructLayout(LayoutKind.Explicit)]
internal struct INTERNAL_SysWMmsgUnion
{
[FieldOffset(0)]
public INTERNAL_windows_wmmsg win;
// could add more native events here if required
}

[StructLayout(LayoutKind.Sequential)]
internal struct SDL_SysWMmsg
{
public SDL.SDL_version version;
public SDL.SDL_SYSWM_TYPE subsystem;
public INTERNAL_SysWMmsgUnion msg;
}

// ReSharper restore InconsistentNaming
// ReSharper restore IdentifierTypo
}
}
17 changes: 17 additions & 0 deletions osu.Framework/Platform/SDL2DesktopWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@ private void handleSDLEvent(SDL.SDL_Event e)
case SDL.SDL_EventType.SDL_DROPCOMPLETE:
handleDropEvent(e.drop);
break;

case SDL.SDL_EventType.SDL_SYSWMEVENT:
HandleSysWMEvent(e.syswm);
break;
}
}

Expand Down Expand Up @@ -986,6 +990,19 @@ private void handleWindowEvent(SDL.SDL_WindowEvent evtWindow)
}
}

/// <summary>
/// Override if platform requires special handling of native events.
/// </summary>
/// <remarks>
/// Make sure to enable the events with
/// <code>
/// SDL.SDL_EventState(SDL.SDL_EventType.SDL_SYSWMEVENT, SDL.SDL_ENABLE);
/// </code>
/// </remarks>
protected virtual void HandleSysWMEvent(SDL.SDL_SysWMEvent sysWM)
{
}

/// <summary>
/// Should be run on a regular basis to check for external window state changes.
/// </summary>
Expand Down

0 comments on commit eb44a5c

Please sign in to comment.