add descriptive titles to split containers
This commit is contained in:
parent
b741c49212
commit
1806c9802e
|
@ -306,4 +306,10 @@ bool con_has_urgent_child(Con *con);
|
||||||
*/
|
*/
|
||||||
void con_update_parents_urgency(Con *con);
|
void con_update_parents_urgency(Con *con);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a string representing the subtree under con.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
char *con_get_tree_representation(Con *con);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
78
src/con.c
78
src/con.c
|
@ -28,6 +28,20 @@ char *colors[] = {
|
||||||
|
|
||||||
static void con_on_remove_child(Con *con);
|
static void con_on_remove_child(Con *con);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* force parent split containers to be redrawn
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void con_force_split_parents_redraw(Con *con) {
|
||||||
|
Con *parent = con;
|
||||||
|
|
||||||
|
while (parent && parent->type != CT_WORKSPACE && parent->type != CT_DOCKAREA) {
|
||||||
|
if (parent->split)
|
||||||
|
FREE(parent->deco_render_params);
|
||||||
|
parent = parent->parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new container (and attach it to the given parent, if not NULL).
|
* Create a new container (and attach it to the given parent, if not NULL).
|
||||||
* This function initializes the data structures and creates the appropriate
|
* This function initializes the data structures and creates the appropriate
|
||||||
|
@ -162,6 +176,7 @@ add_to_focus_head:
|
||||||
* This way, we have the option to insert Cons without having
|
* This way, we have the option to insert Cons without having
|
||||||
* to focus them. */
|
* to focus them. */
|
||||||
TAILQ_INSERT_TAIL(focus_head, con, focused);
|
TAILQ_INSERT_TAIL(focus_head, con, focused);
|
||||||
|
con_force_split_parents_redraw(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -169,6 +184,7 @@ add_to_focus_head:
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void con_detach(Con *con) {
|
void con_detach(Con *con) {
|
||||||
|
con_force_split_parents_redraw(con);
|
||||||
if (con->type == CT_FLOATING_CON) {
|
if (con->type == CT_FLOATING_CON) {
|
||||||
TAILQ_REMOVE(&(con->parent->floating_head), con, floating_windows);
|
TAILQ_REMOVE(&(con->parent->floating_head), con, floating_windows);
|
||||||
TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
|
TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
|
||||||
|
@ -1148,6 +1164,7 @@ void con_set_layout(Con *con, int layout) {
|
||||||
|
|
||||||
tree_flatten(croot);
|
tree_flatten(croot);
|
||||||
}
|
}
|
||||||
|
con_force_split_parents_redraw(con);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1168,6 +1185,7 @@ void con_set_layout(Con *con, int layout) {
|
||||||
} else {
|
} else {
|
||||||
con->layout = layout;
|
con->layout = layout;
|
||||||
}
|
}
|
||||||
|
con_force_split_parents_redraw(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1247,6 +1265,8 @@ static void con_on_remove_child(Con *con) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
con_force_split_parents_redraw(con);
|
||||||
|
|
||||||
/* TODO: check if this container would swallow any other client and
|
/* TODO: check if this container would swallow any other client and
|
||||||
* don’t close it automatically. */
|
* don’t close it automatically. */
|
||||||
int children = con_num_children(con);
|
int children = con_num_children(con);
|
||||||
|
@ -1420,3 +1440,61 @@ void con_update_parents_urgency(Con *con) {
|
||||||
parent = parent->parent;
|
parent = parent->parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a string representing the subtree under con.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
char *con_get_tree_representation(Con *con) {
|
||||||
|
/* this code works as follows:
|
||||||
|
* 1) create a string with the layout type (D/V/H/T/S) and an opening bracket
|
||||||
|
* 2) append the tree representation of the children to the string
|
||||||
|
* 3) add closing bracket
|
||||||
|
*
|
||||||
|
* The recursion ends when we hit a leaf, in which case we return the
|
||||||
|
* class_instance of the contained window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* end of recursion */
|
||||||
|
if (con_is_leaf(con)) {
|
||||||
|
if (!con->window)
|
||||||
|
return sstrdup("nowin");
|
||||||
|
|
||||||
|
if (!con->window->class_instance)
|
||||||
|
return sstrdup("noinstance");
|
||||||
|
|
||||||
|
return sstrdup(con->window->class_instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *buf;
|
||||||
|
/* 1) add the Layout type to buf */
|
||||||
|
if (con->layout == L_DEFAULT)
|
||||||
|
buf = sstrdup("D[");
|
||||||
|
else if (con->layout == L_SPLITV)
|
||||||
|
buf = sstrdup("V[");
|
||||||
|
else if (con->layout == L_SPLITH)
|
||||||
|
buf = sstrdup("H[");
|
||||||
|
else if (con->layout == L_TABBED)
|
||||||
|
buf = sstrdup("T[");
|
||||||
|
else if (con->layout == L_STACKED)
|
||||||
|
buf = sstrdup("S[");
|
||||||
|
|
||||||
|
/* 2) append representation of children */
|
||||||
|
Con *child;
|
||||||
|
TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
|
||||||
|
char *child_txt = con_get_tree_representation(child);
|
||||||
|
|
||||||
|
char *tmp_buf;
|
||||||
|
sasprintf(&tmp_buf, "%s%s%s", buf,
|
||||||
|
(TAILQ_FIRST(&(con->nodes_head)) == child ? "" : " "), child_txt);
|
||||||
|
free(buf);
|
||||||
|
buf = tmp_buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 3) close the brackets */
|
||||||
|
char *complete_buf;
|
||||||
|
sasprintf(&complete_buf, "%s]", buf);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
return complete_buf;
|
||||||
|
}
|
||||||
|
|
14
src/x.c
14
src/x.c
|
@ -482,12 +482,20 @@ void x_draw_decoration(Con *con) {
|
||||||
|
|
||||||
struct Window *win = con->window;
|
struct Window *win = con->window;
|
||||||
if (win == NULL || win->name == NULL) {
|
if (win == NULL || win->name == NULL) {
|
||||||
/* this is a non-leaf container, we need to make up a good description */
|
/* we have a split container which gets a representation
|
||||||
// TODO: use a good description instead of just "another container"
|
* of its children as title
|
||||||
draw_text_ascii("another container",
|
*/
|
||||||
|
char *title;
|
||||||
|
char *tree = con_get_tree_representation(con);
|
||||||
|
sasprintf(&title, "i3: %s", tree);
|
||||||
|
free(tree);
|
||||||
|
|
||||||
|
draw_text_ascii(title,
|
||||||
parent->pixmap, parent->pm_gc,
|
parent->pixmap, parent->pm_gc,
|
||||||
con->deco_rect.x + 2, con->deco_rect.y + text_offset_y,
|
con->deco_rect.x + 2, con->deco_rect.y + text_offset_y,
|
||||||
con->deco_rect.width - 2);
|
con->deco_rect.width - 2);
|
||||||
|
free(title);
|
||||||
|
|
||||||
goto copy_pixmaps;
|
goto copy_pixmaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue