@ -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[
switch ( parent - > layout ) {
if ( buffer ) {
case L_VERT :
switch ( parent - > layout ) {
lenient_strcat ( buffer , " V[ " ) ;
case L_VERT :
break ;
strcpy ( buffer , " V[ " ) ;
case L_HORIZ :
break ;
lenient_strcat ( buffer , " H[ " ) ;
case L_HORIZ :
break ;
strcpy ( buffer , " H[ " ) ;
case L_TABBED :
break ;
lenient_strcat ( buffer , " T[ " ) ;
case L_TABBED :
break ;
strcpy ( buffer , " T[ " ) ;
case L_STACKED :
break ;
lenient_strcat ( buffer , " S[ " ) ;
case L_STACKED :
break ;
strcpy ( buffer , " S[ " ) ;
case L_FLOATING :
break ;
lenient_strcat ( buffer , " F[ " ) ;
case L_FLOATING :
break ;
strcpy ( buffer , " F[ " ) ;
case L_NONE :
break ;
lenient_strcat ( buffer , " D[ " ) ;
case L_NONE :
break ;
strcpy ( buffer , " D[ " ) ;
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 ;
len + = 1 ;
lenient_strcat ( buffer , " ] " ) ;
if ( buffer ) {
strcat ( buffer , " ] " ) ;
}
return len ;
return len ;
}
}
void container_notify_ child_titl e_changed( struct sway_container * container ) {
void container_notify_ subtre e_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 ( ) {