From 7be9583dba5b1baa234f0b280e38c6672c314e55 Mon Sep 17 00:00:00 2001 From: Eideren Date: Sun, 29 Oct 2023 04:43:22 +0100 Subject: [PATCH] [Editor] Re-introduce workaround for missing input while navigating (#1897) * [Editor] Re-introduce workaround for missing input while navigating * [Editor] Slightly faster transition between scene views --- .../Windows/InputSourceWinforms.cs | 35 ------------------- .../Controls/GameEngineHost.cs | 14 +++++++- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/sources/engine/Stride.Input/Windows/InputSourceWinforms.cs b/sources/engine/Stride.Input/Windows/InputSourceWinforms.cs index ca610f4773..31595ec238 100644 --- a/sources/engine/Stride.Input/Windows/InputSourceWinforms.cs +++ b/sources/engine/Stride.Input/Windows/InputSourceWinforms.cs @@ -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); @@ -65,40 +64,6 @@ public override void Initialize(InputManager inputManager) RegisterDevice(mouse); } - /// - /// 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. - /// - 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 diff --git a/sources/presentation/Stride.Core.Presentation/Controls/GameEngineHost.cs b/sources/presentation/Stride.Core.Presentation/Controls/GameEngineHost.cs index 1a7867073e..740f4cec4b 100644 --- a/sources/presentation/Stride.Core.Presentation/Controls/GameEngineHost.cs +++ b/sources/presentation/Stride.Core.Presentation/Controls/GameEngineHost.cs @@ -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; @@ -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(() => { @@ -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);