mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-08-04 08:31:02 +00:00
[Platform] Fixed keys getting stuck on focus loss
NativeWindowBase will now clear all keyboard keys when losing focus. This prevents keys from getting stuck when refocusing the window. [Win] Also fixed WindowState.Maximized when WindowBorder is Hidden and the window is minimized.
This commit is contained in:
parent
4556e54405
commit
d7e0373852
|
@ -398,6 +398,8 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
public override void ProcessEvents()
|
public override void ProcessEvents()
|
||||||
{
|
{
|
||||||
|
base.ProcessEvents();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var e = Cocoa.SendIntPtr(NSApplication.Handle, selNextEventMatchingMask, uint.MaxValue, IntPtr.Zero, NSDefaultRunLoopMode, true);
|
var e = Cocoa.SendIntPtr(NSApplication.Handle, selNextEventMatchingMask, uint.MaxValue, IntPtr.Zero, NSDefaultRunLoopMode, true);
|
||||||
|
|
|
@ -109,20 +109,6 @@ namespace OpenTK.Platform
|
||||||
protected void OnFocusedChanged(EventArgs e)
|
protected void OnFocusedChanged(EventArgs e)
|
||||||
{
|
{
|
||||||
FocusedChanged(this, e);
|
FocusedChanged(this, e);
|
||||||
|
|
||||||
if (!Focused)
|
|
||||||
{
|
|
||||||
// Clear keyboard state, otherwise KeyUp
|
|
||||||
// events may be missed resulting in stuck
|
|
||||||
// keys.
|
|
||||||
for (Key key = 0; key < Key.LastKey; key++)
|
|
||||||
{
|
|
||||||
if (KeyboardState[key])
|
|
||||||
{
|
|
||||||
OnKeyUp(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void OnWindowBorderChanged(EventArgs e)
|
protected void OnWindowBorderChanged(EventArgs e)
|
||||||
|
@ -326,7 +312,22 @@ namespace OpenTK.Platform
|
||||||
|
|
||||||
public abstract void Close();
|
public abstract void Close();
|
||||||
|
|
||||||
public abstract void ProcessEvents();
|
public virtual void ProcessEvents()
|
||||||
|
{
|
||||||
|
if (!Focused)
|
||||||
|
{
|
||||||
|
// Clear keyboard state, otherwise KeyUp
|
||||||
|
// events may be missed resulting in stuck
|
||||||
|
// keys.
|
||||||
|
for (Key key = 0; key < Key.LastKey; key++)
|
||||||
|
{
|
||||||
|
if (KeyboardState[key])
|
||||||
|
{
|
||||||
|
OnKeyUp(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public abstract Point PointToClient(Point point);
|
public abstract Point PointToClient(Point point);
|
||||||
|
|
||||||
|
|
|
@ -550,6 +550,7 @@ namespace OpenTK.Platform.SDL2
|
||||||
|
|
||||||
public override void ProcessEvents()
|
public override void ProcessEvents()
|
||||||
{
|
{
|
||||||
|
base.ProcessEvents();
|
||||||
lock (sync)
|
lock (sync)
|
||||||
{
|
{
|
||||||
if (Exists)
|
if (Exists)
|
||||||
|
|
|
@ -581,7 +581,7 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
bool extended = (lParam.ToInt64() & ExtendedBit) != 0;
|
bool extended = (lParam.ToInt64() & ExtendedBit) != 0;
|
||||||
short scancode = (short)((lParam.ToInt64() >> 16) & 0xff);
|
short scancode = (short)((lParam.ToInt64() >> 16) & 0xff);
|
||||||
ushort repeat_count = unchecked((ushort)((ulong)lParam.ToInt64() & 0xffffu));
|
//ushort repeat_count = unchecked((ushort)((ulong)lParam.ToInt64() & 0xffffu));
|
||||||
VirtualKeys vkey = (VirtualKeys)wParam;
|
VirtualKeys vkey = (VirtualKeys)wParam;
|
||||||
bool is_valid;
|
bool is_valid;
|
||||||
Key key = WinKeyMap.TranslateKey(scancode, vkey, extended, false, out is_valid);
|
Key key = WinKeyMap.TranslateKey(scancode, vkey, extended, false, out is_valid);
|
||||||
|
@ -590,7 +590,8 @@ namespace OpenTK.Platform.Windows
|
||||||
{
|
{
|
||||||
if (pressed)
|
if (pressed)
|
||||||
{
|
{
|
||||||
OnKeyDown(key, repeat_count > 0);
|
//OnKeyDown(key, repeat_count > 0);
|
||||||
|
OnKeyDown(key, KeyboardState[key]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -912,7 +913,6 @@ namespace OpenTK.Platform.Windows
|
||||||
{
|
{
|
||||||
suppress_resize++;
|
suppress_resize++;
|
||||||
WindowBorder = WindowBorder.Hidden;
|
WindowBorder = WindowBorder.Hidden;
|
||||||
ProcessEvents();
|
|
||||||
suppress_resize--;
|
suppress_resize--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -923,7 +923,6 @@ namespace OpenTK.Platform.Windows
|
||||||
deferred_window_border.HasValue ? deferred_window_border.Value :
|
deferred_window_border.HasValue ? deferred_window_border.Value :
|
||||||
previous_window_border.HasValue ? previous_window_border.Value :
|
previous_window_border.HasValue ? previous_window_border.Value :
|
||||||
WindowBorder;
|
WindowBorder;
|
||||||
ProcessEvents();
|
|
||||||
suppress_resize--;
|
suppress_resize--;
|
||||||
deferred_window_border = previous_window_border = null;
|
deferred_window_border = previous_window_border = null;
|
||||||
}
|
}
|
||||||
|
@ -932,7 +931,6 @@ namespace OpenTK.Platform.Windows
|
||||||
{
|
{
|
||||||
suppress_resize++;
|
suppress_resize++;
|
||||||
WindowState = WindowState.Normal;
|
WindowState = WindowState.Normal;
|
||||||
ProcessEvents();
|
|
||||||
suppress_resize--;
|
suppress_resize--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1247,12 +1245,12 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
ShowWindowCommand command = 0;
|
ShowWindowCommand command = 0;
|
||||||
bool exiting_fullscreen = false;
|
bool exiting_fullscreen = false;
|
||||||
borderless_maximized_window_state = false;
|
|
||||||
|
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
case WindowState.Normal:
|
case WindowState.Normal:
|
||||||
command = ShowWindowCommand.RESTORE;
|
command = ShowWindowCommand.RESTORE;
|
||||||
|
borderless_maximized_window_state = false;
|
||||||
|
|
||||||
// If we are leaving fullscreen mode we need to restore the border.
|
// If we are leaving fullscreen mode we need to restore the border.
|
||||||
if (WindowState == WindowState.Fullscreen)
|
if (WindowState == WindowState.Fullscreen)
|
||||||
|
@ -1280,6 +1278,7 @@ namespace OpenTK.Platform.Windows
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
borderless_maximized_window_state = false;
|
||||||
command = ShowWindowCommand.MAXIMIZE;
|
command = ShowWindowCommand.MAXIMIZE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1457,6 +1456,7 @@ namespace OpenTK.Platform.Windows
|
||||||
MSG msg;
|
MSG msg;
|
||||||
public override void ProcessEvents()
|
public override void ProcessEvents()
|
||||||
{
|
{
|
||||||
|
base.ProcessEvents();
|
||||||
while (Functions.PeekMessage(ref msg, IntPtr.Zero, 0, 0, PeekMessageFlags.Remove))
|
while (Functions.PeekMessage(ref msg, IntPtr.Zero, 0, 0, PeekMessageFlags.Remove))
|
||||||
{
|
{
|
||||||
Functions.TranslateMessage(ref msg);
|
Functions.TranslateMessage(ref msg);
|
||||||
|
|
|
@ -795,6 +795,7 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
public override void ProcessEvents()
|
public override void ProcessEvents()
|
||||||
{
|
{
|
||||||
|
base.ProcessEvents();
|
||||||
// Process all pending events
|
// Process all pending events
|
||||||
while (Exists && window != null)
|
while (Exists && window != null)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue