LibGUI/WindowServer: Add fullscreen events
This commit is contained in:
parent
8c2fea9edf
commit
710b896a84
|
|
@ -348,6 +348,10 @@ namespace LibGUI
|
||||||
if (m_window_focus_event_callback)
|
if (m_window_focus_event_callback)
|
||||||
m_window_focus_event_callback(TRY_OR_BREAK(EventPacket::WindowFocusEvent::deserialize(packet_data.span())).event);
|
m_window_focus_event_callback(TRY_OR_BREAK(EventPacket::WindowFocusEvent::deserialize(packet_data.span())).event);
|
||||||
break;
|
break;
|
||||||
|
case PacketType::WindowFullscreenEvent:
|
||||||
|
if (m_window_fullscreen_event_callback)
|
||||||
|
m_window_fullscreen_event_callback(TRY_OR_BREAK(EventPacket::WindowFullscreenEvent::deserialize(packet_data.span())).event);
|
||||||
|
break;
|
||||||
case PacketType::KeyEvent:
|
case PacketType::KeyEvent:
|
||||||
if (m_key_event_callback)
|
if (m_key_event_callback)
|
||||||
m_key_event_callback(TRY_OR_BREAK(EventPacket::KeyEvent::deserialize(packet_data.span())).event);
|
m_key_event_callback(TRY_OR_BREAK(EventPacket::KeyEvent::deserialize(packet_data.span())).event);
|
||||||
|
|
|
||||||
|
|
@ -219,6 +219,7 @@ namespace LibGUI
|
||||||
ResizeWindowEvent,
|
ResizeWindowEvent,
|
||||||
WindowShownEvent,
|
WindowShownEvent,
|
||||||
WindowFocusEvent,
|
WindowFocusEvent,
|
||||||
|
WindowFullscreenEvent,
|
||||||
KeyEvent,
|
KeyEvent,
|
||||||
MouseButtonEvent,
|
MouseButtonEvent,
|
||||||
MouseMoveEvent,
|
MouseMoveEvent,
|
||||||
|
|
@ -345,6 +346,14 @@ namespace LibGUI
|
||||||
event_t, event
|
event_t, event
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DEFINE_PACKET_EXTRA(
|
||||||
|
WindowFullscreenEvent,
|
||||||
|
struct event_t {
|
||||||
|
bool fullscreen;
|
||||||
|
},
|
||||||
|
event_t, event
|
||||||
|
);
|
||||||
|
|
||||||
DEFINE_PACKET_EXTRA(
|
DEFINE_PACKET_EXTRA(
|
||||||
KeyEvent,
|
KeyEvent,
|
||||||
using event_t = LibInput::KeyEvent,
|
using event_t = LibInput::KeyEvent,
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ namespace LibGUI
|
||||||
void set_mouse_scroll_event_callback(BAN::Function<void(EventPacket::MouseScrollEvent::event_t)> callback) { m_mouse_scroll_event_callback = callback; }
|
void set_mouse_scroll_event_callback(BAN::Function<void(EventPacket::MouseScrollEvent::event_t)> callback) { m_mouse_scroll_event_callback = callback; }
|
||||||
void set_window_shown_event_callback(BAN::Function<void(EventPacket::WindowShownEvent::event_t)> callback) { m_window_shown_event_callback = callback; }
|
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_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; }
|
||||||
|
|
||||||
int server_fd() const { return m_server_fd; }
|
int server_fd() const { return m_server_fd; }
|
||||||
|
|
||||||
|
|
@ -112,6 +113,7 @@ namespace LibGUI
|
||||||
BAN::Function<void()> m_resize_window_event_callback;
|
BAN::Function<void()> m_resize_window_event_callback;
|
||||||
BAN::Function<void(EventPacket::WindowShownEvent::event_t)> m_window_shown_event_callback;
|
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::WindowFocusEvent::event_t)> m_window_focus_event_callback;
|
||||||
|
BAN::Function<void(EventPacket::WindowFullscreenEvent::event_t)> m_window_fullscreen_event_callback;
|
||||||
BAN::Function<void(EventPacket::KeyEvent::event_t)> m_key_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::MouseButtonEvent::event_t)> m_mouse_button_event_callback;
|
||||||
BAN::Function<void(EventPacket::MouseMoveEvent::event_t)> m_mouse_move_event_callback;
|
BAN::Function<void(EventPacket::MouseMoveEvent::event_t)> m_mouse_move_event_callback;
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ void WindowServer::on_window_create(int fd, const LibGUI::WindowPacket::WindowCr
|
||||||
|
|
||||||
window_popper.disable();
|
window_popper.disable();
|
||||||
|
|
||||||
if (packet.attributes.shown && packet.attributes.focusable)
|
if (packet.attributes.shown && packet.attributes.focusable && m_state == State::Normal)
|
||||||
set_focused_window(window);
|
set_focused_window(window);
|
||||||
else if (m_client_windows.size() > 1)
|
else if (m_client_windows.size() > 1)
|
||||||
BAN::swap(m_client_windows[m_client_windows.size() - 1], m_client_windows[m_client_windows.size() - 2]);
|
BAN::swap(m_client_windows[m_client_windows.size() - 1], m_client_windows[m_client_windows.size() - 2]);
|
||||||
|
|
@ -177,8 +177,14 @@ void WindowServer::on_window_set_attributes(int fd, const LibGUI::WindowPacket::
|
||||||
|
|
||||||
if ((!packet.attributes.focusable || !packet.attributes.shown) && m_focused_window == target_window)
|
if ((!packet.attributes.focusable || !packet.attributes.shown) && m_focused_window == target_window)
|
||||||
{
|
{
|
||||||
|
if (m_state == State::Fullscreen && m_focused_window->get_attributes().resizable)
|
||||||
|
{
|
||||||
|
if (!resize_window(m_focused_window, m_non_full_screen_rect.width, m_non_full_screen_rect.height))
|
||||||
|
return;
|
||||||
|
m_focused_window->set_position({ m_non_full_screen_rect.x, m_non_full_screen_rect.y });
|
||||||
|
}
|
||||||
|
|
||||||
m_focused_window = nullptr;
|
m_focused_window = nullptr;
|
||||||
if (m_state == State::Moving || m_state == State::Resizing)
|
|
||||||
m_state = State::Normal;
|
m_state = State::Normal;
|
||||||
for (size_t i = m_client_windows.size(); i > 0; i--)
|
for (size_t i = m_client_windows.size(); i > 0; i--)
|
||||||
{
|
{
|
||||||
|
|
@ -202,7 +208,7 @@ void WindowServer::on_window_set_attributes(int fd, const LibGUI::WindowPacket::
|
||||||
if (auto ret = event_packet.send_serialized(target_window->client_fd()); ret.is_error())
|
if (auto ret = event_packet.send_serialized(target_window->client_fd()); ret.is_error())
|
||||||
dwarnln("could not send window shown event: {}", ret.error());
|
dwarnln("could not send window shown event: {}", ret.error());
|
||||||
|
|
||||||
if (packet.attributes.focusable && packet.attributes.shown)
|
if (packet.attributes.focusable && packet.attributes.shown && m_state == State::Normal)
|
||||||
set_focused_window(target_window);
|
set_focused_window(target_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -302,6 +308,13 @@ void WindowServer::on_window_set_fullscreen(int fd, const LibGUI::WindowPacket::
|
||||||
return;
|
return;
|
||||||
m_focused_window->set_position({ m_non_full_screen_rect.x, m_non_full_screen_rect.y });
|
m_focused_window->set_position({ m_non_full_screen_rect.x, m_non_full_screen_rect.y });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto event_packet = LibGUI::EventPacket::WindowFullscreenEvent {
|
||||||
|
.event = { .fullscreen = false }
|
||||||
|
};
|
||||||
|
if (auto ret = event_packet.send_serialized(m_focused_window->client_fd()); ret.is_error())
|
||||||
|
dwarnln("could not send window fullscreen event: {}", ret.error());
|
||||||
|
|
||||||
m_state = State::Normal;
|
m_state = State::Normal;
|
||||||
invalidate(m_framebuffer.area());
|
invalidate(m_framebuffer.area());
|
||||||
return;
|
return;
|
||||||
|
|
@ -331,6 +344,12 @@ void WindowServer::on_window_set_fullscreen(int fd, const LibGUI::WindowPacket::
|
||||||
m_non_full_screen_rect = old_area;
|
m_non_full_screen_rect = old_area;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto event_packet = LibGUI::EventPacket::WindowFullscreenEvent {
|
||||||
|
.event = { .fullscreen = true }
|
||||||
|
};
|
||||||
|
if (auto ret = event_packet.send_serialized(target_window->client_fd()); ret.is_error())
|
||||||
|
dwarnln("could not send window fullscreen event: {}", ret.error());
|
||||||
|
|
||||||
m_state = State::Fullscreen;
|
m_state = State::Fullscreen;
|
||||||
set_focused_window(target_window);
|
set_focused_window(target_window);
|
||||||
invalidate(m_framebuffer.area());
|
invalidate(m_framebuffer.area());
|
||||||
|
|
@ -486,6 +505,12 @@ void WindowServer::on_key_event(LibInput::KeyEvent event)
|
||||||
m_state = State::Fullscreen;
|
m_state = State::Fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto event_packet = LibGUI::EventPacket::WindowFullscreenEvent {
|
||||||
|
.event = { .fullscreen = (m_state == State::Fullscreen) }
|
||||||
|
};
|
||||||
|
if (auto ret = event_packet.send_serialized(m_focused_window->client_fd()); ret.is_error())
|
||||||
|
dwarnln("could not send window fullscreen event: {}", ret.error());
|
||||||
|
|
||||||
invalidate(m_framebuffer.area());
|
invalidate(m_framebuffer.area());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue