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. :^)
This commit is contained in:
Andreas Kling 2021-05-01 18:21:34 +02:00
parent 5c385d06e8
commit 492464f4c1
Notes: sideshowbarker 2024-07-18 18:48:56 +09:00
5 changed files with 41 additions and 1 deletions

View file

@ -903,4 +903,26 @@ OwnPtr<Messages::WindowServer::GetScreenBitmapResponse> ClientConnection::handle
return make<Messages::WindowServer::GetScreenBitmapResponse>(bitmap.to_shareable_bitmap());
}
OwnPtr<Messages::WindowServer::IsWindowModifiedResponse> 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<Messages::WindowServer::IsWindowModifiedResponse>(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());
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -146,6 +146,8 @@ private:
virtual OwnPtr<Messages::WindowServer::GetScreenBitmapResponse> handle(const Messages::WindowServer::GetScreenBitmap&) override;
virtual OwnPtr<Messages::WindowServer::SetDoubleClickSpeedResponse> handle(const Messages::WindowServer::SetDoubleClickSpeed&) override;
virtual OwnPtr<Messages::WindowServer::GetDoubleClickSpeedResponse> handle(const Messages::WindowServer::GetDoubleClickSpeed&) override;
virtual void handle(Messages::WindowServer::SetWindowModified const&) override;
virtual OwnPtr<Messages::WindowServer::IsWindowModifiedResponse> handle(Messages::WindowServer::IsWindowModified const&) override;
Window* window_from_id(i32 window_id);

View file

@ -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();
}
}

View file

@ -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 };
};
}

View file

@ -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)