mirror of
https://github.com/emersion/kanshi
synced 2024-11-22 15:51:58 +01:00
Require profiles with a name to have a profile directive
Also make the syntax without a "profile" directive legacy by removing docs for it. Closes: https://github.com/emersion/kanshi/issues/75
This commit is contained in:
parent
dc9f4c8fc3
commit
ef4c7f083d
@ -6,18 +6,18 @@ kanshi - configuration file
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
A kanshi configuration file is a list of profiles. Each profile starts with an
|
||||
A kanshi configuration file is a list of profiles. Each profile has an
|
||||
optional name and contains directives delimited by brackets (*{* and *}*).
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
{
|
||||
profile {
|
||||
output LVDS-1 disable
|
||||
output "Some Company ASDF 4242" mode 1600x900 position 0,0
|
||||
}
|
||||
|
||||
nomad {
|
||||
profile nomad {
|
||||
output LVDS-1 enable scale 2
|
||||
}
|
||||
```
|
||||
@ -65,7 +65,6 @@ Directives are followed by space-separated arguments. Arguments can be quoted
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# OUTPUT DIRECTIVES
|
||||
|
||||
*enable*|*disable*
|
||||
@ -96,7 +95,6 @@ Directives are followed by space-separated arguments. Arguments can be quoted
|
||||
or "flipped", "flipped-90", "flipped-180", "flipped-270" for a rotation and
|
||||
a flip; or "normal" for no transform.
|
||||
|
||||
|
||||
# AUTHORS
|
||||
|
||||
Maintained by Simon Ser <contact@emersion.fr>, who is assisted by other
|
||||
|
52
parser.c
52
parser.c
@ -400,18 +400,23 @@ static struct kanshi_profile *parse_profile(struct kanshi_parser *parser) {
|
||||
wl_list_init(&profile->outputs);
|
||||
wl_list_init(&profile->commands);
|
||||
|
||||
// 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));
|
||||
if (!parser_next_token(parser)) {
|
||||
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;
|
||||
switch (parser->tok_type) {
|
||||
case KANSHI_TOKEN_LBRACKET:
|
||||
break;
|
||||
case KANSHI_TOKEN_STR:
|
||||
// Parse an optional profile name
|
||||
profile->name = strdup(parser->tok_str);
|
||||
if (!parser_expect_token(parser, KANSHI_TOKEN_LBRACKET)) {
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unexpected %s, expected '{' or a profile name\n",
|
||||
token_type_str(parser->tok_type));
|
||||
}
|
||||
|
||||
// Use the bracket position to generate a default profile name
|
||||
@ -491,13 +496,30 @@ static struct kanshi_config *_parse_config(struct kanshi_parser *parser) {
|
||||
continue;
|
||||
}
|
||||
|
||||
struct kanshi_profile *profile = parse_profile(parser);
|
||||
if (!profile) {
|
||||
return NULL;
|
||||
}
|
||||
if (ch == '{') {
|
||||
// Legacy profile syntax without a profile directive
|
||||
struct kanshi_profile *profile = parse_profile(parser);
|
||||
if (!profile) {
|
||||
return NULL;
|
||||
}
|
||||
wl_list_insert(config->profiles.prev, &profile->link);
|
||||
} else {
|
||||
if (!parser_expect_token(parser, KANSHI_TOKEN_STR)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Inset at the end to preserve ordering
|
||||
wl_list_insert(config->profiles.prev, &profile->link);
|
||||
const char *directive = parser->tok_str;
|
||||
if (strcmp(parser->tok_str, "profile") == 0) {
|
||||
struct kanshi_profile *profile = parse_profile(parser);
|
||||
if (!profile) {
|
||||
return NULL;
|
||||
}
|
||||
wl_list_insert(config->profiles.prev, &profile->link);
|
||||
} else {
|
||||
fprintf(stderr, "unknown directive '%s'\n", directive);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user