update TreeNode function usages to use pointers

This commit is contained in:
Akos Horvath 2023-08-09 20:00:06 +02:00
parent b0f446a514
commit 077c2b5f69
3 changed files with 28 additions and 39 deletions

View File

@ -40,7 +40,7 @@ XWindowChanges wm_client_to_xwchanges(Client *c)
Client* wm_client_find(Wm *wm, Window w)
{
PtrArray clients = wm_treenode_find_client_nodes_ptr(&wm->smon->workspaces[wm->smon->selws].tree);
PtrArray clients = wm_treenode_find_client_nodes_ptr(wm->smon->workspaces[wm->smon->selws].tree);
Client *ret = NULL;
for (size_t i = 0; i < clients.size; i++) {
@ -83,15 +83,6 @@ Client* wm_client_create(Wm *wm, Window w)
strcpy(c->name, (char*)xtp.value);
}
if (wm->smon->clients == NULL) {
wm->smon->clients = c;
} else {
t = wm_get_last_client(wm, *c->m);
t->next = c;
c->prev = t;
c->next = NULL;
}
XSelectInput(wm->display, c->window, FocusChangeMask | EnterWindowMask |
PointerMotionMask);
@ -131,6 +122,7 @@ void wm_client_handle_window_types(Wm *wm, Client *c, XMapRequestEvent e)
} else if (strcmp(atom_name, "_NET_WM_WINDOW_TYPE_DIALOG") == 0) {
c->is_floating = true;
}
XFree(atom_name);
}
if (!is_normal) {
@ -239,7 +231,7 @@ void wm_client_kill(Wm *wm, Client *c)
if (XSendEvent(wm->display, c->window, false, NoEventMask, &event) != Success)
XKillClient(wm->display, c->window);
TreeNode* parent = wm_treenode_remove_client(wm, &c->ws->tree, c);
TreeNode* parent = wm_treenode_remove_client(wm, c->ws->tree, c);
wm_client_free(wm, c);
wm->focused_client = NULL;
@ -310,7 +302,7 @@ Client* wm_client_get_dir_rel_c(Client *c, int dir)
if (!c)
return NULL;
Client *r;
Client *r = NULL;
int x, y, dx, dy;
switch (dir) {
@ -343,7 +335,7 @@ Client* wm_client_get_dir_rel_c(Client *c, int dir)
return NULL;
}
PtrArray client_nodes = wm_treenode_find_client_nodes_ptr(&c->ws->tree);
PtrArray client_nodes = wm_treenode_find_client_nodes_ptr(c->ws->tree);
x+=dx*5;
y+=dy*5;
@ -364,6 +356,7 @@ Client* wm_client_get_dir_rel_c(Client *c, int dir)
} while((x > 0 && x < c->m->info.width) &&
(y > 0 && y < c->m->info.height));
DEBUG_PRINT("%s returning %p\n", __func__, r);
return r;
}
@ -372,7 +365,7 @@ Client* wm_client_get_focused(Wm *wm)
Client *c = NULL;
Workspace *ws = &wm->smon->workspaces[wm->smon->selws];
TreeNode *node = wm_treenode_ptr_find_focused_client_node(&ws->tree);
TreeNode *node = wm_treenode_ptr_find_focused_client_node(ws->tree);
if (!node)
return NULL;
@ -412,7 +405,7 @@ void wm_monitor_clients_border(Wm *wm, Monitor *m)
{
DEBUG_PRINT("%s\n", __func__)
RETURN_IF_NULL(m);
PtrArray clients = wm_treenode_find_client_nodes_ptr(&m->workspaces[m->selws].tree);
PtrArray clients = wm_treenode_find_client_nodes_ptr(m->workspaces[m->selws].tree);
if (clients.size == 0)
return;

View File

@ -192,10 +192,10 @@ void wm_ws_tree_insert_client(Wm *wm, Workspace *ws, Client *client)
dock_y = x.height;
}
if (wm_treenode_is_empty(&ws->tree) && ws->tree.client == NULL) {
ws->tree.type = NODE_CLIENT;
ws->tree.client = client;
ws->tree.pos = (Rect) {
if (wm_treenode_is_empty(ws->tree) && ws->tree->client == NULL) {
ws->tree->type = NODE_CLIENT;
ws->tree->client = client;
ws->tree->pos = (Rect) {
.x = wm->config.border_width, .y = wm->config.border_width + dock_y ,
.w = ws->monitor->info.width - wm->config.border_width*2,
.h = ws->monitor->info.height - wm->config.border_width*2 - dock_y,
@ -203,18 +203,18 @@ void wm_ws_tree_insert_client(Wm *wm, Workspace *ws, Client *client)
return;
}
TreeNode *focused_node = wm_treenode_ptr_find_focused_client_node(&ws->tree);
TreeNode *focused_node = wm_treenode_ptr_find_focused_client_node(ws->tree);
assert(focused_node);
Client *old_client = focused_node->client;
focused_node->type = wm_split_to_nodetype(ws->split);
TreeNode child1 = wm_treenode_new(NODE_CLIENT, focused_node);
TreeNode child2 = wm_treenode_new(NODE_CLIENT, focused_node);
TreeNode *child1 = wm_treenode_new(NODE_CLIENT, focused_node);
TreeNode *child2 = wm_treenode_new(NODE_CLIENT, focused_node);
wm_treenode_split_space(focused_node, &child1.pos, &child2.pos);
child1.client = old_client;
child2.client = client;
wm_treenode_split_space(focused_node, &child1->pos, &child2->pos);
child1->client = old_client;
child2->client = client;
wm_nodearray_push(&focused_node->children, child1);
wm_nodearray_push(&focused_node->children, child2);
@ -229,7 +229,7 @@ void wm_switch_ws(Wm *wm, size_t ws)
Client *c;
PtrArray current_ws_clients = wm_treenode_find_client_nodes_ptr(
&wm->smon->workspaces[wm->smon->selws].tree);
wm->smon->workspaces[wm->smon->selws].tree);
for (size_t i = 0; i < current_ws_clients.size; i++) {
c = ((TreeNode**)current_ws_clients.ptrs)[i]->client;
@ -246,7 +246,7 @@ void wm_switch_ws(Wm *wm, size_t ws)
(unsigned char*) &(ws), XA_CARDINAL, 1);
PtrArray switch_ws_clients = wm_treenode_find_client_nodes_ptr(
&wm->smon->workspaces[wm->smon->selws].tree);
wm->smon->workspaces[wm->smon->selws].tree);
for (size_t i = 0; i < switch_ws_clients.size; i++) {
c = ((TreeNode**)switch_ws_clients.ptrs)[i]->client;
@ -377,7 +377,7 @@ void wm_layout(Wm *wm, Monitor *m)
DEBUG_PRINT("%s\n", __func__);
Workspace *ws = &m->workspaces[m->selws];
PtrArray clients = wm_treenode_find_client_nodes_ptr(&ws->tree);
PtrArray clients = wm_treenode_find_client_nodes_ptr(ws->tree);
if (clients.size == 0)
goto ret;
@ -411,6 +411,7 @@ ret:
Client *wm_get_last_client(Wm *wm, Monitor m)
{
return NULL;
Client *c = m.clients;
if (c == NULL)
@ -549,7 +550,6 @@ void wm_exit(Wm *wm)
DEBUG_PRINT("%s\n", __func__);
XUngrabKey(wm->display, AnyKey, AnyModifier, wm->root.window);
PtrArray all_clients = wm_ptrarray_new();
// TODO: perhaps add created clients to a PtrArray field in workspace.
// would reduce number of calls to wm_treenode_find_client_nodes_ptr
@ -557,24 +557,20 @@ void wm_exit(Wm *wm)
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);
wm->monitors[i].workspaces[j].tree);
for (size_t k = 0; k < clients.size; k++) {
wm_ptrarray_push(&all_clients, clients.ptrs[i]);
Client *c = ((TreeNode*)clients.ptrs[k])->client;
XKillClient(wm->display, c->window);
DEBUG_PRINT("freeing client %p\n", c);
wm_client_free(wm, c);
}
wm_ptrarray_free(&clients);
}
}
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);
}
XCloseDisplay(wm->display);
wm_ptrarray_free(&all_clients);
exit(EXIT_SUCCESS);
}

View File

@ -90,7 +90,7 @@ struct Monitor {
};
struct Workspace {
TreeNode tree;
TreeNode *tree;
size_t index;
char name[WM_WS_NAME_LEN];
Monitor *monitor;