implement moving clients directionally
This commit is contained in:
parent
449911a089
commit
8c49238e95
29
src/client.c
29
src/client.c
@ -201,6 +201,24 @@ void wm_client_focus_dir(Wm *wm, Client *c, int dir)
|
||||
}
|
||||
}
|
||||
|
||||
void wm_client_swap_dir(Wm* wm, Client *c, int dir)
|
||||
{
|
||||
RETURN_IF_NULL(c);
|
||||
|
||||
TreeNode *client_node = wm_treenode_ptr_find_client_node(c->ws->tree, c);
|
||||
assert(client_node);
|
||||
|
||||
Client *client = wm_client_get_dir_rel_c(c, dir);
|
||||
if (!client)
|
||||
return;
|
||||
|
||||
TreeNode *client_node1 = wm_treenode_ptr_find_client_node(c->ws->tree, client);
|
||||
|
||||
wm_treenode_swap(c->ws->tree, client_node, client_node1);
|
||||
|
||||
wm_layout(wm, wm->smon);
|
||||
}
|
||||
|
||||
void wm_client_free(Wm *wm, Client *c)
|
||||
{
|
||||
DEBUG_PRINT("%s\n", __func__);
|
||||
@ -304,7 +322,7 @@ Client* wm_client_get_dir_rel_c(Client *c, int dir)
|
||||
if (!c)
|
||||
return NULL;
|
||||
|
||||
Client *r = NULL;
|
||||
Client *ret = NULL;
|
||||
int x, y, dx, dy;
|
||||
|
||||
switch (dir) {
|
||||
@ -351,15 +369,18 @@ Client* wm_client_get_dir_rel_c(Client *c, int dir)
|
||||
DEBUG_PRINT("%s ", __func__)
|
||||
DEBUG_PRINT("found window %d in direction ", (int)c->window)
|
||||
DEBUG_PRINT("%d\n", dir)
|
||||
return r;
|
||||
ret = r;
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
// TODO: bar
|
||||
} 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;
|
||||
ret:
|
||||
wm_ptrarray_free(&client_nodes);
|
||||
DEBUG_PRINT("%s returning %p\n", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Client* wm_client_get_focused(Wm *wm)
|
||||
|
@ -55,6 +55,7 @@ void wm_client_hide(Wm *wm, Client *c);
|
||||
void wm_client_show(Wm* wm, Client *c);
|
||||
void wm_client_focus(Wm* wm, Client *c);
|
||||
void wm_client_focus_dir(Wm* wm, Client *c, int dir);
|
||||
void wm_client_swap_dir(Wm* wm, Client *c, int dir);
|
||||
void wm_client_free(Wm *wm, Client *c);
|
||||
void wm_client_kill(Wm *wm, Client *c);
|
||||
|
||||
|
16
src/config.c
16
src/config.c
@ -24,7 +24,7 @@ void wm_cfg_init_def(Config *config)
|
||||
|
||||
void wm_keybinds_init_def(Config *config)
|
||||
{
|
||||
char *st[] = {"alacritty", NULL};
|
||||
char *st[] = {"st", NULL};
|
||||
char **sth = malloc(sizeof(st));
|
||||
memcpy(sth, st, sizeof(st));
|
||||
|
||||
@ -85,6 +85,18 @@ void wm_keybinds_init_def(Config *config)
|
||||
(Keybind) {Mod4Mask, XK_l, *wm_kb_focus_dir,
|
||||
(Arg) {.i = RIGHT}},
|
||||
|
||||
(Keybind) {Mod4Mask | ShiftMask, XK_h, *wm_kb_move_dir,
|
||||
(Arg) {.i = LEFT}},
|
||||
|
||||
(Keybind) {Mod4Mask | ShiftMask, XK_j, *wm_kb_move_dir,
|
||||
(Arg) {.i = DOWN}},
|
||||
|
||||
(Keybind) {Mod4Mask | ShiftMask, XK_k, *wm_kb_move_dir,
|
||||
(Arg) {.i = UP}},
|
||||
|
||||
(Keybind) {Mod4Mask | ShiftMask, XK_l, *wm_kb_move_dir,
|
||||
(Arg) {.i = RIGHT}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_b, *wm_kb_switch_split_mode,
|
||||
(Arg) {.i = SPLIT_VERTICAL}},
|
||||
|
||||
@ -159,7 +171,7 @@ void wm_configfile_read(ConfigFile *cfile, Config *config)
|
||||
|
||||
if (!fp) {
|
||||
fprintf(stderr, "wm: could not open config file: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
const int max_line_len = 8192;
|
||||
|
14
src/util.c
14
src/util.c
@ -83,6 +83,20 @@ void wm_treenode_recalculate_space(TreeNode *node)
|
||||
&node->children.nodes[1]->pos);
|
||||
}
|
||||
|
||||
void wm_treenode_swap(TreeNode *root, TreeNode *node1, TreeNode* node2)
|
||||
{
|
||||
assert(root);
|
||||
assert(node1);
|
||||
assert(node2);
|
||||
|
||||
assert(node1->type == NODE_CLIENT);
|
||||
assert(node2->type == NODE_CLIENT);
|
||||
|
||||
Client *tmp = node1->client;
|
||||
node1->client = node2->client;
|
||||
node2->client = tmp;
|
||||
}
|
||||
|
||||
void wm_node_type_to_str(NodeType type, char *buf, size_t bufsize)
|
||||
{
|
||||
switch (type) {
|
||||
|
@ -67,6 +67,7 @@ void wm_treenode_free(TreeNode *node);
|
||||
bool wm_treenode_is_empty(TreeNode *node);
|
||||
void wm_treenode_split_space(TreeNode *node, Rect *ret1, Rect *ret2);
|
||||
void wm_treenode_recalculate_space(TreeNode *node);
|
||||
void wm_treenode_swap(TreeNode *root, TreeNode *node1, TreeNode* node2);
|
||||
TreeNode* wm_treenode_remove_client(Wm *wm, TreeNode *root, Client *client);
|
||||
void wm_treenode_remove_node(TreeNode *root, unsigned int node_id);
|
||||
int wm_get_node_index(TreeNode *parent, unsigned int node_id);
|
||||
|
10
src/wm.c
10
src/wm.c
@ -664,6 +664,16 @@ void wm_kb_focus_dir(Wm *wm, Arg *args)
|
||||
wm_client_focus_dir(wm, c, args->i);
|
||||
}
|
||||
|
||||
void wm_kb_move_dir(Wm *wm, Arg *args)
|
||||
{
|
||||
Client *c;
|
||||
RETURN_IF_NULL(args)
|
||||
|
||||
c = wm_client_get_focused(wm);
|
||||
|
||||
wm_client_swap_dir(wm, c, args->i);
|
||||
}
|
||||
|
||||
void wm_kb_switch_split_mode(Wm *wm, Arg *args)
|
||||
{
|
||||
RETURN_IF_NULL(args)
|
||||
|
1
src/wm.h
1
src/wm.h
@ -147,6 +147,7 @@ void wm_kb_spawn(Wm *wm, Arg *args);
|
||||
void wm_kb_kill(Wm *wm, Arg *args);
|
||||
void wm_kb_switch_ws(Wm *wm, Arg *args);
|
||||
void wm_kb_focus_dir(Wm *wm, Arg *args);
|
||||
void wm_kb_move_dir(Wm *wm, Arg *args);
|
||||
void wm_kb_exit(Wm* wm, Arg *args);
|
||||
void wm_kb_switch_split_mode(Wm *wm, Arg *args);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user