LibGUI: Cleanup packet creation

This commit is contained in:
2026-06-23 23:30:42 +03:00
parent 763a742f6d
commit 1287c8e335

View File

@@ -63,10 +63,12 @@ namespace LibGUI
auto window = TRY(BAN::UniqPtr<Window>::create(server_fd, epoll_fd, attributes)); auto window = TRY(BAN::UniqPtr<Window>::create(server_fd, epoll_fd, attributes));
WindowPacket::WindowCreate create_packet; WindowPacket::WindowCreate create_packet {
create_packet.width = width; .width = width,
create_packet.height = height; .height = height,
create_packet.attributes = attributes; .attributes = attributes,
.title = {},
};
TRY(create_packet.title.append(title)); TRY(create_packet.title.append(title));
window->send_packet(create_packet, __FUNCTION__); window->send_packet(create_packet, __FUNCTION__);
@@ -169,40 +171,46 @@ namespace LibGUI
); );
} }
WindowPacket::WindowInvalidate packet; const WindowPacket::WindowInvalidate packet {
packet.x = x; .x = static_cast<uint32_t>(x),
packet.y = y; .y = static_cast<uint32_t>(y),
packet.width = width; .width = width,
packet.height = height; .height = height,
};
send_packet(packet, __FUNCTION__); send_packet(packet, __FUNCTION__);
} }
void Window::set_mouse_relative(bool enabled) void Window::set_mouse_relative(bool enabled)
{ {
WindowPacket::WindowSetMouseRelative packet; const WindowPacket::WindowSetMouseRelative packet {
packet.enabled = enabled; .enabled = enabled,
};
send_packet(packet, __FUNCTION__); send_packet(packet, __FUNCTION__);
} }
void Window::set_fullscreen(bool fullscreen) void Window::set_fullscreen(bool fullscreen)
{ {
WindowPacket::WindowSetFullscreen packet; const WindowPacket::WindowSetFullscreen packet {
packet.fullscreen = fullscreen; .fullscreen = fullscreen,
};
send_packet(packet, __FUNCTION__); send_packet(packet, __FUNCTION__);
} }
void Window::set_title(BAN::StringView title) void Window::set_title(BAN::StringView title)
{ {
WindowPacket::WindowSetTitle packet; WindowPacket::WindowSetTitle packet {
.title = {},
};
MUST(packet.title.append(title)); MUST(packet.title.append(title));
send_packet(packet, __FUNCTION__); send_packet(packet, __FUNCTION__);
} }
void Window::set_position(int32_t x, int32_t y) void Window::set_position(int32_t x, int32_t y)
{ {
WindowPacket::WindowSetPosition packet; const WindowPacket::WindowSetPosition packet {
packet.x = x; .x = x,
packet.y = y; .y = y,
};
send_packet(packet, __FUNCTION__); send_packet(packet, __FUNCTION__);
} }
@@ -217,11 +225,14 @@ namespace LibGUI
void Window::set_cursor(uint32_t width, uint32_t height, BAN::Span<const uint32_t> pixels, int32_t origin_x, int32_t origin_y) void Window::set_cursor(uint32_t width, uint32_t height, BAN::Span<const uint32_t> pixels, int32_t origin_x, int32_t origin_y)
{ {
WindowPacket::WindowSetCursor packet; // TODO: no need to copy here
packet.width = width; WindowPacket::WindowSetCursor packet {
packet.height = height; .width = width,
packet.origin_x = origin_x; .height = height,
packet.origin_y = origin_y; .origin_x = origin_x,
.origin_y = origin_y,
.pixels = {},
};
MUST(packet.pixels.resize(pixels.size())); MUST(packet.pixels.resize(pixels.size()));
for (size_t i = 0; i < packet.pixels.size(); i++) for (size_t i = 0; i < packet.pixels.size(); i++)
packet.pixels[i] = pixels[i]; packet.pixels[i] = pixels[i];
@@ -230,17 +241,19 @@ namespace LibGUI
void Window::set_min_size(uint32_t width, uint32_t height) void Window::set_min_size(uint32_t width, uint32_t height)
{ {
WindowPacket::WindowSetMinSize packet; const WindowPacket::WindowSetMinSize packet {
packet.width = width; .width = width,
packet.height = height; .height = height,
};
send_packet(packet, __FUNCTION__); send_packet(packet, __FUNCTION__);
} }
void Window::set_max_size(uint32_t width, uint32_t height) void Window::set_max_size(uint32_t width, uint32_t height)
{ {
WindowPacket::WindowSetMaxSize packet; const WindowPacket::WindowSetMaxSize packet {
packet.width = width; .width = width,
packet.height = height; .height = height,
};
send_packet(packet, __FUNCTION__); send_packet(packet, __FUNCTION__);
} }
@@ -254,9 +267,10 @@ namespace LibGUI
void Window::request_resize(uint32_t width, uint32_t height) void Window::request_resize(uint32_t width, uint32_t height)
{ {
WindowPacket::WindowSetSize packet; const WindowPacket::WindowSetSize packet {
packet.width = width; .width = width,
packet.height = height; .height = height,
};
send_packet(packet, __FUNCTION__); send_packet(packet, __FUNCTION__);
} }