aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-10-27 15:07:24 +0100
committerdec05eba <dec05eba@protonmail.com>2024-10-27 15:07:24 +0100
commitcd89668d0c4fabeafe5b65223e58d652b6542519 (patch)
tree8a2c2b4bce44620db51e40218f90960af09ecd6e
parent3206458c8da8d950298558df54e90907a4cc539b (diff)
Reduce cpu usage when ui is not visible
-rw-r--r--include/Overlay.hpp3
-rw-r--r--src/Overlay.cpp10
-rw-r--r--src/main.cpp4
3 files changed, 11 insertions, 6 deletions
diff --git a/include/Overlay.hpp b/include/Overlay.hpp
index c580a12..218dee7 100644
--- a/include/Overlay.hpp
+++ b/include/Overlay.hpp
@@ -39,7 +39,8 @@ namespace gsr {
void handle_events();
void on_event(mgl::Event &event);
- void draw();
+ // Returns false if not visible
+ bool draw();
void show();
void hide();
diff --git a/src/Overlay.cpp b/src/Overlay.cpp
index ed5c3a7..f8148bf 100644
--- a/src/Overlay.cpp
+++ b/src/Overlay.cpp
@@ -279,20 +279,20 @@ namespace gsr {
process_key_bindings(event);
}
- void Overlay::draw() {
+ bool Overlay::draw() {
update_notification_process_status();
update_gsr_process_status();
if(!visible)
- return;
+ return false;
if(page_stack.empty()) {
hide();
- return;
+ return false;
}
if(!window)
- return;
+ return false;
window->clear();
@@ -312,6 +312,8 @@ namespace gsr {
page_stack.draw(*window, mgl::vec2f(0.0f, 0.0f));
window->display();
+
+ return true;
}
void Overlay::show() {
diff --git a/src/main.cpp b/src/main.cpp
index 3d367fa..0cc8076 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,6 +7,7 @@
#include <unistd.h>
#include <signal.h>
+#include <thread>
#include <X11/keysym.h>
#include <mglpp/mglpp.hpp>
@@ -160,7 +161,8 @@ int main(int argc, char **argv) {
global_hotkeys.poll_events();
overlay->handle_events();
- overlay->draw();
+ if(!overlay->draw())
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
fprintf(stderr, "info: shutting down!\n");