/* compile with:
 *   gcc -o screen-info screen-info.c \
 *     `pkg-config --cflags --libs gtk+-2.0 xrandr xxf86vm`
 */

#include <stdio.h>

#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/extensions/xf86vmode.h>
#include <X11/extensions/Xrandr.h>

#include <gtk/gtk.h>
#include <gdk/gdkx.h>

int
main(int argc, char **argv)
{
  XF86VidModeModeLine modeline;
  XRRScreenConfiguration *xr_screen_conf;
  XRRScreenSize *sizes;
  SizeID current_size;
  Rotation current_rotation;
  int res, dotclock, nsizes, i;

  gtk_init(&argc, &argv);

  printf ("Screen size: %d x %d\n", gdk_screen_width(), gdk_screen_height());

  res = XF86VidModeGetModeLine (GDK_DISPLAY(), XDefaultScreen (GDK_DISPLAY ()),
                                &dotclock, &modeline);
  if (res) {
    printf ("Current vid mode: hdisplay = %d, vdisplay = %d\n",
            modeline.hdisplay, modeline.vdisplay);
  }

  xr_screen_conf = XRRGetScreenInfo (GDK_DISPLAY(), GDK_ROOT_WINDOW());
  current_size = XRRConfigCurrentConfiguration (xr_screen_conf, &current_rotation);
  sizes = XRRConfigSizes (xr_screen_conf, &nsizes);

  printf("XRANDR screen sizes:\n");
  for (i = 0; i < nsizes; i++) {
    printf ("  %c %d x %d\n", i == current_size ? '*' : ' ',
            sizes[i].width, sizes[i].height);
  }
  return 0;
}
