Screensaver.h 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Error.h>
  8. #include <AK/Function.h>
  9. #include <AK/NonnullRefPtr.h>
  10. #include <AK/Optional.h>
  11. #include <AK/Time.h>
  12. #include <LibGUI/Widget.h>
  13. #include <LibGUI/Window.h>
  14. #include <LibGfx/Point.h>
  15. namespace Desktop {
  16. class Screensaver : public GUI::Widget {
  17. C_OBJECT_ABSTRACT(Screensaver)
  18. public:
  19. Function<void()> on_screensaver_exit;
  20. static ErrorOr<NonnullRefPtr<GUI::Window>> create_window(StringView title, StringView icon);
  21. virtual void keydown_event(GUI::KeyEvent&) override;
  22. virtual void mousedown_event(GUI::MouseEvent& event) override;
  23. virtual void mousemove_event(GUI::MouseEvent& event) override;
  24. protected:
  25. Screensaver()
  26. : m_start_time(MonotonicTime::now())
  27. {
  28. }
  29. private:
  30. void trigger_exit();
  31. Optional<Gfx::IntPoint> m_mouse_origin;
  32. MonotonicTime m_start_time;
  33. };
  34. }