From 492464f4c1d3f90ff1a31f0a0c133091748603c2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 1 May 2021 18:21:34 +0200 Subject: [PATCH] WindowServer: Add Window "modified" state This will be used to track which windows contain some kind of unsaved data that the user may want some help remembering to save. :^) --- .../WindowServer/ClientConnection.cpp | 22 +++++++++++++++++++ .../Services/WindowServer/ClientConnection.h | 4 +++- Userland/Services/WindowServer/Window.cpp | 9 ++++++++ Userland/Services/WindowServer/Window.h | 4 ++++ .../Services/WindowServer/WindowServer.ipc | 3 +++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Userland/Services/WindowServer/ClientConnection.cpp b/Userland/Services/WindowServer/ClientConnection.cpp index 5c980af88a..fdd530bd34 100644 --- a/Userland/Services/WindowServer/ClientConnection.cpp +++ b/Userland/Services/WindowServer/ClientConnection.cpp @@ -903,4 +903,26 @@ OwnPtr ClientConnection::handle return make(bitmap.to_shareable_bitmap()); } +OwnPtr ClientConnection::handle(Messages::WindowServer::IsWindowModified const& message) +{ + auto it = m_windows.find(message.window_id()); + if (it == m_windows.end()) { + did_misbehave("IsWindowModified: Bad window ID"); + return {}; + } + auto& window = *it->value; + return make(window.is_modified()); +} + +void ClientConnection::handle(Messages::WindowServer::SetWindowModified const& message) +{ + auto it = m_windows.find(message.window_id()); + if (it == m_windows.end()) { + did_misbehave("SetWindowModified: Bad window ID"); + return; + } + auto& window = *it->value; + window.set_modified(message.modified()); +} + } diff --git a/Userland/Services/WindowServer/ClientConnection.h b/Userland/Services/WindowServer/ClientConnection.h index 0116fe32ea..b4f17cb431 100644 --- a/Userland/Services/WindowServer/ClientConnection.h +++ b/Userland/Services/WindowServer/ClientConnection.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -146,6 +146,8 @@ private: virtual OwnPtr handle(const Messages::WindowServer::GetScreenBitmap&) override; virtual OwnPtr handle(const Messages::WindowServer::SetDoubleClickSpeed&) override; virtual OwnPtr handle(const Messages::WindowServer::GetDoubleClickSpeed&) override; + virtual void handle(Messages::WindowServer::SetWindowModified const&) override; + virtual OwnPtr handle(Messages::WindowServer::IsWindowModified const&) override; Window* window_from_id(i32 window_id); diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index 41e6939501..07d99c9fc4 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -992,4 +992,13 @@ void Window::invalidate_menubar() frame().invalidate(); } +void Window::set_modified(bool modified) +{ + if (m_modified == modified) + return; + + m_modified = modified; + invalidate(); +} + } diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h index 4d44fe290b..13fee234d2 100644 --- a/Userland/Services/WindowServer/Window.h +++ b/Userland/Services/WindowServer/Window.h @@ -76,6 +76,9 @@ public: Window(Core::Object&, WindowType); virtual ~Window() override; + bool is_modified() const { return m_modified; } + void set_modified(bool); + void popup_window_menu(const Gfx::IntPoint&, WindowMenuDefaultAction); void handle_window_menu_action(WindowMenuAction); void window_menu_activate_default(); @@ -397,6 +400,7 @@ private: int m_minimize_animation_step { -1 }; int m_progress { -1 }; bool m_should_show_menubar { true }; + bool m_modified { false }; }; } diff --git a/Userland/Services/WindowServer/WindowServer.ipc b/Userland/Services/WindowServer/WindowServer.ipc index 948e6c7bce..3aef59ca30 100644 --- a/Userland/Services/WindowServer/WindowServer.ipc +++ b/Userland/Services/WindowServer/WindowServer.ipc @@ -56,6 +56,9 @@ endpoint WindowServer SetWindowProgress(i32 window_id, i32 progress) =| + SetWindowModified(i32 window_id, bool modified) =| + IsWindowModified(i32 window_id) => (bool modified) + SetWindowRect(i32 window_id, Gfx::IntRect rect) => (Gfx::IntRect rect) GetWindowRect(i32 window_id) => (Gfx::IntRect rect)