From f89555710f123aef71d461ef79b302c967790140 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 2 Jun 2020 19:34:36 +0100 Subject: [PATCH 1/3] Added mouse tasks to the idle handlers. Fixed keyModifiers. --- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 55 ++++++++++++-------- Terminal.Gui/Core/Application.cs | 2 +- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 53ecbf236..75e539049 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 (() => { + ProcessButtonDoubleClicked ().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 ProcessButtonDoubleClicked () + { + 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 3c41d67db..53bfb3ae5 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; From 3f1ce65127f744cc76739e764fa55efaaad11c80 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 2 Jun 2020 20:08:35 +0100 Subject: [PATCH 2/3] Added Async in the end as per tenets for async calls. --- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 75e539049..016da4112 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -728,7 +728,7 @@ namespace Terminal.Gui { if (IsButtonDoubleClicked) { Application.MainLoop.AddIdle (() => { - ProcessButtonDoubleClicked ().ConfigureAwait (false); + ProcessButtonDoubleClickedAsync ().ConfigureAwait (false); return false; }); } @@ -879,7 +879,7 @@ namespace Terminal.Gui { }; } - private async Task ProcessButtonDoubleClicked () + private async Task ProcessButtonDoubleClickedAsync () { await Task.Delay (200); IsButtonDoubleClicked = false; From 857bdcbe24b810cb4b03094813ce390eb914952e Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Wed, 3 Jun 2020 10:18:13 -0600 Subject: [PATCH 3/3] fixes crashing bug on exit --- Terminal.Gui/Core/Application.cs | 2 +- UICatalog/UICatalog.cs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index ca42eb848..1d5ba97e9 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -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 (); } ///