From a45d65bbdd4514b2434b58ab868fd300b25c320a Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 31 Aug 2023 19:03:05 +0100 Subject: [PATCH 1/5] Fixes #2847. CursesDriver doesn't processing response from task threading. --- Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs | 5 ++--- UICatalog/Scenarios/Threading.cs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index f0c7cb9df..df5359542 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -82,7 +82,6 @@ namespace Terminal.Gui { bool poll_dirty = true; int [] wakeupPipes = new int [2]; static IntPtr ignore = Marshal.AllocHGlobal (1); - static IntPtr readHandle = Marshal.AllocHGlobal (1); MainLoop mainLoop; bool winChanged; @@ -97,8 +96,8 @@ namespace Terminal.Gui { { this.mainLoop = mainLoop; pipe (wakeupPipes); - AddWatch (wakeupPipes [1], Condition.PollIn, ml => { - read (wakeupPipes [1], ignore, readHandle); + AddWatch (wakeupPipes [0], Condition.PollIn, ml => { + read (wakeupPipes [0], ignore, (IntPtr)1); return true; }); } diff --git a/UICatalog/Scenarios/Threading.cs b/UICatalog/Scenarios/Threading.cs index 6bd159497..fe2c15f42 100644 --- a/UICatalog/Scenarios/Threading.cs +++ b/UICatalog/Scenarios/Threading.cs @@ -157,7 +157,7 @@ namespace UICatalog.Scenarios { LogJob ($"Returned from task Thread:{Thread.CurrentThread.ManagedThreadId} {DateTime.Now}"); _itemsList.SetSource (items); LogJob ($"Finished populate list view Thread:{Thread.CurrentThread.ManagedThreadId} {DateTime.Now}"); - _btnActionCancel.Text = "Load Items"; + _btnActionCancel.Text = "Cancelable Load Items"; } else { LogJob ("Task was canceled!"); } From c90366a03d986d786eaa09c107bb0da466838958 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 22 Sep 2023 14:00:09 +0100 Subject: [PATCH 2/5] Fixes #2860. Application views do not refresh when the cursor is moved with CursesDriver. --- Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index df5359542..373699071 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -175,6 +175,10 @@ namespace Terminal.Gui { if (mainLoop.timeouts.Count > 0) { pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond); if (pollTimeout < 0) { + // This avoids poll waiting infinitely if pollTimeout=-1 until some action is detected + if (pollTimeout == -1) { + pollTimeout = 0; + } return true; } } else From 1262d236e55b26ca5a32b6daf404f24c84d70f70 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 22 Sep 2023 20:08:46 +0100 Subject: [PATCH 3/5] The pollTimeout must be set to zero if less than zero. --- .../ConsoleDrivers/CursesDriver/UnixMainLoop.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index 373699071..7ffa43eea 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -175,10 +175,18 @@ namespace Terminal.Gui { if (mainLoop.timeouts.Count > 0) { pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond); if (pollTimeout < 0) { - // This avoids poll waiting infinitely if pollTimeout=-1 until some action is detected - if (pollTimeout == -1) { - pollTimeout = 0; - } + // This avoids 'poll' waiting infinitely if 'pollTimeout < 0' until some action is detected + // This can occur after IMainLoopDriver.Wakeup is executed where the pollTimeout is less than 0 + // and no event occurred in elapsed time when the 'poll' is start running again. + /* + The 'poll' function in the C standard library uses a signed integer as the timeout argument, where: + + - A positive value specifies a timeout in milliseconds. + - A value of 0 means the poll function will return immediately, checking for events and not waiting. + - A value of -1 means the poll function will wait indefinitely until an event occurs or an error occurs. + - A negative value other than -1 typically indicates an error. + */ + pollTimeout = 0; return true; } } else From e86687ee0baeb27dd3791fd4f06956bd47ef1ed1 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 23 Sep 2023 21:38:45 +0100 Subject: [PATCH 4/5] Ensures always resizing if needed on macOS. --- Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index 986a1b012..8a9f0d2a6 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -142,6 +142,7 @@ namespace Terminal.Gui { Curses.raw (); Curses.noecho (); Curses.refresh (); + ProcessWinChange (); } private void ProcessWinChange () From 8a779505b3d6ecd88fc3280b1d883ad8a433f33b Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 23 Sep 2023 21:44:51 +0100 Subject: [PATCH 5/5] Fixes freezing on resizing when read function is executed and many Wakeup calls are done. --- Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index 7ffa43eea..3e23b78a5 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -97,7 +97,7 @@ namespace Terminal.Gui { this.mainLoop = mainLoop; pipe (wakeupPipes); AddWatch (wakeupPipes [0], Condition.PollIn, ml => { - read (wakeupPipes [0], ignore, (IntPtr)1); + read (wakeupPipes [1], ignore, (IntPtr)1); return true; }); }