update directional focus to work with tree structure, focus another client after closing one

This commit is contained in:
Akos Horvath 2023-07-01 20:10:27 +02:00
parent 867757734f
commit 64d2adbe49

View File

@ -163,12 +163,20 @@ void wm_client_show(Wm *wm, Client *c)
void wm_client_focus(Wm *wm, Client *c)
{
DEBUG_PRINT("%s\n", __func__);
RETURN_IF_NULL(c);
Client *old_focused_client = wm->focused_client;
if (!old_focused_client)
old_focused_client = wm_client_get_focused(wm);
assert(old_focused_client);
old_focused_client->focused = false;
XSetInputFocus(wm->display, c->window, RevertToPointerRoot, CurrentTime);
wm_client_set_atom(wm, c, "_NET_ACTIVE_WINDOW", (unsigned char*) &c->window,
XA_WINDOW, 1);
c->focused = true;
wm->focused_client = c;
wm_monitor_clients_border(wm, c->m);
}
@ -236,11 +244,20 @@ void wm_client_kill(Wm *wm, Client *c)
if (XSendEvent(wm->display, c->window, false, NoEventMask, &event) != Success)
XKillClient(wm->display, c->window);
wm_treenode_remove_client(&c->ws->tree, c);
TreeNode* parent = wm_treenode_remove_client(&c->ws->tree, c);
Client *client_to_be_focused = NULL;
if (!parent || parent->type != NODE_CLIENT || !parent->client) {
PtrArray clients = wm_treenode_find_client_nodes_ptr(&c->ws->tree);
if (clients.size > 0)
client_to_be_focused = ((TreeNode*)clients.ptrs[0])->client;
}
wm_client_free(wm, c);
wm_layout(wm, m);
wm_client_focus(wm, parent->client);
}
void wm_client_set_atom(Wm *wm, Client *c, const char* name, const unsigned char *data,
@ -297,7 +314,7 @@ Atom wm_client_get_atom(Wm *wm, Client *c, const char *name, unsigned char **ato
Client* wm_client_get_dir_rel_c(Client *c, int dir)
{
DEBUG_PRINT("%s\n", __func__)
DEBUG_PRINT("%s c: %p\n", __func__, c)
if (!c)
return NULL;
@ -335,12 +352,16 @@ 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);
x+=dx*5;
y+=dy*5;
do {
x+=dx*2;
y+=dy*2;
for (r = c->m->clients; r; r = r->next) {
for (size_t i = 0; i < client_nodes.size; i++) {
Client *r = ((TreeNode**)client_nodes.ptrs)[i]->client;
if ((x > r->x && x < r->x+r->w) && (y > r->y && y < r->y+r->h)) {
DEBUG_PRINT("%s ", __func__)
DEBUG_PRINT("found window %d in direction ", (int)c->window)
@ -370,8 +391,8 @@ void wm_client_border(Wm *wm, Client *c)
{
RETURN_IF_NULL(c);
DEBUG_PRINT("border col: %s\nfocused border col: %s\n",
wm->cfg_border_col, wm->cfg_focused_border_col);
// DEBUG_PRINT("border col: %s\nfocused border col: %s\n",
// wm->cfg_border_col, wm->cfg_focused_border_col);
XVisualInfo vinfo;
XColor color;