Move OSD handler for view destruction to osd.c

This commit is contained in:
Consolatis 2022-08-22 02:54:40 +02:00
parent ca3c83aafc
commit 2550c984f8
3 changed files with 50 additions and 32 deletions

View file

@ -583,6 +583,8 @@ void osd_update(struct server *server);
void osd_finish(struct server *server);
/* Moves preview views back into their original stacking order and state */
void osd_preview_restore(struct server *server);
/* Notify OSD about a destroying view */
void osd_on_view_destroy(struct view *view);
/*
* wlroots "input inhibitor" extension (required for swaylock) blocks

View file

@ -108,6 +108,52 @@ osd_update_preview_outlines(struct view *view)
wlr_scene_node_set_position(&rect->tree->node, geo.x, geo.y);
}
void
osd_on_view_destroy(struct view *view)
{
assert(view);
struct osd_state *osd_state = &view->server->osd_state;
if (!osd_state->cycle_view) {
/* OSD not active, no need for clean up */
return;
}
if (osd_state->cycle_view == view) {
/*
* If we are the current OSD selected view, cycle
* to the next because we are dying.
*/
osd_state->cycle_view = desktop_cycle_view(view->server,
osd_state->cycle_view, LAB_CYCLE_DIR_BACKWARD);
/*
* If we cycled back to ourselves, then we have no more windows.
* Just close the OSD for good.
*/
if (osd_state->cycle_view == view || !osd_state->cycle_view) {
/* osd_finish() additionally resets cycle_view to NULL */
osd_finish(view->server);
}
}
if (view->scene_tree) {
struct wlr_scene_node *node = &view->scene_tree->node;
if (osd_state->preview_anchor == node) {
/*
* If we are the anchor for the current OSD selected view,
* replace the anchor with the node before us.
*/
osd_state->preview_anchor = lab_wlr_scene_get_prev_node(node);
}
}
if (osd_state->cycle_view) {
/* Update the OSD to reflect the view has now gone. */
osd_update(view->server);
}
}
void
osd_finish(struct server *server)
{

View file

@ -809,41 +809,11 @@ view_destroy(struct view *view)
server->focused_view = NULL;
}
struct osd_state *osd_state = &view->server->osd_state;
if (osd_state->cycle_view == view) {
/*
* If we are the current OSD selected view, cycle
* to the next because we are dying.
*/
osd_state->cycle_view = desktop_cycle_view(server,
osd_state->cycle_view, LAB_CYCLE_DIR_BACKWARD);
/*
* If we cycled back to ourselves, then we have no windows.
* just remove it and close the OSD for good.
*/
if (osd_state->cycle_view == view || !osd_state->cycle_view) {
/* osd_finish() additionally resets cycle_view to NULL */
osd_finish(server);
}
}
if (osd_state->cycle_view) {
/* Update the OSD to reflect the view has now gone. */
osd_update(server);
}
osd_on_view_destroy(view);
if (view->scene_tree) {
struct wlr_scene_node *node = &view->scene_tree->node;
if (osd_state->preview_anchor == node) {
/*
* If we are the anchor for the current OSD selected view,
* replace the anchor with the node before us.
*/
osd_state->preview_anchor = lab_wlr_scene_get_prev_node(node);
}
ssd_destroy(view);
wlr_scene_node_destroy(node);
wlr_scene_node_destroy(&view->scene_tree->node);
view->scene_tree = NULL;
}