Compare commits
2 Commits
867757734f
...
e350587aa2
Author | SHA1 | Date | |
---|---|---|---|
e350587aa2 | |||
64d2adbe49 |
31
client.c
31
client.c
@ -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;
|
||||
|
63
util.c
63
util.c
@ -65,7 +65,7 @@ void wm_treenode_split_space(TreeNode *node, Rect *ret1, Rect *ret2)
|
||||
}
|
||||
}
|
||||
|
||||
void wm_treenode_remove_client(TreeNode *root, Client *client)
|
||||
TreeNode* wm_treenode_remove_client(TreeNode *root, Client *client)
|
||||
{
|
||||
DEBUG_PRINT("%s\n", __func__);
|
||||
TreeNode *client_node = wm_treenode_ptr_find_client_node(root, client);
|
||||
@ -73,23 +73,24 @@ void wm_treenode_remove_client(TreeNode *root, Client *client)
|
||||
if (client_node->parent == NULL) {
|
||||
client_node->client = NULL;
|
||||
wm_nodearray_clear(&client_node->children);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TreeNode *parent = client_node->parent;
|
||||
parent->type = NODE_CLIENT;
|
||||
TreeNode *node = client_node->parent;
|
||||
node->type = NODE_CLIENT;
|
||||
Client *other_client = NULL;
|
||||
|
||||
for (size_t i = 0; i < parent->children.size; i++) {
|
||||
if (parent->children.nodes[i].type == NODE_CLIENT &&
|
||||
parent->children.nodes[i].client != client) {
|
||||
other_client = parent->children.nodes[i].client;
|
||||
for (size_t i = 0; i < node->children.size; i++) {
|
||||
if (node->children.nodes[i].type == NODE_CLIENT &&
|
||||
node->children.nodes[i].client != client) {
|
||||
other_client = node->children.nodes[i].client;
|
||||
}
|
||||
}
|
||||
|
||||
assert(other_client);
|
||||
parent->client = other_client;
|
||||
wm_nodearray_clear(&parent->children);
|
||||
node->client = other_client;
|
||||
wm_nodearray_clear(&node->children);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
NodeArray wm_nodearray_new()
|
||||
@ -364,7 +365,7 @@ TreeNode* wm_treenode_ptr_find_focused_client_node(TreeNode *root)
|
||||
if (!wm_ptrarray_pop_front(&queue, (void**)&node))
|
||||
goto ret;
|
||||
|
||||
if (node->type == NODE_CLIENT && node->client->focused) {
|
||||
if (node->type == NODE_CLIENT && node->client && node->client->focused) {
|
||||
ret = node;
|
||||
goto ret;
|
||||
}
|
||||
@ -395,50 +396,22 @@ ret:
|
||||
|
||||
TreeNode* wm_treenode_ptr_find_client_node(TreeNode *root, Client *client)
|
||||
{
|
||||
DEBUG_PRINT("%s\n", __func__);
|
||||
assert(root);
|
||||
assert(client);
|
||||
|
||||
TreeNode *ret = NULL;
|
||||
PtrArray client_nodes = wm_treenode_find_client_nodes_ptr(root);
|
||||
|
||||
NodeArray visited = wm_nodearray_new();
|
||||
wm_nodearray_push(&visited, *root);
|
||||
|
||||
PtrArray queue = wm_ptrarray_new();
|
||||
|
||||
wm_ptrarray_push(&queue, root);
|
||||
|
||||
while (queue.size > 0) {
|
||||
TreeNode *node;
|
||||
|
||||
if (!wm_ptrarray_pop_front(&queue, (void*)node))
|
||||
goto ret;
|
||||
|
||||
for (size_t i = 0; i < client_nodes.size; i++) {
|
||||
TreeNode *node = (TreeNode*)client_nodes.ptrs[i];
|
||||
if (node->client == client) {
|
||||
ret = node;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
for (int i = 0; i < node->children.size; i++) {
|
||||
TreeNode child_node = node->children.nodes[i];
|
||||
bool _visited = false;
|
||||
|
||||
for (int j = 0; j < visited.size; j++) {
|
||||
if (visited.nodes[j].id == child_node.id) {
|
||||
_visited = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_visited) {
|
||||
wm_nodearray_push(&visited, child_node);
|
||||
wm_ptrarray_push(&queue, &child_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret:
|
||||
wm_nodearray_free(&visited);
|
||||
wm_ptrarray_free(&queue);
|
||||
wm_ptrarray_free(&client_nodes);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
2
util.h
2
util.h
@ -65,7 +65,7 @@ struct TreeNode {
|
||||
TreeNode wm_treenode_new(NodeType type, TreeNode *parent);
|
||||
bool wm_treenode_is_empty(TreeNode *node);
|
||||
void wm_treenode_split_space(TreeNode *node, Rect *ret1, Rect *ret2);
|
||||
void wm_treenode_remove_client(TreeNode *root, Client *client);
|
||||
TreeNode* wm_treenode_remove_client(TreeNode *root, Client *client);
|
||||
|
||||
NodeArray wm_nodearray_new();
|
||||
void wm_nodearray_push(NodeArray *arr, TreeNode node);
|
||||
|
Loading…
x
Reference in New Issue
Block a user