summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibDesktop/Screensaver.h
blob: 0cebf0082f31a0df4efc507348d8fe19f3a9fe8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * 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 <AK/Time.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;

protected:
    Screensaver()
        : m_start_time(AK::Time::now_monotonic())
    {
    }

private:
    void trigger_exit();

    Optional<Gfx::IntPoint> m_mouse_origin;
    AK::Time m_start_time;
};

}