Skip to content

Commit

Permalink
More thorough heuristic and actual asynchronous destruction
Browse files Browse the repository at this point in the history
I think I found a project setting to disable resizing, so let's just
add that the window has to be also borderless to be considered a popup.

We could additionally filter the main window out by forcing a popup to
be initialized with a parent (the main window can't have a parent) but
I'm lazy and this is all temporary anyways - this heuristic is just a
quick hack to keep everything toghether while I finish the foundations
for multiwin.

Still gotta handle the events which allow "null" surfaces such as the
keyboard exit one. I'll have to pass through all of the "allow null"
wl_surface-related events eventually, if there's more.

It looks like those are the only kind of meaningful events left after
destroying a window's objects so we can roundtrip the wl_display after
deleting everything instead of doing it half-way in the destruction.

Also, for some reason, while everything is "fine" on sway, input
handling is very wonky on Weston, almost as if we passed the position to
the child toplevel, although we certainly do not.
  • Loading branch information
Riteo committed Oct 23, 2024
1 parent d6f14ec commit 9730bd0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 4 additions & 3 deletions platform/linuxbsd/wayland/display_server_wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ DisplayServer::WindowID DisplayServerWayland::create_sub_window(WindowMode p_mod

// I mean, popups need it :P
// FIXME super rough heuristic
if (p_flags | WINDOW_FLAG_RESIZE_DISABLED) {
if (p_flags | (WINDOW_FLAG_RESIZE_DISABLED & WINDOW_FLAG_BORDERLESS)) {
wd.rect.position = p_rect.position;
}

Expand All @@ -580,9 +580,9 @@ void DisplayServerWayland::show_window(WindowID p_window_id) {
WindowMode setup_mode = wd.mode;

// DEBUG: Temporary heuristic to test popup logic. I'm pretty darn sure that
// we should not rely on it as a "popup flag".
// we should not rely on any set of "popup flags".
// FIXME
if (!window_get_flag(WINDOW_FLAG_RESIZE_DISABLED, p_window_id)) {
if (!window_get_flag(WINDOW_FLAG_RESIZE_DISABLED, p_window_id) && !window_get_flag(WINDOW_FLAG_BORDERLESS, p_window_id)) {
wayland_thread.window_create(p_window_id, wd.rect.size.width, wd.rect.size.height);
wayland_thread.window_set_min_size(p_window_id, wd.min_size);
wayland_thread.window_set_max_size(p_window_id, wd.max_size);
Expand Down Expand Up @@ -1238,6 +1238,7 @@ void DisplayServerWayland::process_events() {

Ref<WaylandThread::WindowEventMessage> winev_msg = msg;
if (winev_msg.is_valid()) {
DEBUG_LOG_WAYLAND(vformat("Sending event %d to window %d", winev_msg->event, winev_msg->id));
_send_window_event(winev_msg->event, winev_msg->id);

if (winev_msg->event == WINDOW_EVENT_FOCUS_IN) {
Expand Down
16 changes: 13 additions & 3 deletions platform/linuxbsd/wayland/wayland_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3384,9 +3384,6 @@ void WaylandThread::window_destroy(DisplayServer::WindowID p_window_id) {
xdg_toplevel_destroy(ws.xdg_toplevel);
}

// Let's handle any leftover event...
wl_display_roundtrip(wl_display);

if (ws.wp_fractional_scale) {
wp_fractional_scale_v1_destroy(ws.wp_fractional_scale);
}
Expand All @@ -3413,6 +3410,19 @@ void WaylandThread::window_destroy(DisplayServer::WindowID p_window_id) {
wl_surface_destroy(ws.wl_surface);
}

// Before continuing, let's handle any leftover event that might still refer to
// this window.
wl_display_roundtrip(wl_display);

// We might now have some message referring to this window in the WL->GD queue.
// We'll use a `WindowDestroyedMessage` event as our "done" signal to tell the
// DS when to clean its window data.
Ref<WindowDestroyedMessage> msg;
msg.instantiate();
msg->id = p_window_id;
push_message(msg);

// We can already clean up here, we're done.
windows.erase(p_window_id);
}

Expand Down

0 comments on commit 9730bd0

Please sign in to comment.