diff options
author | Jelle Raaijmakers <jelle@gmta.nl> | 2021-04-28 01:06:38 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-04-28 09:37:37 +0200 |
commit | 4387a4864cab56782da56a7781bf7b475d076806 (patch) | |
tree | d96558149f0e1933b27fcd7fc8f94eb71a5779ec | |
parent | 906460e62ada28086f0971d01b7cd6ce5dbc11c4 (diff) | |
download | serenity-4387a4864cab56782da56a7781bf7b475d076806.zip |
Screensaver: Implement mouse hysteresis
Allow the mouse to move a bit before actually closing the app.
Fixes #6692
-rw-r--r-- | Userland/Demos/Screensaver/Screensaver.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Userland/Demos/Screensaver/Screensaver.cpp b/Userland/Demos/Screensaver/Screensaver.cpp index f1fe79a04e..b218a4fc76 100644 --- a/Userland/Demos/Screensaver/Screensaver.cpp +++ b/Userland/Demos/Screensaver/Screensaver.cpp @@ -23,6 +23,7 @@ public: private: Screensaver(int width = 64, int height = 48, int interval = 10000); RefPtr<Gfx::Bitmap> m_bitmap; + Gfx::IntPoint m_mouse_origin; void draw(); virtual void paint_event(GUI::PaintEvent&) override; @@ -45,9 +46,14 @@ Screensaver::~Screensaver() { } -void Screensaver::mousemove_event(GUI::MouseEvent&) +void Screensaver::mousemove_event(GUI::MouseEvent& event) { - ::exit(0); + constexpr float max_distance_move = 10; + if (m_mouse_origin.is_null()) { + m_mouse_origin = event.position(); + } else if (event.position().distance_from(m_mouse_origin) > max_distance_move) { + ::exit(0); + } } void Screensaver::mousedown_event(GUI::MouseEvent&) |