From 2942cc096882fdaca0a2a6783906dd611d506bd1 Mon Sep 17 00:00:00 2001 From: dandistine <34634876+dandistine@users.noreply.github.com> Date: Sun, 20 Sep 2026 11:13:57 -0500 Subject: [PATCH 1/4] Only copy the header if it is different --- dev/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/CMakeLists.txt b/dev/CMakeLists.txt index 4895ce0..51a9c6d 100644 --- a/dev/CMakeLists.txt +++ b/dev/CMakeLists.txt @@ -45,7 +45,8 @@ else() endif() add_custom_target(CopyHeader - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/olcPixelGameEngine3.h ${REPO_ROOT_DIR}/olcPixelGameEngine3.h + BYPRODUCTS ${REPO_ROOT_DIR}/olcPixelGameEngine3.h + COMMAND ${CMAKE_COMMAND} -E copy_if_newer ${CMAKE_BINARY_DIR}/olcPixelGameEngine3.h ${REPO_ROOT_DIR}/olcPixelGameEngine3.h DEPENDS olcPixelGameEngine3.h ) From e8082f0c28fb254c871a2f66fcf8ab648d4fdd2b Mon Sep 17 00:00:00 2001 From: dandistine <34634876+dandistine@users.noreply.github.com> Date: Sun, 20 Sep 2026 11:27:46 -0500 Subject: [PATCH 2/4] Change to copy_if_different since the github runner is out-of-date. --- dev/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/CMakeLists.txt b/dev/CMakeLists.txt index 51a9c6d..61704c9 100644 --- a/dev/CMakeLists.txt +++ b/dev/CMakeLists.txt @@ -46,7 +46,7 @@ endif() add_custom_target(CopyHeader BYPRODUCTS ${REPO_ROOT_DIR}/olcPixelGameEngine3.h - COMMAND ${CMAKE_COMMAND} -E copy_if_newer ${CMAKE_BINARY_DIR}/olcPixelGameEngine3.h ${REPO_ROOT_DIR}/olcPixelGameEngine3.h + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/olcPixelGameEngine3.h ${REPO_ROOT_DIR}/olcPixelGameEngine3.h DEPENDS olcPixelGameEngine3.h ) From ad2610fc08190c8752601a0ad712d159b019dfab Mon Sep 17 00:00:00 2001 From: dandistine <34634876+dandistine@users.noreply.github.com> Date: Sun, 20 Sep 2026 12:45:12 -0500 Subject: [PATCH 3/4] Allow the x11 event queue to block if no events are present, saving cpu time. --- dev/src/host_lin_x11.cpp | 7 +++++++ dev/src/host_lin_x11.h | 1 + olcPixelGameEngine3.h | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/dev/src/host_lin_x11.cpp b/dev/src/host_lin_x11.cpp index cb6866c..750f669 100644 --- a/dev/src/host_lin_x11.cpp +++ b/dev/src/host_lin_x11.cpp @@ -131,6 +131,10 @@ namespace olc::host return nullptr; }; + // Create a pollfd that we will use later to wait for events to appear on the queue + // preventing the event loop from becoming a busy loop + pollfd x11_connection_fd {.fd = ConnectionNumber(olc_Display), .events = POLLIN}; + X11::XEvent xev; while(systemActive){ while (XPending(olc_Display)) @@ -297,6 +301,9 @@ namespace olc::host } } } + + // Wait until an event appears on the x11 event queue file descriptor + poll(&x11_connection_fd, 1, -1); } systemActive = false; diff --git a/dev/src/host_lin_x11.h b/dev/src/host_lin_x11.h index 832f268..f5604bd 100644 --- a/dev/src/host_lin_x11.h +++ b/dev/src/host_lin_x11.h @@ -16,6 +16,7 @@ //! START DECLARATION #include +#include namespace X11 { #include diff --git a/olcPixelGameEngine3.h b/olcPixelGameEngine3.h index 2b919d7..f1bb19f 100644 --- a/olcPixelGameEngine3.h +++ b/olcPixelGameEngine3.h @@ -5965,6 +5965,7 @@ namespace olc #if OLC_HOST == OLC_HOST_LINUX_X11 #include +#include namespace X11 { #include @@ -12365,6 +12366,10 @@ namespace olc::host return nullptr; }; + // Create a pollfd that we will use later to wait for events to appear on the queue + // preventing the event loop from becoming a busy loop + pollfd x11_connection_fd {.fd = ConnectionNumber(olc_Display), .events = POLLIN}; + X11::XEvent xev; while(systemActive){ while (XPending(olc_Display)) @@ -12531,6 +12536,9 @@ namespace olc::host } } } + + // Wait until an event appears on the x11 event queue file descriptor + poll(&x11_connection_fd, 1, -1); } systemActive = false; From 5bcf847db355fb080e74dd20db86e3b431f58f16 Mon Sep 17 00:00:00 2001 From: dandistine <34634876+dandistine@users.noreply.github.com> Date: Sun, 20 Sep 2026 13:25:57 -0500 Subject: [PATCH 4/4] Apply the polling change to wayland too. --- dev/src/host_lin_wayland.cpp | 11 ++++++++--- dev/src/host_lin_wayland.h | 1 + olcPixelGameEngine3.h | 12 +++++++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/dev/src/host_lin_wayland.cpp b/dev/src/host_lin_wayland.cpp index 831cef3..84300f0 100644 --- a/dev/src/host_lin_wayland.cpp +++ b/dev/src/host_lin_wayland.cpp @@ -219,7 +219,7 @@ namespace olc::host { pPrimaryPGE->OnPreContextStart(); - // Create system thread - handles gpu context + // Create system thread - handles gpu context std::thread threadSystem([this]() { // Notify start of system thread @@ -247,11 +247,16 @@ namespace olc::host } }); + pollfd decor_wl_fd {.fd = libdecor_get_fd(decor_context), .events = POLLIN}; + bool keep_running = true; while(systemActive && keep_running) { if(decor_context) { - std::lock_guard l{decor_mutex}; - keep_running = libdecor_dispatch(decor_context, 0) >= 0; + poll(&decor_wl_fd, 1, -1); + { + std::lock_guard l{decor_mutex}; + keep_running = libdecor_dispatch(decor_context, 0) >= 0; + } } } diff --git a/dev/src/host_lin_wayland.h b/dev/src/host_lin_wayland.h index acbd1ea..d5f4100 100644 --- a/dev/src/host_lin_wayland.h +++ b/dev/src/host_lin_wayland.h @@ -29,6 +29,7 @@ #include #include #include +#include #include "libdecor.h" diff --git a/olcPixelGameEngine3.h b/olcPixelGameEngine3.h index f1bb19f..84de689 100644 --- a/olcPixelGameEngine3.h +++ b/olcPixelGameEngine3.h @@ -6058,6 +6058,7 @@ namespace olc::host #include #include #include +#include #include "libdecor.h" @@ -13103,7 +13104,7 @@ namespace olc::host { pPrimaryPGE->OnPreContextStart(); - // Create system thread - handles gpu context + // Create system thread - handles gpu context std::thread threadSystem([this]() { // Notify start of system thread @@ -13131,11 +13132,16 @@ namespace olc::host } }); + pollfd decor_wl_fd {.fd = libdecor_get_fd(decor_context), .events = POLLIN}; + bool keep_running = true; while(systemActive && keep_running) { if(decor_context) { - std::lock_guard l{decor_mutex}; - keep_running = libdecor_dispatch(decor_context, 0) >= 0; + poll(&decor_wl_fd, 1, -1); + { + std::lock_guard l{decor_mutex}; + keep_running = libdecor_dispatch(decor_context, 0) >= 0; + } } }