From 73d41d4774ad77e0d10024f4d1a67dbfe64159b0 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Sun, 15 Nov 2020 09:08:56 +0100 Subject: [PATCH] adapted to new app run loop --- main.cpp | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/main.cpp b/main.cpp index 50ff00e..f2a6c48 100644 --- a/main.cpp +++ b/main.cpp @@ -33,8 +33,6 @@ const int HEIGHT {900}; sc::gui::Window* main_window {nullptr}; sc::gui::Image* main_image {nullptr}; ScreensaverPlugin* main_saver {nullptr}; -bool expired {true}; -bool should_run {true}; void print_help() { std::cout << "usage: screensaver [-h|-l|--version]\n"; @@ -53,24 +51,11 @@ void list_plugins() { } } -void update_frame() { - while (should_run) { - expired = true; - - struct timespec delay; - delay.tv_sec = 0; - delay.tv_nsec = static_cast(round(1000000000.0 / main_saver->fps())); - nanosleep(&delay, nullptr); - } -} - void draw() { - if (expired) { - expired = false; - sc::gui::ImageLock lock {*main_image}; - main_saver->draw_frame(); - main_window->show_image(*main_image); - } + sc::gui::ImageLock lock {*main_image}; + main_saver->draw_frame(); + main_window->dirty(true); + main_window->show_image(*main_image); } int main(int argc, const char * argv[]) { @@ -154,15 +139,10 @@ int main(int argc, const char * argv[]) { main_saver = saver.get(); main_saver->setup(cr, {0, 0, WIDTH, HEIGHT}); - // setup thread which periodically sets 'expired' - std::thread frame_timer {update_frame}; - + sc::gui::app().fps(main_saver->fps()); sc::gui::app().add_run_loop_action(draw); sc::gui::app().run(); - should_run = false; - frame_timer.join(); - } catch (const std::exception& ex) { std::cerr << "screensaver: " << ex.what() << '\n'; return EXIT_FAILURE;