diff --git a/userspace/libraries/LibGUI/Window.cpp b/userspace/libraries/LibGUI/Window.cpp index 0af4cf5b..064c02b6 100644 --- a/userspace/libraries/LibGUI/Window.cpp +++ b/userspace/libraries/LibGUI/Window.cpp @@ -287,6 +287,15 @@ namespace LibGUI return on_socket_error(__FUNCTION__); } + void Window::set_title(BAN::StringView title) + { + WindowPacket::WindowSetTitle packet; + MUST(packet.title.append(title)); + + if (auto ret = packet.send_serialized(m_server_fd); ret.is_error()) + return on_socket_error(__FUNCTION__); + } + void Window::set_position(int32_t x, int32_t y) { WindowPacket::WindowSetPosition packet; diff --git a/userspace/libraries/LibGUI/include/LibGUI/Packet.h b/userspace/libraries/LibGUI/include/LibGUI/Packet.h index f4b1f711..9df9409f 100644 --- a/userspace/libraries/LibGUI/include/LibGUI/Packet.h +++ b/userspace/libraries/LibGUI/include/LibGUI/Packet.h @@ -165,6 +165,7 @@ namespace LibGUI WindowSetMouseCapture, WindowSetSize, WindowSetFullscreen, + WindowSetTitle, DestroyWindowEvent, CloseWindowEvent, @@ -230,6 +231,11 @@ namespace LibGUI bool, fullscreen ); + DEFINE_PACKET( + WindowSetTitle, + BAN::String, title + ); + } namespace EventPacket diff --git a/userspace/libraries/LibGUI/include/LibGUI/Window.h b/userspace/libraries/LibGUI/include/LibGUI/Window.h index e84c683e..e24a1047 100644 --- a/userspace/libraries/LibGUI/include/LibGUI/Window.h +++ b/userspace/libraries/LibGUI/include/LibGUI/Window.h @@ -68,6 +68,7 @@ namespace LibGUI void set_mouse_capture(bool captured); void set_fullscreen(bool fullscreen); + void set_title(BAN::StringView title); void set_position(int32_t x, int32_t y); diff --git a/userspace/programs/WindowServer/Window.h b/userspace/programs/WindowServer/Window.h index 2313173c..ba30ec62 100644 --- a/userspace/programs/WindowServer/Window.h +++ b/userspace/programs/WindowServer/Window.h @@ -52,6 +52,8 @@ public: LibGUI::Window::Attributes get_attributes() const { return m_attributes; }; void set_attributes(LibGUI::Window::Attributes attributes) { m_attributes = attributes; }; + BAN::ErrorOr set_title(BAN::StringView title) { m_title.clear(); TRY(m_title.append(title)); TRY(prepare_title_bar()); return {}; } + const uint32_t* framebuffer() const { return m_fb_addr; } uint32_t title_bar_pixel(int32_t abs_x, int32_t abs_y, Position cursor) const diff --git a/userspace/programs/WindowServer/WindowServer.cpp b/userspace/programs/WindowServer/WindowServer.cpp index 19f9d269..cb703231 100644 --- a/userspace/programs/WindowServer/WindowServer.cpp +++ b/userspace/programs/WindowServer/WindowServer.cpp @@ -307,7 +307,7 @@ void WindowServer::on_window_set_fullscreen(int fd, const LibGUI::WindowPacket:: if (!target_window) { - dwarnln("client tried to set window size while not owning a window"); + dwarnln("client tried to set window fullscreen while not owning a window"); return; } @@ -316,6 +316,32 @@ void WindowServer::on_window_set_fullscreen(int fd, const LibGUI::WindowPacket:: invalidate(m_framebuffer.area()); } +void WindowServer::on_window_set_title(int fd, const LibGUI::WindowPacket::WindowSetTitle& packet) +{ + BAN::RefPtr target_window; + for (auto& window : m_client_windows) + { + if (window->client_fd() != fd) + continue; + target_window = window; + break; + } + + if (!target_window) + { + dwarnln("client tried to set window title while not owning a window"); + return; + } + + if (auto ret = target_window->set_title(packet.title); ret.is_error()) + { + dwarnln("failed to set window title: {}", ret.error()); + return; + } + + invalidate(target_window->title_bar_area()); +} + void WindowServer::on_key_event(LibInput::KeyEvent event) { // Mod key is not passed to clients diff --git a/userspace/programs/WindowServer/WindowServer.h b/userspace/programs/WindowServer/WindowServer.h index c768c289..12242237 100644 --- a/userspace/programs/WindowServer/WindowServer.h +++ b/userspace/programs/WindowServer/WindowServer.h @@ -38,6 +38,7 @@ public: void on_window_set_mouse_capture(int fd, const LibGUI::WindowPacket::WindowSetMouseCapture&); void on_window_set_size(int fd, const LibGUI::WindowPacket::WindowSetSize&); void on_window_set_fullscreen(int fd, const LibGUI::WindowPacket::WindowSetFullscreen&); + void on_window_set_title(int fd, const LibGUI::WindowPacket::WindowSetTitle&); void on_key_event(LibInput::KeyEvent event); void on_mouse_button(LibInput::MouseButtonEvent event); diff --git a/userspace/programs/WindowServer/main.cpp b/userspace/programs/WindowServer/main.cpp index 7fc8736f..2d3546ce 100644 --- a/userspace/programs/WindowServer/main.cpp +++ b/userspace/programs/WindowServer/main.cpp @@ -379,6 +379,10 @@ int main() if (auto ret = LibGUI::WindowPacket::WindowSetFullscreen::deserialize(client_data.packet_buffer.span()); !ret.is_error()) window_server.on_window_set_fullscreen(fd, ret.release_value()); break; + case LibGUI::PacketType::WindowSetTitle: + if (auto ret = LibGUI::WindowPacket::WindowSetTitle::deserialize(client_data.packet_buffer.span()); !ret.is_error()) + window_server.on_window_set_title(fd, ret.release_value()); + break; default: dprintln("unhandled packet type: {}", *reinterpret_cast(client_data.packet_buffer.data())); }