LibGUI/WindowServer: Send window move events

This commit is contained in:
2026-06-23 20:52:12 +03:00
parent 8bc93069be
commit 4ad586552d
5 changed files with 60 additions and 22 deletions

View File

@@ -70,15 +70,21 @@ namespace LibGUI
TRY(create_packet.title.append(title));
window->send_packet(create_packet, __FUNCTION__);
bool resized = false;
int32_t x, y;
bool resized { false }, moved { false };
window->set_resize_window_event_callback([&]() { resized = true; });
while (!resized)
window->set_window_move_event_callback([&](auto event) { x = event.x; y = event.y; moved = true; });
while (!resized || !moved)
{
// FIXME: timeout?
window->wait_events();
window->poll_events();
}
window->set_resize_window_event_callback({});
window->set_window_move_event_callback({});
// hack to resend move event :^)
window->set_position(x, y);
server_closer.disable();
epoll_closer.disable();
@@ -365,6 +371,10 @@ namespace LibGUI
if (m_window_fullscreen_event_callback)
m_window_fullscreen_event_callback(TRY_OR_BREAK(EventPacket::WindowFullscreenEvent::deserialize(packet_span)).event);
break;
case PacketType::WindowMoveEvent:
if (m_window_move_event_callback)
m_window_move_event_callback(TRY_OR_BREAK(EventPacket::WindowMoveEvent::deserialize(packet_span)).event);
break;
case PacketType::KeyEvent:
if (m_key_event_callback)
m_key_event_callback(TRY_OR_BREAK(EventPacket::KeyEvent::deserialize(packet_span)).event);

View File

@@ -206,6 +206,7 @@ namespace LibGUI
WindowShownEvent,
WindowFocusEvent,
WindowFullscreenEvent,
WindowMoveEvent,
KeyEvent,
MouseButtonEvent,
MouseMoveEvent,
@@ -346,6 +347,15 @@ namespace LibGUI
event_t, event
);
DEFINE_PACKET_EXTRA(
WindowMoveEvent,
struct event_t {
int32_t x;
int32_t y;
},
event_t, event
);
DEFINE_PACKET_EXTRA(
KeyEvent,
using event_t = LibInput::KeyEvent,

View File

@@ -79,6 +79,7 @@ namespace LibGUI
void set_window_shown_event_callback(BAN::Function<void(EventPacket::WindowShownEvent::event_t)> callback) { m_window_shown_event_callback = callback; }
void set_window_focus_event_callback(BAN::Function<void(EventPacket::WindowFocusEvent::event_t)> callback) { m_window_focus_event_callback = callback; }
void set_window_fullscreen_event_callback(BAN::Function<void(EventPacket::WindowFullscreenEvent::event_t)> callback) { m_window_fullscreen_event_callback = callback; }
void set_window_move_event_callback(BAN::Function<void(EventPacket::WindowMoveEvent::event_t)> callback) { m_window_move_event_callback = callback; }
int server_fd() const { return m_server_fd; }
@@ -118,6 +119,7 @@ namespace LibGUI
BAN::Function<void(EventPacket::WindowShownEvent::event_t)> m_window_shown_event_callback;
BAN::Function<void(EventPacket::WindowFocusEvent::event_t)> m_window_focus_event_callback;
BAN::Function<void(EventPacket::WindowFullscreenEvent::event_t)> m_window_fullscreen_event_callback;
BAN::Function<void(EventPacket::WindowMoveEvent::event_t)> m_window_move_event_callback;
BAN::Function<void(EventPacket::KeyEvent::event_t)> m_key_event_callback;
BAN::Function<void(EventPacket::MouseButtonEvent::event_t)> m_mouse_button_event_callback;
BAN::Function<void(EventPacket::MouseMoveEvent::event_t)> m_mouse_move_event_callback;