Skip to content

Commit

Permalink
Revert "[Editor] Fix missing editor keyboard input (stride3d#1274)"
Browse files Browse the repository at this point in the history
This reverts commit 7015814.
  • Loading branch information
xen2 committed Jul 15, 2022
1 parent 56a4015 commit 49912f9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
35 changes: 35 additions & 0 deletions sources/engine/Stride.Input/Windows/InputSourceWinforms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ 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 @@ -64,6 +65,40 @@ 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 @@ -126,6 +126,7 @@ private void Attach()
dpiScale = VisualTreeHelper.GetDpi(this);

var style = NativeHelper.GetWindowLong(Handle, NativeHelper.GWL_STYLE);
// Removes Caption bar and the sizing border
// Must be a child window to be hosted
style |= NativeHelper.WS_CHILD;

Expand Down Expand Up @@ -200,10 +201,6 @@ private void UpdateWindowPosition()
// TODO: do we want SWP_NOCOPYBITS?
const int flags = NativeHelper.SWP_ASYNCWINDOWPOS | NativeHelper.SWP_NOACTIVATE | NativeHelper.SWP_NOZORDER;
NativeHelper.SetWindowPos(Handle, NativeHelper.HWND_TOP, boundingBox.X, boundingBox.Y, boundingBox.Z, boundingBox.W, flags);

var style = NativeHelper.GetWindowLong(Handle, NativeHelper.GWL_STYLE);
// Workaround for missing keyboard input see issue #94
NativeHelper.SetWindowLong(Handle, NativeHelper.GWL_STYLE, style & ~NativeHelper.WS_CHILD);
}

if (attached)
Expand Down

0 comments on commit 49912f9

Please sign in to comment.