From dac874adf896f12e85676190f8d0196fffdbe75b Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sat, 31 May 2008 20:17:21 -0400 Subject: [PATCH] Extend xaspect to support showing screen dimensions as well. --- scripts/C/Makefile | 4 ++-- scripts/C/xaspect.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/scripts/C/Makefile b/scripts/C/Makefile index 342509f..ee422c6 100644 --- a/scripts/C/Makefile +++ b/scripts/C/Makefile @@ -1,7 +1,7 @@ -CFLAGS = -O2 -Wall -Wextra -Wno-sign-compare +CFLAGS = -O2 -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers LDFLAGS = -CC = c89 +CC = c99 LD = $(CC) all: xaspect diff --git a/scripts/C/xaspect.c b/scripts/C/xaspect.c index e10f506..3e07caa 100644 --- a/scripts/C/xaspect.c +++ b/scripts/C/xaspect.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #define MKASPECT(w, h) { (double)w/h, #w ":" #h } @@ -57,17 +58,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 +103,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); -- 2.43.2