7 #define MKASPECT(w, h) { (double)w/h, #w ":" #h }
9 /* Table of common monitor aspect ratios. Add to this as necessary. */
10 static struct aspect {
22 * Get the xcb screen structure for the specified screen, or NULL if it doesn't
25 static xcb_screen_t *getscreen(xcb_connection_t *c, int screen)
27 xcb_screen_iterator_t iter;
29 iter = xcb_setup_roots_iterator(xcb_get_setup(c));
34 xcb_screen_next(&iter);
40 char *testaspect(xcb_screen_t *screen)
42 unsigned int w = screen->width_in_millimeters;
43 unsigned int h = screen->height_in_millimeters;
45 double ratio = (double)w/h;
50 for (i = 0; i < (sizeof aspects / sizeof aspects[0]); i++) {
51 if (!best || fabs(aspects[i].ratio - ratio) < diff) {
52 best = aspects[i].name;
53 diff = fabs(aspects[i].ratio - ratio);
60 int main(int argc, char **argv)
62 xcb_connection_t *display;
67 if (argc > 2 && strcmp(argv[1], "-display") == 0)
70 display = xcb_connect(dpynam, &screen_num);
71 if (xcb_connection_has_error(display)) {
72 fprintf(stderr, "Failed to open display.\n");
73 xcb_disconnect(display);
77 screen = getscreen(display, screen_num);
79 fprintf(stderr, "Invalid screen number.\n");
80 xcb_disconnect(display);
84 printf("%s\n", testaspect(screen));
86 xcb_disconnect(display);