forked from Bananymous/banan-os
LibGUI: Implement attributes for windows
Windows can now change whether they have title bar, rounded corners, alpha channel and whether they are movable. Also windows can also change their own position
This commit is contained in:
@@ -65,9 +65,6 @@ namespace LibGUI
|
||||
|
||||
BAN::ErrorOr<BAN::UniqPtr<Window>> Window::create(uint32_t width, uint32_t height, BAN::StringView title)
|
||||
{
|
||||
BAN::Vector<uint32_t> framebuffer;
|
||||
TRY(framebuffer.resize(width * height, 0xFF000000));
|
||||
|
||||
int server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (server_fd == -1)
|
||||
return BAN::Error::from_errno(errno);
|
||||
@@ -113,6 +110,11 @@ namespace LibGUI
|
||||
void* framebuffer_addr = smo_map(create_response.smo_key);
|
||||
if (framebuffer_addr == nullptr)
|
||||
return BAN::Error::from_errno(errno);
|
||||
width = create_response.width;
|
||||
height = create_response.height;
|
||||
|
||||
BAN::Vector<uint32_t> framebuffer;
|
||||
TRY(framebuffer.resize(width * height, 0xFFFFFFFF));
|
||||
|
||||
auto window = TRY(BAN::UniqPtr<Window>::create(
|
||||
server_fd,
|
||||
@@ -258,13 +260,46 @@ namespace LibGUI
|
||||
|
||||
if (auto ret = packet.send_serialized(m_server_fd); ret.is_error())
|
||||
{
|
||||
dprintln("Failed to send packet: {}", ret.error().get_message());
|
||||
dprintln("failed to invalidate window: {}", ret.error());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Window::set_position(int32_t x, int32_t y)
|
||||
{
|
||||
WindowPacket::WindowSetPosition packet;
|
||||
packet.x = x;
|
||||
packet.y = y;
|
||||
|
||||
if (auto ret = packet.send_serialized(m_server_fd); ret.is_error())
|
||||
{
|
||||
dprintln("failed to set window position: {}", ret.error());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Window::set_attributes(Attributes attributes)
|
||||
{
|
||||
WindowPacket::WindowSetAttributes packet;
|
||||
packet.title_bar = attributes.title_bar;
|
||||
packet.movable = attributes.movable;
|
||||
packet.rounded_corners = attributes.rounded_corners;
|
||||
packet.alpha_channel = attributes.alpha_channel;
|
||||
|
||||
if (auto ret = packet.send_serialized(m_server_fd); ret.is_error())
|
||||
{
|
||||
dprintln("failed to set window attributes: {}", ret.error());
|
||||
return false;
|
||||
}
|
||||
|
||||
m_attributes = attributes;
|
||||
return true;
|
||||
}
|
||||
|
||||
#define TRY_OR_BREAK(...) ({ auto&& e = (__VA_ARGS__); if (e.is_error()) break; e.release_value(); })
|
||||
|
||||
void Window::poll_events()
|
||||
|
||||
@@ -160,6 +160,8 @@ namespace LibGUI
|
||||
WindowCreate,
|
||||
WindowCreateResponse,
|
||||
WindowInvalidate,
|
||||
WindowSetPosition,
|
||||
WindowSetAttributes,
|
||||
|
||||
DestroyWindowEvent,
|
||||
CloseWindowEvent,
|
||||
@@ -179,6 +181,8 @@ namespace LibGUI
|
||||
);
|
||||
|
||||
DEFINE_PACKET(WindowCreateResponse,
|
||||
uint32_t, width,
|
||||
uint32_t, height,
|
||||
long, smo_key
|
||||
);
|
||||
|
||||
@@ -189,6 +193,18 @@ namespace LibGUI
|
||||
uint32_t, height
|
||||
);
|
||||
|
||||
DEFINE_PACKET(WindowSetPosition,
|
||||
int32_t, x,
|
||||
int32_t, y
|
||||
);
|
||||
|
||||
DEFINE_PACKET(WindowSetAttributes,
|
||||
bool, title_bar,
|
||||
bool, rounded_corners,
|
||||
bool, movable,
|
||||
bool, alpha_channel
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
namespace EventPacket
|
||||
|
||||
@@ -13,6 +13,15 @@ namespace LibGUI
|
||||
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
struct Attributes
|
||||
{
|
||||
bool title_bar { true };
|
||||
bool movable { true };
|
||||
bool rounded_corners { true };
|
||||
bool alpha_channel { false };
|
||||
};
|
||||
|
||||
public:
|
||||
~Window();
|
||||
|
||||
@@ -49,6 +58,11 @@ namespace LibGUI
|
||||
bool invalidate(int32_t x, int32_t y, uint32_t width, uint32_t height);
|
||||
bool invalidate() { return invalidate(0, 0, width(), height()); }
|
||||
|
||||
bool set_position(int32_t x, int32_t y);
|
||||
|
||||
Attributes get_attributes() const { return m_attributes; }
|
||||
bool set_attributes(Attributes attributes);
|
||||
|
||||
uint32_t width() const { return m_width; }
|
||||
uint32_t height() const { return m_height; }
|
||||
|
||||
@@ -75,6 +89,8 @@ namespace LibGUI
|
||||
private:
|
||||
int m_server_fd;
|
||||
|
||||
Attributes m_attributes;
|
||||
|
||||
BAN::Vector<uint32_t> m_framebuffer;
|
||||
uint32_t* m_framebuffer_smo;
|
||||
uint32_t m_width;
|
||||
|
||||
Reference in New Issue
Block a user