1
0
mirror of https://github.com/emersion/kanshi synced 2024-09-18 09:51:36 +02:00

Allow names to distinguish configurations

This commit is contained in:
Guillaume Maudoux 2019-08-09 14:27:43 +02:00 committed by Simon Ser
parent 823cdb0f6f
commit 15029bd28b
4 changed files with 40 additions and 13 deletions

View File

@ -31,6 +31,7 @@ struct kanshi_profile_output {
struct kanshi_profile {
struct wl_list link;
char *name;
// Wildcard outputs are stored at the end of the list
struct wl_list outputs;
};

View File

@ -6,8 +6,8 @@ kanshi - configuration file
# DESCRIPTION
A kanshi configuration file is a list of profiles. Each profile is delimited by
brackets (*{* and *}*) and contains directives.
A kanshi configuration file is a list of profiles. Each profile starts with an
optional name and contains directives delimited by brackets (*{* and *}*).
Example:
@ -17,7 +17,7 @@ Example:
output "Some Company ASDF 4242" mode 1600x900 position 0,0
}
{
nomad {
output LVDS-1 enable scale 2
}
```

11
main.c
View File

@ -75,7 +75,8 @@ static void config_handle_succeeded(void *data,
struct zwlr_output_configuration_v1 *config) {
struct kanshi_pending_profile *pending = data;
zwlr_output_configuration_v1_destroy(config);
fprintf(stderr, "configuration applied\n");
fprintf(stderr, "configuration for profile '%s' applied\n",
pending->profile->name);
pending->state->current_profile = pending->profile;
free(pending);
}
@ -84,7 +85,8 @@ static void config_handle_failed(void *data,
struct zwlr_output_configuration_v1 *config) {
struct kanshi_pending_profile *pending = data;
zwlr_output_configuration_v1_destroy(config);
fprintf(stderr, "failed to apply configuration\n");
fprintf(stderr, "failed to apply configuration for profile '%s'\n",
pending->profile->name);
free(pending);
}
@ -93,7 +95,8 @@ static void config_handle_cancelled(void *data,
struct kanshi_pending_profile *pending = data;
zwlr_output_configuration_v1_destroy(config);
// Wait for new serial
fprintf(stderr, "configuration cancelled, retrying\n");
fprintf(stderr, "configuration for profile '%s' cancelled, retrying\n",
pending->profile->name);
free(pending);
}
@ -347,7 +350,7 @@ static void output_manager_handle_done(void *data,
struct kanshi_profile_output *matches[HEADS_MAX];
struct kanshi_profile *profile = match(state, matches);
if (profile != NULL) {
fprintf(stderr, "applying profile\n");
fprintf(stderr, "applying profile '%s'\n", profile->name);
apply_profile(state, profile, matches);
} else {
fprintf(stderr, "no profile matched\n");

View File

@ -339,13 +339,36 @@ static struct kanshi_profile_output *parse_profile_output(
}
static struct kanshi_profile *parse_profile(struct kanshi_parser *parser) {
struct kanshi_profile *profile = calloc(1, sizeof(*profile));
wl_list_init(&profile->outputs);
// First parse an optional profile name
parser->tok_str_len = 0;
if (!parser_read_str(parser)) {
fprintf(stderr, "expected new profile, got %s\n",
token_type_str(parser->tok_type));
return NULL;
}
profile->name = (parser->tok_str_len == 0) ? NULL : strdup(parser->tok_str);
// Then parse the opening bracket
if (!parser_expect_token(parser, KANSHI_TOKEN_LBRACKET)) {
return NULL;
}
struct kanshi_profile *profile = calloc(1, sizeof(*profile));
wl_list_init(&profile->outputs);
// Use the bracket position to generate a default profile name
if (profile->name == NULL) {
char generated_name[100];
int ret = snprintf(generated_name, sizeof(generated_name),
"<anonymous at line %d, col %d>", parser->line, parser->col);
if (ret >= 0) {
profile->name = strdup(generated_name);
} else {
profile->name = strdup("<anonymous>");
}
}
// Parse the profile commands until the closing bracket
while (1) {
if (!parser_next_token(parser)) {
return NULL;
@ -369,16 +392,16 @@ static struct kanshi_profile *parse_profile(struct kanshi_parser *parser) {
wl_list_insert(&profile->outputs, &output->link);
}
} else {
fprintf(stderr, "unknown directive '%s' in profile\n",
directive);
fprintf(stderr, "unknown directive '%s' in profile '%s'\n",
directive, profile->name);
return NULL;
}
break;
case KANSHI_TOKEN_NEWLINE:
break; // No-op
default:
fprintf(stderr, "unexpected %s in profile\n",
token_type_str(parser->tok_type));
fprintf(stderr, "unexpected %s in profile '%s'\n",
token_type_str(parser->tok_type), profile->name);
return NULL;
}
}