diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 53ecbf236..016da4112 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -695,7 +695,8 @@ namespace Terminal.Gui { keyUpHandler (new KeyEvent (map, keyModifiers)); } } - keyModifiers = null; + if (!inputEvent.KeyEvent.bKeyDown) + keyModifiers = null; break; case WindowsConsole.EventType.Mouse: @@ -726,9 +727,9 @@ namespace Terminal.Gui { MouseFlags mouseFlag = MouseFlags.AllEvents; if (IsButtonDoubleClicked) { - Task.Run (async () => { - await Task.Delay (100); - IsButtonDoubleClicked = false; + Application.MainLoop.AddIdle (() => { + ProcessButtonDoubleClickedAsync ().ConfigureAwait (false); + return false; }); } @@ -774,23 +775,9 @@ namespace Terminal.Gui { IsButtonPressed = true; if ((mouseFlag & MouseFlags.ReportMousePosition) == 0) { - Task.Run (async () => { - while (IsButtonPressed) { - await Task.Delay (200); - var me = new MouseEvent () { - X = mouseEvent.MousePosition.X, - Y = mouseEvent.MousePosition.Y, - Flags = mouseFlag - }; - - var view = Application.wantContinuousButtonPressedView; - if (view == null) - break; - if (IsButtonPressed && (mouseFlag & MouseFlags.ReportMousePosition) == 0) { - mouseHandler (me); - //mainLoop.Driver.Wakeup (); - } - } + Application.MainLoop.AddIdle (() => { + ProcessContinuousButtonPressedAsync (mouseEvent, mouseFlag).ConfigureAwait (false); + return false; }); } @@ -892,6 +879,32 @@ namespace Terminal.Gui { }; } + private async Task ProcessButtonDoubleClickedAsync () + { + await Task.Delay (200); + IsButtonDoubleClicked = false; + } + + async Task ProcessContinuousButtonPressedAsync (WindowsConsole.MouseEventRecord mouseEvent, MouseFlags mouseFlag) + { + while (IsButtonPressed) { + await Task.Delay (200); + var me = new MouseEvent () { + X = mouseEvent.MousePosition.X, + Y = mouseEvent.MousePosition.Y, + Flags = mouseFlag + }; + + var view = Application.wantContinuousButtonPressedView; + if (view == null) + break; + if (IsButtonPressed && (mouseFlag & MouseFlags.ReportMousePosition) == 0) { + mouseHandler (me); + //mainLoop.Driver.Wakeup (); + } + } + } + static MouseFlags SetControlKeyStates (WindowsConsole.MouseEventRecord mouseEvent, MouseFlags mouseFlag) { if (mouseEvent.ControlKeyState.HasFlag (WindowsConsole.ControlKeyState.RightControlPressed) || diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index ca42eb848..3d33fd785 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -352,7 +352,7 @@ namespace Terminal.Gui { View = view }; if (OutsideFrame (new Point (nme.X, nme.Y), mouseGrabView.Frame)) - lastMouseOwnerView.OnMouseLeave (me); + lastMouseOwnerView?.OnMouseLeave (me); if (mouseGrabView != null) { mouseGrabView.OnMouseEvent (nme); return; @@ -480,7 +480,7 @@ namespace Terminal.Gui { // Closes the application if it's true. if (closeDriver) { MainLoop = null; - Driver.End (); + Driver?.End (); Driver = null; } diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index d48441e10..028046a5d 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -88,8 +88,6 @@ namespace UICatalog { scenario.Run (); scenario = GetScenarioToRun (); } - // Now closes the driver too. - Application.Shutdown (); } ///