1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:57:45 +00:00

Demos+LibDesktop: Centralize screensaver logic

We have 3 demos with pretty similar window logic and quitting behavior
on user activity, so centralize that into `Desktop::Screensaver`.
This commit is contained in:
Jelle Raaijmakers 2022-12-27 00:40:39 +01:00 committed by Andreas Kling
parent 379e4a2432
commit 18b6bdb563
11 changed files with 108 additions and 99 deletions

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Error.h>
#include <AK/Function.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <LibGUI/Widget.h>
#include <LibGUI/Window.h>
#include <LibGfx/Point.h>
namespace Desktop {
class Screensaver : public GUI::Widget {
C_OBJECT_ABSTRACT(Screensaver)
public:
Function<void()> on_screensaver_exit;
static ErrorOr<NonnullRefPtr<GUI::Window>> create_window(StringView title, StringView icon);
virtual void keydown_event(GUI::KeyEvent&) override;
virtual void mousedown_event(GUI::MouseEvent& event) override;
virtual void mousemove_event(GUI::MouseEvent& event) override;
private:
void trigger_exit();
Optional<Gfx::IntPoint> m_mouse_origin;
};
}