This commit is contained in:
Christoph Gysin 2015-11-28 23:10:02 +00:00
commit d00d0c2c35
2 changed files with 89 additions and 75 deletions

View file

@ -133,10 +133,6 @@ Commands
Disables the specified output. Disables the specified output.
**NOTES FOR THE OUTPUT COMMAND**:: **NOTES FOR THE OUTPUT COMMAND**::
You may combine output commands into one, like so:
+
output HDMI-A-1 res 1920x1080 pos 1920,0 bg ~/wallpaper.png stretch
+
You can get a list of output names like so: You can get a list of output names like so:
+ +
swaymsg -t get_outputs swaymsg -t get_outputs

View file

@ -711,26 +711,42 @@ static struct cmd_results *cmd_orientation(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
int output_name_cmp(const void *item, const void *data)
{
const struct output_config *output = item;
const char *name = data;
return strcmp(output->name, name);
}
static struct cmd_results *cmd_output(int argc, char **argv) { static struct cmd_results *cmd_output(int argc, char **argv) {
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) { if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) {
return error; return error;
} }
struct output_config *output = calloc(1, sizeof(struct output_config));
const char *name = argv[0];
const char *command = argv[1];
struct output_config *output;
int index = list_seq_find(config->output_configs, output_name_cmp, name);
if (index >= 0) {
output = config->output_configs->items[index];
} else {
output = calloc(1, sizeof(struct output_config));
output->x = output->y = output->width = output->height = -1; output->x = output->y = output->width = output->height = -1;
output->name = strdup(argv[0]); output->name = strdup(name);
output->enabled = true; output->enabled = true;
}
// TODO: atoi doesn't handle invalid numbers // TODO: atoi doesn't handle invalid numbers
if (strcasecmp(argv[1], "disable") == 0) { if (strcasecmp(command, "disable") == 0) {
output->enabled = false; output->enabled = false;
} }
// TODO: Check missing params after each sub-command // TODO: Check missing params after each sub-command
int i; if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) {
for (i = 1; i < argc; ++i) { char *res = argv[2];
if (strcasecmp(argv[i], "resolution") == 0 || strcasecmp(argv[i], "res") == 0) {
char *res = argv[++i];
char *x = strchr(res, 'x'); char *x = strchr(res, 'x');
int width = -1, height = -1; int width = -1, height = -1;
if (x != NULL) { if (x != NULL) {
@ -742,13 +758,13 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
} else { } else {
// Format is 1234 4321 // Format is 1234 4321
width = atoi(res); width = atoi(res);
res = argv[++i]; res = argv[3];
height = atoi(res); height = atoi(res);
} }
output->width = width; output->width = width;
output->height = height; output->height = height;
} else if (strcasecmp(argv[i], "position") == 0 || strcasecmp(argv[i], "pos") == 0) { } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) {
char *res = argv[++i]; char *res = argv[2];
char *c = strchr(res, ','); char *c = strchr(res, ',');
int x = -1, y = -1; int x = -1, y = -1;
if (c != NULL) { if (c != NULL) {
@ -760,15 +776,15 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
} else { } else {
// Format is 1234 4321 // Format is 1234 4321
x = atoi(res); x = atoi(res);
res = argv[++i]; res = argv[3];
y = atoi(res); y = atoi(res);
} }
output->x = x; output->x = x;
output->y = y; output->y = y;
} else if (strcasecmp(argv[i], "bg") == 0 || strcasecmp(argv[i], "background") == 0) { } else if (strcasecmp(command, "bg") == 0 || strcasecmp(command, "background") == 0) {
wordexp_t p; wordexp_t p;
char *src = argv[++i]; char *src = argv[2];
char *mode = argv[++i]; char *mode = argv[3];
if (wordexp(src, &p, 0) != 0) { if (wordexp(src, &p, 0) != 0) {
return cmd_results_new(CMD_INVALID, "output", "Invalid syntax (%s)", src); return cmd_results_new(CMD_INVALID, "output", "Invalid syntax (%s)", src);
} }
@ -793,8 +809,8 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
output->background_option = strdup(mode); output->background_option = strdup(mode);
wordfree(&p); wordfree(&p);
} }
}
int i = 1;
for (i = 0; i < config->output_configs->length; ++i) { for (i = 0; i < config->output_configs->length; ++i) {
struct output_config *oc = config->output_configs->items[i]; struct output_config *oc = config->output_configs->items[i];
if (strcmp(oc->name, output->name) == 0) { if (strcmp(oc->name, output->name) == 0) {
@ -804,7 +820,9 @@ static struct cmd_results *cmd_output(int argc, char **argv) {
break; break;
} }
} }
if (index == -1) {
list_add(config->output_configs, output); list_add(config->output_configs, output);
}
sway_log(L_DEBUG, "Config stored for output %s (%d x %d @ %d, %d) (bg %s %s)", sway_log(L_DEBUG, "Config stored for output %s (%d x %d @ %d, %d) (bg %s %s)",
output->name, output->width, output->height, output->x, output->y, output->name, output->width, output->height, output->x, output->y,