1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:17:46 +00:00

LibDesktop: Do not quit screensaver on immediate mouse move

Let's delay this way of quitting the screensavers by 750ms. :^)
This commit is contained in:
Jelle Raaijmakers 2022-12-27 00:50:57 +01:00 committed by Andreas Kling
parent 18b6bdb563
commit 7d5839f793
2 changed files with 13 additions and 0 deletions

View file

@ -10,6 +10,7 @@
namespace Desktop {
static constexpr int mouse_max_distance_move = 10;
static constexpr int mouse_tracking_delay_milliseconds = 750;
ErrorOr<NonnullRefPtr<GUI::Window>> Screensaver::create_window(StringView title, StringView icon)
{
@ -39,6 +40,10 @@ void Screensaver::mousedown_event(GUI::MouseEvent&)
void Screensaver::mousemove_event(GUI::MouseEvent& event)
{
auto now = AK::Time::now_monotonic();
if ((now - m_start_time).to_milliseconds() < mouse_tracking_delay_milliseconds)
return;
if (!m_mouse_origin.has_value())
m_mouse_origin = event.position();
else if (event.position().distance_from(m_mouse_origin.value()) > mouse_max_distance_move)

View file

@ -10,6 +10,7 @@
#include <AK/Function.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <AK/Time.h>
#include <LibGUI/Widget.h>
#include <LibGUI/Window.h>
#include <LibGfx/Point.h>
@ -27,10 +28,17 @@ public:
virtual void mousedown_event(GUI::MouseEvent& event) override;
virtual void mousemove_event(GUI::MouseEvent& event) override;
protected:
Screensaver()
: m_start_time(AK::Time::now_monotonic())
{
}
private:
void trigger_exit();
Optional<Gfx::IntPoint> m_mouse_origin;
AK::Time m_start_time;
};
}