@ -33,16 +33,17 @@ struct workspace_config *workspace_find_config(const char *ws_name) {
struct sway_output * workspace_get_initial_output ( const char * name ) {
struct sway_output * workspace_get_initial_output ( const char * name ) {
// Check workspace configs for a workspace<->output pair
// Check workspace configs for a workspace<->output pair
struct workspace_config * wsc = workspace_find_config ( name ) ;
struct workspace_config * wsc = workspace_find_config ( name ) ;
if ( wsc & & wsc - > output ) {
if ( wsc ) {
struct sway_output * output = output_by_name ( wsc - > output ) ;
for ( int i = 0 ; i < wsc - > outputs - > length ; i + + ) {
struct sway_output * output = output_by_name ( wsc - > outputs - > items [ i ] ) ;
if ( ! output ) {
if ( ! output ) {
output = output_by_identifier ( wsc - > output ) ;
output = output_by_identifier ( wsc - > output s- > items [ i ] ) ;
}
}
if ( output ) {
if ( output ) {
return output ;
return output ;
}
}
}
}
}
// Otherwise put it on the focused output
// Otherwise put it on the focused output
struct sway_seat * seat = input_manager_current_seat ( ) ;
struct sway_seat * seat = input_manager_current_seat ( ) ;
struct sway_workspace * focus = seat_get_focused_workspace ( seat ) ;
struct sway_workspace * focus = seat_get_focused_workspace ( seat ) ;
@ -85,7 +86,6 @@ struct sway_workspace *workspace_create(struct sway_output *output,
ws - > floating = create_list ( ) ;
ws - > floating = create_list ( ) ;
ws - > tiling = create_list ( ) ;
ws - > tiling = create_list ( ) ;
ws - > output_priority = create_list ( ) ;
ws - > output_priority = create_list ( ) ;
workspace_output_add_priority ( ws , output ) ;
ws - > gaps_outer = config - > gaps_outer ;
ws - > gaps_outer = config - > gaps_outer ;
ws - > gaps_inner = config - > gaps_inner ;
ws - > gaps_inner = config - > gaps_inner ;
@ -110,9 +110,17 @@ struct sway_workspace *workspace_create(struct sway_output *output,
// Since default outer gaps can be smaller than the negation of
// Since default outer gaps can be smaller than the negation of
// workspace specific inner gaps, check outer gaps again
// workspace specific inner gaps, check outer gaps again
prevent_invalid_outer_gaps ( ws ) ;
prevent_invalid_outer_gaps ( ws ) ;
// Add output priorities
for ( int i = 0 ; i < wsc - > outputs - > length ; + + i ) {
list_add ( ws - > output_priority , strdup ( wsc - > outputs - > items [ i ] ) ) ;
}
}
}
}
}
// If not already added, add the output to the lowest priority
workspace_output_add_priority ( ws , output ) ;
output_add_workspace ( output , ws ) ;
output_add_workspace ( output , ws ) ;
output_sort_workspaces ( output ) ;
output_sort_workspaces ( output ) ;
@ -134,8 +142,7 @@ void workspace_destroy(struct sway_workspace *workspace) {
free ( workspace - > name ) ;
free ( workspace - > name ) ;
free ( workspace - > representation ) ;
free ( workspace - > representation ) ;
list_foreach ( workspace - > output_priority , free ) ;
free_flat_list ( workspace - > output_priority ) ;
list_free ( workspace - > output_priority ) ;
list_free ( workspace - > floating ) ;
list_free ( workspace - > floating ) ;
list_free ( workspace - > tiling ) ;
list_free ( workspace - > tiling ) ;
list_free ( workspace - > current . floating ) ;
list_free ( workspace - > current . floating ) ;
@ -178,7 +185,18 @@ static bool workspace_valid_on_output(const char *output_name,
struct sway_output * output = output_by_name ( output_name ) ;
struct sway_output * output = output_by_name ( output_name ) ;
output_get_identifier ( identifier , sizeof ( identifier ) , output ) ;
output_get_identifier ( identifier , sizeof ( identifier ) , output ) ;
return ! wsc | | ! wsc - > output | | strcmp ( wsc - > output , output_name ) = = 0 | | strcasecmp ( identifier , output_name ) = = 0 ;
if ( ! wsc ) {
return true ;
}
for ( int i = 0 ; i < wsc - > outputs - > length ; i + + ) {
if ( strcmp ( wsc - > outputs - > items [ i ] , output_name ) = = 0 | |
strcmp ( wsc - > outputs - > items [ i ] , identifier ) = = 0 ) {
return true ;
}
}
return false ;
}
}
static void workspace_name_from_binding ( const struct sway_binding * binding ,
static void workspace_name_from_binding ( const struct sway_binding * binding ,
@ -281,13 +299,22 @@ char *workspace_next_name(const char *output_name) {
for ( int i = 0 ; i < config - > workspace_configs - > length ; + + i ) {
for ( int i = 0 ; i < config - > workspace_configs - > length ; + + i ) {
// Unlike with bindings, this does not guarantee order
// Unlike with bindings, this does not guarantee order
const struct workspace_config * wsc = config - > workspace_configs - > items [ i ] ;
const struct workspace_config * wsc = config - > workspace_configs - > items [ i ] ;
if ( wsc - > output & & strcmp ( wsc - > output , output_name ) = = 0
if ( workspace_by_name ( wsc - > workspace ) ) {
& & workspace_by_name ( wsc - > workspace ) = = NULL ) {
continue ;
}
bool found = false ;
for ( int j = 0 ; j < wsc - > outputs - > length ; + + j ) {
if ( strcmp ( wsc - > outputs - > items [ j ] , output_name ) = = 0 ) {
found = true ;
free ( target ) ;
free ( target ) ;
target = strdup ( wsc - > workspace ) ;
target = strdup ( wsc - > workspace ) ;
break ;
break ;
}
}
}
}
if ( found ) {
break ;
}
}
if ( target ! = NULL ) {
if ( target ! = NULL ) {
return target ;
return target ;
}
}