initializer.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef SIMPLE_GRAPHICAL_INITIALIZER_H
  2. #define SIMPLE_GRAPHICAL_INITIALIZER_H
  3. #include "simple/sdlcore/initializer.h"
  4. #include "display.h"
  5. namespace simple::graphical
  6. {
  7. // in general we want this class to not exist and library initialization to be unnecessary
  8. class initializer : private sdlcore::initializer
  9. {
  10. private:
  11. class screensaver_control
  12. {
  13. public:
  14. screensaver_control() noexcept;
  15. ~screensaver_control() noexcept;
  16. void keep_alive() noexcept;
  17. void release_one() noexcept;
  18. void release_all() noexcept;
  19. [[nodiscard]] bool kept_alive() const noexcept;
  20. [[nodiscard]] static bool global_kept_alive() noexcept;
  21. private:
  22. int keep_alive_count;
  23. // TODO: make the global state atomic maybe?
  24. static int global_keep_alive_count;
  25. };
  26. public:
  27. initializer();
  28. // the main reason this is here is to change SDL's default by enabling screensaver in the constructor, which SDL just disables, cause idk, it's a game?
  29. // in contrast to doing it in initializer constructor without the global state, it's impervious to library reinitialization, goes with our theme of pretending that it doesn't exist
  30. // TODO: all the counting stuff is a bit dubious though, it's a generic thing akin to reference counting, so doesn't feel right to bake it into this API
  31. screensaver_control screensaver;
  32. // TODO: no point in this being member though
  33. display_list displays() const noexcept;
  34. };
  35. } // namespace simple::graphical
  36. #endif /* end of include guard */