/*
 * Xpsitouch header file
 * 
 * Copyright 2002 Tony Lindgren <tony@atomide.com>
 * License:	GPL
 * Warranty:	None
 */

#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>

#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>

#define DEBUG

#if defined(DEBUG)
#define TPDEBUG(x...)			printf(x)
#else
#define TPDEBUG(x...)			do { ; } while(0)
#endif

#define NUM_PSION_MOUSEBUTTONS		3
#define NUM_MAX_MOUSEBUTTONS		5

#define AUTO_RESTORE
#if defined(AUTO_RESTORE)
#define AUTO_RESTORE_VAL		1500000
#endif

//#define KEY1				100
#define KEY1				66
#define MOD1				1
//#define KEY2				104
#define KEY2				49
#define MOD2				1
//#define KEY3				102
#define KEY3				65
#define MOD3				1

/* Left "Y" toolbar */
#define Y_TOOLB_X_TRIGGER		0
#define Y_TOOLB_NUM_BUTTONS		5
#define LCD_HEIGHT			239
#define Y_TOOLB_CALIBRATION		0
#define Y_TOOLB_BUTTON_HEIGHT		(LCD_HEIGHT / Y_TOOLB_NUM_BUTTONS)

/* Bottom "X" toolbar */
#define X_TOOLB_Y_TRIGGER		LCD_HEIGHT
#define X_TOOLB_NUM_BUTTONS		9
#define LCD_WIDTH			632
#define X_TOOLB_CALIBRATION       	70
#define X_TOOLB_BUTTON_WIDTH		((LCD_WIDTH + X_TOOLB_CALIBRATION) / X_TOOLB_NUM_BUTTONS)

/* Shell script to execute */
#define TOOLBAR_SYSTEM_SHELL_SCRIPT	"/etc/xpsitouchrc.sh"

typedef struct {
	int		keycode;
	int		modifier;
} touch_keymap;

typedef struct {
	char		*display_name;
	Display		*display;
	int		screen;
	Window		window;

	touch_keymap	**keymap_list;
	int		no_keys;

	int		no_buttons;
	int		x_no_buttons;
	unsigned char	*orig_map;
	unsigned char	*new_map;
	int		queued;

} touchpanel;

touchpanel * tp_init(int argc, char *argv[]);
void tp_exit(touchpanel *tp, int code);
void tp_handle_keypress(touchpanel *tp, XEvent xev);
void tp_handle_keyrelease(touchpanel *tp, XEvent xev);
void tp_handle_toolbars(touchpanel *tp, XEvent xev);
void tp_signal_handler(int sig);
