/*****************************************************************************/

/*
 *      getres.c -- Get the current X resolution
 *
 *      Copyright (C) 2000 Sigma Designs
 *                    written by Nicolas Vignal <nicolas_vignal@sdesigns.com>
 *                    modified by Emmanuel Michon <emmanuel_michon@sdesigns.com>
 *                                Pascal Cannenterre <pascal_cannenterre@sdesigns.com>
 *
 *      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.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*****************************************************************************/
#include <stdlib.h>
#include <X11/Xlib.h>
#include <X11/extensions/xf86vmode.h>

typedef unsigned long DWORD;

/* return the current resolution */
DWORD getres(DWORD *x, DWORD *y, DWORD *depth,DWORD *freq)
{
	Display *mydpy;
	int myscr;
	XF86VidModeModeLine mode_line;
	int dot_clock;
		
	mydpy = XOpenDisplay (NULL);
	if (!mydpy) return 1;

	myscr=DefaultScreen(mydpy);

	if (!XF86VidModeGetModeLine (mydpy, myscr, &dot_clock, &mode_line)) exit(1);
	
	*x=( DWORD )mode_line.hdisplay;
	*y=( DWORD )mode_line.vdisplay;	

	*depth=( DWORD )XDefaultDepth(mydpy,myscr);

	// so funny.
	*freq=(DWORD)((double)dot_clock*1000.0
		      /(double)mode_line.htotal
		      /(double)mode_line.vtotal); 

	return 0;
}
