Introduce a way to show config warnings in swaynag
Adds the function `config_add_swaynag_warning(char *fmt, ...)` so that handlers can add warnings to the swaynag config log in a uniform way. The formatting is identical to errors and include the line number, line, and config path. This also alters the background file access warning to use the function and introduces a warning for duplicate bindings.
This commit is contained in:
parent
a22d0c0ff6
commit
e5f90f25d7
|
@ -425,6 +425,8 @@ struct sway_config {
|
||||||
list_t *config_chain;
|
list_t *config_chain;
|
||||||
const char *current_config_path;
|
const char *current_config_path;
|
||||||
const char *current_config;
|
const char *current_config;
|
||||||
|
int current_config_line_number;
|
||||||
|
char *current_config_line;
|
||||||
|
|
||||||
enum sway_container_border border;
|
enum sway_container_border border;
|
||||||
enum sway_container_border floating_border;
|
enum sway_container_border floating_border;
|
||||||
|
@ -489,6 +491,11 @@ bool load_include_configs(const char *path, struct sway_config *config,
|
||||||
bool read_config(FILE *file, struct sway_config *config,
|
bool read_config(FILE *file, struct sway_config *config,
|
||||||
struct swaynag_instance *swaynag);
|
struct swaynag_instance *swaynag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a warning entry to the swaynag instance used for errors.
|
||||||
|
*/
|
||||||
|
void config_add_swaynag_warning(char *fmt, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free config struct
|
* Free config struct
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -255,8 +255,12 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
|
||||||
for (int i = 0; i < mode_bindings->length; ++i) {
|
for (int i = 0; i < mode_bindings->length; ++i) {
|
||||||
struct sway_binding *config_binding = mode_bindings->items[i];
|
struct sway_binding *config_binding = mode_bindings->items[i];
|
||||||
if (binding_key_compare(binding, config_binding)) {
|
if (binding_key_compare(binding, config_binding)) {
|
||||||
wlr_log(WLR_DEBUG, "overwriting old binding with command '%s'",
|
wlr_log(WLR_INFO, "Overwriting binding '%s' for device '%s' "
|
||||||
config_binding->command);
|
"from `%s` to `%s`", argv[0], binding->input,
|
||||||
|
binding->command, config_binding->command);
|
||||||
|
config_add_swaynag_warning("Overwriting binding '%s' for device "
|
||||||
|
"'%s' to `%s` from `%s`", argv[0], binding->input,
|
||||||
|
binding->command, config_binding->command);
|
||||||
free_sway_binding(config_binding);
|
free_sway_binding(config_binding);
|
||||||
mode_bindings->items[i] = binding;
|
mode_bindings->items[i] = binding;
|
||||||
overwritten = true;
|
overwritten = true;
|
||||||
|
|
|
@ -116,11 +116,8 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
|
||||||
if (!can_access) {
|
if (!can_access) {
|
||||||
wlr_log(WLR_ERROR, "Unable to access background file '%s': %s",
|
wlr_log(WLR_ERROR, "Unable to access background file '%s': %s",
|
||||||
src, strerror(errno));
|
src, strerror(errno));
|
||||||
if (config->reading && !config->validating) {
|
config_add_swaynag_warning("Unable to access background file '%s'",
|
||||||
swaynag_log(config->swaynag_command,
|
src);
|
||||||
&config->swaynag_config_errors,
|
|
||||||
"Unable to access background file '%s'", src);
|
|
||||||
}
|
|
||||||
free(src);
|
free(src);
|
||||||
} else {
|
} else {
|
||||||
// Escape double quotes in the final path for swaybg
|
// Escape double quotes in the final path for swaybg
|
||||||
|
|
|
@ -700,6 +700,8 @@ bool read_config(FILE *file, struct sway_config *config,
|
||||||
free(line);
|
free(line);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
config->current_config_line_number = line_number;
|
||||||
|
config->current_config_line = line;
|
||||||
struct cmd_results *res;
|
struct cmd_results *res;
|
||||||
if (block && strcmp(block, "<commands>") == 0) {
|
if (block && strcmp(block, "<commands>") == 0) {
|
||||||
// Special case
|
// Special case
|
||||||
|
@ -761,10 +763,36 @@ bool read_config(FILE *file, struct sway_config *config,
|
||||||
}
|
}
|
||||||
list_foreach(stack, free);
|
list_foreach(stack, free);
|
||||||
list_free(stack);
|
list_free(stack);
|
||||||
|
config->current_config_line_number = 0;
|
||||||
|
config->current_config_line = NULL;
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void config_add_swaynag_warning(char *fmt, ...) {
|
||||||
|
if (config->reading && !config->validating) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
size_t length = vsnprintf(NULL, 0, fmt, args) + 1;
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
char *temp = malloc(length + 1);
|
||||||
|
if (!temp) {
|
||||||
|
wlr_log(WLR_ERROR, "Failed to allocate buffer for warning.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
vsnprintf(temp, length, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
swaynag_log(config->swaynag_command, &config->swaynag_config_errors,
|
||||||
|
"Warning on line %i (%s) '%s': %s",
|
||||||
|
config->current_config_line_number, config->current_config_path,
|
||||||
|
config->current_config_line, temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char *do_var_replacement(char *str) {
|
char *do_var_replacement(char *str) {
|
||||||
int i;
|
int i;
|
||||||
char *find = str;
|
char *find = str;
|
||||||
|
|
Loading…
Reference in a new issue