diff --git a/Base/res/icons/16x16/catdog-sleeping.png b/Base/res/icons/16x16/catdog-sleeping.png new file mode 100644 index 00000000000..60f845ea908 Binary files /dev/null and b/Base/res/icons/16x16/catdog-sleeping.png differ diff --git a/Base/res/icons/16x16/catdog-wake-up.png b/Base/res/icons/16x16/catdog-wake-up.png new file mode 100644 index 00000000000..3530fe6214f Binary files /dev/null and b/Base/res/icons/16x16/catdog-wake-up.png differ diff --git a/Userland/Demos/CatDog/CatDog.cpp b/Userland/Demos/CatDog/CatDog.cpp index fd34b224dd2..d23cce501f8 100644 --- a/Userland/Demos/CatDog/CatDog.cpp +++ b/Userland/Demos/CatDog/CatDog.cpp @@ -8,6 +8,7 @@ #include "CatDog.h" #include #include +#include #include #include @@ -67,6 +68,12 @@ void CatDog::set_roaming(bool roaming) update(); } +void CatDog::set_sleeping(bool sleeping) +{ + m_state = (sleeping ? State::Sleeping : State::Idle) | special_application_states(); + update(); +} + CatDog::State CatDog::special_application_states() const { auto maybe_proc_info = Core::ProcessStatisticsReader::get_all(*m_proc_all); @@ -99,6 +106,11 @@ bool CatDog::is_inspector() const return has_flag(special_application_states(), State::Inspector); } +bool CatDog::is_sleeping() const +{ + return has_flag(m_state, State::Sleeping); +} + void CatDog::timer_event(Core::TimerEvent&) { using namespace AK::TimeLiterals; @@ -106,6 +118,9 @@ void CatDog::timer_event(Core::TimerEvent&) if (has_flag(m_state, State::Alert)) return; + if (has_flag(m_state, State::Sleeping)) + return; + m_state = special_application_states(); auto const size = window()->size(); @@ -164,6 +179,9 @@ void CatDog::track_mouse_move(Gfx::IntPoint point) if (has_flag(m_state, State::Alert)) return; + if (has_flag(m_state, State::Sleeping)) + return; + Gfx::IntPoint relative_offset = point - window()->position(); if (m_mouse_offset != relative_offset) { m_mouse_offset = relative_offset; diff --git a/Userland/Demos/CatDog/CatDog.h b/Userland/Demos/CatDog/CatDog.h index b7e878aca01..9b45317a270 100644 --- a/Userland/Demos/CatDog/CatDog.h +++ b/Userland/Demos/CatDog/CatDog.h @@ -35,9 +35,11 @@ public: Function on_context_menu_request; void set_roaming(bool roaming); + void set_sleeping(bool sleeping); [[nodiscard]] bool is_artist() const; [[nodiscard]] bool is_inspector() const; + [[nodiscard]] bool is_sleeping() const; private: enum class State : u16 { diff --git a/Userland/Demos/CatDog/main.cpp b/Userland/Demos/CatDog/main.cpp index 408df755d14..8f32622d213 100644 --- a/Userland/Demos/CatDog/main.cpp +++ b/Userland/Demos/CatDog/main.cpp @@ -24,6 +24,9 @@ ErrorOr serenity_main(Main::Arguments arguments) auto app = TRY(GUI::Application::create(arguments)); auto app_icon = TRY(GUI::Icon::try_create_default_icon("app-catdog"sv)); + auto catdog_icon_sleep = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/catdog-sleeping.png"sv)); + auto catdog_icon_wake = TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/catdog-wake-up.png"sv)); + TRY(Core::System::pledge("stdio recvfd sendfd rpath")); TRY(Core::System::unveil("/res", "r")); TRY(Core::System::unveil("/sys/kernel/processes", "r")); @@ -46,6 +49,12 @@ ErrorOr serenity_main(Main::Arguments arguments) auto context_menu = GUI::Menu::construct(); context_menu->add_action(GUI::CommonActions::make_about_action("CatDog Demo"_string, app_icon, window)); + context_menu->add_action(GUI::Action::create("Put CatDog to sleep...", catdog_icon_sleep, [&](GUI::Action& action) { + catdog_widget->set_sleeping(!catdog_widget->is_sleeping()); + + action.set_text(catdog_widget->is_sleeping() ? "Wake CatDog..." : "Put CatDog to sleep..."); + action.set_icon(catdog_widget->is_sleeping() ? catdog_icon_wake : catdog_icon_sleep); + })); context_menu->add_separator(); context_menu->add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));