summaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-22 11:18:55 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-22 11:18:55 -0400
commitb7f4607544d51811e986b98c8c3eda7ed7c68b1a (patch)
tree0e2cf9f02e1d2cde3bf7d0b7424ff5ac3ee6c1e3 /sway/commands.c
parentMerge pull request #118 from Luminarys/master (diff)
downloadsway-b7f4607544d51811e986b98c8c3eda7ed7c68b1a.tar.gz
sway-b7f4607544d51811e986b98c8c3eda7ed7c68b1a.tar.zst
sway-b7f4607544d51811e986b98c8c3eda7ed7c68b1a.zip
Implement output configuration through config
Do not use `output res WIDTHxHEIGHT` yet, wlc has issues with it (cc @Cloudef)
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 62794111..5de1fb0c 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -364,6 +364,66 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) {
364 return true; 364 return true;
365} 365}
366 366
367static bool cmd_output(struct sway_config *config, int argc, char **argv) {
368 if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) {
369 return false;
370 }
371
372 struct output_config *output = calloc(1, sizeof(struct output_config));
373 output->x = output->y = output->width = output->height = -1;
374 output->name = strdup(argv[0]);
375
376 // TODO: atoi doesn't handle invalid numbers
377
378 int i;
379 for (i = 1; i < argc; ++i) {
380 if (strcasecmp(argv[i], "resolution") == 0 || strcasecmp(argv[i], "res") == 0) {
381 char *res = argv[++i];
382 char *x = strchr(res, 'x');
383 int width = -1, height = -1;
384 if (x != NULL) {
385 // Format is 1234x4321
386 *x = '\0';
387 width = atoi(res);
388 height = atoi(x + 1);
389 *x = 'x';
390 } else {
391 // Format is 1234 4321
392 width = atoi(res);
393 res = argv[++i];
394 height = atoi(res);
395 }
396 output->width = width;
397 output->height = height;
398 } else if (strcasecmp(argv[i], "position") == 0 || strcasecmp(argv[i], "pos") == 0) {
399 char *res = argv[++i];
400 char *c = strchr(res, ',');
401 int x = -1, y = -1;
402 if (c != NULL) {
403 // Format is 1234,4321
404 *c = '\0';
405 x = atoi(res);
406 y = atoi(c + 1);
407 *c = ',';
408 } else {
409 // Format is 1234 4321
410 x = atoi(res);
411 res = argv[++i];
412 y = atoi(res);
413 }
414 output->x = x;
415 output->y = y;
416 }
417 }
418
419 list_add(config->output_configs, output);
420
421 sway_log(L_DEBUG, "Configured output %s to %d x %d @ %d, %d",
422 output->name, output->width, output->height, output->x, output->y);
423
424 return true;
425}
426
367static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { 427static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
368 if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { 428 if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) {
369 return false; 429 return false;
@@ -637,6 +697,7 @@ static struct cmd_handler handlers[] = {
637 { "layout", cmd_layout }, 697 { "layout", cmd_layout },
638 { "log_colors", cmd_log_colors }, 698 { "log_colors", cmd_log_colors },
639 { "move", cmd_move}, 699 { "move", cmd_move},
700 { "output", cmd_output},
640 { "reload", cmd_reload }, 701 { "reload", cmd_reload },
641 { "resize", cmd_resize }, 702 { "resize", cmd_resize },
642 { "set", cmd_set }, 703 { "set", cmd_set },