diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs index 842888a2e..0451a72d6 100644 --- a/Terminal.Gui/Core.cs +++ b/Terminal.Gui/Core.cs @@ -1082,7 +1082,7 @@ namespace Terminal.Gui { ClearNeedsDisplay (); } -#if false +#if true // // It does not look like the event is raised on clicked-drag // need to figure that out. @@ -1090,7 +1090,14 @@ namespace Terminal.Gui { Point? dragPosition; public override bool MouseEvent(MouseEvent me) { - if (me.Flags == MouseFlags.Button1Pressed){ + // The code is currently disabled, because the + // Driver.UncookMouse does not seem to have an effect if there is + // a pending mouse event activated. + if (true) + return false; + + if ((me.Flags == MouseFlags.Button1Pressed|| me.Flags == MouseFlags.Button4Pressed)){ + if (dragPosition.HasValue) { var dx = me.X - dragPosition.Value.X; var dy = me.Y - dragPosition.Value.Y; @@ -1102,7 +1109,7 @@ namespace Terminal.Gui { if (ny < 0) ny = 0; - Demo.ml2.Text = $"{dx},{dy}"; + //Demo.ml2.Text = $"{dx},{dy}"; dragPosition = new Point (me.X, me.Y); // TODO: optimize, only SetNeedsDisplay on the before/after regions. @@ -1114,23 +1121,26 @@ namespace Terminal.Gui { SetNeedsDisplay (); return true; } else { - dragPosition = new Point (me.X, me.Y); - Application.GrabMouse (this); + // Only start grabbing if the user clicks on the title bar. + if (me.Y == 0) { + dragPosition = new Point (me.X, me.Y); + Application.GrabMouse (this); + } - Demo.ml2.Text = $"Starting at {dragPosition}"; + //Demo.ml2.Text = $"Starting at {dragPosition}"; return true; } - - } if (me.Flags == MouseFlags.Button1Released) { Application.UngrabMouse (); + Driver.UncookMouse (); + dragPosition = null; //Driver.StopReportingMouseMoves (); } - Demo.ml.Text = me.ToString (); + //Demo.ml.Text = me.ToString (); return false; } #endif @@ -1340,6 +1350,7 @@ namespace Terminal.Gui { if (view == null) return; mouseGrabView = view; + Driver.UncookMouse (); } /// @@ -1348,6 +1359,7 @@ namespace Terminal.Gui { public static void UngrabMouse () { mouseGrabView = null; + Driver.CookMouse (); } /// diff --git a/Terminal.Gui/Driver.cs b/Terminal.Gui/Driver.cs index 49fc3dfcc..dceb0e796 100644 --- a/Terminal.Gui/Driver.cs +++ b/Terminal.Gui/Driver.cs @@ -309,6 +309,16 @@ namespace Terminal.Gui { public abstract void StartReportingMouseMoves (); public abstract void StopReportingMouseMoves (); + + /// + /// Disables the cooked event processing from the mouse driver. At startup, it is assumed mouse events are cooked. + /// + public abstract void UncookMouse (); + + /// + /// Enables the cooked event processing from the mouse driver + /// + public abstract void CookMouse (); } /// @@ -607,6 +617,7 @@ namespace Terminal.Gui { } Curses.raw (); Curses.noecho (); + Curses.Window.Standard.keypad (true); reportableMouseEvents = Curses.mousemask (Curses.Event.AllEvents | Curses.Event.ReportMousePosition, out oldMouseEvents); this.terminalResized = terminalResized; @@ -685,6 +696,23 @@ namespace Terminal.Gui { Console.Out.Write ("\x1b[?1003l"); Console.Out.Flush (); } + + int lastMouseInterval; + bool mouseGrabbed; + + public override void UncookMouse() + { + if (mouseGrabbed) + return; + lastMouseInterval = Curses.mouseinterval (0); + mouseGrabbed = true; + } + + public override void CookMouse() + { + mouseGrabbed = false; + Curses.mouseinterval (lastMouseInterval); + } } internal static class Platform { @@ -924,5 +952,13 @@ namespace Terminal.Gui { { throw new NotImplementedException(); } + + public override void CookMouse() + { + } + + public override void UncookMouse() + { + } } }