@ -21,6 +21,7 @@
# include "sway/tree/view.h"
# include "sway/tree/view.h"
# include "sway/tree/workspace.h"
# include "sway/tree/workspace.h"
# include "log.h"
# include "log.h"
# include "stringop.h"
static list_t * bfs_queue ;
static list_t * bfs_queue ;
@ -774,42 +775,36 @@ void container_calculate_title_height(struct sway_container *container) {
}
}
/**
/**
* Calculate and return the length of the concatenated child titles .
* Calculate and return the length of the tree representation .
* An example concatenated title is : V [ Terminal , Firefox ]
* An example tree representation is : V [ Terminal , Firefox ]
* If buffer is not NULL , also populate the buffer with the concatenated title .
* If buffer is not NULL , also populate the buffer with the representation .
*/
*/
static size_t concatenate_child_titles ( struct sway_container * parent ,
static size_t get_tree_representation ( struct sway_container * parent , char * buffer ) {
char * buffer ) {
size_t len = 2 ;
size_t len = 2 ; // V[
if ( buffer ) {
switch ( parent - > layout ) {
switch ( parent - > layout ) {
case L_VERT :
case L_VERT :
strcpy ( buffer , " V[ " ) ;
lenient_strcat ( buffer , " V[ " ) ;
break ;
break ;
case L_HORIZ :
case L_HORIZ :
strcpy ( buffer , " H[ " ) ;
lenient_strcat ( buffer , " H[ " ) ;
break ;
break ;
case L_TABBED :
case L_TABBED :
strcpy ( buffer , " T[ " ) ;
lenient_strcat ( buffer , " T[ " ) ;
break ;
break ;
case L_STACKED :
case L_STACKED :
strcpy ( buffer , " S[ " ) ;
lenient_strcat ( buffer , " S[ " ) ;
break ;
break ;
case L_FLOATING :
case L_FLOATING :
strcpy ( buffer , " F[ " ) ;
lenient_strcat ( buffer , " F[ " ) ;
break ;
break ;
case L_NONE :
case L_NONE :
strcpy ( buffer , " D[ " ) ;
lenient_strcat ( buffer , " D[ " ) ;
break ;
break ;
}
}
}
for ( int i = 0 ; i < parent - > children - > length ; + + i ) {
for ( int i = 0 ; i < parent - > children - > length ; + + i ) {
if ( i ! = 0 ) {
if ( i ! = 0 ) {
len + = 1 ;
+ + len ;
if ( buffer ) {
lenient_strcat ( buffer , " " ) ;
strcat ( buffer , " " ) ;
}
}
}
struct sway_container * child = parent - > children - > items [ i ] ;
struct sway_container * child = parent - > children - > items [ i ] ;
const char * identifier = NULL ;
const char * identifier = NULL ;
@ -819,48 +814,39 @@ static size_t concatenate_child_titles(struct sway_container *parent,
identifier = view_get_app_id ( child - > sway_view ) ;
identifier = view_get_app_id ( child - > sway_view ) ;
}
}
} else {
} else {
identifier = child - > nam e;
identifier = child - > formatted_titl e;
}
}
if ( identifier ) {
if ( identifier ) {
len + = strlen ( identifier ) ;
len + = strlen ( identifier ) ;
if ( buffer ) {
lenient_strcat ( buffer , identifier ) ;
strcat ( buffer , identifier ) ;
}
} else {
} else {
len + = 6 ;
len + = 6 ;
if ( buffer ) {
lenient_strcat ( buffer , " (null) " ) ;
strcat ( buffer , " (null) " ) ;
}
}
}
}
}
+ + len ;
lenient_strcat ( buffer , " ] " ) ;
len + = 1 ;
if ( buffer ) {
strcat ( buffer , " ] " ) ;
}
return len ;
return len ;
}
}
void container_notify_ child_titl e_changed( struct sway_container * container ) {
void container_notify_subtree_changed ( struct sway_container * container ) {
if ( ! container | | container - > type ! = C_CONTAINER ) {
if ( ! container | | container - > type ! = C_CONTAINER ) {
return ;
return ;
}
}
if ( container - > formatted_title ) {
free ( container - > formatted_title ) ;
free ( container - > formatted_title ) ;
}
container - > formatted_title = NULL ;
size_t len = concatenate_child_titles ( container , NULL ) ;
size_t len = get_tree_representation ( container , NULL ) ;
char * buffer = calloc ( len + 1 , sizeof ( char ) ) ;
char * buffer = calloc ( len + 1 , sizeof ( char ) ) ;
if ( ! sway_assert ( buffer , " Unable to allocate title string " ) ) {
if ( ! sway_assert ( buffer , " Unable to allocate title string " ) ) {
return ;
return ;
}
}
concatenate_child_titles ( container , buffer ) ;
get_tree_representation ( container , buffer ) ;
container - > name = buffer ;
container - > formatted_title = buffer ;
container - > formatted_title = buffer ;
container_calculate_title_height ( container ) ;
container_calculate_title_height ( container ) ;
container_update_title_textures ( container ) ;
container_update_title_textures ( container ) ;
container_notify_ child_titl e_changed( container - > parent ) ;
container_notify_ subtre e_changed( container - > parent ) ;
}
}
size_t container_titlebar_height ( ) {
size_t container_titlebar_height ( ) {