improve xdg states handling

This commit is contained in:
DanyLE
2024-04-13 05:17:28 +02:00
parent 68a0b669ef
commit 5088bf8ac2
6 changed files with 191 additions and 86 deletions

40
xdg.c
View File

@@ -53,7 +53,19 @@ static void begin_interactive(struct diyac_view *toplevel,
server->resize_edges = edges;
}
}
static void xdg_toplevel_commit(struct wl_listener *listener, void *data)
{
struct diyac_view *view = wl_container_of(listener, view, commit);
uint32_t serial = view->configuration_serial;
if (serial > 0 && serial == view->xdg_surface->current.configure_serial)
{
wl_event_source_remove(view->configuration_timeout);
view->configuration_serial = 0;
view->configuration_timeout = NULL;
// TODO move view
}
diyac_view_sync_geo(view);
}
static void xdg_toplevel_map(struct wl_listener *listener, void *data)
{
@@ -69,21 +81,24 @@ static void xdg_toplevel_map(struct wl_listener *listener, void *data)
WLR_XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE);
//WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN
*/
wlr_xdg_surface_get_geometry(toplevel->xdg_toplevel->base, &toplevel->original);
wlr_xdg_surface_get_geometry(toplevel->xdg_toplevel->base, &toplevel->pending_size);
wlr_scene_node_set_enabled(&toplevel->scene_tree->node, true);
toplevel->mapped = true;
wl_list_insert(&toplevel->server->views, &toplevel->link);
toplevel->commit.notify = xdg_toplevel_commit;
wl_signal_add(&toplevel->xdg_surface->surface->events.commit, &toplevel->commit);
diyac_view_update_app_id(toplevel);
diyac_view_update_title(toplevel);
toplevel->original.x = (toplevel->output->usable_area.width - toplevel->original.width) / 2;
toplevel->original.y = (toplevel->output->usable_area.height - toplevel->original.height) / 2;
if (toplevel->original.width > toplevel->output->usable_area.width)
toplevel->pending_size.x = (toplevel->output->usable_area.width - toplevel->pending_size.width) / 2;
toplevel->pending_size.y = (toplevel->output->usable_area.height - toplevel->pending_size.height) / 2;
if (toplevel->pending_size.width > toplevel->output->usable_area.width)
{
toplevel->original.width = toplevel->output->usable_area.width;
toplevel->pending_size.width = toplevel->output->usable_area.width;
}
if (toplevel->original.height > toplevel->output->usable_area.height)
if (toplevel->pending_size.height > toplevel->output->usable_area.height)
{
toplevel->original.height = toplevel->output->usable_area.height;
toplevel->pending_size.height = toplevel->output->usable_area.height;
}
diyac_view_update_geometry(toplevel, false);
diyac_focus_view(toplevel, false);
@@ -188,6 +203,12 @@ static void xdg_toplevel_destroy(struct wl_listener *listener, void *data)
{
wlr_foreign_toplevel_handle_v1_destroy(toplevel->toplevel.handle);
}
if (toplevel->configuration_timeout)
{
wl_event_source_remove(toplevel->configuration_timeout);
toplevel->configuration_timeout = NULL;
}
wl_list_remove(&toplevel->commit.link);
wl_list_remove(&toplevel->map.link);
wl_list_remove(&toplevel->unmap.link);
wl_list_remove(&toplevel->destroy.link);
@@ -378,6 +399,7 @@ void diyac_new_xdg_surface(struct wl_listener *listener, void *data)
toplevel->xdg_toplevel = xdg_surface->toplevel;
toplevel->xdg_surface = xdg_surface;
toplevel->mapped = false;
toplevel->configuration_timeout = NULL;
toplevel->output = diyac_output_from_cursor(server);
toplevel->scene_tree = wlr_scene_xdg_surface_create(
toplevel->server->view_tree, toplevel->xdg_toplevel->base);
@@ -393,7 +415,7 @@ void diyac_new_xdg_surface(struct wl_listener *listener, void *data)
diyac_node_descriptor_create(&toplevel->scene_tree->node,
DIYAC_NODE_VIEW, toplevel);
diyac_init_foreign_toplevel(toplevel);
/* Listen to the various events it can emit */
toplevel->map.notify = xdg_toplevel_map;
wl_signal_add(&xdg_surface->surface->events.map, &toplevel->map);