/*

$Id: x-resolution.c,v 1.1 2005/07/11 13:28:35 roderick Exp $

Roderick Schertler <roderick@argon.org>

*/

/*

Copyright (C) 2005 Roderick Schertler

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

For a copy of the GNU General Public License write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

*/

/*

This program outputs the X and Y resolutions of your display.

I don't really know anything about X programming.

*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xos.h>

int
main(int argc, char *argv[])
{
    Display *dpy;
    XWindowAttributes wa;
    char *arg0;

    arg0 = strrchr(argv[0], '/');
    if (arg0)
	arg0++;
    else
	arg0 = argv[0];

    if (argc > 1) {
	fprintf(stderr, "usage: %s\n", arg0);
	exit(1);
    }

    dpy = XOpenDisplay(NULL);
    if (!dpy) {
	fprintf(stderr, "%s: cannot connect to display\n", arg0);
	exit(1);
    }

    if (!XGetWindowAttributes(dpy, RootWindow(dpy, DefaultScreen(dpy)), &wa)) {
	fprintf(stderr, "%s: can't get root window geometry\n", arg0);
	exit(1);
    }

    printf("%ld %ld\n", (long)wa.width, (long)wa.height);

    XCloseDisplay(dpy);

    return 0;
}
