Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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.
  • Loading branch information...
commit d7e037385253e9f811fdd29f8fcc81e6f6aeae1e 1 parent 4556e54
thefiddler thefiddler authored
2  Source/OpenTK/Platform/MacOS/CocoaNativeWindow.cs
View
@@ -398,6 +398,8 @@ private MouseButton GetMouseButton(int cocoaButtonIndex)
public override void ProcessEvents()
{
+ base.ProcessEvents();
+
while (true)
{
var e = Cocoa.SendIntPtr(NSApplication.Handle, selNextEventMatchingMask, uint.MaxValue, IntPtr.Zero, NSDefaultRunLoopMode, true);
31 Source/OpenTK/Platform/NativeWindowBase.cs
View
@@ -109,20 +109,6 @@ protected void OnVisibleChanged(EventArgs e)
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 @@ protected void OnMouseWheel(float dx, float dy)
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);
1  Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs
View
@@ -550,6 +550,7 @@ public override void Close()
public override void ProcessEvents()
{
+ base.ProcessEvents();
lock (sync)
{
if (Exists)
12 Source/OpenTK/Platform/Windows/WinGLNative.cs
View
@@ -581,7 +581,7 @@ void HandleKeyboard(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr
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 @@ void HandleKeyboard(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr
{
if (pressed)
{
- OnKeyDown(key, repeat_count > 0);
+ //OnKeyDown(key, repeat_count > 0);
+ OnKeyDown(key, KeyboardState[key]);
}
else
{
@@ -912,7 +913,6 @@ void HideBorder()
{
suppress_resize++;
WindowBorder = WindowBorder.Hidden;
- ProcessEvents();
suppress_resize--;
}
@@ -923,7 +923,6 @@ void RestoreBorder()
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 @@ void ResetWindowState()
{
suppress_resize++;
WindowState = WindowState.Normal;
- ProcessEvents();
suppress_resize--;
}
@@ -1247,12 +1245,12 @@ public override WindowState WindowState
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 @@ public override WindowState WindowState
}
else
{
+ borderless_maximized_window_state = false;
command = ShowWindowCommand.MAXIMIZE;
}
break;
@@ -1457,6 +1456,7 @@ public override Point PointToScreen(Point point)
MSG msg;
public override void ProcessEvents()
{
+ base.ProcessEvents();
while (Functions.PeekMessage(ref msg, IntPtr.Zero, 0, 0, PeekMessageFlags.Remove))
{
Functions.TranslateMessage(ref msg);
1  Source/OpenTK/Platform/X11/X11GLNative.cs
View
@@ -795,6 +795,7 @@ static IntPtr CreateEmptyCursor(X11WindowInfo window)
public override void ProcessEvents()
{
+ base.ProcessEvents();
// Process all pending events
while (Exists && window != null)
{
Please sign in to comment.
Something went wrong with that request. Please try again.