diff --git a/userspace/libraries/LibGUI/Window.cpp b/userspace/libraries/LibGUI/Window.cpp index 3277a5d1c5..687753d4f9 100644 --- a/userspace/libraries/LibGUI/Window.cpp +++ b/userspace/libraries/LibGUI/Window.cpp @@ -62,7 +62,7 @@ namespace LibGUI cleanup(); } - BAN::ErrorOr> Window::create(uint32_t width, uint32_t height, BAN::StringView title) + BAN::ErrorOr> Window::create(uint32_t width, uint32_t height, BAN::StringView title, Attributes attributes) { int server_fd = socket(AF_UNIX, SOCK_STREAM, 0); if (server_fd == -1) @@ -101,7 +101,7 @@ namespace LibGUI TRY(create_packet.title.append(title)); TRY(create_packet.send_serialized(server_fd)); - auto window = TRY(BAN::UniqPtr::create(server_fd)); + auto window = TRY(BAN::UniqPtr::create(server_fd, attributes)); bool resized = false; window->set_resize_window_event_callback([&]() { resized = true; }); diff --git a/userspace/libraries/LibGUI/include/LibGUI/Packet.h b/userspace/libraries/LibGUI/include/LibGUI/Packet.h index f8290cf779..f4b1f7114e 100644 --- a/userspace/libraries/LibGUI/include/LibGUI/Packet.h +++ b/userspace/libraries/LibGUI/include/LibGUI/Packet.h @@ -178,10 +178,20 @@ namespace LibGUI namespace WindowPacket { + struct Attributes + { + bool title_bar; + bool movable; + bool focusable; + bool rounded_corners; + bool alpha_channel; + }; + DEFINE_PACKET( WindowCreate, uint32_t, width, uint32_t, height, + Attributes, attributes, BAN::String, title ); @@ -199,15 +209,8 @@ namespace LibGUI int32_t, y ); - DEFINE_PACKET_EXTRA( + DEFINE_PACKET( WindowSetAttributes, - struct Attributes { - bool title_bar; - bool movable; - bool focusable; - bool rounded_corners; - bool alpha_channel; - }, Attributes, attributes ); diff --git a/userspace/libraries/LibGUI/include/LibGUI/Window.h b/userspace/libraries/LibGUI/include/LibGUI/Window.h index e8f40d10c3..e27bd0a61d 100644 --- a/userspace/libraries/LibGUI/include/LibGUI/Window.h +++ b/userspace/libraries/LibGUI/include/LibGUI/Window.h @@ -14,7 +14,7 @@ namespace LibGUI class Window { public: - using Attributes = WindowPacket::WindowSetAttributes::Attributes; + using Attributes = WindowPacket::Attributes; static constexpr Attributes default_attributes = { .title_bar = true, @@ -27,7 +27,7 @@ namespace LibGUI public: ~Window(); - static BAN::ErrorOr> create(uint32_t width, uint32_t height, BAN::StringView title); + static BAN::ErrorOr> create(uint32_t width, uint32_t height, BAN::StringView title, Attributes attributes = default_attributes); void set_pixel(uint32_t x, uint32_t y, uint32_t color) { @@ -87,8 +87,9 @@ namespace LibGUI int server_fd() const { return m_server_fd; } private: - Window(int server_fd) + Window(int server_fd, Attributes attributes) : m_server_fd(server_fd) + , m_attributes(attributes) { } bool clamp_to_framebuffer(int32_t& x, int32_t& y, uint32_t& width, uint32_t& height) const; diff --git a/userspace/programs/TaskBar/main.cpp b/userspace/programs/TaskBar/main.cpp index a286a404dd..3179ca44ab 100644 --- a/userspace/programs/TaskBar/main.cpp +++ b/userspace/programs/TaskBar/main.cpp @@ -22,15 +22,14 @@ int main() auto font = MUST(LibFont::Font::load("/usr/share/fonts/lat0-16.psfu"_sv)); - auto window = MUST(LibGUI::Window::create(0, font.height() + 2 * padding, "TaskBar")); - auto attributes = LibGUI::Window::default_attributes; attributes.title_bar = false; attributes.movable = false; attributes.focusable = false; attributes.alpha_channel = false; attributes.rounded_corners = false; - window->set_attributes(attributes); + + auto window = MUST(LibGUI::Window::create(0, font.height() + 2 * padding, "TaskBar", attributes)); window->set_close_window_event_callback([]() {}); diff --git a/userspace/programs/Terminal/Terminal.cpp b/userspace/programs/Terminal/Terminal.cpp index c87bf579c2..4d6aba2bad 100644 --- a/userspace/programs/Terminal/Terminal.cpp +++ b/userspace/programs/Terminal/Terminal.cpp @@ -110,12 +110,10 @@ void Terminal::run() m_bg_color = s_colors_dark[0]; m_fg_color = s_colors_bright[7]; - m_window = MUST(LibGUI::Window::create(600, 400, "Terminal"_sv)); - auto attributes = LibGUI::Window::default_attributes; attributes.alpha_channel = true; - m_window->set_attributes(attributes); + m_window = MUST(LibGUI::Window::create(600, 400, "Terminal"_sv, attributes)); m_window->fill(m_bg_color); m_window->invalidate(); diff --git a/userspace/programs/WindowServer/WindowServer.cpp b/userspace/programs/WindowServer/WindowServer.cpp index 341800486c..5f77fd6ac1 100644 --- a/userspace/programs/WindowServer/WindowServer.cpp +++ b/userspace/programs/WindowServer/WindowServer.cpp @@ -67,6 +67,7 @@ void WindowServer::on_window_create(int fd, const LibGUI::WindowPacket::WindowCr return; } + window->set_attributes(packet.attributes); window->set_position({ static_cast((m_framebuffer.width - window->client_width()) / 2), static_cast((m_framebuffer.height - window->client_height()) / 2),