Lagrange [release]

TUI: Always use idle sleep to reduce CPU usage

=> 43ea78c6bbc304ab4ea8002dc356a09ff323c2cf

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a223c9c0..36c7e0ea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -593,6 +593,11 @@ if (ENABLE_TUI)
         target_link_libraries (tuiapp PUBLIC ${SEALCURSES_LDFLAGS})
     endif ()
     set_common_app_properties (tuiapp)
+    if (NOT ENABLE_IDLE_SLEEP)
+        # SEALCurses does not have a waiting event getter, so ease the CPU load by sleeping
+        # when nothing is happening.
+        target_compile_definitions (tuiapp LAGRANGE_ENABLE_IDLE_SLEEP=1)
+    endif ()
 endif ()
 
 # Deployment.
diff --git a/src/app.c b/src/app.c
index 21b1f803..8174524a 100644
--- a/src/app.c
+++ b/src/app.c
@@ -88,9 +88,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 #if defined (iPlatformMsys)
 #   include "win32.h"
 #endif
-#if defined (iPlatformTerminal)
-#   undef LAGRANGE_ENABLE_IDLE_SLEEP
-#endif
 #if defined (LAGRANGE_ENABLE_X11_XLIB)
 #   include "x11.h"
 #endif
@@ -1463,6 +1460,9 @@ static void init_App_(iApp *d, int argc, char **argv) {
         d->isIdling      = iFalse;
         d->lastEventTime = 0;
         d->sleepTimer    = SDL_AddTimer(1000, checkAsleep_App_, d);
+#if defined (iPlatformTerminal)
+        d->idleSleepDelayMs = 1000 / 60;
+#else
         SDL_DisplayMode dispMode;
         SDL_GetWindowDisplayMode(d->window->win, &dispMode);
         if (dispMode.refresh_rate) {
@@ -1471,6 +1471,7 @@ static void init_App_(iApp *d, int argc, char **argv) {
         else {
             d->idleSleepDelayMs = 1000 / 60;
         }
+#endif
         d->idleSleepDelayMs *= 0.9f;
     }
 #endif
@@ -1927,7 +1928,7 @@ static iBool nextEvent_App_(iApp *d, enum iAppEventMode eventMode, SDL_Event *ev
     /* SDL regression circa 2.0.18? SDL_PollEvent() doesn't always return
        events posted immediately beforehand. Waiting with a very short timeout
        seems to work better. */
-#if defined (iPlatformLinux) && SDL_VERSION_ATLEAST(2, 0, 18)
+#if !defined (iPlatformTerminal) && defined (iPlatformLinux) && SDL_VERSION_ATLEAST(2, 0, 18)
     return SDL_WaitEventTimeout(event, 1);
 #else
     return SDL_PollEvent(event);
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/release/cdiff/43ea78c6bbc304ab4ea8002dc356a09ff323c2cf
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
78.400677 milliseconds
Gemini-to-HTML Time
0.249067 milliseconds

This content has been proxied by September (3851b).