Преглед изворни кода

Another attempt at getting tracking events, does not look like it will work

Miguel de Icaza пре 7 година
родитељ
комит
d1a93925cb
2 измењених фајлова са 57 додато и 9 уклоњено
  1. 21 9
      Terminal.Gui/Core.cs
  2. 36 0
      Terminal.Gui/Driver.cs

+ 21 - 9
Terminal.Gui/Core.cs

@@ -1082,7 +1082,7 @@ namespace Terminal.Gui {
 			ClearNeedsDisplay ();
 			ClearNeedsDisplay ();
 		}
 		}
 
 
-#if false
+#if true
 		// 
 		// 
 		// It does not look like the event is raised on clicked-drag
 		// It does not look like the event is raised on clicked-drag
 		// need to figure that out.
 		// need to figure that out.
@@ -1090,7 +1090,14 @@ namespace Terminal.Gui {
 		Point? dragPosition;
 		Point? dragPosition;
 		public override bool MouseEvent(MouseEvent me)
 		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) {
 				if (dragPosition.HasValue) {
 					var dx = me.X - dragPosition.Value.X;
 					var dx = me.X - dragPosition.Value.X;
 					var dy = me.Y - dragPosition.Value.Y;
 					var dy = me.Y - dragPosition.Value.Y;
@@ -1102,7 +1109,7 @@ namespace Terminal.Gui {
 					if (ny < 0)
 					if (ny < 0)
 						ny = 0;
 						ny = 0;
 
 
-					Demo.ml2.Text = $"{dx},{dy}";
+					//Demo.ml2.Text = $"{dx},{dy}";
 					dragPosition = new Point (me.X, me.Y);
 					dragPosition = new Point (me.X, me.Y);
 
 
 					// TODO: optimize, only SetNeedsDisplay on the before/after regions.
 					// TODO: optimize, only SetNeedsDisplay on the before/after regions.
@@ -1114,23 +1121,26 @@ namespace Terminal.Gui {
 					SetNeedsDisplay ();
 					SetNeedsDisplay ();
 					return true;
 					return true;
 				} else {
 				} 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;
 					return true;
 				}
 				}
-
-
 			}
 			}
 
 
 			if (me.Flags == MouseFlags.Button1Released) {
 			if (me.Flags == MouseFlags.Button1Released) {
 				Application.UngrabMouse ();
 				Application.UngrabMouse ();
+				Driver.UncookMouse ();
+
 				dragPosition = null;
 				dragPosition = null;
 				//Driver.StopReportingMouseMoves ();
 				//Driver.StopReportingMouseMoves ();
 			}
 			}
 
 
-			Demo.ml.Text = me.ToString ();
+			//Demo.ml.Text = me.ToString ();
 			return false;
 			return false;
 		}
 		}
 #endif
 #endif
@@ -1340,6 +1350,7 @@ namespace Terminal.Gui {
 			if (view == null)
 			if (view == null)
 				return;
 				return;
 			mouseGrabView = view;
 			mouseGrabView = view;
+			Driver.UncookMouse ();
 		}
 		}
 
 
 		/// <summary>
 		/// <summary>
@@ -1348,6 +1359,7 @@ namespace Terminal.Gui {
 		public static void UngrabMouse ()
 		public static void UngrabMouse ()
 		{
 		{
 			mouseGrabView = null;
 			mouseGrabView = null;
+			Driver.CookMouse ();
 		}
 		}
 
 
 		/// <summary>
 		/// <summary>

+ 36 - 0
Terminal.Gui/Driver.cs

@@ -309,6 +309,16 @@ namespace Terminal.Gui {
 
 
 		public abstract void StartReportingMouseMoves ();
 		public abstract void StartReportingMouseMoves ();
 		public abstract void StopReportingMouseMoves ();
 		public abstract void StopReportingMouseMoves ();
+
+		/// <summary>
+		/// Disables the cooked event processing from the mouse driver.  At startup, it is assumed mouse events are cooked.
+		/// </summary>
+		public abstract void UncookMouse ();
+
+		/// <summary>
+		/// Enables the cooked event processing from the mouse driver
+		/// </summary>
+		public abstract void CookMouse ();
 	}
 	}
 
 
 	/// <summary>
 	/// <summary>
@@ -607,6 +617,7 @@ namespace Terminal.Gui {
 			}
 			}
 			Curses.raw ();
 			Curses.raw ();
 			Curses.noecho ();
 			Curses.noecho ();
+
 			Curses.Window.Standard.keypad (true);
 			Curses.Window.Standard.keypad (true);
 			reportableMouseEvents = Curses.mousemask (Curses.Event.AllEvents | Curses.Event.ReportMousePosition, out oldMouseEvents);
 			reportableMouseEvents = Curses.mousemask (Curses.Event.AllEvents | Curses.Event.ReportMousePosition, out oldMouseEvents);
 			this.terminalResized = terminalResized;
 			this.terminalResized = terminalResized;
@@ -685,6 +696,23 @@ namespace Terminal.Gui {
 			Console.Out.Write ("\x1b[?1003l");
 			Console.Out.Write ("\x1b[?1003l");
 			Console.Out.Flush ();
 			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 {
 	internal static class Platform {
@@ -924,5 +952,13 @@ namespace Terminal.Gui {
 		{
 		{
 			throw new NotImplementedException();
 			throw new NotImplementedException();
 		}
 		}
+
+		public override void CookMouse()
+		{
+		}
+
+		public override void UncookMouse()
+		{
+		}
 	}
 	}
 }
 }