@ -348,7 +348,6 @@ struct sway_container *container_view_create(struct sway_container *sibling,
swayc , title , sibling , sibling ? sibling - > type : 0 , sibling - > name ) ;
swayc , title , sibling , sibling ? sibling - > type : 0 , sibling - > name ) ;
// Setup values
// Setup values
swayc - > sway_view = sway_view ;
swayc - > sway_view = sway_view ;
container_update_title ( swayc , title ) ;
swayc - > width = 0 ;
swayc - > width = 0 ;
swayc - > height = 0 ;
swayc - > height = 0 ;
@ -572,7 +571,7 @@ static void update_title_texture(struct sway_container *con,
if ( * texture ) {
if ( * texture ) {
wlr_texture_destroy ( * texture ) ;
wlr_texture_destroy ( * texture ) ;
}
}
if ( ! con - > nam e) {
if ( ! con - > formatted_titl e) {
return ;
return ;
}
}
@ -581,7 +580,8 @@ static void update_title_texture(struct sway_container *con,
int height = config - > font_height * scale ;
int height = config - > font_height * scale ;
cairo_t * c = cairo_create ( NULL ) ;
cairo_t * c = cairo_create ( NULL ) ;
get_text_size ( c , config - > font , & width , NULL , scale , false , " %s " , con - > name ) ;
get_text_size ( c , config - > font , & width , NULL , scale , false ,
" %s " , con - > formatted_title ) ;
cairo_destroy ( c ) ;
cairo_destroy ( c ) ;
cairo_surface_t * surface = cairo_image_surface_create (
cairo_surface_t * surface = cairo_image_surface_create (
@ -596,7 +596,7 @@ static void update_title_texture(struct sway_container *con,
class - > text [ 2 ] , class - > text [ 3 ] ) ;
class - > text [ 2 ] , class - > text [ 3 ] ) ;
cairo_move_to ( cairo , 0 , 0 ) ;
cairo_move_to ( cairo , 0 , 0 ) ;
pango_printf ( cairo , config - > font , scale , false , " %s " , con - > nam e) ;
pango_printf ( cairo , config - > font , scale , false , " %s " , con - > formatted_titl e) ;
cairo_surface_flush ( surface ) ;
cairo_surface_flush ( surface ) ;
unsigned char * data = cairo_image_surface_get_data ( surface ) ;
unsigned char * data = cairo_image_surface_get_data ( surface ) ;
@ -622,57 +622,31 @@ void container_update_title_textures(struct sway_container *container) {
}
}
void container_calculate_title_height ( struct sway_container * container ) {
void container_calculate_title_height ( struct sway_container * container ) {
if ( ! container - > nam e) {
if ( ! container - > formatted_titl e) {
container - > title_height = 0 ;
container - > title_height = 0 ;
return ;
return ;
}
}
cairo_t * cairo = cairo_create ( NULL ) ;
cairo_t * cairo = cairo_create ( NULL ) ;
int height ;
int height ;
get_text_size ( cairo , config - > font , NULL , & height , 1 , false ,
get_text_size ( cairo , config - > font , NULL , & height , 1 , false ,
" %s " , container - > nam e) ;
" %s " , container - > formatted_titl e) ;
cairo_destroy ( cairo ) ;
cairo_destroy ( cairo ) ;
container - > title_height = height ;
container - > title_height = height ;
}
}
static void container_notify_child_title_changed (
void container_notify_child_title_changed ( struct sway_container * container ) {
struct sway_container * container ) {
if ( ! container | | container - > type ! = C_CONTAINER ) {
if ( ! container | | container - > type ! = C_CONTAINER ) {
return ;
return ;
}
}
if ( container - > layout ! = L_TABBED & & container - > layout ! = L_STACKED ) {
if ( container - > layout ! = L_TABBED & & container - > layout ! = L_STACKED ) {
return ;
return ;
}
}
if ( container - > nam e) {
if ( container - > formatted_titl e) {
free ( container - > nam e) ;
free ( container - > formatted_titl e) ;
}
}
// TODO: iterate children and concatenate their titles
// TODO: iterate children and concatenate their titles
container - > nam e = strdup ( " " ) ;
container - > formatted_titl e = strdup ( " " ) ;
container_calculate_title_height ( container ) ;
container_calculate_title_height ( container ) ;
container_update_title_textures ( container ) ;
container_update_title_textures ( container ) ;
container_notify_child_title_changed ( container - > parent ) ;
container_notify_child_title_changed ( container - > parent ) ;
}
}
void container_update_title ( struct sway_container * container ,
const char * new_title ) {
if ( ! new_title ) {
new_title = " " ;
}
if ( container - > name & & strcmp ( container - > name , new_title ) = = 0 ) {
return ;
}
if ( container - > name ) {
free ( container - > name ) ;
}
container - > name = strdup ( new_title ) ;
container_calculate_title_height ( container ) ;
container_update_title_textures ( container ) ;
container_notify_child_title_changed ( container - > parent ) ;
size_t prev_max_height = config - > font_height ;
config_find_font_height ( false ) ;
if ( config - > font_height ! = prev_max_height ) {
arrange_root ( ) ;
}
}