Refactor output configuration

* Allow independent rotation of different outputs
  * Allow specification of scale independent of mode
  * Clean up output configuration code
This commit is contained in:
project-repo 2022-12-26 08:14:57 +01:00
commit 32095b4253
5 changed files with 175 additions and 86 deletions

47
parse.c
View file

@ -509,6 +509,10 @@ parse_output_config_keyword(char *key_str, enum output_status *status) {
*status = OUTPUT_DEFAULT;
} else if(strcmp(key_str, "prio") == 0) {
*status = OUTPUT_DEFAULT;
} else if(strcmp(key_str, "angle") == 0) {
*status = OUTPUT_DEFAULT;
} else if(strcmp(key_str, "scale") == 0) {
*status = OUTPUT_DEFAULT;
} else if(strcmp(key_str, "enable") == 0) {
*status = OUTPUT_ENABLE;
} else if(strcmp(key_str, "disable") == 0) {
@ -532,7 +536,8 @@ parse_output_config(char **saveptr, char **errstr) {
cfg->output_name = NULL;
cfg->refresh_rate = 0;
cfg->priority = -1;
cfg->scale = NULL;
cfg->scale = -1;
cfg->angle = -1;
char *name = strtok_r(NULL, " ", saveptr);
if(name == NULL) {
*errstr =
@ -551,6 +556,20 @@ parse_output_config(char **saveptr, char **errstr) {
return cfg;
}
if(strcmp(key_str, "angle") == 0) {
uint32_t angle = parse_uint(saveptr, " ");
//360 degrees is equivalent to 0 degrees
cfg->angle = angle%4;
if(cfg->angle < 0) {
*errstr = log_error(
"Error parsing angle specification for output %s",
name);
goto error;
}
cfg->output_name=strdup(name);
return cfg;
}
if(strcmp(key_str, "prio") == 0) {
cfg->priority = parse_uint(saveptr, " ");
if(cfg->priority < 0) {
@ -563,6 +582,19 @@ parse_output_config(char **saveptr, char **errstr) {
return cfg;
}
if(strcmp(key_str, "scale") == 0) {
cfg->scale = parse_float(saveptr, " ");
if(cfg->scale <= 0.0) {
*errstr =
log_error("Error parsing scale of output configuration for "
"output %s, expected positive float",
name);
goto error;
}
cfg->output_name = strdup(name);
return cfg;
}
cfg->pos.x = parse_uint(saveptr, " ");
if(cfg->pos.x < 0) {
*errstr = log_error(
@ -620,19 +652,6 @@ parse_output_config(char **saveptr, char **errstr) {
goto error;
}
char *scale_str = strtok_r(NULL, " ", saveptr);
if(scale_str != NULL && strcmp(scale_str, "scale") == 0) {
cfg->scale = malloc(sizeof(float));
*cfg->scale = parse_float(saveptr, " ");
if(*cfg->scale <= 0.0) {
*errstr =
log_error("Error parsing scale of output configuration for "
"output %s, expected positive float",
name);
goto error;
}
}
cfg->output_name = strdup(name);
return cfg;
error: