#ifndef _MISC_
#define _MISC_

#include "global.hh"
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/Xft/Xft.h>

// (a/b)*x; a, b, x supposed to be ints
#define ifrac(a,b,x) ((int) (((float) (a))/((float) (b))*((float) (x))))

#ifndef TRUE
#define TRUE	1
#define FALSE	0
#endif

struct Timer
{
	Timer *next;
	volatile int t; // time in milliseconds
	// have to be volatile

	int tick ();
};

struct MyColor
{
	char *name;
	XColor xcolor;
	Pixel pixel;
#ifdef FONTS_XFT
	XftColor xftcolor;
#endif

	MyColor ();
	MyColor (char *);
	int operator= (char *);
	int parse ();
	int init ();
};

struct MyFont
{
	char *name;
#ifdef FONTS_XFT
	XftFont *font;
#elif defined FONTS_XCORE
	XFontStruct *font;
#endif
	int ht;
	int y;

	MyFont ();
	int parse ();
	int init ();
	int done ();
};

struct MyPixmap
{
	Pixmap pm;
	Pixmap clip_mask;
	int wd, ht;
	unsigned int depth;

	MyPixmap ();
	~MyPixmap ();
	int load (char *);
	int create (char **);
	int shrink (Window, int);
	int shrink (MyPixmap *, int);

	int set (Window);
	int gx_or (Window, int, int);
	int gx_copy (Window, int, int);
	int gx_copy_mask (Window, int, int);
};

struct PointerPos
{
	Window r;
	int rx, ry;
	Window w;
	int wx, wy;
	unsigned int mask;
	int sx, sy;

	int warp_by (int, int);
	int warp_to (int, int);
	int query ();
	int save ();
	int restore ();
};

struct Junk
{
	int x, y;
	Window root, child, win;
	unsigned int wd, ht, bw, depth, mask;
	XEvent event;
};

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


extern GC pixGC;
extern unsigned long vm;
extern XGCValues gcv;
extern unsigned long gcm;

extern MyFont swm_font;
extern MyColor pointer_fore;
extern MyColor pointer_back;
extern MyColor root_mycolor;
extern MyPixmap *root_mypixmap;

extern PointerPos ppos;
extern Junk junk;
extern char *white;
extern char *black;
extern char *grey;

extern Window fake_win;
extern XftDraw *xft_draw;
extern int grab_active;
extern Window grab_win;

extern int restrict (int &, int, int);
extern int iifrac (int, int);
extern int absi (int);
extern int sgn (int);
extern int match_wildcards (char *, char *);
extern int grab_setup (Window);
extern int grab_cancel ();
extern int my_pix_init ();
extern int timer_init ();
extern int timer_done ();
extern Timer * add_timer (int);
extern int rm_timer (Timer *);
extern int pointer_warping ();
extern int fake_win_init ();

extern int XftTextWidthUtf8 (XftFont *, char *, int);

#endif
