mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 16:01:27 +00:00
Replace refresh_rate and position by mode in output command
This commit is contained in:
parent
ec2fd6e5c0
commit
4d389f8b65
|
@ -42,61 +42,84 @@ struct cmd_results *cmd_output(int argc, char **argv) {
|
||||||
|
|
||||||
if (strcasecmp(command, "disable") == 0) {
|
if (strcasecmp(command, "disable") == 0) {
|
||||||
output->enabled = 0;
|
output->enabled = 0;
|
||||||
} else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) {
|
} else if (strcasecmp(command, "mode") == 0 ||
|
||||||
|
strcasecmp(command, "resolution") == 0 ||
|
||||||
|
strcasecmp(command, "res") == 0) {
|
||||||
if (++i >= argc) {
|
if (++i >= argc) {
|
||||||
error = cmd_results_new(CMD_INVALID, "output", "Missing resolution argument.");
|
error = cmd_results_new(CMD_INVALID, "output",
|
||||||
|
"Missing mode argument.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
char *res = argv[i];
|
|
||||||
char *x = strchr(res, 'x');
|
|
||||||
int width = -1, height = -1;
|
int width = -1, height = -1;
|
||||||
if (x != NULL) {
|
float refresh_rate = -1;
|
||||||
|
|
||||||
|
char *end;
|
||||||
|
width = strtol(argv[i], &end, 10);
|
||||||
|
if (*end) {
|
||||||
// Format is 1234x4321
|
// Format is 1234x4321
|
||||||
*x = '\0';
|
if (*end != 'x') {
|
||||||
width = atoi(res);
|
error = cmd_results_new(CMD_INVALID, "output",
|
||||||
height = atoi(x + 1);
|
"Invalid mode width.");
|
||||||
*x = 'x';
|
goto fail;
|
||||||
} else {
|
}
|
||||||
// Format is 1234 4321
|
++end;
|
||||||
width = atoi(res);
|
height = strtol(end, &end, 10);
|
||||||
if (++i >= argc) {
|
if (*end) {
|
||||||
error = cmd_results_new(CMD_INVALID, "output", "Missing resolution argument (height).");
|
if (*end != '@') {
|
||||||
|
error = cmd_results_new(CMD_INVALID, "output",
|
||||||
|
"Invalid mode height.");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
++end;
|
||||||
|
refresh_rate = strtof(end, &end);
|
||||||
|
if (strcasecmp("Hz", end) != 0) {
|
||||||
|
error = cmd_results_new(CMD_INVALID, "output",
|
||||||
|
"Invalid mode refresh rate.");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Format is 1234 4321 (legacy)
|
||||||
|
++i;
|
||||||
|
if (i >= argc) {
|
||||||
|
error = cmd_results_new(CMD_INVALID, "output",
|
||||||
|
"Missing mode argument (height).");
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
height = strtol(argv[i], &end, 10);
|
||||||
|
if (*end) {
|
||||||
|
error = cmd_results_new(CMD_INVALID, "output",
|
||||||
|
"Invalid mode height.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
res = argv[i];
|
|
||||||
height = atoi(res);
|
|
||||||
}
|
}
|
||||||
output->width = width;
|
output->width = width;
|
||||||
output->height = height;
|
output->height = height;
|
||||||
} else if (strcasecmp(command, "refresh_rate") == 0) {
|
output->refresh_rate = refresh_rate;
|
||||||
if (++i >= argc) {
|
|
||||||
error = cmd_results_new(CMD_INVALID, "output", "Missing refresh_rate argument.");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
output->refresh_rate = atof(argv[i]);
|
|
||||||
} else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) {
|
} else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) {
|
||||||
if (++i >= argc) {
|
if (++i >= argc) {
|
||||||
error = cmd_results_new(CMD_INVALID, "output", "Missing position argument.");
|
error = cmd_results_new(CMD_INVALID, "output", "Missing position argument.");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
char *res = argv[i];
|
char *pos = argv[i];
|
||||||
char *c = strchr(res, ',');
|
char *c = strchr(pos, ',');
|
||||||
int x = -1, y = -1;
|
int x = -1, y = -1;
|
||||||
if (c != NULL) {
|
if (c != NULL) {
|
||||||
// Format is 1234,4321
|
// Format is 1234,4321
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
x = atoi(res);
|
x = atoi(pos);
|
||||||
y = atoi(c + 1);
|
y = atoi(c + 1);
|
||||||
*c = ',';
|
*c = ',';
|
||||||
} else {
|
} else {
|
||||||
// Format is 1234 4321
|
// Format is 1234 4321
|
||||||
x = atoi(res);
|
x = atoi(pos);
|
||||||
if (++i >= argc) {
|
if (++i >= argc) {
|
||||||
error = cmd_results_new(CMD_INVALID, "output", "Missing position argument (y).");
|
error = cmd_results_new(CMD_INVALID, "output", "Missing position argument (y).");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
res = argv[i];
|
pos = argv[i];
|
||||||
y = atoi(res);
|
y = atoi(pos);
|
||||||
}
|
}
|
||||||
output->x = x;
|
output->x = x;
|
||||||
output->y = y;
|
output->y = y;
|
||||||
|
@ -218,11 +241,11 @@ struct cmd_results *cmd_output(int argc, char **argv) {
|
||||||
list_add(config->output_configs, output);
|
list_add(config->output_configs, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ "
|
sway_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
|
||||||
"%d, %d scale %d transform %d refresh_rate %f) (bg %s %s)",
|
"position %d,%d scale %d transform %d) (bg %s %s)",
|
||||||
output->name, output->enabled, output->width,
|
output->name, output->enabled, output->width,
|
||||||
output->height, output->x, output->y, output->scale,
|
output->height, output->refresh_rate, output->x, output->y,
|
||||||
output->transform, output->refresh_rate,
|
output->scale, output->transform,
|
||||||
output->background, output->background_option);
|
output->background, output->background_option);
|
||||||
|
|
||||||
if (output->name) {
|
if (output->name) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ struct output_config *new_output_config() {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
oc->enabled = -1;
|
oc->enabled = -1;
|
||||||
oc->width = oc->height -1;
|
oc->width = oc->height = -1;
|
||||||
oc->refresh_rate = -1;
|
oc->refresh_rate = -1;
|
||||||
oc->x = oc->y = -1;
|
oc->x = oc->y = -1;
|
||||||
oc->scale = -1;
|
oc->scale = -1;
|
||||||
|
|
Loading…
Reference in a new issue