X-Git-Url: http://git.draconx.ca/gitweb/fvwmconf.git/blobdiff_plain/383401a5e46855bc36fca8f9f2c98bb9f814f21a..ecef356bbdbdda0c26b7f139556c9916a3927d8d:/scripts/C/xaspect.c diff --git a/scripts/C/xaspect.c b/scripts/C/xaspect.c index 0dbc83d..3900c6d 100644 --- a/scripts/C/xaspect.c +++ b/scripts/C/xaspect.c @@ -1,7 +1,15 @@ +/* + * Copyright (C) 2007 Nick Bowler + * Copying and distribution of this file, with or without modification, + * are permitted in any medium without royalty provided the copyright + * notice and this notice are preserved. This file is offered as-is, + * without any warranty. + */ #include #include #include #include +#include #include #define MKASPECT(w, h) { (double)w/h, #w ":" #h } @@ -13,7 +21,7 @@ static struct aspect { } aspects[] = { MKASPECT(16, 10), MKASPECT(16, 9), - MKASPECT(8, 5), + MKASPECT(8, 3), MKASPECT(5, 4), MKASPECT(4, 3) }; @@ -57,17 +65,38 @@ char *testaspect(xcb_screen_t *screen) return best; } +struct options { + char *displayname; + int showdimensions; +} *parseoptions(int argc, char **argv) +{ + static struct options opts = { 0 }; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + if (++i < argc) { + opts.displayname = argv[i]; + continue; + } + fprintf(stderr, "-display requires an argument\n"); + } else if (strcmp(argv[i], "-dimensions") == 0) { + opts.showdimensions = 1; + } + } + + return &opts; +} + int main(int argc, char **argv) { xcb_connection_t *display; xcb_screen_t *screen; - char *dpynam = NULL; int screen_num; - if (argc > 2 && strcmp(argv[1], "-display") == 0) - dpynam = argv[2]; + struct options *opts = parseoptions(argc, argv); - display = xcb_connect(dpynam, &screen_num); + display = xcb_connect(opts->displayname, &screen_num); if (xcb_connection_has_error(display)) { fprintf(stderr, "Failed to open display.\n"); xcb_disconnect(display); @@ -81,6 +110,10 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + if (opts->showdimensions) { + printf("%" PRIu16 "x%" PRIu16 "-", + screen->width_in_pixels, screen->height_in_pixels); + } printf("%s\n", testaspect(screen)); xcb_disconnect(display);