Fixes #4172 Timeout revamp and remove continuous mouse (#4173)

* Remove continous press code from Application

* WIP prototype code to handle continuous press as subcomponent of View

* Prototype with Button

* Implement CWP

* Move to seperate classes and prevent double entry to Start

* Fix repeat clicking when moving mouse by removing phantom click code (old implementation of WantContinuousButtonPressed)

* Remove initial tick because it results in double activation e.g. button firing twice immediately as mouse is pressed down.

* Refactor DatePicker lamdas

* WIP investigate subcomponents instead of statics

* Add IMouseGrabHandler to IApplication

* Make mouse grabbing non static activity

* Make MouseHeldDown suppress when null fields e.g. app not initialized in tests

* Update test and remove dependency on Application

* Fix other mouse click and hold tests

* Code cleanup

* Update class diagram

* Fix bad xml doc references

* Fix timed events not getting passed through in v2 applications

* Make timed events nullable for tests that dont create an Application

* Remove strange blocking test

* WIP remove all idles and replace with zero timeouts

* Fix build of tests

* Fix unit tests

* Add wakeup call back in

* Comment out incredibly complicated test and fix others

* Fix test

* test fix

* Make Post execute immediately if already on UI thread

* Re enable test and simplify Invoke to just execute if in UI thread (up front)

* Remove xml doc references to idles

* Remove more references to idles

* Make Screen initialization threadsafe

* Add more exciting timeouts

* WIP add tests

* fix log

* fix test

* make continuous key press use smoth acceleration

* Rename _lock to _lockScreen

* Remove section on idles, they are not a thing anymore - and they kinda never were.

* Add nullable enable

* Add xml comment

* Fix namings and cleanup code

* xmldoc fix

* Rename LockAndRunTimers to just RunTimers

* Rename AddTimeout and RemoveTimeout (and event) to just Add/Remove

* Update description of MainLoop

* Commented out Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver

* Again? Commented out Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver

* Revert Commented out Run_T_Call_Init_ForceDriver_Should_Pick_Correct_Driver

* When mouse is released from MouseHeldDown reset host MouseState

* Fix namespaces in class diagram

* Apply @BDisp suggested fix

* Fix class diagrams

* Add lock

* Make TimeSpan.Zero definetly run

* Fix duplicate entry in package props

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
This commit is contained in:
Thomas Nind
2025-07-10 18:59:27 +01:00
committed by GitHub
parent 23cacaee93
commit ec827e901e
68 changed files with 1788 additions and 1448 deletions

View File

@@ -307,8 +307,7 @@ public class ApplicationTests
// Public Properties
Assert.Null (Application.Top);
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.WantContinuousButtonPressedView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Don't check Application.ForceDriver
// Assert.Empty (Application.ForceDriver);
@@ -569,8 +568,7 @@ public class ApplicationTests
Assert.Null (Application.Top);
RunState rs = Application.Begin (new ());
Assert.Equal (Application.Top, rs.Toplevel);
Assert.Null (Application.MouseGrabView); // public
Assert.Null (Application.WantContinuousButtonPressedView); // public
Assert.Null (Application.MouseGrabHandler.MouseGrabView); // public
Application.Top!.Dispose ();
}
@@ -952,7 +950,7 @@ public class ApplicationTests
Assert.Equal (new (0, 0), w.Frame.Location);
Application.RaiseMouseEvent (new () { Flags = MouseFlags.Button1Pressed });
Assert.Equal (w.Border, Application.MouseGrabView);
Assert.Equal (w.Border, Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (new (0, 0), w.Frame.Location);
// Move down and to the right.
@@ -1116,6 +1114,8 @@ public class ApplicationTests
private class TestToplevel : Toplevel { }
private readonly object _forceDriverLock = new ();
[Theory]
[InlineData ("v2win", typeof (ConsoleDriverFacade<WindowsConsole.InputRecord>))]
[InlineData ("v2net", typeof (ConsoleDriverFacade<ConsoleKeyInfo>))]
@@ -1129,20 +1129,29 @@ public class ApplicationTests
var result = false;
Task.Run (() =>
{
Task.Delay (300).Wait ();
}).ContinueWith (
(t, _) =>
lock (_forceDriverLock)
{
Task.Run (() =>
{
while (!Application.Initialized)
{
Task.Delay (300).Wait ();
}
})
.ContinueWith (
(t, _) =>
{
// no longer loading
Assert.True (Application.Initialized);
Application.Invoke (() =>
{
// no longer loading
Application.Invoke (() =>
{
result = true;
Application.RequestStop ();
});
},
TaskScheduler.FromCurrentSynchronizationContext ());
result = true;
Application.RequestStop ();
});
},
TaskScheduler.FromCurrentSynchronizationContext ());
}
Application.ForceDriver = driverName;
Application.Run<TestToplevel> ();

View File

@@ -29,61 +29,38 @@ public class MainLoopTests
// Idle Handler tests
[Fact]
public void AddIdle_Adds_And_Removes ()
public void AddTimeout_Adds_And_Removes ()
{
var ml = new MainLoop (new FakeMainLoop ());
Func<bool> fnTrue = () => true;
Func<bool> fnFalse = () => false;
ml.AddIdle (fnTrue);
ml.AddIdle (fnFalse);
var a = ml.TimedEvents.Add (TimeSpan.Zero, fnTrue);
var b = ml.TimedEvents.Add (TimeSpan.Zero, fnFalse);
Assert.Equal (2, ml.TimedEvents.IdleHandlers.Count);
Assert.Equal (fnTrue, ml.TimedEvents.IdleHandlers [0]);
Assert.NotEqual (fnFalse, ml.TimedEvents.IdleHandlers [0]);
Assert.Equal (2, ml.TimedEvents.Timeouts.Count);
Assert.Equal (fnTrue, ml.TimedEvents.Timeouts.ElementAt (0).Value.Callback);
Assert.NotEqual (fnFalse, ml.TimedEvents.Timeouts.ElementAt (0).Value.Callback);
Assert.True (ml.TimedEvents.RemoveIdle (fnTrue));
Assert.Single (ml.TimedEvents.IdleHandlers);
Assert.True (ml.TimedEvents.Remove (a));
Assert.Single (ml.TimedEvents.Timeouts);
// BUGBUG: This doesn't throw or indicate an error. Ideally RemoveIdle would either
// throw an exception in this case, or return an error.
// No. Only need to return a boolean.
Assert.False (ml.TimedEvents.RemoveIdle (fnTrue));
Assert.False (ml.TimedEvents.Remove (a));
Assert.True (ml.TimedEvents.RemoveIdle (fnFalse));
Assert.True (ml.TimedEvents.Remove (b));
// BUGBUG: This doesn't throw an exception or indicate an error. Ideally RemoveIdle would either
// throw an exception in this case, or return an error.
// No. Only need to return a boolean.
Assert.False (ml.TimedEvents.RemoveIdle (fnFalse));
// Add again, but with dupe
ml.AddIdle (fnTrue);
ml.AddIdle (fnTrue);
Assert.Equal (2, ml.TimedEvents.IdleHandlers.Count);
Assert.Equal (fnTrue, ml.TimedEvents.IdleHandlers [0]);
Assert.True (ml.TimedEvents.IdleHandlers [0] ());
Assert.Equal (fnTrue, ml.TimedEvents.IdleHandlers [1]);
Assert.True (ml.TimedEvents.IdleHandlers [1] ());
Assert.True (ml.TimedEvents.RemoveIdle (fnTrue));
Assert.Single (ml.TimedEvents.IdleHandlers);
Assert.Equal (fnTrue, ml.TimedEvents.IdleHandlers [0]);
Assert.NotEqual (fnFalse, ml.TimedEvents.IdleHandlers [0]);
Assert.True (ml.TimedEvents.RemoveIdle (fnTrue));
Assert.Empty (ml.TimedEvents.IdleHandlers);
// BUGBUG: This doesn't throw an exception or indicate an error. Ideally RemoveIdle would either
// throw an exception in this case, or return an error.
// No. Only need to return a boolean.
Assert.False (ml.TimedEvents.RemoveIdle (fnTrue));
Assert.False (ml.TimedEvents.Remove(b));
}
[Fact]
public void AddIdle_Function_GetsCalled_OnIteration ()
public void AddTimeout_Function_GetsCalled_OnIteration ()
{
var ml = new MainLoop (new FakeMainLoop ());
@@ -96,13 +73,13 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fn);
ml.TimedEvents.Add (TimeSpan.Zero, fn);
ml.RunIteration ();
Assert.Equal (1, functionCalled);
}
[Fact]
public void AddIdle_Twice_Returns_False_Called_Twice ()
public void AddTimeout_Twice_Returns_False_Called_Twice ()
{
var ml = new MainLoop (new FakeMainLoop ());
@@ -130,19 +107,21 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fnStop);
ml.AddIdle (fn1);
ml.AddIdle (fn1);
var a = ml.TimedEvents.Add (TimeSpan.Zero, fnStop);
var b = ml.TimedEvents.Add (TimeSpan.Zero, fn1);
ml.Run ();
Assert.True (ml.TimedEvents.RemoveIdle (fnStop));
Assert.False (ml.TimedEvents.RemoveIdle (fn1));
Assert.False (ml.TimedEvents.RemoveIdle (fn1));
Assert.Equal (2, functionCalled);
Assert.True (ml.TimedEvents.Remove(a));
Assert.False (ml.TimedEvents.Remove (a));
// Cannot remove b because it returned false i.e. auto removes itself
Assert.False (ml.TimedEvents.Remove (b));
Assert.Equal (1, functionCalled);
}
[Fact]
public void AddIdleTwice_Function_CalledTwice ()
public void AddTimeoutTwice_Function_CalledTwice ()
{
var ml = new MainLoop (new FakeMainLoop ());
@@ -155,24 +134,24 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fn);
ml.AddIdle (fn);
var a = ml.TimedEvents.Add (TimeSpan.Zero, fn);
var b = ml.TimedEvents.Add (TimeSpan.Zero, fn);
ml.RunIteration ();
Assert.Equal (2, functionCalled);
Assert.Equal (2, ml.TimedEvents.IdleHandlers.Count);
Assert.Equal (2, ml.TimedEvents.Timeouts.Count);
functionCalled = 0;
Assert.True (ml.TimedEvents.RemoveIdle (fn));
Assert.Single (ml.TimedEvents.IdleHandlers);
Assert.True (ml.TimedEvents.Remove (a));
Assert.Single (ml.TimedEvents.Timeouts);
ml.RunIteration ();
Assert.Equal (1, functionCalled);
functionCalled = 0;
Assert.True (ml.TimedEvents.RemoveIdle (fn));
Assert.Empty (ml.TimedEvents.IdleHandlers);
Assert.True (ml.TimedEvents.Remove (b));
Assert.Empty (ml.TimedEvents.Timeouts);
ml.RunIteration ();
Assert.Equal (0, functionCalled);
Assert.False (ml.TimedEvents.RemoveIdle (fn));
Assert.False (ml.TimedEvents.Remove (b));
}
[Fact]
@@ -189,8 +168,8 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fn);
Assert.True (ml.TimedEvents.RemoveIdle (fn));
var a = ml.TimedEvents.Add (TimeSpan.Zero, fn);
Assert.True (ml.TimedEvents.Remove (a));
ml.RunIteration ();
Assert.Equal (0, functionCalled);
}
@@ -211,13 +190,13 @@ public class MainLoopTests
return true;
};
object token = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback);
object token = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback);
Assert.True (ml.TimedEvents.RemoveTimeout (token));
Assert.True (ml.TimedEvents.Remove (token));
// BUGBUG: This should probably fault?
// Must return a boolean.
Assert.False (ml.TimedEvents.RemoveTimeout (token));
Assert.False (ml.TimedEvents.Remove (token));
}
[Fact]
@@ -241,8 +220,8 @@ public class MainLoopTests
return true;
};
var task1 = new Task (() => token1 = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback));
var task2 = new Task (() => token2 = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback));
var task1 = new Task (() => token1 = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback));
var task2 = new Task (() => token2 = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback));
Assert.Null (token1);
Assert.Null (token2);
task1.Start ();
@@ -251,8 +230,8 @@ public class MainLoopTests
Assert.NotNull (token1);
Assert.NotNull (token2);
await Task.WhenAll (task1, task2);
Assert.True (ml.TimedEvents.RemoveTimeout (token1));
Assert.True (ml.TimedEvents.RemoveTimeout (token2));
Assert.True (ml.TimedEvents.Remove (token1));
Assert.True (ml.TimedEvents.Remove (token2));
Assert.Equal (2, callbackCount);
}
@@ -278,13 +257,13 @@ public class MainLoopTests
object sender = null;
TimeoutEventArgs args = null;
ml.TimedEvents.TimeoutAdded += (s, e) =>
ml.TimedEvents.Added += (s, e) =>
{
sender = s;
args = e;
};
object token = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback);
object token = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback);
Assert.Same (ml.TimedEvents, sender);
Assert.NotNull (args.Timeout);
@@ -313,14 +292,14 @@ public class MainLoopTests
};
Parallel.Invoke (
() => token1 = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback),
() => token2 = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback)
() => token1 = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback),
() => token2 = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback)
);
ml.Run ();
Assert.NotNull (token1);
Assert.NotNull (token2);
Assert.True (ml.TimedEvents.RemoveTimeout (token1));
Assert.True (ml.TimedEvents.RemoveTimeout (token2));
Assert.True (ml.TimedEvents.Remove (token1));
Assert.True (ml.TimedEvents.Remove (token2));
Assert.Equal (2, callbackCount);
}
@@ -345,7 +324,7 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fnStop);
ml.TimedEvents.Add (TimeSpan.Zero, fnStop);
var callbackCount = 0;
@@ -356,8 +335,8 @@ public class MainLoopTests
return true;
};
object token = ml.TimedEvents.AddTimeout (ms, callback);
Assert.True (ml.TimedEvents.RemoveTimeout (token));
object token = ml.TimedEvents.Add (ms, callback);
Assert.True (ml.TimedEvents.Remove (token));
ml.Run ();
Assert.Equal (0, callbackCount);
}
@@ -383,7 +362,7 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fnStop);
ml.TimedEvents.Add (TimeSpan.Zero, fnStop);
var callbackCount = 0;
@@ -394,11 +373,11 @@ public class MainLoopTests
return false;
};
object token = ml.TimedEvents.AddTimeout (ms, callback);
object token = ml.TimedEvents.Add (ms, callback);
ml.Run ();
Assert.Equal (1, callbackCount);
Assert.Equal (10, stopCount);
Assert.False (ml.TimedEvents.RemoveTimeout (token));
Assert.False (ml.TimedEvents.Remove (token));
}
[Fact]
@@ -417,9 +396,9 @@ public class MainLoopTests
return true;
};
object token = ml.TimedEvents.AddTimeout (TimeSpan.FromMilliseconds (ms), callback);
object token = ml.TimedEvents.Add (TimeSpan.FromMilliseconds (ms), callback);
ml.Run ();
Assert.True (ml.TimedEvents.RemoveTimeout (token));
Assert.True (ml.TimedEvents.Remove (token));
Assert.Equal (1, callbackCount);
}
@@ -442,7 +421,7 @@ public class MainLoopTests
return true;
};
object token = ml.TimedEvents.AddTimeout (ms, callback);
object token = ml.TimedEvents.Add (ms, callback);
watch.Start ();
ml.Run ();
@@ -450,7 +429,7 @@ public class MainLoopTests
// https://github.com/xunit/assert.xunit/pull/25
Assert.Equal (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));
Assert.True (ml.TimedEvents.RemoveTimeout (token));
Assert.True (ml.TimedEvents.Remove (token));
Assert.Equal (1, callbackCount);
}
@@ -476,7 +455,7 @@ public class MainLoopTests
return true;
};
object token = ml.TimedEvents.AddTimeout (ms, callback);
object token = ml.TimedEvents.Add (ms, callback);
watch.Start ();
ml.Run ();
@@ -484,7 +463,7 @@ public class MainLoopTests
// https://github.com/xunit/assert.xunit/pull/25
Assert.Equal (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));
Assert.True (ml.TimedEvents.RemoveTimeout (token));
Assert.True (ml.TimedEvents.Remove (token));
Assert.Equal (2, callbackCount);
}
@@ -492,7 +471,7 @@ public class MainLoopTests
public void CheckTimersAndIdleHandlers_NoTimers_Returns_False ()
{
var ml = new MainLoop (new FakeMainLoop ());
bool retVal = ml.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeOut);
bool retVal = ml.TimedEvents.CheckTimers(out int waitTimeOut);
Assert.False (retVal);
Assert.Equal (-1, waitTimeOut);
}
@@ -503,10 +482,10 @@ public class MainLoopTests
var ml = new MainLoop (new FakeMainLoop ());
Func<bool> fnTrue = () => true;
ml.AddIdle (fnTrue);
bool retVal = ml.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeOut);
ml.TimedEvents.Add (TimeSpan.Zero, fnTrue);
bool retVal = ml.TimedEvents.CheckTimers(out int waitTimeOut);
Assert.True (retVal);
Assert.Equal (-1, waitTimeOut);
Assert.Equal (0, waitTimeOut);
}
[Fact]
@@ -517,8 +496,8 @@ public class MainLoopTests
static bool Callback () { return false; }
_ = ml.TimedEvents.AddTimeout (ms, Callback);
bool retVal = ml.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeOut);
_ = ml.TimedEvents.Add (ms, Callback);
bool retVal = ml.TimedEvents.CheckTimers (out int waitTimeOut);
Assert.True (retVal);
@@ -534,9 +513,9 @@ public class MainLoopTests
static bool Callback () { return false; }
_ = ml.TimedEvents.AddTimeout (ms, Callback);
_ = ml.TimedEvents.AddTimeout (ms, Callback);
bool retVal = ml.TimedEvents.CheckTimersAndIdleHandlers (out int waitTimeOut);
_ = ml.TimedEvents.Add (ms, Callback);
_ = ml.TimedEvents.Add (ms, Callback);
bool retVal = ml.TimedEvents.CheckTimers (out int waitTimeOut);
Assert.True (retVal);
@@ -578,11 +557,11 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fnStop);
ml.AddIdle (fn1);
var a = ml.TimedEvents.Add (TimeSpan.Zero, fnStop);
var b = ml.TimedEvents.Add (TimeSpan.Zero, fn1);
ml.Run ();
Assert.True (ml.TimedEvents.RemoveIdle (fnStop));
Assert.False (ml.TimedEvents.RemoveIdle (fn1));
Assert.True (ml.TimedEvents.Remove (a));
Assert.False (ml.TimedEvents.Remove (a));
Assert.Equal (10, functionCalled);
Assert.Equal (20, stopCount);
@@ -594,7 +573,6 @@ public class MainLoopTests
var testMainloop = new TestMainloop ();
var mainloop = new MainLoop (testMainloop);
Assert.Empty (mainloop.TimedEvents.Timeouts);
Assert.Empty (mainloop.TimedEvents.IdleHandlers);
Assert.NotNull (
new App.Timeout { Span = new (), Callback = () => true }
@@ -602,8 +580,8 @@ public class MainLoopTests
}
[Theory]
[MemberData (nameof (TestAddIdle))]
public void Mainloop_Invoke_Or_AddIdle_Can_Be_Used_For_Events_Or_Actions (
[MemberData (nameof (TestAddTimeout))]
public void Mainloop_Invoke_Or_AddTimeout_Can_Be_Used_For_Events_Or_Actions (
Action action,
string pclickMe,
string pcancel,
@@ -683,7 +661,7 @@ public class MainLoopTests
Application.Shutdown ();
}
[Fact]
public void RemoveIdle_Function_NotCalled ()
{
@@ -698,7 +676,7 @@ public class MainLoopTests
return true;
};
Assert.False (ml.TimedEvents.RemoveIdle (fn));
Assert.False (ml.TimedEvents.Remove ("flibble"));
ml.RunIteration ();
Assert.Equal (0, functionCalled);
}
@@ -722,14 +700,14 @@ public class MainLoopTests
return true;
};
ml.AddIdle (fn);
var a = ml.TimedEvents.Add (TimeSpan.Zero, fn);
ml.Run ();
Assert.True (ml.TimedEvents.RemoveIdle (fn));
Assert.True (ml.TimedEvents.Remove (a));
Assert.Equal (10, functionCalled);
}
public static IEnumerable<object []> TestAddIdle
public static IEnumerable<object []> TestAddTimeout
{
get
{

View File

@@ -260,39 +260,39 @@ public class ApplicationMouseTests
// if (iterations == 0)
// {
// Assert.True (tf.HasFocus);
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RaiseMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.ReportMousePosition });
// Assert.Equal (sv, Application.MouseGrabView);
// Assert.Equal (sv, Application.MouseGrabHandler.MouseGrabView);
// MessageBox.Query ("Title", "Test", "Ok");
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// }
// else if (iterations == 1)
// {
// // Application.MouseGrabView is null because
// // Application.MouseGrabHandler.MouseGrabView is null because
// // another toplevel (Dialog) was opened
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RaiseMouseEvent (new () { ScreenPosition = new (5, 5), Flags = MouseFlags.ReportMousePosition });
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RaiseMouseEvent (new () { ScreenPosition = new (40, 12), Flags = MouseFlags.ReportMousePosition });
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed });
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RequestStop ();
// }
// else if (iterations == 2)
// {
// Assert.Null (Application.MouseGrabView);
// Assert.Null (Application.MouseGrabHandler.MouseGrabView);
// Application.RequestStop ();
// }
@@ -313,33 +313,33 @@ public class ApplicationMouseTests
var view2 = new View { Id = "view2" };
var view3 = new View { Id = "view3" };
Application.GrabbedMouse += Application_GrabbedMouse;
Application.UnGrabbedMouse += Application_UnGrabbedMouse;
Application.MouseGrabHandler.GrabbedMouse += Application_GrabbedMouse;
Application.MouseGrabHandler.UnGrabbedMouse += Application_UnGrabbedMouse;
Application.GrabMouse (view1);
Application.MouseGrabHandler.GrabMouse (view1);
Assert.Equal (0, count);
Assert.Equal (grabView, view1);
Assert.Equal (view1, Application.MouseGrabView);
Assert.Equal (view1, Application.MouseGrabHandler.MouseGrabView);
Application.UngrabMouse ();
Application.MouseGrabHandler.UngrabMouse ();
Assert.Equal (1, count);
Assert.Equal (grabView, view1);
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
Application.GrabbedMouse += Application_GrabbedMouse;
Application.UnGrabbedMouse += Application_UnGrabbedMouse;
Application.MouseGrabHandler.GrabbedMouse += Application_GrabbedMouse;
Application.MouseGrabHandler.UnGrabbedMouse += Application_UnGrabbedMouse;
Application.GrabMouse (view2);
Application.MouseGrabHandler.GrabMouse (view2);
Assert.Equal (1, count);
Assert.Equal (grabView, view2);
Assert.Equal (view2, Application.MouseGrabView);
Assert.Equal (view2, Application.MouseGrabHandler.MouseGrabView);
Application.UngrabMouse ();
Application.MouseGrabHandler.UngrabMouse ();
Assert.Equal (2, count);
Assert.Equal (grabView, view2);
Assert.Equal (view3, Application.MouseGrabView);
Application.UngrabMouse ();
Assert.Null (Application.MouseGrabView);
Assert.Equal (view3, Application.MouseGrabHandler.MouseGrabView);
Application.MouseGrabHandler.UngrabMouse ();
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
void Application_GrabbedMouse (object sender, ViewEventArgs e)
{
@@ -354,7 +354,7 @@ public class ApplicationMouseTests
grabView = view2;
}
Application.GrabbedMouse -= Application_GrabbedMouse;
Application.MouseGrabHandler.GrabbedMouse -= Application_GrabbedMouse;
}
void Application_UnGrabbedMouse (object sender, ViewEventArgs e)
@@ -375,10 +375,10 @@ public class ApplicationMouseTests
if (count > 1)
{
// It's possible to grab another view after the previous was ungrabbed
Application.GrabMouse (view3);
Application.MouseGrabHandler.GrabMouse (view3);
}
Application.UnGrabbedMouse -= Application_UnGrabbedMouse;
Application.MouseGrabHandler.UnGrabbedMouse -= Application_UnGrabbedMouse;
}
}
@@ -393,18 +393,18 @@ public class ApplicationMouseTests
top.Add (view);
Application.Begin (top);
Assert.Null (Application.MouseGrabView);
Application.GrabMouse (view);
Assert.Equal (view, Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
Application.MouseGrabHandler.GrabMouse (view);
Assert.Equal (view, Application.MouseGrabHandler.MouseGrabView);
top.Remove (view);
Application.UngrabMouse ();
Application.MouseGrabHandler.UngrabMouse ();
view.Dispose ();
#if DEBUG_IDISPOSABLE
Assert.True (view.WasDisposed);
#endif
Application.RaiseMouseEvent (new () { ScreenPosition = new (0, 0), Flags = MouseFlags.Button1Pressed });
Assert.Null (Application.MouseGrabView);
Assert.Null (Application.MouseGrabHandler.MouseGrabView);
Assert.Equal (0, count);
top.Dispose ();
}