remanage_window: Refactor to make clearer when a swallowing happens

This commit is contained in:
Orestis Floros 2023-09-06 10:56:25 +02:00 committed by Michael Stapelberg
parent 82b9821204
commit 908c86544b
1 changed files with 22 additions and 15 deletions

View File

@ -678,27 +678,34 @@ out:
free(attr);
}
static Con *placeholder_for_con(Con *con) {
/* Make sure this windows hasn't already been swallowed. */
if (con->window->swallowed) {
return NULL;
}
Match *match;
Con *nc = con_for_window(croot, con->window, &match);
if (nc == NULL || nc->window == NULL || nc->window == con->window) {
return NULL;
}
/* Make sure the placeholder that wants to swallow this window didn't spawn
* after the window to follow current behavior: adding a placeholder won't
* swallow windows currently managed. */
if (nc->window->managed_since > con->window->managed_since) {
return NULL;
}
return nc;
}
/*
* Remanages a window: performs a swallow check and runs assignments.
* Returns con for the window regardless if it updated.
*
*/
Con *remanage_window(Con *con) {
/* Make sure this windows hasn't already been swallowed. */
if (con->window->swallowed) {
run_assignments(con->window);
return con;
}
Match *match;
Con *nc = con_for_window(croot, con->window, &match);
if (nc == NULL || nc->window == NULL || nc->window == con->window) {
run_assignments(con->window);
return con;
}
/* Make sure the placeholder that wants to swallow this window didn't spawn
* after the window to follow current behavior: adding a placeholder won't
* swallow windows currently managed. */
if (nc->window->managed_since > con->window->managed_since) {
Con *nc = placeholder_for_con(con);
if (!nc) {
/* The con is not updated, just run assignments */
run_assignments(con->window);
return con;
}