diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 60989c5861..9742d25914 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -472,6 +472,7 @@ public readonly override string ToString () [Flags] public enum ButtonState { + NoButtonPressed = 0, Button1Pressed = 1, Button2Pressed = 4, Button3Pressed = 8, @@ -482,6 +483,7 @@ public enum ButtonState [Flags] public enum ControlKeyState { + NoControlKeyPressed = 0, RightAltPressed = 1, LeftAltPressed = 2, RightControlPressed = 4, @@ -496,6 +498,7 @@ public enum ControlKeyState [Flags] public enum EventFlags { + NoEvent = 0, MouseMoved = 1, DoubleClick = 2, MouseWheeled = 4, @@ -517,7 +520,7 @@ public struct MouseEventRecord [FieldOffset (12)] public EventFlags EventFlags; - public readonly override string ToString () { return $"[Mouse({MousePosition},{ButtonState},{ControlKeyState},{EventFlags}"; } + public readonly override string ToString () { return $"[Mouse{MousePosition},{ButtonState},{ControlKeyState},{EventFlags}]"; } } public struct WindowBufferSizeRecord @@ -1388,7 +1391,7 @@ internal void ProcessInput (WindowsConsole.InputRecord inputEvent) case WindowsConsole.EventType.Mouse: MouseEvent me = ToDriverMouse (inputEvent.MouseEvent); - if (me is null) + if (me is null || me.Flags == MouseFlags.None) { break; } @@ -1774,8 +1777,7 @@ private MouseEvent ToDriverMouse (WindowsConsole.MouseEventRecord mouseEvent) { var mouseFlag = MouseFlags.AllEvents; - //System.Diagnostics.Debug.WriteLine ( - // $"X:{mouseEvent.MousePosition.X};Y:{mouseEvent.MousePosition.Y};ButtonState:{mouseEvent.ButtonState};EventFlags:{mouseEvent.EventFlags}"); + //Debug.WriteLine ($"ToDriverMouse: {mouseEvent}"); if (_isButtonDoubleClicked || _isOneFingerDoubleClicked) { @@ -2003,7 +2005,7 @@ private MouseEvent ToDriverMouse (WindowsConsole.MouseEventRecord mouseEvent) else if (mouseEvent is { ButtonState: 0, EventFlags: 0 }) { // This happens on a double or triple click event. - mouseFlag = 0; + mouseFlag = MouseFlags.None; } mouseFlag = SetControlKeyStates (mouseEvent, mouseFlag); @@ -2128,6 +2130,19 @@ void IMainLoopDriver.Iteration () void IMainLoopDriver.TearDown () { + // Eat any outstanding events. See # + //var records = + _winConsole.ReadConsoleInput (); + + //if (records != null) + //{ + // foreach (var rec in records) + // { + // Debug.WriteLine ($"Teardown: {rec.ToString ()}"); + // //Debug.Assert (rec is not { EventType: WindowsConsole.EventType.Mouse, MouseEvent.ButtonState: WindowsConsole.ButtonState.Button1Pressed }); + // } + //} + _inputHandlerTokenSource?.Cancel (); _inputHandlerTokenSource?.Dispose (); diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index bcac93b9b5..856df8e035 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -883,20 +883,9 @@ private void ShowDetails () } catch (HttpRequestException e) { - (s as Dialog).Text = e.Message; - - Application.Invoke ( - () => - { - spinner.Visible = false; - errorLabel.Text = e.Message; - errorLabel.ColorScheme = Colors.ColorSchemes ["Error"]; - errorLabel.Visible = true; - } - ); + Application.Invoke (() => waitIndicator.RequestStop ()); } - (s as Dialog)?.RequestStop (); }; Application.Run (waitIndicator); waitIndicator.Dispose (); diff --git a/UICatalog/Scenarios/Mouse.cs b/UICatalog/Scenarios/Mouse.cs index 0e214a3a07..7c8bcaf357 100644 --- a/UICatalog/Scenarios/Mouse.cs +++ b/UICatalog/Scenarios/Mouse.cs @@ -7,45 +7,102 @@ namespace UICatalog.Scenarios; [ScenarioCategory ("Mouse and Keyboard")] public class Mouse : Scenario { - public override void Setup () + public override void Main () { + Application.Init (); + Window win = new () + { + Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}", + }; + Label ml; var count = 0; ml = new Label { X = 1, Y = 1, Text = "Mouse: " }; - List rme = new (); - Win.Add (ml); + win.Add (ml); + + CheckBox cbWantContinuousPresses = new CheckBox () + { + X = 0, + Y = Pos.Bottom(ml) + 1, + Title = "_Want Continuous Button Presses", + }; + cbWantContinuousPresses.Toggled += (s,e) => + { + win.WantContinuousButtonPressed = !win.WantContinuousButtonPressed; + }; + + win.Add (cbWantContinuousPresses); + + var demo = new MouseDemo () + { + X = 0, + Y = Pos.Bottom (cbWantContinuousPresses) + 1, + Width = 20, + Height = 5, + Text = "Enter/Leave Demo", + TextAlignment = TextAlignment.Centered, + VerticalTextAlignment = VerticalTextAlignment.Middle, + ColorScheme = Colors.ColorSchemes ["Dialog"], + }; + win.Add (demo); - var logList = new ListView + var label = new Label () { - X = Pos.AnchorEnd (41), - Y = 0, - Width = 41, + Text = "_App Events:", + X = 0, + Y = Pos.Bottom (demo), + }; + List appLogList = new (); + var appLog = new ListView + { + X = Pos.Left (label), + Y = Pos.Bottom (label), + Width = Dim.Percent(49), Height = Dim.Fill (), ColorScheme = Colors.ColorSchemes ["TopLevel"], - Source = new ListWrapper (rme) + Source = new ListWrapper (appLogList) }; - Win.Add (logList); + win.Add (label, appLog); Application.MouseEvent += (sender, a) => { - ml.Text = $"Mouse: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count}"; - rme.Add ($"({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count++}"); - logList.MoveDown (); + ml.Text = $"MouseEvent: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count}"; + appLogList.Add ($"({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count++}"); + appLog.MoveDown (); }; - Win.Add (new MouseDemo () + + label = new Label () { - X = 0, - Y = 3, - Width = 15, - Height = 10, - Text = "Mouse Demo", - TextAlignment = TextAlignment.Centered, - VerticalTextAlignment = VerticalTextAlignment.Middle, - ColorScheme = Colors.ColorSchemes ["Dialog"], - }); + Text = "_Window Events:", + X = Pos.Percent(50), + Y = Pos.Bottom (demo), + }; + List winLogList = new (); + var winLog = new ListView + { + X = Pos.Left(label), + Y = Pos.Bottom (label), + Width = Dim.Percent (50), + Height = Dim.Fill (), + ColorScheme = Colors.ColorSchemes ["TopLevel"], + Source = new ListWrapper (winLogList) + }; + win.Add (label, winLog); + win.MouseEvent += (sender, a) => + { + winLogList.Add ($"MouseEvent: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count++}"); + winLog.MoveDown (); + }; + win.MouseClick += (sender, a) => + { + winLogList.Add ($"MouseClick: ({a.MouseEvent.X},{a.MouseEvent.Y}) - {a.MouseEvent.Flags} {count++}"); + winLog.MoveDown (); + }; + Application.Run (win); + win.Dispose (); } public class MouseDemo : View