window.hpp 916 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _UI_WINDOW_H_
  2. #define _UI_WINDOW_H_
  3. #include <mutex>
  4. #include <gtkmm.h>
  5. namespace ui
  6. {
  7. class Window: public Gtk::Window
  8. {
  9. std::mutex visible_mutex;
  10. bool visible = false;
  11. bool shown = false;
  12. public:
  13. void dismiss()
  14. {
  15. std::lock_guard<std::mutex> guard(visible_mutex);
  16. visible = false;
  17. hide();
  18. }
  19. void summon()
  20. {
  21. std::lock_guard<std::mutex> guard(visible_mutex);
  22. visible = true;
  23. if(!shown) {
  24. shown = true;
  25. show();
  26. }
  27. present();
  28. }
  29. void toggle()
  30. {
  31. std::lock_guard<std::mutex> guard(visible_mutex);
  32. if(visible) {
  33. visible = false;
  34. hide();
  35. } else {
  36. visible = true;
  37. if(!shown) {
  38. shown = true;
  39. show();
  40. }
  41. present();
  42. }
  43. }
  44. };
  45. }
  46. #endif