replace old client linked list code

This commit is contained in:
2023-07-06 14:54:33 +02:00
parent 4b1a638633
commit f822c400e5
2 changed files with 34 additions and 12 deletions

@@ -42,14 +42,20 @@ XWindowChanges wm_client_to_xwchanges(Client *c)
Client* wm_client_find(Wm *wm, Window w)
{
Client *c;
PtrArray clients = wm_treenode_find_client_nodes_ptr(&wm->smon->workspaces[wm->smon->selws].tree);
Client *ret = NULL;
for (c = wm->smon->clients; c; c = c->next) {
if (c->window == w)
return c;
for (size_t i = 0; i < clients.size; i++) {
Client *c = ((TreeNode*)clients.ptrs[i])->client;
if (c->window == w) {
ret = c;
goto ret;
}
}
return NULL;
ret:
wm_ptrarray_free(&clients);
return ret;
}
Client* wm_client_create(Wm *wm, Window w)
@@ -239,6 +245,7 @@ void wm_client_kill(Wm *wm, Client *c)
TreeNode* parent = wm_treenode_remove_client(wm, &c->ws->tree, c);
wm_client_free(wm, c);
wm->focused_client = NULL;
wm_layout(wm, m);

@@ -57,7 +57,8 @@ void wm_monitors_open_all(Wm *wm, Display *d)
printf("wm: Could not open display. Exiting.\n");
exit(1);
}
wm->wm_mc = count;
wm->monitors = malloc(count * sizeof(Monitor));
for (int i = 0; i < count; i++) {
@@ -600,20 +601,34 @@ void wm_init(Wm *wm)
void wm_exit(Wm *wm)
{
DEBUG_PRINT("%s\n", __func__);
Client *c;
XUngrabKey(wm->display, AnyKey, AnyModifier, wm->root.window);
PtrArray all_clients = wm_ptrarray_new();
// todo add clients to root client linked list
for (c = wm->smon->clients; c; c = c->next) {
XKillClient(wm->display, c->window);
// TODO: perhaps add created clients to a PtrArray field in workspace.
// would reduce number of calls to wm_treenode_find_client_nodes_ptr
for (size_t i = 0; i < wm->wm_mc; i++) {
for (size_t j = 0; j < wm->monitors[i].wscount; j++) {
PtrArray clients = wm_treenode_find_client_nodes_ptr(
&wm->monitors[i].workspaces[j].tree);
for (size_t k = 0; k < clients.size; k++) {
wm_ptrarray_push(&all_clients, clients.ptrs[i]);
}
wm_ptrarray_free(&clients);
}
}
for (c = wm->smon->clients; c; c = c->next) {
for (size_t i = 0; i < all_clients.size; i++) {
Client *c = ((TreeNode*)all_clients.ptrs[i])->client;
XKillClient(wm->display, c->window);
wm_client_free(wm, c);
}
DEBUG_PRINT("%s1\n", __func__);
XCloseDisplay(wm->display);
wm_ptrarray_free(&all_clients);
exit(EXIT_SUCCESS);
}