swayfx/sway/commands/bar/tray_padding.c
M Stoeckl 2a684cad5f Remove now-unused "input" argument of cmd_results_new
Patch tested by compiling with `__attribute__ ((format (printf, 2, 3)))`
applied to `cmd_results_new`.

String usage constants have been converted from pointers to arrays when
encountered. General handler format strings were sometimes modified to
include the old input string, especially for unknown command errors.
2019-01-14 08:05:29 -05:00

43 lines
1.2 KiB
C

#include <stdlib.h>
#include <strings.h>
#include "config.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "log.h"
struct cmd_results *bar_cmd_tray_padding(int argc, char **argv) {
#if HAVE_TRAY
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_LEAST, 1))) {
return error;
}
if ((error = checkarg(argc, "tray_padding", EXPECTED_AT_MOST, 2))) {
return error;
}
if (!config->current_bar) {
return cmd_results_new(CMD_FAILURE, "No bar defined.");
}
struct bar_config *bar = config->current_bar;
char *end;
int padding = strtol(argv[0], &end, 10);
if (padding < 0 || (*end != '\0' && strcasecmp(end, "px") != 0)) {
return cmd_results_new(CMD_INVALID,
"[Bar %s] Invalid tray padding value: %s", bar->id, argv[0]);
}
if (argc == 2 && strcasecmp(argv[1], "px") != 0) {
return cmd_results_new(CMD_INVALID,
"Expected 'tray_padding <px> [px]'");
}
wlr_log(WLR_DEBUG, "[Bar %s] Setting tray padding to %d", bar->id, padding);
config->current_bar->tray_padding = padding;
return cmd_results_new(CMD_SUCCESS, NULL);
#else
return cmd_results_new(CMD_INVALID,
"Sway has been compiled without tray support");
#endif
}