Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2921 - MainLoop refactoring #2922

Merged
merged 27 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8520435
Adds basic MainLoop unit tests
tig Oct 18, 2023
80fd49e
Remove WinChange action from Curses
tig Oct 18, 2023
55a5d25
Remove WinChange action from Curses
tig Oct 18, 2023
6ff0b6d
Remove ProcessInput action from Windows MainLoop
tig Oct 18, 2023
9eab13b
Simplified MainLoop/ConsoleDriver by making MainLoop internal and mov…
tig Oct 19, 2023
2d2345b
Modernized Terminal resize events
tig Oct 19, 2023
fcea946
Modernized Terminal resize events
tig Oct 19, 2023
9a87303
Removed un used property
tig Oct 19, 2023
54f200a
for _isWindowsTerminal devenv->wininit; not sure what changed
tig Oct 19, 2023
e6db63e
Modernized mouse/keyboard events (Action->EventHandler)
tig Oct 19, 2023
1016777
Updated OnMouseEvent API docs
tig Oct 19, 2023
916f335
Using WT_SESSION to detect WT
tig Oct 20, 2023
f7ad241
removes hacky GetParentProcess
tig Oct 20, 2023
934ce0e
Updates to fix #2634 (clear last line)
tig Oct 20, 2023
6c13cc7
removes hacky GetParentProcess2
tig Oct 20, 2023
6242306
Addressed mac resize issue
tig Oct 20, 2023
aa4e568
Addressed mac resize issue
tig Oct 20, 2023
237c407
Removes ConsoleDriver.PrepareToRun, has Init return MainLoop
tig Oct 20, 2023
d52a147
Removes unneeded Attribute methods
tig Oct 20, 2023
dcb972d
Removed GetProcesssName
tig Oct 20, 2023
f3ee290
Removed GetProcesssName
tig Oct 20, 2023
88a0065
Refactored KeyEvent and KeyEventEventArgs into a single class
tig Oct 20, 2023
36903cb
Revert "Refactored KeyEvent and KeyEventEventArgs into a single class"
tig Oct 20, 2023
95af5b5
Fixed key repeat issue; reverted stupidity on 1049/1047 confusion
tig Oct 21, 2023
891b9dc
Updated CSI API Docs
tig Oct 21, 2023
2b9bbf6
merge
tig Oct 21, 2023
760c522
merge
tig Oct 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ public override void End ()

if (_mainLoop != null) {
_mainLoop.RemoveWatch (_processInputToken);
_mainLoop.WinChanged -= ProcessInput;
}

if (RunningUnitTests) {
Expand Down Expand Up @@ -371,7 +370,7 @@ KeyModifiers MapKeyModifiers (Key key)
return _keyModifiers;
}

void ProcessInput ()
internal void ProcessInput ()
{
int wch;
var code = Curses.get_wch (out wch);
Expand Down Expand Up @@ -626,8 +625,6 @@ public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandle
ProcessInput ();
return true;
});

_mainLoop.WinChanged = ProcessInput;
}

public override void Init (Action terminalResized)
Expand Down
7 changes: 5 additions & 2 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ namespace Terminal.Gui {
/// can watch file descriptors using the AddWatch methods.
/// </remarks>
internal class UnixMainLoop : IMainLoopDriver {
private CursesDriver _cursesDriver;
public UnixMainLoop (ConsoleDriver consoleDriver = null)
{
// UnixDriver doesn't use the consoleDriver parameter, but the WindowsDriver does.
_cursesDriver = (CursesDriver)Application.Driver;
tig marked this conversation as resolved.
Show resolved Hide resolved
}

public const int KEY_RESIZE = unchecked((int)0xffffffffffffffff);
Expand Down Expand Up @@ -86,7 +88,7 @@ class Watch {
MainLoop _mainLoop;
bool _winChanged;

internal Action WinChanged;
//internal Action WinChanged;

void IMainLoopDriver.Wakeup ()
{
Expand Down Expand Up @@ -187,7 +189,8 @@ void IMainLoopDriver.Iteration ()
{
if (_winChanged) {
_winChanged = false;
WinChanged?.Invoke ();
_cursesDriver.ProcessInput ();
tig marked this conversation as resolved.
Show resolved Hide resolved
//WinChanged?.Invoke ();
}
tig marked this conversation as resolved.
Show resolved Hide resolved
if (_pollMap == null) return;
foreach (var p in _pollMap) {
Expand Down
4 changes: 2 additions & 2 deletions Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandle
_mouseHandler = mouseHandler;

_mainLoop = mainLoop.MainLoopDriver as WindowsMainLoop;
_mainLoop.ProcessInput = ProcessInput;
_mainLoop.ProcessInput += ProcessInput;
tig marked this conversation as resolved.
Show resolved Hide resolved
#if HACK_CHECK_WINCHANGED
_mainLoop.WinChanged = ChangeWin;
#endif
Expand Down Expand Up @@ -1879,7 +1879,7 @@ void IMainLoopDriver.Wakeup ()
bool IMainLoopDriver.EventsPending ()
{
_waitForProbe.Set ();
#if HACK_CHECK_WINCHANGED
#if HACK_CHECK_WINCHANGED
_winChange.Set ();
#endif
if (_mainLoop.CheckTimersAndIdleHandlers (out var waitTimeout)) {
Expand Down
17 changes: 10 additions & 7 deletions Terminal.Gui/MainLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ void RunIdle ()
}
}

bool _running;
/// <summary>
/// Used for unit tests.
/// </summary>
internal bool Running { get; private set; }

/// <summary>
/// Determines whether there are pending events to be processed.
Expand Down Expand Up @@ -353,21 +356,21 @@ public void RunIteration ()
/// </summary>
public void Run ()
{
var prev = _running;
_running = true;
while (_running) {
var prev = Running;
Running = true;
while (Running) {
EventsPending ();
RunIteration ();
}
_running = prev;
Running = prev;
}

/// <summary>
/// Stops the main loop driver and calls <see cref="IMainLoopDriver.Wakeup"/>.
/// </summary>
public void Stop ()
{
_running = false;
Running = false;
MainLoopDriver.Wakeup ();
}

Expand All @@ -376,7 +379,7 @@ public void Dispose ()
{
GC.SuppressFinalize (this);
Stop ();
_running = false;
Running = false;
MainLoopDriver?.TearDown ();
MainLoopDriver = null;
}
Expand Down
Loading
Loading