// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once #include #include #include #include #include "common/common_types.h" #include "core/hle/service/am/am_types.h" namespace Core { class System; } namespace Service::AM { struct Applet; class EventObserver; enum class ButtonPressDuration { ShortPressing, MiddlePressing, LongPressing, }; class WindowSystem { public: explicit WindowSystem(Core::System& system); ~WindowSystem(); public: void SetEventObserver(EventObserver* event_observer); void Update(); void RequestUpdate(); public: void TrackApplet(std::shared_ptr applet, bool is_application); std::shared_ptr GetByAppletResourceUserId(u64 aruid); std::shared_ptr GetMainApplet(); std::shared_ptr GetOverlayDisplayApplet(); public: void RequestHomeMenuToGetForeground(); void RequestApplicationToGetForeground(); void RequestLockHomeMenuIntoForeground(); void RequestUnlockHomeMenuIntoForeground(); void RequestAppletVisibilityState(Applet& applet, bool visible); public: void OnOperationModeChanged(); void OnExitRequested(); void OnHomeButtonPressed(ButtonPressDuration type); void OnSystemButtonPress(SystemButtonType type); void OnCaptureButtonPressed(ButtonPressDuration type) {} void OnPowerButtonPressed(ButtonPressDuration type) {} private: void UpdateCurrentApplicationLocked(); void NotifyApplicationChangedIfNeeded(); void PruneTerminatedAppletsLocked(); bool RestartAppletProcessLocked(Applet* applet); bool LockHomeMenuIntoForegroundLocked(); void TerminateChildAppletsLocked(Applet* applet); bool IsOverlayOpenLocked(const Applet& overlay) const; bool DoesOverlayTakeInputLocked() const; void UpdateAppletStateLocked(Applet* applet, bool is_foreground, bool overlay_takes_input); void SendButtonAppletMessageLocked(AppletMessage message); private: // System reference. Core::System& m_system; // Event observer. EventObserver* m_event_observer{}; // Lock. std::mutex m_lock{}; // Home menu state. bool m_home_menu_foreground_locked{}; Applet* m_foreground_requested_applet{}; // Foreground roots. Applet* m_home_menu{}; Applet* m_application{}; Applet* m_overlay_display{}; // Applet map by aruid. std::map> m_applets{}; std::optional m_pending_application_notification{}; }; } // namespace Service::AM