[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:
thefiddler 2014-05-09 16:45:45 +02:00
parent 4556e54405
commit d7e0373852
5 changed files with 26 additions and 21 deletions

View file

@ -398,6 +398,8 @@ namespace OpenTK.Platform.MacOS
public override void ProcessEvents()
{
base.ProcessEvents();
while (true)
{
var e = Cocoa.SendIntPtr(NSApplication.Handle, selNextEventMatchingMask, uint.MaxValue, IntPtr.Zero, NSDefaultRunLoopMode, true);

View file

@ -109,20 +109,6 @@ namespace OpenTK.Platform
protected void OnFocusedChanged(EventArgs 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)
@ -326,7 +312,22 @@ namespace OpenTK.Platform
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);

View file

@ -550,6 +550,7 @@ namespace OpenTK.Platform.SDL2
public override void ProcessEvents()
{
base.ProcessEvents();
lock (sync)
{
if (Exists)

View file

@ -581,7 +581,7 @@ namespace OpenTK.Platform.Windows
bool extended = (lParam.ToInt64() & ExtendedBit) != 0;
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;
bool is_valid;
Key key = WinKeyMap.TranslateKey(scancode, vkey, extended, false, out is_valid);
@ -590,7 +590,8 @@ namespace OpenTK.Platform.Windows
{
if (pressed)
{
OnKeyDown(key, repeat_count > 0);
//OnKeyDown(key, repeat_count > 0);
OnKeyDown(key, KeyboardState[key]);
}
else
{
@ -912,7 +913,6 @@ namespace OpenTK.Platform.Windows
{
suppress_resize++;
WindowBorder = WindowBorder.Hidden;
ProcessEvents();
suppress_resize--;
}
@ -923,7 +923,6 @@ namespace OpenTK.Platform.Windows
deferred_window_border.HasValue ? deferred_window_border.Value :
previous_window_border.HasValue ? previous_window_border.Value :
WindowBorder;
ProcessEvents();
suppress_resize--;
deferred_window_border = previous_window_border = null;
}
@ -932,7 +931,6 @@ namespace OpenTK.Platform.Windows
{
suppress_resize++;
WindowState = WindowState.Normal;
ProcessEvents();
suppress_resize--;
}
@ -1247,12 +1245,12 @@ namespace OpenTK.Platform.Windows
ShowWindowCommand command = 0;
bool exiting_fullscreen = false;
borderless_maximized_window_state = false;
switch (value)
{
case WindowState.Normal:
command = ShowWindowCommand.RESTORE;
borderless_maximized_window_state = false;
// If we are leaving fullscreen mode we need to restore the border.
if (WindowState == WindowState.Fullscreen)
@ -1280,6 +1278,7 @@ namespace OpenTK.Platform.Windows
}
else
{
borderless_maximized_window_state = false;
command = ShowWindowCommand.MAXIMIZE;
}
break;
@ -1457,6 +1456,7 @@ namespace OpenTK.Platform.Windows
MSG msg;
public override void ProcessEvents()
{
base.ProcessEvents();
while (Functions.PeekMessage(ref msg, IntPtr.Zero, 0, 0, PeekMessageFlags.Remove))
{
Functions.TranslateMessage(ref msg);

View file

@ -795,6 +795,7 @@ namespace OpenTK.Platform.X11
public override void ProcessEvents()
{
base.ProcessEvents();
// Process all pending events
while (Exists && window != null)
{