Index: programs/Xserver/hw/xfree86/input/hyperpen/xf86HyperPen.c =================================================================== RCS file: /cvs/xorg/xc/programs/Xserver/hw/xfree86/input/hyperpen/xf86HyperPen.c,v retrieving revision 1.3 diff -u -r1.3 xf86HyperPen.c --- programs/Xserver/hw/xfree86/input/hyperpen/xf86HyperPen.c 4 Dec 2004 00:43:10 -0000 1.3 +++ programs/Xserver/hw/xfree86/input/hyperpen/xf86HyperPen.c 26 Jan 2005 11:13:03 -0000 @@ -39,12 +39,6 @@ #include -#if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(3,9,0,0,0) -#define XFREE86_V4 1 -#endif - -#ifdef XFREE86_V4 -/* post 3.9 headers */ #ifndef XFree86LOADER #include @@ -68,14 +62,6 @@ #include #endif -#define wait_for_fd(fd) xf86WaitForInput((fd), 1000) -#define tcflush(fd, n) xf86FlushInput((fd)) -#undef read -#define read(a,b,c) xf86ReadSerial((a),(b),(c)) -#undef write -#define write(a,b,c) xf86WriteSerial((a),(char*)(b),(c)) -#undef close -#define close(a) xf86CloseSerial((a)) #define XCONFIG_PROBED "(==)" #define XCONFIG_GIVEN "(**)" #define xf86Verbose 1 @@ -102,56 +88,6 @@ static InputDriverPtr hypDrv; -#else /* pre 3.9 headers */ - -#include "Xos.h" -#include -#include - -#define NEED_EVENTS -#include "X.h" -#include "Xproto.h" -#include "misc.h" -#include "inputstr.h" -#include "scrnintstr.h" -#include "XI.h" -#include "XIproto.h" - -#if defined(sun) && !defined(i386) -#define POSIX_TTY -#include -#include -#include -#include - -#include "extio.h" -#else -#include "compiler.h" - -#ifdef XFree86LOADER -#include "xf86_libc.h" -#endif -#include "xf86.h" -#include "xf86Procs.h" -#include "xf86_OSlib.h" -#include "xf86_Config.h" -#include "xf86Xinput.h" -#include "atKeynames.h" -#include "xf86Version.h" -#endif - -#if !defined(sun) || defined(i386) -#include "osdep.h" -#include "exevents.h" - -#include "extnsionst.h" -#include "extinit.h" -#endif - -#if defined(__QNX__) || defined(__QNXNTO__) -#define POSIX_TTY -#endif -#endif /* pre 3.9 headers */ /* ** Debugging macros @@ -199,7 +135,9 @@ int hypOldBarrel; /* previous buttons state */ int hypOldBarrel1; /* previous buttons state */ int hypOldPressure; /* previous pen pressure */ - int hypMaxX; /* max X value */ + int hypOldFKey; /* previous f-key or 0 */ + int hypOldFKey_count; /* repeat count */ + int hypMaxX; /* max X value */ int hypMaxY; /* max Y value */ int hypMaxZ; /* max Z value */ int hypXSize; /* active area X size */ @@ -235,65 +173,6 @@ */ #define HYPERPEN_SECTION_NAME "HyperPen" -#ifndef XFREE86_V4 - -#define PORT 1 -#define DEVICENAME 2 -#define THE_MODE 3 -#define CURSOR 4 -#define BORDER 5 -#define DEBUG_LEVEL 6 -#define HISTORY_SIZE 7 -#define ALWAYS_CORE 8 -#define ACTIVE_AREA 9 -#define ACTIVE_OFFSET 10 -#define INVX 11 -#define INVY 12 -#define BAUD_RATE 13 -#define PMIN 14 -#define PMAX 15 - -#if !defined(sun) || defined(i386) -static SymTabRec HypTab[] = { - {ENDSUBSECTION, "endsubsection"}, - {PORT, "port"}, - {DEVICENAME, "devicename"}, - {THE_MODE, "mode"}, - {CURSOR, "cursor"}, - {BORDER, "border"}, - {DEBUG_LEVEL, "debuglevel"}, - {HISTORY_SIZE, "historysize"}, - {ALWAYS_CORE, "alwayscore"}, - {ACTIVE_AREA, "activearea"}, - {ACTIVE_OFFSET, "activeoffset"}, - {INVX, "invx"}, - {INVY, "invy"}, - {BAUD_RATE, "baudrate"}, - {PMIN, "pmin"}, - {PMAX, "pmax"}, - {-1, ""} -}; - -#define RELATIVE 1 -#define ABSOLUTE 2 - -static SymTabRec HypModeTabRec[] = { - {RELATIVE, "relative"}, - {ABSOLUTE, "absolute"}, - {-1, ""} -}; - -#define PUCK 1 -#define STYLUS 2 - -static SymTabRec HypPointTabRec[] = { - {PUCK, "puck"}, - {STYLUS, "stylus"}, - {-1, ""} -}; - -#endif -#endif /* Pre 3.9 headers */ /* ** Contants and macro @@ -301,8 +180,6 @@ #define BUFFER_SIZE 256 /* size of reception buffer */ #define XI_NAME "HYPERPEN" /* X device name for the stylus */ -#define SYSCALL(call) while(((call) == -1) && (errno == EINTR)) - #define SS_RESET "\0" /* Reset */ #define SS_GETID "\5" /* Get Model ID */ @@ -337,286 +214,6 @@ ** External declarations */ -#ifndef XFREE86_V4 - -#if defined(sun) && !defined(i386) -#define ENQUEUE suneqEnqueue -#else -#define ENQUEUE xf86eqEnqueue - -extern void xf86eqEnqueue( - xEventPtr /*e */ - ); -#endif - -extern void miPointerDeltaCursor( - int /*dx */ , - int /*dy */ , - unsigned long /*time */ - ); - - -#ifndef XFREE86_V4 -/* - *************************************************************************** - * - * set_serial_speed -- - * - * Set speed of the serial port. - * - *************************************************************************** - */ -static int -set_serial_speed(int fd, int speed_code) -{ - struct termios termios_tty; - int err; -#ifdef POSIX_TTY - SYSCALL(err = tcgetattr(fd, &termios_tty)); - if (err == -1) { - ErrorF("HyperPen tcgetattr error : %s\n", strerror(errno)); - return !Success; - } - termios_tty.c_iflag = IXOFF; - termios_tty.c_oflag = 0; - termios_tty.c_cflag = speed_code|CS8|CREAD|CLOCAL|HUPCL|PARENB|PARODD; - termios_tty.c_lflag = 0; - termios_tty.c_cc[VINTR] = 0; - termios_tty.c_cc[VQUIT] = 0; - termios_tty.c_cc[VERASE] = 0; - termios_tty.c_cc[VEOF] = 0; -#ifdef VWERASE - termios_tty.c_cc[VWERASE] = 0; -#endif -#ifdef VREPRINT - termios_tty.c_cc[VREPRINT] = 0; -#endif - termios_tty.c_cc[VKILL] = 0; - termios_tty.c_cc[VEOF] = 0; - termios_tty.c_cc[VEOL] = 0; -#ifdef VEOL2 - termios_tty.c_cc[VEOL2] = 0; -#endif - termios_tty.c_cc[VSUSP] = 0; -#ifdef VDSUSP - termios_tty.c_cc[VDSUSP] = 0; -#endif -#ifdef VDISCARD - termios_tty.c_cc[VDISCARD] = 0; -#endif -#ifdef VLNEXT - termios_tty.c_cc[VLNEXT] = 0; -#endif - /* minimum 1 character in one read call and timeout to 100 ms */ - termios_tty.c_cc[VMIN] = 1; - termios_tty.c_cc[VTIME] = 10; - SYSCALL(err = tcsetattr(fd, TCSANOW, &termios_tty)); - if (err == -1) { - ErrorF("HyperPen tcsetattr TCSANOW error : %s\n", strerror(errno)); - return !Success; - } -#else - Code for OSs without POSIX tty functions -#endif - return Success; -} -#endif /* Pre 3.9 stuff */ - -#if !defined(sun) || defined(i386) -/* -** xf86HypConfig -** Reads the HyperPen section from the XF86Config file -*/ -static Bool -xf86HypConfig(LocalDevicePtr *array, int inx, int max, LexPtr val) -{ - LocalDevicePtr dev = array[inx]; - HyperPenDevicePtr priv = (HyperPenDevicePtr)(dev->private); - int token; - int mtoken; - - DBG(1, ErrorF("xf86HypConfig\n")); - - priv->AutoPT=1; - priv->PMax=1000; - - while ((token = xf86GetToken(HypTab)) != ENDSUBSECTION) { - switch(token) { - case DEVICENAME: - if (xf86GetToken(NULL) != STRING) - xf86ConfigError("Option string expected"); - else { - dev->name = strdup(val->str); - if (xf86Verbose) - ErrorF("%s HyperPen X device name is %s\n", XCONFIG_GIVEN, - dev->name); - } - break; - - case PORT: - if (xf86GetToken(NULL) != STRING) - xf86ConfigError("Option string expected"); - else { - priv->hypDevice = strdup(val->str); - if (xf86Verbose) - ErrorF("%s HyperPen port is %s\n", XCONFIG_GIVEN, - priv->hypDevice); - } - break; - - case THE_MODE: - mtoken = xf86GetToken(HypModeTabRec); - if ((mtoken == EOF) || (mtoken == STRING) || (mtoken == NUMBER)) - xf86ConfigError("Mode type token expected"); - else { - switch (mtoken) { - case ABSOLUTE: - priv->flags |= ABSOLUTE_FLAG; - break; - case RELATIVE: - priv->flags &= ~ABSOLUTE_FLAG; - break; - default: - xf86ConfigError("Illegal Mode type"); - break; - } - } - break; - - case CURSOR: - mtoken = xf86GetToken(HypPointTabRec); - if ((mtoken == EOF) || (mtoken == STRING) || (mtoken == NUMBER)) - xf86ConfigError("Cursor token expected"); - else { - switch (mtoken) { - case STYLUS: - priv->flags |= STYLUS_FLAG; - break; - case PUCK: - priv->flags &= ~STYLUS_FLAG; - break; - default: - xf86ConfigError("Illegal cursor type"); - break; - } - } - break; - - case DEBUG_LEVEL: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Option number expected"); - debug_level = val->num; - if (xf86Verbose) { -#if DEBUG - ErrorF("%s HyperPen debug level set to %d\n", XCONFIG_GIVEN, - debug_level); -#else - ErrorF("%s HyperPen debug level not set to %d because" - " debugging is not compiled with the xf86HyperPen driver\n", XCONFIG_GIVEN, - debug_level); -#endif - } - break; - - case HISTORY_SIZE: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Option number expected"); - dev->history_size = val->num; - if (xf86Verbose) - ErrorF("%s HyperPen Motion history size is %d\n", XCONFIG_GIVEN, - dev->history_size); - break; - - case ALWAYS_CORE: - xf86AlwaysCore(dev, TRUE); - if (xf86Verbose) - ErrorF("%s HyperPen device always stays core pointer\n", - XCONFIG_GIVEN); - break; - - case ACTIVE_AREA: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Option number expected"); - priv->hypXSize = val->realnum * 100; - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Option number expected"); - priv->hypYSize = val->realnum * 100; - if (xf86Verbose) - ErrorF("%s HyperPen active area: %d.%02dx%d.%02d" - " inches\n", XCONFIG_GIVEN, priv->hypXSize / 100, - priv->hypXSize % 100, priv->hypYSize / 100, - priv->hypYSize % 100); - break; - - case ACTIVE_OFFSET: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Option number expected"); - priv->hypXOffset = val->realnum * 100; - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Option number expected"); - priv->hypYOffset = val->realnum * 100; - if (xf86Verbose) - ErrorF("%s HyperPen active area offsets: %d.%02d %d.%02d" - " inches\n", XCONFIG_GIVEN, priv->hypXOffset / 100, - priv->hypXOffset % 100, priv->hypYOffset / 100, - priv->hypYOffset % 100); - break; - case INVX: - priv->flags |= INVX_FLAG; - break; - case INVY: - priv->flags |= INVY_FLAG; - break; - case BAUD_RATE: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Option number expected"); - switch (val->num) { - case 19200: - priv->flags |= BAUD_19200_FLAG; - break; - case 9600: - priv->flags &= ~BAUD_19200_FLAG; - break; - default: - xf86ConfigError("Illegal speed value"); - break; - } - break; - case PMIN: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Option number expected"); - if (val->num < 2) - xf86ConfigError("Illegal minimum pressure"); - else - { - priv->AutoPT = 0; /* desactivate auto threshold adjustment*/ - priv->PT = val->num; - }; - break; - case PMAX: - if (xf86GetToken(NULL) != NUMBER) - xf86ConfigError("Option number expected"); - if (val->num < 3) - xf86ConfigError("Illegal maximum pressure"); - else - priv->PMax = val->num; - break; - case EOF: - FatalError("Unexpected EOF (missing EndSubSection)"); - break; - - default: - xf86ConfigError("HyperPen subsection keyword expected"); - break; - } - } - - DBG(1, ErrorF("xf86HypConfig name=%s\n", priv->hypDevice)); - - return Success; -} -#endif -#endif /* pre 3.9 headers */ /* ** xf86HypConvert @@ -698,7 +295,7 @@ - SYSCALL(len = read(local->fd, buffer, sizeof(buffer))); + len = xf86ReadSerial(local->fd, buffer, sizeof(buffer)); if (len <= 0) { Error("error reading HyperPen device"); @@ -857,10 +454,46 @@ xf86PostProximityEvent(device, 0, 0, 3, x, y, pressure); priv->hypOldProximity = 0; } + { + /* Dietrich: F-Keys */ + /* active fields for keys aren't seperated well, + so don't change directly from one key to another */ + int minkcode = 8; + if(f_key && !priv->hypOldFKey) { + DBG(5, ErrorF("hyperpen: send key press event F%d\n", + f_key)); + xf86PostKeyEvent(device, minkcode-1 + f_key, + 1, is_absolute, 0, 3, 0, 0, pressure); + priv->hypOldFKey = f_key; + priv->hypOldFKey_count = 1; + } + if(priv->hypOldFKey && !f_key) { + DBG(5, ErrorF("hyperpen: send key release event F%d\n", + priv->hypOldFKey)); + xf86PostKeyEvent(device, minkcode-1 + priv->hypOldFKey, + 0, is_absolute, 0, 3, 0, 0, pressure); + priv->hypOldFKey = 0; + } + /* autorepeater */ + if(f_key && f_key == priv->hypOldFKey) { + /* these are the delay counts, like standard keyboard */ + int firstcount = 25, secondcount = 8; + int t; + if(priv->flags & BAUD_19200_FLAG) { + firstcount *= 2; + secondcount *= 2; + } + t = ++priv->hypOldFKey_count; + if(t == firstcount || + (t > firstcount + && !((t - firstcount) % secondcount)) ) { + xf86PostKeyEvent(device, minkcode-1 + f_key, + 1, is_absolute, 0, 3, 0, 0, pressure); + } + } + } } } - - } /* @@ -881,30 +514,15 @@ xf86HypWriteAndRead(int fd, char *data, char *buffer, int len, int cr_term) { int err, numread = 0; -#ifndef XFREE86_V4 - fd_set readfds; - struct timeval timeout; -#endif - SYSCALL(err = write(fd, data, strlen(data))); + err = xf86WriteSerial(fd, data, strlen(data)); if (err == -1) { Error("HyperPen write"); return NULL; } -#ifndef XFREE86_V4 - FD_ZERO(&readfds); - FD_SET(fd, &readfds); -#endif while (numread < len) { -#ifndef XFREE86_V4 - timeout.tv_sec = 0; - timeout.tv_usec = 100000; - - SYSCALL(err = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout)); -#else err = xf86WaitForInput(fd, 100000); -#endif if (err == -1) { Error("HyperPen select"); return NULL; @@ -914,7 +532,7 @@ return NULL; } - SYSCALL(err = read(fd, buffer + numread++, 1)); + err = xf86ReadSerial(fd, buffer + numread++, 1); if (err == -1) { Error("HyperPen read"); return NULL; @@ -937,31 +555,16 @@ ** Open and initialize the tablet, as well as probe for any needed data. */ -#ifdef XFREE86_V4 #define WAIT(t) \ err = xf86WaitForInput(-1, ((t) * 1000)); \ if (err == -1) { \ ErrorF("HyperPen select error : %s\n", strerror(errno)); \ return !Success; \ } -#else -#define WAIT(t) \ - timeout.tv_sec = 0; \ - timeout.tv_usec = (t) * 1000; \ - SYSCALL(err = select(0, NULL, NULL, NULL, &timeout)); \ - if (err == -1) { \ - ErrorF("HyperPen select error : %s\n", strerror(errno)); \ - return !Success; \ - } -#endif static Bool xf86HypOpen(LocalDevicePtr local) { -#ifndef XFREE86_V4 - struct termios termios_tty; - struct timeval timeout; -#endif char buffer[256]; int err, idx; int i, n; @@ -971,187 +574,176 @@ DBG(1, ErrorF("opening %s\n", priv->hypDevice)); -#ifdef XFREE86_V4 local->fd = xf86OpenSerial(local->options); -#else - SYSCALL(local->fd = open(priv->hypDevice, O_RDWR | O_NDELAY, 0)); -#endif if (local->fd == -1) { Error(priv->hypDevice); return !Success; } DBG(2, ErrorF("%s opened as fd %d\n", priv->hypDevice, local->fd)); -#ifdef XFREE86_V4 - if (xf86SetSerialSpeed(local->fd, 9600) < 0) + if (xf86SetSerialSpeed(local->fd, 9600) < 0) return !Success; -#else - if (set_serial_speed(local->fd, B9600) == !Success) - return !Success; -#endif DBG(1, ErrorF("initializing HyperPen tablet\n")); -/* Send reset to the tablet */ + /* Send reset to the tablet */ - write(local->fd, SS_RESET, strlen(SS_RESET)); - WAIT(1000); + xf86WriteSerial(local->fd, SS_RESET, strlen(SS_RESET)); + WAIT(1000); -/* Put it in prompt mode so it doesn't say anything before we're ready */ - SYSCALL(err = write(local->fd, SS_PROMPT_MODE, strlen(SS_PROMPT_MODE))); - if (err == -1) { + /* Put it in prompt mode so it doesn't say anything before we're ready */ + err = xf86WriteSerial(local->fd, SS_PROMPT_MODE, strlen(SS_PROMPT_MODE)); + if (err == -1) { Error("HyperPen write"); return !Success; - } -/* Clear any pending input */ - tcflush(local->fd, TCIFLUSH); - + } + /* Clear any pending input */ + xf86FlushInput(local->fd); + DBG(2, ErrorF("reading model\n")); - - if (!xf86HypWriteAndRead(local->fd, SS_GETID, buffer, 1, 0)) - return !Success; - priv->modelid=buffer[0]; - - for (n = -1, i = 0; models[i].id != 0; i++) - if (models[i].id == priv->modelid) - n = i; - - if (xf86Verbose) - ErrorF("%s HyperPen Model: 0x%x (%s)\n", - XCONFIG_PROBED, priv->modelid, n==-1? "UNKNOWN":models[n].name); - + if (!priv->modelid) { + if (!xf86HypWriteAndRead(local->fd, SS_GETID, buffer, 1, 0)) + return !Success; + + priv->modelid=buffer[0]; + for (n = -1, i = 0; models[i].id != 0; i++) + if (models[i].id == priv->modelid) + n = i; + + if (xf86Verbose) + ErrorF("%s HyperPen Model: 0x%x (%s)\n", + XCONFIG_PROBED, priv->modelid, n==-1? + "UNKNOWN":models[n].name); - /* enable F-Keys */ - SYSCALL(err = write(local->fd, SS_MACROKEY, strlen(SS_MACROKEY))); - if (err == -1) { - ErrorF("HyperPen write error : %s\n", strerror(errno)); - return !Success; - } + } + - DBG(6, ErrorF("prepared F-keys\n")); + /* enable F-Keys */ + err = xf86WriteSerial(local->fd, SS_MACROKEY, strlen(SS_MACROKEY)); + if (err == -1) { + ErrorF("HyperPen write error : %s\n", strerror(errno)); + return !Success; + } + + DBG(6, ErrorF("prepared F-keys\n")); - /* start sequence depends on model ID */ - if (priv->modelid == 0x43) SYSCALL(err = write(local->fd, SS_MACRO_4K, strlen(SS_MACRO_4K))); else SYSCALL(err = write(local->fd, SS_MACRO_56K, strlen(SS_MACRO_56K))); - - if (err == -1) { - ErrorF("HyperPen write error : %s\n", strerror(errno)); - return !Success; - } - - DBG(6, ErrorF("started F-keys\n")); + /* start sequence depends on model ID */ + if (priv->modelid == 0x43) + err = xf86WriteSerial(local->fd, SS_MACRO_4K, strlen(SS_MACRO_4K)); + else + err = xf86WriteSerial(local->fd, SS_MACRO_56K, strlen(SS_MACRO_56K)); + if (err == -1) { + ErrorF("HyperPen write error : %s\n", strerror(errno)); + return !Success; + } + DBG(6, ErrorF("started F-keys\n")); - priv->hypRes = 500; - res100 = priv->hypRes / 100; + if (priv->hypRes == 0) { + priv->hypRes = 500; + res100 = priv->hypRes / 100; - DBG(2, ErrorF("reading max coordinates\n")); + DBG(2, ErrorF("reading max coordinates\n")); - if (!xf86HypWriteAndRead(local->fd, SS_CONFIG, buffer, 5, 0)) - return !Success; - - priv->hypMaxX = (buffer[1] & 0x7f) | (buffer[2] << 7); - priv->hypMaxY = (buffer[3] & 0x7f) | (buffer[4] << 7); - priv->hypMaxZ = 512; + if (!xf86HypWriteAndRead(local->fd, SS_CONFIG, buffer, 5, 0)) + return !Success; + + priv->hypMaxX = (buffer[1] & 0x7f) | (buffer[2] << 7); + priv->hypMaxY = (buffer[3] & 0x7f) | (buffer[4] << 7); + priv->hypMaxZ = 512; -if (xf86Verbose) - ErrorF("%s HyperPen max tablet size %d.%02dinx%d.%02din, %dx%d " - "lines of resolution\n", XCONFIG_PROBED, - priv->hypMaxX / priv->hypRes, - (priv->hypMaxX * 100 / priv->hypRes) % 100, - priv->hypMaxY / priv->hypRes, - (priv->hypMaxY * 100 / priv->hypRes) % 100, - priv->hypMaxX, priv->hypMaxY); - - if (priv->hypXOffset >= 0 && priv->hypYOffset >= 0) { - priv->hypXOffset *= res100; - priv->hypYOffset *= res100; - priv->hypMaxX -= priv->hypXOffset; - priv->hypMaxY -= priv->hypYOffset; - } - - if (priv->hypXSize > 0 && priv->hypYSize > 0) { - if ((priv->hypXSize * res100) <= priv->hypMaxX && - (priv->hypYSize * res100) <= priv->hypMaxY) { - priv->hypXSize *= res100; - priv->hypYSize *= res100; + if (xf86Verbose) + ErrorF("%s HyperPen max tablet size %d.%02dinx%d.%02din, %dx%d " + "lines of resolution\n", XCONFIG_PROBED, + priv->hypMaxX / priv->hypRes, + (priv->hypMaxX * 100 / priv->hypRes) % 100, + priv->hypMaxY / priv->hypRes, + (priv->hypMaxY * 100 / priv->hypRes) % 100, + priv->hypMaxX, priv->hypMaxY); + + if (priv->hypXOffset >= 0 && priv->hypYOffset >= 0) { + priv->hypXOffset *= res100; + priv->hypYOffset *= res100; + priv->hypMaxX -= priv->hypXOffset; + priv->hypMaxY -= priv->hypYOffset; + } + + if (priv->hypXSize > 0 && priv->hypYSize > 0) { + if ((priv->hypXSize * res100) <= priv->hypMaxX && + (priv->hypYSize * res100) <= priv->hypMaxY) { + priv->hypXSize *= res100; + priv->hypYSize *= res100; + } else { + ErrorF("%s HyperPen active area bigger than tablet, " + "assuming maximum\n", XCONFIG_PROBED); + priv->hypXSize = priv->hypMaxX; + priv->hypYSize = priv->hypMaxY; + } } else { - ErrorF("%s HyperPen active area bigger than tablet, " - "assuming maximum\n", XCONFIG_PROBED); priv->hypXSize = priv->hypMaxX; priv->hypYSize = priv->hypMaxY; } - } else { - priv->hypXSize = priv->hypMaxX; - priv->hypYSize = priv->hypMaxY; + + /* map tablet area by screen aspect ratio */ + sratio = (double)screenInfo.screens[0]->height / + (double)screenInfo.screens[0]->width; + tratio = (double)priv->hypMaxY / (double)priv->hypMaxX; + + if (tratio <= 1.0) { /* tablet horizontal > vertical */ + priv->hypXSize = (double)priv->hypYSize / sratio; + if (priv->hypXSize > priv->hypMaxX) priv->hypXSize = priv->hypMaxX; + } else { + priv->hypYSize = (double)priv->hypXSize / sratio; + if (priv->hypYSize > priv->hypMaxY) priv->hypYSize = priv->hypMaxY; + } + ErrorF("%s HyperPen using tablet area %d by %d, at res %d lpi\n", + XCONFIG_PROBED, priv->hypXSize, priv->hypYSize, priv->hypRes); } + + if (priv->flags & BAUD_19200_FLAG) { + /* Send 19200 baud to the tablet */ + err = xf86WriteSerial(local->fd, SS_RATE, strlen(SS_RATE)); + if (err == -1) { + ErrorF("HyperPen write error : %s\n", strerror(errno)); + return !Success; + } - /* map tablet area by screen aspect ratio */ - sratio = (double)screenInfo.screens[0]->height / - (double)screenInfo.screens[0]->width; - tratio = (double)priv->hypMaxY / (double)priv->hypMaxX; + DBG(6, ErrorF("tablet set to 19200 bps\n")); - if (tratio <= 1.0) { /* tablet horizontal > vertical */ - priv->hypXSize = (double)priv->hypYSize / sratio; - if (priv->hypXSize > priv->hypMaxX) priv->hypXSize = priv->hypMaxX; - } - else { - priv->hypYSize = (double)priv->hypXSize / sratio; - if (priv->hypYSize > priv->hypMaxY) priv->hypYSize = priv->hypMaxY; - } - ErrorF("%s HyperPen using tablet area %d by %d, at res %d lpi\n", - XCONFIG_PROBED, priv->hypXSize, priv->hypYSize, priv->hypRes); - if (priv->flags & BAUD_19200_FLAG) { -/* Send 19200 baud to the tablet */ - SYSCALL(err = write(local->fd, SS_RATE, strlen(SS_RATE))); - if (err == -1) { - ErrorF("HyperPen write error : %s\n", strerror(errno)); - return !Success; - } - - DBG(6, ErrorF("tablet set to 19200 bps\n")); - - - /* Wait 10 mSecs */ - WAIT(10); - - /* Set the speed of the serial link to 19200 */ -#ifdef XFREE86_V4 - if (xf86SetSerialSpeed(local->fd, 19200) < 0) { - return !Success; - } -#else - if (set_serial_speed(local->fd, B19200) == !Success) - return !Success; -#endif + /* Wait 10 mSecs */ + WAIT(10); - DBG(6, ErrorF("set serial speed to 19200\n")); + /* Set the speed of the serial link to 19200 */ + if (xf86SetSerialSpeed(local->fd, 19200) < 0) { + return !Success; + } + + DBG(6, ErrorF("set serial speed to 19200\n")); } -/* Sets up the tablet mode to increment, stream, and such */ - for (idx = 0; ss_initstr[idx]; idx++) { + /* Sets up the tablet mode to increment, stream, and such */ + for (idx = 0; ss_initstr[idx]; idx++) { buffer[idx] = ss_initstr[idx]; - } - - buffer[idx] = 0; + } - SYSCALL(err = write(local->fd, buffer, idx)); + buffer[idx] = 0; - + err = xf86WriteSerial(local->fd, buffer, idx); - if (err == -1) { + if (err == -1) { Error("HyperPen write"); return !Success; - } + } - if (err <= 0) { - SYSCALL(close(local->fd)); + if (err <= 0) { + xf86CloseSerial(local->fd); return !Success; - } + } return Success; } @@ -1167,7 +759,7 @@ if (xf86HypOpen(local) != Success) { if (local->fd >= 0) { - SYSCALL(close(local->fd)); + xf86CloseSerial(local->fd); } local->fd = -1; } @@ -1254,11 +846,31 @@ ErrorF("unable to allocate Valuator class device\n"); return !Success; } + { + KeySym ftable[] = { NoSymbol, NoSymbol, NoSymbol, NoSymbol, + NoSymbol, NoSymbol, NoSymbol, NoSymbol, + XK_F1, XK_F2, XK_F3, XK_F4, + XK_F5, XK_F6, XK_F7, XK_F8, + XK_F9, XK_F10, XK_F11, XK_F12 }; + CARD8 keymodmap[10]; + int i; + KeySymsRec keysyms; + keysyms.map = ftable; + keysyms.minKeyCode = 8; + keysyms.maxKeyCode = 8 + 11; + keysyms.mapWidth = 1; + for(i=0; i<10; i++) + keymodmap[i] = 0; + + if (InitKeyClassDeviceStruct(pHyp, &keysyms, keymodmap) + == FALSE) { + ErrorF("unable to init key class device\n"); + return !Success; + } + } + /* allocate the motion history buffer if needed */ xf86MotionHistoryAllocate(local); -#ifndef XFREE86_V4 - AssignTypeAndName(pHyp, local->atom, local->name); -#endif /* open the device to gather informations */ xf86HypOpenDevice(pHyp); break; @@ -1266,33 +878,22 @@ case DEVICE_ON: DBG(1, ErrorF("xf86HypProc pHyp=%p what=ON\n", (void *)pHyp)); - if ((local->fd < 0) && (!xf86HypOpenDevice(pHyp))) { + if ((local->fd < 0) && (!xf86HypOpen(local))) { return !Success; } -#ifdef XFREE86_V4 xf86AddEnabledDevice(local); -#else - AddEnabledDevice(local->fd); -#endif pHyp->public.on = TRUE; break; case DEVICE_OFF: + case DEVICE_CLOSE: DBG(1, ErrorF("xf86HypProc pHyp=%p what=%s\n", (void *)pHyp, (what == DEVICE_CLOSE) ? "CLOSE" : "OFF")); if (local->fd >= 0) -#ifdef XFREE86_V4 xf86RemoveEnabledDevice(local); -#else - RemoveEnabledDevice(local->fd); -#endif pHyp->public.on = FALSE; - break; - case DEVICE_CLOSE: - DBG(1, ErrorF("xf86HypProc pHyp=%p what=%s\n", (void *)pHyp, - (what == DEVICE_CLOSE) ? "CLOSE" : "OFF")); - SYSCALL(close(local->fd)); + xf86CloseSerial(local->fd); local->fd = -1; break; @@ -1314,7 +915,7 @@ xf86HypClose(LocalDevicePtr local) { if (local->fd >= 0) { - SYSCALL(close(local->fd)); + xf86CloseSerial(local->fd); } local->fd = -1; } @@ -1367,7 +968,7 @@ (void *)dev, mode)); return BadMatch; } - SYSCALL(write(local->fd, &newmode, 1)); + xf86WriteSerial(local->fd, &newmode, 1); return Success; } @@ -1378,11 +979,7 @@ static LocalDevicePtr xf86HypAllocate(void) { -#ifdef XFREE86_V4 LocalDevicePtr local = xf86AllocateInput(hypDrv, 0); -#else - LocalDevicePtr local = (LocalDevicePtr)xalloc(sizeof(LocalDeviceRec)); -#endif HyperPenDevicePtr priv = (HyperPenDevicePtr)xalloc(sizeof(HyperPenDeviceRec)); #if defined (sun) && !defined(i386) char *dev_name = getenv("HYPERPEN_DEV"); @@ -1391,11 +988,6 @@ local->name = XI_NAME; local->type_name = "HyperPen Tablet"; local->flags = 0; /*XI86_NO_OPEN_ON_INIT;*/ -#ifndef XFREE86_V4 -#if !defined(sun) || defined(i386) - local->device_config = xf86HypConfig; -#endif -#endif local->device_control = xf86HypProc; local->read_input = xf86HypReadInput; local->control_proc = xf86HypChangeControl; @@ -1425,6 +1017,7 @@ priv->hypOldY = -1; /* previous Y position */ priv->hypOldProximity = 0; /* previous proximity */ priv->hypOldButtons = 0; /* previous buttons state */ + priv->hypOldFKey = 0; /* previous f-key or 0 */ priv->hypMaxX = -1; /* max X value */ priv->hypMaxY = -1; /* max Y value */ priv->hypXSize = -1; /* active area X */ @@ -1439,85 +1032,6 @@ return local; } -#ifndef XFREE86_V4 - -/* -** HyperPen device association -** Device section name and allocation function. -*/ -DeviceAssocRec hypmasketch_assoc = -{ - HYPERPEN_SECTION_NAME, /* config_section_name */ - xf86HypAllocate /* device_allocate */ -}; - -#ifdef DYNAMIC_MODULE -/* -** init_module -** Entry point for dynamic module. -*/ -int -#ifndef DLSYM_BUG -init_module(unsigned long server_version) -#else -init_xf86HyperPen(unsigned long server_version) -#endif -{ - xf86AddDeviceAssoc(&hypmasketch_assoc); - - if (server_version != XF86_VERSION_CURRENT) { - ErrorF("Warning: HyperPen module compiled for version %s\n", - XF86_VERSION); - return 0; - } else { - return 1; - } -} -#endif - -#ifdef XFree86LOADER -/* - * Entry point for the loader code - */ -XF86ModuleVersionInfo xf86HyperPenVersion = { - "hyperpen", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0x00010000, - {0,0,0,0} -}; - -void -xf86HyperPenModuleInit(data, magic) - pointer *data; - INT32 *magic; -{ - static int cnt = 0; - - switch (cnt) { - case 0: - *magic = MAGIC_VERSION; - *data = &xf86HyperPenVersion; - cnt++; - break; - - case 1: - *magic = MAGIC_ADD_XINPUT_DEVICE; - *data = &hypmasketch_assoc; - cnt++; - break; - - default: - *magic = MAGIC_DONE; - *data = NULL; - break; - } -} -#endif - -#else /* * xf86HypUninit -- @@ -1779,7 +1293,6 @@ xf86HypPlug, xf86HypUnplug}; -#endif /* XFree86LOADER */ -#endif /* XFREE86_V4 */ +# endif /* XFree86LOADER */ /* end of xf86HyperPen.c */