adapted to new app run loop

This commit is contained in:
Bob Polis 2020-11-15 09:08:56 +01:00
parent 1838a9d6cf
commit 73d41d4774

View File

@ -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<int>(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;