Skip to content

Commit

Permalink
[Editor] Re-introduce workaround for missing input while navigating (#…
Browse files Browse the repository at this point in the history
…1897)

* [Editor] Re-introduce workaround for missing input while navigating

* [Editor] Slightly faster transition between scene views
  • Loading branch information
Eideren authored Oct 29, 2023
1 parent bbd23c9 commit 7be9583
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 36 deletions.
35 changes: 0 additions & 35 deletions sources/engine/Stride.Input/Windows/InputSourceWinforms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public override void Initialize(InputManager inputManager)
input = inputManager;

uiControl.LostFocus += UIControlOnLostFocus;
MissingInputHack();

// Hook window proc
defaultWndProc = Win32Native.GetWindowLong(uiControl.Handle, Win32Native.WindowLongType.WndProc);
Expand All @@ -65,40 +64,6 @@ public override void Initialize(InputManager inputManager)
RegisterDevice(mouse);
}

/// <summary>
/// This function houses a hack to fix the window missing some input events,
/// see Stride pull #181 for more information (https://github.com/stride3d/stride/pull/181).
/// TODO: Find a proper solution to replace this workaround.
/// </summary>
private void MissingInputHack()
{
#if STRIDE_INPUT_RAWINPUT
Device.RegisterDevice(SharpDX.Multimedia.UsagePage.Generic, SharpDX.Multimedia.UsageId.GenericKeyboard, DeviceFlags.None);
Device.KeyboardInput += (sender, args) =>
{
switch (args.State)
{
case KeyState.SystemKeyDown:
case KeyState.ImeKeyDown:
case KeyState.KeyDown:
{
keyboard?.HandleKeyUp(args.Key);
heldKeys.Add(args.Key);
break;
}
case KeyState.SystemKeyUp:
case KeyState.ImeKeyUp:
case KeyState.KeyUp:
{
heldKeys.Remove(args.Key);
keyboard?.HandleKeyDown(args.Key);
break;
}
}
};
#endif
}

public override void Dispose()
{
// Unregisters devices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ private void Detach()

// Hide window, clear parent
NativeHelper.ShowWindow(Handle, NativeHelper.SW_HIDE);
NativeHelper.SetParent(Handle, IntPtr.Zero);

// Unregister keyboard sink
var site = ((IKeyboardInputSink)this).KeyboardInputSite;
Expand Down Expand Up @@ -223,6 +222,13 @@ public void ForwardMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)
switch (msg)
{
case NativeHelper.WM_RBUTTONDOWN:
// Workaround for #94 - Missing input in editor when the window is a child of the gamestudio
// We're disabling the `WS_CHILD` flag when the user is navigating around the scene (holding right click+wasd)
// TODO: Find a proper solution to replace this workaround. Good luck.
int style = NativeHelper.GetWindowLong(Handle, NativeHelper.GWL_STYLE);
style &= ~NativeHelper.WS_CHILD;
NativeHelper.SetWindowLong(Handle, NativeHelper.GWL_STYLE, style);

mouseMoveCount = 0;
task = Dispatcher.InvokeAsync(() =>
{
Expand All @@ -232,6 +238,12 @@ public void ForwardMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)
task.Wait(TimeSpan.FromSeconds(1.0f));
break;
case NativeHelper.WM_RBUTTONUP:
// Workaround for #94 - Missing input in editor when the window is a child of the gamestudio
// We're re-enabling the `WS_CHILD` flag when the user finished navigating around the scene (released right click)
int style2 = NativeHelper.GetWindowLong(Handle, NativeHelper.GWL_STYLE);
style2 |= NativeHelper.WS_CHILD;
NativeHelper.SetWindowLong(Handle, NativeHelper.GWL_STYLE, style2);

task = Dispatcher.InvokeAsync(() =>
{
RaiseMouseButtonEvent(Mouse.PreviewMouseUpEvent, MouseButton.Right);
Expand Down

0 comments on commit 7be9583

Please # to comment.