aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/output.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2017-12-14 00:45:47 +0100
committerLibravatar emersion <contact@emersion.fr>2017-12-14 00:45:47 +0100
commit4d389f8b6523af741761009effd4d6dd79156afe (patch)
tree165eb772674068ab1c06bf6b3bd407a3335901cf /sway/commands/output.c
parentHandle output remove (diff)
downloadsway-4d389f8b6523af741761009effd4d6dd79156afe.tar.gz
sway-4d389f8b6523af741761009effd4d6dd79156afe.tar.zst
sway-4d389f8b6523af741761009effd4d6dd79156afe.zip
Replace refresh_rate and position by mode in output command
Diffstat (limited to 'sway/commands/output.c')
-rw-r--r--sway/commands/output.c85
1 files changed, 54 insertions, 31 deletions
diff --git a/sway/commands/output.c b/sway/commands/output.c
index 23792855..daaacad7 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -42,61 +42,84 @@ struct cmd_results *cmd_output(int argc, char **argv) {
42 42
43 if (strcasecmp(command, "disable") == 0) { 43 if (strcasecmp(command, "disable") == 0) {
44 output->enabled = 0; 44 output->enabled = 0;
45 } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) { 45 } else if (strcasecmp(command, "mode") == 0 ||
46 strcasecmp(command, "resolution") == 0 ||
47 strcasecmp(command, "res") == 0) {
46 if (++i >= argc) { 48 if (++i >= argc) {
47 error = cmd_results_new(CMD_INVALID, "output", "Missing resolution argument."); 49 error = cmd_results_new(CMD_INVALID, "output",
50 "Missing mode argument.");
48 goto fail; 51 goto fail;
49 } 52 }
50 char *res = argv[i]; 53
51 char *x = strchr(res, 'x');
52 int width = -1, height = -1; 54 int width = -1, height = -1;
53 if (x != NULL) { 55 float refresh_rate = -1;
56
57 char *end;
58 width = strtol(argv[i], &end, 10);
59 if (*end) {
54 // Format is 1234x4321 60 // Format is 1234x4321
55 *x = '\0'; 61 if (*end != 'x') {
56 width = atoi(res); 62 error = cmd_results_new(CMD_INVALID, "output",
57 height = atoi(x + 1); 63 "Invalid mode width.");
58 *x = 'x'; 64 goto fail;
65 }
66 ++end;
67 height = strtol(end, &end, 10);
68 if (*end) {
69 if (*end != '@') {
70 error = cmd_results_new(CMD_INVALID, "output",
71 "Invalid mode height.");
72 goto fail;
73 }
74 ++end;
75 refresh_rate = strtof(end, &end);
76 if (strcasecmp("Hz", end) != 0) {
77 error = cmd_results_new(CMD_INVALID, "output",
78 "Invalid mode refresh rate.");
79 goto fail;
80 }
81 }
59 } else { 82 } else {
60 // Format is 1234 4321 83 // Format is 1234 4321 (legacy)
61 width = atoi(res); 84 ++i;
62 if (++i >= argc) { 85 if (i >= argc) {
63 error = cmd_results_new(CMD_INVALID, "output", "Missing resolution argument (height)."); 86 error = cmd_results_new(CMD_INVALID, "output",
87 "Missing mode argument (height).");
88 goto fail;
89 }
90 height = strtol(argv[i], &end, 10);
91 if (*end) {
92 error = cmd_results_new(CMD_INVALID, "output",
93 "Invalid mode height.");
64 goto fail; 94 goto fail;
65 } 95 }
66 res = argv[i];
67 height = atoi(res);
68 } 96 }
69 output->width = width; 97 output->width = width;
70 output->height = height; 98 output->height = height;
71 } else if (strcasecmp(command, "refresh_rate") == 0) { 99 output->refresh_rate = refresh_rate;
72 if (++i >= argc) {
73 error = cmd_results_new(CMD_INVALID, "output", "Missing refresh_rate argument.");
74 goto fail;
75 }
76 output->refresh_rate = atof(argv[i]);
77 } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) { 100 } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) {
78 if (++i >= argc) { 101 if (++i >= argc) {
79 error = cmd_results_new(CMD_INVALID, "output", "Missing position argument."); 102 error = cmd_results_new(CMD_INVALID, "output", "Missing position argument.");
80 goto fail; 103 goto fail;
81 } 104 }
82 char *res = argv[i]; 105 char *pos = argv[i];
83 char *c = strchr(res, ','); 106 char *c = strchr(pos, ',');
84 int x = -1, y = -1; 107 int x = -1, y = -1;
85 if (c != NULL) { 108 if (c != NULL) {
86 // Format is 1234,4321 109 // Format is 1234,4321
87 *c = '\0'; 110 *c = '\0';
88 x = atoi(res); 111 x = atoi(pos);
89 y = atoi(c + 1); 112 y = atoi(c + 1);
90 *c = ','; 113 *c = ',';
91 } else { 114 } else {
92 // Format is 1234 4321 115 // Format is 1234 4321
93 x = atoi(res); 116 x = atoi(pos);
94 if (++i >= argc) { 117 if (++i >= argc) {
95 error = cmd_results_new(CMD_INVALID, "output", "Missing position argument (y)."); 118 error = cmd_results_new(CMD_INVALID, "output", "Missing position argument (y).");
96 goto fail; 119 goto fail;
97 } 120 }
98 res = argv[i]; 121 pos = argv[i];
99 y = atoi(res); 122 y = atoi(pos);
100 } 123 }
101 output->x = x; 124 output->x = x;
102 output->y = y; 125 output->y = y;
@@ -218,11 +241,11 @@ struct cmd_results *cmd_output(int argc, char **argv) {
218 list_add(config->output_configs, output); 241 list_add(config->output_configs, output);
219 } 242 }
220 243
221 sway_log(L_DEBUG, "Config stored for output %s (enabled:%d) (%d x %d @ " 244 sway_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
222 "%d, %d scale %d transform %d refresh_rate %f) (bg %s %s)", 245 "position %d,%d scale %d transform %d) (bg %s %s)",
223 output->name, output->enabled, output->width, 246 output->name, output->enabled, output->width,
224 output->height, output->x, output->y, output->scale, 247 output->height, output->refresh_rate, output->x, output->y,
225 output->transform, output->refresh_rate, 248 output->scale, output->transform,
226 output->background, output->background_option); 249 output->background, output->background_option);
227 250
228 if (output->name) { 251 if (output->name) {