=================================================================== ChangeSet@xxxx, 2004-08-10 00:52:54-05:00, dtor_core@xxxxxxxxxxxxx Get rid of 2 mice limitation by removing mouse_features array, mice are allocated on the heap. Protocol drivers can allocate and attach private data to the mouse structure for later use. gpm.c | 435 +++++++++++++++++++++++----------------------------- gpn.c | 232 ++++++++++++++------------- headers/gpmInt.h | 120 +++++--------- headers/synaptics.h | 4 mice.c | 357 +++++++++++++++++++++--------------------- prog/mouse-test.c | 168 +++++++++----------- server_tools.c | 177 ++++++--------------- startup.c | 107 +++++++----- synaptics.c | 19 +- 9 files changed, 739 insertions(+), 880 deletions(-) =================================================================== diff -Nru a/src/gpm.c b/src/gpm.c --- a/src/gpm.c 2004-08-10 01:17:58 -05:00 +++ b/src/gpm.c 2004-08-10 01:17:58 -05:00 @@ -42,43 +42,19 @@ #endif #define NULL_SET ((fd_set *)NULL) -#define resetTimeout() (timeout.tv_sec=SELECT_TIME,timeout.tv_usec=0) - -extern int errno; - -static void gpm_killed(int); +#define resetTimeout() (timeout.tv_sec = SELECT_TIME, timeout.tv_usec = 0) +#define GET_TIME(tv) (gettimeofday(&tv, (struct timezone *)NULL)) +#define DIF_TIME(t1,t2) ((t2.tv_sec - t1.tv_sec)*1000 + (t2.tv_usec - t1.tv_usec)/1000) -/* - * all the values duplicated for dual-mouse operation are - * now in this structure (see gpmInt.h) - * mouse_table[0] is single mouse, mouse_table[1] and mouse_table[2] - * are copied data from mouse_table[0] for dual mouse operation. - */ -struct mouse_features mouse_table[3] = { - { - DEF_TYPE, DEF_DEV, DEF_SEQUENCE, - DEF_BAUD, DEF_SAMPLE, DEF_DELTA, DEF_ACCEL, DEF_SCALE, 0 /* scaley */, - DEF_TIME, DEF_CLUSTER, DEF_THREE, DEF_GLIDEPOINT_TAP, - (char *)NULL /* extra */, - (Gpm_Type *)NULL, - -1 - } -}; -struct mouse_features *which_mouse; +enum mouse_rslt { MOUSE_NO_DATA, MOUSE_DATA_OK, MOUSE_MORE_DATA }; -/* These are only the 'global' options */ +extern int errno; -int opt_test=DEF_TEST; -int opt_double=0; char *opt_special=NULL; /* special commands, like reboot or such */ - -static int opt_resize=0; /* not really an option */ - struct repeater repeater; -int eventFlag=0; -fd_set selSet, readySet, connSet; +static int console_resized; /* not really an option */ static struct { int x, y; @@ -86,63 +62,77 @@ int clicks; } state; +/*-------------------------------------------------------------------*/ +static void gpm_killed(int signo) +{ + if (signo == SIGWINCH) { + gpm_report(GPM_PR_WARN, GPM_MESS_RESIZING, option.progname, getpid()); + console_resized = 1; + } else { + if (signo == SIGUSR1) + gpm_report(GPM_PR_WARN, GPM_MESS_KILLED_BY, option.progname, getpid(), option.progname); + exit(0); + } +} + /*------------------------------------------------------------------- * fetch the actual device data from the mouse device, dependent on * what Gpm_Type is being passed. *-------------------------------------------------------------------*/ -static inline char *getMouseData(int fd, Gpm_Type *type, int text_mode) +static char *getMouseData(int fd, Gpm_Type *type, int text_mode) { static unsigned char data[32]; /* quite a big margin :) */ - char *edata=data+type->packetlen; - int howmany=type->howmany; - int i,j; + unsigned char *pdata; + int len, togo; -/*....................................... read and identify one byte */ - - if (read(fd, data, howmany)!=howmany) { - if (opt_test) exit(0); + /*....................................... read and identify one byte */ + if (read(fd, data, type->howmany) != type->howmany) { + if (option.test) exit(0); gpm_report(GPM_PR_ERR,GPM_MESS_READ_FIRST, strerror(errno)); return NULL; } if (!text_mode && repeater.fd != -1 && repeater.raw) - write(repeater.fd, data, howmany); + write(repeater.fd, data, type->howmany); - if ((data[0]&(m_type->proto)[0]) != (m_type->proto)[1]) { - if (m_type->getextra == 1) { - data[1]=GPM_EXTRA_MAGIC_1; data[2]=GPM_EXTRA_MAGIC_2; - gpm_report(GPM_PR_DEBUG,GPM_EXTRA_DATA,data[0]); + if ((data[0] & type->proto[0]) != type->proto[1]) { + if (type->getextra == 1) { + data[1] = GPM_EXTRA_MAGIC_1; data[2] = GPM_EXTRA_MAGIC_2; + gpm_report(GPM_PR_DEBUG, GPM_EXTRA_DATA, data[0]); return data; } - gpm_report(GPM_PR_DEBUG,GPM_MESS_PROT_ERR); + gpm_report(GPM_PR_DEBUG, GPM_MESS_PROT_ERR); return NULL; } -/*....................................... read the rest */ + /*....................................... read the rest */ /* * well, this seems to work almost right with ps2 mice. However, I've never * tried ps2 with the original selection package, which called usleep() */ - - if((i=m_type->packetlen-howmany)) /* still to get */ + if ((togo = type->packetlen - type->howmany)) { /* still to get */ + pdata = &data[type->howmany]; do { - j = read(fd,edata-i,i); /* edata is pointer just after data */ - if (!text_mode && repeater.fd != -1 && repeater.raw && j > 0) - write(repeater.fd, edata - i, j); - i -= j; - } while (i && j); + if ((len = read(fd, pdata, togo)) == 0) + break; + if (!text_mode && repeater.fd != -1 && repeater.raw && len > 0) + write(repeater.fd, pdata, len); + pdata += len; + togo -= len; + } while (togo); + } - if (i) { - gpm_report(GPM_PR_ERR,GPM_MESS_READ_REST, strerror(errno)); + if (togo) { + gpm_report(GPM_PR_ERR, GPM_MESS_READ_REST, strerror(errno)); return NULL; } - if ((data[1]&(m_type->proto)[2]) != (m_type->proto)[3]) { - gpm_report(GPM_PR_INFO,GPM_MESS_SKIP_DATA); + if ((data[1] & type->proto[2]) != type->proto[3]) { + gpm_report(GPM_PR_INFO, GPM_MESS_SKIP_DATA); return NULL; } - gpm_report(GPM_PR_DEBUG,GPM_MESS_DATA_4,data[0],data[1],data[2],data[3]); + gpm_report(GPM_PR_DEBUG, GPM_MESS_DATA_4, data[0], data[1], data[2], data[3]); return data; } @@ -150,8 +140,7 @@ void handle_console_resize(Gpm_Event *ePtr) { int old_x, old_y; - int i; - struct mouse_features *which_mouse; /* local */ + struct micetab *mouse; old_x = console.max_x; old_y = console.max_y; refresh_console_size(); @@ -163,18 +152,18 @@ state.y = ePtr->y = ePtr->y * console.max_y / old_y; } - for (i=1; i <= 1+opt_double; i++) { - which_mouse=mouse_table+i; /* used to access options */ + for (mouse = micelist; mouse; mouse = mouse->next) { /* * the following operation is based on the observation that 80x50 * has square cells. (An author-centric observation ;-) */ - opt_scaley = opt_scale * 50 * console.max_x / 80 / console.max_y; - gpm_report(GPM_PR_DEBUG, GPM_MESS_X_Y_VAL, opt_scale, opt_scaley); + mouse->options.scaley = mouse->options.scalex * 50 * console.max_x / 80 / console.max_y; + gpm_report(GPM_PR_DEBUG, GPM_MESS_X_Y_VAL, + mouse->options.scalex, mouse->options.scaley); } } -static void handle_repeater(Gpm_Event *new_event, Gpm_Event *event) +static void handle_repeater(struct Gpm_Type *m_type, Gpm_Event *new_event, Gpm_Event *event) { static struct timeval last; struct timeval now; @@ -201,126 +190,122 @@ * to retrieve the hardware independent event data, then optionally repeat * the data via repeat_fun() to the repeater device *-------------------------------------------------------------------*/ -static inline int processMouse(int fd, Gpm_Event *event, Gpm_Type *type, int text_mode) +static enum mouse_rslt processMouse(struct micetab *mouse, int attempt, + Gpm_Event *event, int text_mode) { char *data; unsigned char shift_state; static int last_active; static int fine_dx, fine_dy; - static int i, m; + int i; static Gpm_Event nEvent; - static struct timeval tv1={0,0}, tv2; /* tv1==0: first click is single */ - static struct timeval timeout={0,0}; + struct timeval now; + static struct timeval button_release; /* tv1==0: first click is single */ + static struct timeval timeout = {0, 0}; fd_set fdSet; - static int newB=0, oldB=0, oldT=0; /* old buttons and Type to chain events */ - /* static int buttonlock, buttonlockflag; */ - -#define GET_TIME(tv) (gettimeofday(&tv, (struct timezone *)NULL)) -#define DIF_TIME(t1,t2) ((t2.tv_sec -t1.tv_sec) *1000+ \ - (t2.tv_usec-t1.tv_usec)/1000) - - - oldT=event->type; - - if (eventFlag) { - eventFlag=0; - - if (m_type->absolute) { /* a pen or other absolute device */ - event->x=nEvent.x; - event->y=nEvent.y; + struct Gpm_Type *type = mouse->type; + struct miceopt *opt = &mouse->options; + static int oldB; /* old buttons and Type to chain events */ + int oldT = event->type; + enum mouse_rslt rslt = MOUSE_DATA_OK; + + if (attempt > 1) { + if (type->absolute) { /* a pen or other absolute device */ + event->x = nEvent.x; + event->y = nEvent.y; } - event->dx=nEvent.dx; - event->dy=nEvent.dy; - event->buttons=nEvent.buttons; + event->dx = nEvent.dx; + event->dy = nEvent.dy; + event->buttons = nEvent.buttons; } else { - event->dx=event->dy=0; - event->wdx=event->wdy=0; + event->dx = event->dy = 0; + event->wdx = event->wdy = 0; nEvent.modifiers = 0; /* some mice set them */ - FD_ZERO(&fdSet); FD_SET(fd,&fdSet); i=0; + FD_ZERO(&fdSet); FD_SET(mouse->dev.fd, &fdSet); + i = 0; do { /* cluster loop */ - if(((data=getMouseData(fd,m_type, text_mode))==NULL) - || ((*(m_type->fun))(&nEvent,data)==-1) ) { - if (!i) return 0; + if ((data = getMouseData(mouse->dev.fd, type, text_mode)) == NULL || + type->fun(&mouse->dev, &mouse->options, data, &nEvent) == -1) { + if (!i) return MOUSE_NO_DATA; else break; } event->modifiers = nEvent.modifiers; /* propagate modifiers */ /* propagate buttons */ - nEvent.buttons = (opt_sequence[nEvent.buttons&7]&7) | - (nEvent.buttons & ~7); /* change the order */ - oldB=newB; newB=nEvent.buttons; - if (!i) event->buttons=nEvent.buttons; + nEvent.buttons = (opt->sequence[nEvent.buttons & 7] & 7) | + (nEvent.buttons & ~7); /* change the order */ + if (!i) event->buttons = nEvent.buttons; - if (oldB!=newB) { - eventFlag = (i!=0)*(which_mouse-mouse_table); /* 1 or 2 */ + if (oldB != nEvent.buttons) { + rslt = MOUSE_MORE_DATA; break; } /* propagate movement */ - if (!(m_type->absolute)) { /* mouse */ - if (abs(nEvent.dx)+abs(nEvent.dy) > opt_delta) - nEvent.dx*=opt_accel, nEvent.dy*=opt_accel; + if (!type->absolute) { /* mouse */ + if (abs(nEvent.dx) + abs(nEvent.dy) > opt->delta) + nEvent.dx *= opt->accel, nEvent.dy *= opt->accel; /* increment the reported dx,dy */ - event->dx+=nEvent.dx; - event->dy+=nEvent.dy; + event->dx += nEvent.dx; + event->dy += nEvent.dy; } else { /* a pen */ /* get dx,dy to check if there has been movement */ - event->dx = (nEvent.x) - (event->x); - event->dy = (nEvent.y) - (event->y); + event->dx = nEvent.x - event->x; + event->dy = nEvent.y - event->y; } /* propagate wheel */ event->wdx += nEvent.wdx; event->wdy += nEvent.wdy; - select(fd+1,&fdSet,(fd_set *)NULL,(fd_set *)NULL,&timeout/* zero */); + select(mouse->dev.fd + 1, &fdSet, NULL_SET, NULL_SET, &timeout/* zero */); - } while (i++ <opt_cluster && nEvent.buttons==oldB && FD_ISSET(fd,&fdSet)); - + } while (i++ < opt->cluster && FD_ISSET(mouse->dev.fd, &fdSet)); } /* if(eventFlag) */ -/*....................................... update the button number */ + /*....................................... update the button number */ - if ((event->buttons&GPM_B_MIDDLE) && !opt_three) opt_three++; + if ((event->buttons & GPM_B_MIDDLE) && opt->three_button) opt->three_button++; -/*....................................... we're a repeater, aren't we? */ + /*....................................... we're a repeater, aren't we? */ if (!text_mode) { if (repeater.fd != -1 && !repeater.raw) - handle_repeater(&nEvent, event); - return 0; /* no events nor information for clients */ + handle_repeater(type, &nEvent, event); + oldB = nEvent.buttons; + return MOUSE_NO_DATA; /* no events nor information for clients */ } /*....................................... no, we arent a repeater, go on */ /* use fine delta values now, if delta is the information */ - if (!(m_type)->absolute) { - fine_dx+=event->dx; fine_dy+=event->dy; - event->dx=fine_dx/opt_scale; event->dy=fine_dy/opt_scaley; - fine_dx %= opt_scale; fine_dy %= opt_scaley; + if (!mouse->type->absolute) { + fine_dx += event->dx; + fine_dy += event->dy; + event->dx = fine_dx / opt->scalex; + event->dy = fine_dy / opt->scaley; + fine_dx %= opt->scalex; + fine_dy %= opt->scaley; } /* up and down, up and down, ... who does a do..while(0) loop ??? and then makes a break into it... argh ! */ - if (!event->dx && !event->dy && (event->buttons==oldB)) - do { /* so to break */ - static long awaketime; - /* - * Ret information also if never happens, but enough time has elapsed. - * Note: return 1 will segfault due to missing event->vc; FIXME! - */ - if (time(NULL)<=awaketime) return 0; - awaketime=time(NULL)+1; - break; - } while (0); - -/*....................................... fill missing fields */ + if (!event->dx && !event->dy && event->buttons == oldB) { + static time_t awaketime; + /* + * Ret information also if never happens, but enough time has elapsed. + * Note: return 1 will segfault due to missing event->vc; FIXME! + */ + if (time(NULL) <= awaketime) return MOUSE_NO_DATA; + awaketime = time(NULL) + 1; + } - event->x += event->dx, event->y += event->dy; + /*....................................... fill missing fields */ + event->x += event->dx; event->y += event->dy; state.buttons = event->buttons; event->vc = get_console_state(&shift_state); @@ -337,8 +322,8 @@ switch(event->type) { /* now provide the cooked bits */ case GPM_DOWN: - GET_TIME(tv2); - if (tv1.tv_sec && (DIF_TIME(tv1, tv2) < opt_time)) /* check first click */ + GET_TIME(now); + if (button_release.tv_sec && (DIF_TIME(button_release, now) < opt->time)) /* check first click */ state.clicks++, state.clicks %= 3; /* 0, 1 or 2 */ else state.clicks = 0; @@ -346,7 +331,7 @@ break; case GPM_UP: - GET_TIME(tv1); + GET_TIME(button_release); event->buttons ^= oldB; /* for button-up, tell which one */ event->type |= oldT & GPM_MFLAG; event->type |= GPM_SINGLE << state.clicks; @@ -379,99 +364,63 @@ * The i variable is how much margin is allowed. "m" is which one is there. */ - m = 0; i = (event->type & (GPM_DRAG|GPM_UP)) != 0; /* i is boolean */ if (event->y > console.max_y) { event->y = console.max_y + 1 - !i; i = 0; - m = GPM_BOT; + event->margin = GPM_BOT; } else if (event->y <= 0) { event->y = 1 - i; i = 0; - m = GPM_TOP; + event->margin = GPM_TOP; } if (event->x > console.max_x) { event->x = console.max_x + 1 - !i; - if (!m) m = GPM_RGT; + if (!event->margin) event->margin = GPM_RGT; } else if (event->x <= 0) { event->x = 1 - i; - if (!m) m = GPM_LFT; + if (!event->margin) event->margin = GPM_LFT; } - event->margin = m; - gpm_report(GPM_PR_DEBUG,"M: %3i %3i (%3i %3i) - butt=%i vc=%i cl=%i", - event->dx,event->dy, - event->x,event->y, - event->buttons, event->vc, - event->clicks); + event->dx, event->dy, event->x, event->y, + event->buttons, event->vc, event->clicks); /* update the global state */ state.x = event->x; state.y = event->y; + oldB = nEvent.buttons; - if (opt_special && event->type & GPM_DOWN) - return processSpecial(event); - - return 1; -} - -/*-------------------------------------------------------------------*/ -static void gpm_killed(int signo) -{ - if(signo==SIGWINCH) { - gpm_report(GPM_PR_WARN,GPM_MESS_RESIZING, option.progname, getpid()); - opt_resize++; - return; - } - if (signo==SIGUSR1) - gpm_report(GPM_PR_WARN,GPM_MESS_KILLED_BY,option.progname, getpid(),option.progname); - exit(0); + if (opt_special && (event->type & GPM_DOWN) && !processSpecial(event)) + rslt = MOUSE_NO_DATA; + + return rslt; } /*-------------------------------------------------------------------*/ int old_main() { int ctlfd; - int i, text_mode, fd; + int i, text_mode; struct timeval timeout; int maxfd = -1; - int pending; + int pending, attempt; Gpm_Event event; + struct micetab *mouse; struct client_info *ci; + fd_set selSet, readySet, connSet; + enum mouse_rslt rslt; - for (i = 1; i <= 1+opt_double; i++) { - which_mouse=mouse_table+i; /* used to access options */ - - if (!opt_dev) gpm_report(GPM_PR_OOPS,GPM_MESS_NEED_MDEV); - - if(!strcmp(opt_dev,"-")) fd=0; /* use stdin */ - else if( (fd=open(opt_dev,O_RDWR | O_NDELAY)) < 0) - gpm_report(GPM_PR_OOPS,GPM_MESS_OPEN,opt_dev); - - /* and then reset the flag */ - fcntl(fd,F_SETFL,fcntl(fd,F_GETFL) & ~O_NDELAY); - - /* init the device, and use the return value as new mouse type */ - if (m_type->init) - m_type=(m_type->init)(fd, m_type->flags, m_type); - if (!m_type) gpm_report(GPM_PR_OOPS,GPM_MESS_MOUSE_INIT); - - which_mouse->fd=fd; - maxfd=max(fd, maxfd); - } - -/*....................................... catch interesting signals */ - + /*....................................... catch interesting signals */ signal(SIGTERM, gpm_killed); signal(SIGINT, gpm_killed); signal(SIGUSR1, gpm_killed); /* usr1 is used by a new gpm killing the old */ signal(SIGWINCH,gpm_killed); /* winch can be sent if console is resized */ signal(SIGPIPE, SIG_IGN); /* WARN */ + init_mice(); handle_console_resize(&event); /* get screen dimensions */ - ctlfd = listen_for_clients(); /*....................................... wait for mouse and connections */ @@ -479,86 +428,88 @@ FD_SET(ctlfd, &connSet); maxfd = max(maxfd, ctlfd); - if (opt_double) FD_SET(mouse_table[2].fd, &connSet); + for (mouse = micelist; mouse; mouse = mouse->next) { + FD_SET(mouse->dev.fd, &connSet); + maxfd = max(maxfd, mouse->dev.fd); + } readySet = connSet; - FD_SET(mouse_table[1].fd, &readySet); -/*--------------------------------------- main loop begins here */ + /*--------------------------------------- main loop begins here */ - while(1) { - selSet=readySet; + while (1) { + selSet = readySet; resetTimeout(); - if (opt_test) timeout.tv_sec=0; + if (option.test) timeout.tv_sec = 0; - if (eventFlag) { /* an event left over by clustering */ - pending=1; - FD_ZERO(&selSet); - FD_SET(mouse_table[eventFlag].fd,&selSet); + while ((pending = select(maxfd + 1, &selSet, NULL_SET, NULL_SET, &timeout)) == 0) { + selSet = readySet; + resetTimeout(); } - else - while((pending=select(maxfd+1,&selSet,NULL_SET,NULL_SET,&timeout))==0){ - selSet=readySet; - resetTimeout(); - } /* go on */ - if (opt_resize) { /* did the console resize? */ + if (console_resized) { /* did the console resize? */ handle_console_resize(&event); - opt_resize--; + console_resized = 0; signal(SIGWINCH, gpm_killed); /* reinstall handler */ notify_clients_resize(); } if (pending < 0) { - if (errno==EBADF) gpm_report(GPM_PR_OOPS,GPM_MESS_SELECT_PROB); - gpm_report(GPM_PR_ERR,GPM_MESS_SELECT_STRING,strerror(errno)); - selSet=readySet; + if (errno == EBADF) gpm_report(GPM_PR_OOPS, GPM_MESS_SELECT_PROB); + gpm_report(GPM_PR_ERR, GPM_MESS_SELECT_STRING, strerror(errno)); + selSet = readySet; resetTimeout(); continue; } - gpm_report(GPM_PR_DEBUG,GPM_MESS_SELECT_TIMES,pending); + gpm_report(GPM_PR_DEBUG, GPM_MESS_SELECT_TIMES, pending); -/*....................................... manage graphic mode */ + /*....................................... manage graphic mode */ - /* - * Be sure to be in text mode. This used to be before select, - * but actually it only matters if you have events. - */ + /* + * Be sure to be in text mode. This used to be before select, + * but actually it only matters if you have events. + */ text_mode = is_text_console(); if (!text_mode && !repeater.type && !repeater.raw) { - close(mouse_table[i].fd); + /* if we don't have repeater then there is only one mouse so + * we can safely use micelist + */ + close(micelist->dev.fd); wait_text_console(); /* reopen, reinit (the function is only used if we have one mouse device) */ - if ((mouse_table[i].fd = open(opt_dev, O_RDWR)) < 0) - gpm_report(GPM_PR_OOPS, GPM_MESS_OPEN,opt_dev); - if (m_type->init) - m_type->init(mouse_table[i].fd, m_type->flags, m_type); - maxfd = max(maxfd, mouse_table[1].fd); + if ((micelist->dev.fd = open(micelist->device, O_RDWR)) < 0) + gpm_report(GPM_PR_OOPS, GPM_MESS_OPEN, micelist->device); + if (micelist->type->init) + micelist->type->init(&micelist->dev, &micelist->options, micelist->type); + maxfd = max(maxfd, micelist->dev.fd); readySet = connSet; - FD_SET(mouse_table[1].fd, &readySet); + FD_SET(micelist->dev.fd, &readySet); continue; /* reselect */ } -/*....................................... got mouse, process event */ -/* - * Well, actually, run a loop to maintain inlining of functions without - * lenghtening the file. This is not too clean a code, but it works.... - */ - - for (i=1; i <= 1+opt_double; i++) { - which_mouse=mouse_table+i; /* used to access options */ - if (FD_ISSET(which_mouse->fd,&selSet)) { - FD_CLR(which_mouse->fd,&selSet); pending--; - if (processMouse(which_mouse->fd, &event, m_type, text_mode)) { - /* pass it to the client or to the default handler, - * or to the selection handler - */ - if (event.vc > MAX_VC) event.vc = 0; - if (event.vc == 0 || !cinfo[event.vc] || !do_client(cinfo[event.vc], &event)) - if (!cinfo[0] || !do_client(cinfo[0], &event)) - do_selection(&event, opt_three); - } + /*....................................... got mouse, process event */ + /* + * Well, actually, run a loop to maintain inlining of functions without + * lenghtening the file. This is not too clean a code, but it works.... + */ + for (mouse = micelist; mouse; mouse = mouse->next) { + if (FD_ISSET(mouse->dev.fd, &selSet)) { + FD_CLR(mouse->dev.fd, &selSet); + pending--; + attempt = 0; + do { + rslt = processMouse(mouse, ++attempt, &event, text_mode); + if (rslt != MOUSE_NO_DATA) { + /* pass it to the client or to the default handler, + * or to the selection handler + */ + if (event.vc > MAX_VC) event.vc = 0; + if (event.vc == 0 || !cinfo[event.vc] || !do_client(cinfo[event.vc], &event)) + if (!cinfo[0] || !do_client(cinfo[0], &event)) + do_selection(&event, mouse->options.three_button); + } + } while (rslt == MOUSE_MORE_DATA); } } @@ -586,7 +537,7 @@ FD_CLR(ci->fd, &selSet); pending--; if (!process_client_request(ci, i, state.x, state.y, state.clicks, - state.buttons, opt_three)) { + state.buttons, micelist->options.three_button)) { FD_CLR(ci->fd, &connSet); FD_CLR(ci->fd, &readySet); remove_client(ci, i); diff -Nru a/src/gpn.c b/src/gpn.c --- a/src/gpn.c 2004-08-10 01:17:58 -05:00 +++ b/src/gpn.c 2004-08-10 01:17:58 -05:00 @@ -28,8 +28,6 @@ #include <stdlib.h> #include <string.h> /* strerror(); ?!? memcpy() */ #include <ctype.h> /* isdigit */ -#include <signal.h> -#include <stdarg.h> /* Log uses it */ #include <unistd.h> /* getopt(),symlink() */ #include "headers/message.h" @@ -49,83 +47,67 @@ return 1; } -/* itz Sat Sep 12 10:55:51 PDT 1998 Added this as replacement for the - unwanted functionality in check_uniqueness. */ - -void check_kill(void) -{ - int old_pid; - FILE* fp = fopen(GPM_NODE_PID, "r"); - - /* if we cannot find the old pid file, leave */ - if (fp == NULL) gpm_report(GPM_PR_OOPS,GPM_MESS_OPEN, GPM_NODE_PID); - - /* else read the pid */ - if (fscanf(fp,"%d",&old_pid) != 1) - gpm_report(GPM_PR_OOPS,GPM_MESS_READ_PROB,GPM_NODE_PID); - fclose(fp); - - gpm_report(GPM_PR_DEBUG,GPM_MESS_KILLING,old_pid); - - /* first check if we run */ - if (kill(old_pid,0) == -1) { - gpm_report(GPM_PR_INFO,GPM_MESS_STALE_PID, GPM_NODE_PID); - unlink(GPM_NODE_PID); - } - /* then kill us (not directly, but the other instance ... ) */ - if (kill(old_pid,SIGTERM) == -1) - gpm_report(GPM_PR_OOPS,GPM_MESS_CANT_KILL, old_pid); - - gpm_report(GPM_PR_INFO,GPM_MESS_KILLED,old_pid); - exit(0); -} - -/* itz Sat Sep 12 10:30:05 PDT 1998 this function used to mix two - completely different things; opening a socket to a running daemon - and checking that a running daemon existed. Ugly. */ -/* rewritten mostly on 20th of February 2002 - nico */ -void check_uniqueness(void) -{ - FILE *fp = 0; - int old_pid = -1; - - if((fp = fopen(GPM_NODE_PID, "r")) != NULL) { - fscanf(fp, "%d", &old_pid); - if (kill(old_pid,0) == -1) { - gpm_report(GPM_PR_INFO,GPM_MESS_STALE_PID, GPM_NODE_PID); - unlink(GPM_NODE_PID); - } else /* we are really running, exit asap! */ - gpm_report(GPM_PR_OOPS,GPM_MESS_ALREADY_RUN, old_pid); - } - /* now try to sign ourself */ - if ((fp = fopen(GPM_NODE_PID,"w")) != NULL) { - fprintf(fp,"%d\n",getpid()); - fclose(fp); - } else { - gpm_report(GPM_PR_OOPS,GPM_MESS_NOTWRITE,GPM_NODE_PID); - } -} - /***************************************************************************** * the function returns a valid type pointer or NULL if not found *****************************************************************************/ -struct Gpm_Type *find_mouse_by_name(char *name) +static struct Gpm_Type *find_mouse_by_name(char *name) { Gpm_Type *type; char *s; int len = strlen(name); - for (type=mice; type->fun; type++) { + for (type = mice; type->fun; type++) { if (!strcasecmp(name, type->name)) break; /* otherwise, look in the synonym list */ for (s = type->synonyms; s; s = strchr(s, ' ')) { while (*s && isspace(*s)) s++; /* skip spaces */ - if(!strncasecmp(name, s, len) && !isprint(*(s + len))) break;/*found*/ + if (!strncasecmp(name, s, len) && !isprint(*(s + len))) break;/*found*/ } - if(s) break; /* found a synonym */ + if (s) break; /* found a synonym */ } - if (!type->fun) return NULL; - return type; + return type->fun ? type : NULL; +} + +static void init_button_sequence(struct miceopt *opt, char *arg) +{ + int i; + static struct { + char *in; + char *out; + } seq[] = { + {"123", "01234567"}, + {"132", "02134657"}, + {"213", "01452367"}, /* warning: these must be readable as integers... */ + {"231", "02461357"}, + {"312", "04152637"}, + {"321", "04261537"}, + {NULL, NULL} + }; + + if (strlen(arg) != 3 || atoi(arg) < 100) + exit(usage("sequence")); + + for (i = 0; seq[i].in && strcmp(seq[i].in, arg); i++); + if (!seq[i].in) + exit(usage("button sequence")); + opt->sequence = strdup(seq[i].out); /* I can rewrite on it */ +} + +static void validate_mouse(struct micetab *mouse, int mouse_no) +{ + if (!mouse->device) { + if (!mouse->type && mouse_no > 1) + gpm_report(GPM_PR_OOPS, + "No device/protocol specified for mouse #%d, probably extra -M option?", mouse_no); + else + gpm_report(GPM_PR_OOPS, "No device specified for mouse #%d", mouse_no); + } + + if (!mouse->type) + mouse->type = find_mouse_by_name(DEF_TYPE); + + if (!mouse->options.sequence) + init_button_sequence(&mouse->options, DEF_SEQUENCE); } static void validate_repeater(char *type) @@ -149,57 +131,87 @@ *****************************************************************************/ void cmdline(int argc, char **argv) { - extern struct options option; + struct micetab *mouse; + struct miceopt *opt; char options[]="a:A::b:B:d:Dg:hi:kl:m:Mo:pr:R::s:S:t:TuvV::23"; - int opt; + int opt_char, tmp; + int mouse_no = 1; - /* initialize for the dual mouse */ - mouse_table[2]=mouse_table[1]=mouse_table[0]; /* copy defaults */ - which_mouse=mouse_table+1; /* use the first */ - - while ((opt = getopt(argc, argv, options)) != -1) { - switch (opt) { - case 'a': opt_accel = atoi(optarg); break; - case 'A': sel_opts.aged = 1; - if (optarg) - sel_opts.age_limit = atoi(optarg); break; - case 'b': opt_baud = atoi(optarg); break; - case 'B': opt_sequence = optarg; break; - case 'd': opt_delta = atoi(optarg); break; - case 'D': option.run_status = GPM_RUN_DEBUG; break; - case 'g': opt_glidepoint_tap=atoi(optarg); break; - case 'h': exit(usage(NULL)); - case 'i': opt_time=atoi(optarg); break; - case 'k': check_kill(); break; - case 'l': console.charset = optarg; break; - case 'm': add_mouse(GPM_ADD_DEVICE,optarg); - opt_dev = optarg; break; /* GO AWAY!*/ - case 'M': opt_double++; + mouse = add_mouse(); + opt = &mouse->options; + + while ((opt_char = getopt(argc, argv, options)) != -1) { + switch (opt_char) { + case 'a': if ((opt->accel = atoi(optarg)) < 1) + exit(usage("acceleration")); + break; + case 'A': sel_opts.aged = 1; + if (optarg) + sel_opts.age_limit = atoi(optarg); + break; + case 'b': opt->baud = atoi(optarg); + break; + case 'B': init_button_sequence(opt, optarg); + break; + case 'd': if ((opt->delta = atoi(optarg)) < 2) + exit(usage("delta")); + break; + case 'D': option.run_status = GPM_RUN_DEBUG; + break; + case 'g': if (atoi(optarg) > 3) + exit(usage("glidepoint tap button")); + opt->glidepoint_tap = GPM_B_LEFT >> (atoi(optarg) - 1); + break; + case 'h': exit(usage(NULL)); + case 'i': opt->time = atoi(optarg); + break; + case 'k': kill_gpm(); + break; + case 'l': console.charset = optarg; + break; + case 'm': mouse->device = optarg; + break; + case 'M': validate_mouse(mouse, mouse_no); + mouse = add_mouse(); + opt = &mouse->options; + mouse_no++; if (!repeater.type && !repeater.raw) repeater.type = find_mouse_by_name(DEF_REP_TYPE); - which_mouse=mouse_table+2; break; - case 'o': add_mouse(GPM_ADD_OPTIONS,optarg); - gpm_report(GPM_PR_DEBUG,"options: %s",optarg); - opt_options = optarg; break; /* GO AWAY */ - case 'p': sel_opts.ptrdrag = 0; break; - case 'r': - /* being called responsiveness, I must take the inverse */ - opt_scale=atoi(optarg); - if(!opt_scale || opt_scale > 100) opt_scale=100; /* the maximum */ - else opt_scale=100/opt_scale; break; + break; + case 'o': gpm_report(GPM_PR_DEBUG,"options: %s", optarg); + opt->text = optarg; + break; + case 'p': sel_opts.ptrdrag = 0; + break; + case 'r': /* being called responsiveness, I must take the inverse */ + tmp = atoi(optarg); + if (!tmp || tmp > 100) tmp = 1; + opt->scalex = 100 / tmp; + break; case 'R': validate_repeater((optarg) ? optarg : DEF_REP_TYPE); break; - case 's': opt_sample = atoi(optarg); break; - case 'S': if (optarg) opt_special = optarg; - else opt_special=""; break; - case 't': add_mouse(GPM_ADD_TYPE,optarg); - opt_type = optarg; break; /* GO AWAY */ - case 'u': option.autodetect = 1; break; - case 'T': opt_test++; break; - case 'v': printf(GPM_MESS_VERSION "\n"); exit(0); - case '2': opt_three = -1; break; - case '3': opt_three = 1; break; - default: exit(usage("commandline")); + case 's': opt->sample = atoi(optarg); + break; + case 'S': if (optarg) opt_special = optarg; + else opt_special=""; + break; + case 't': mouse->type = find_mouse_by_name(optarg); + if (!mouse->type) + exit(M_listTypes()); + break; + case 'u': option.autodetect = 1; + break; + case 'T': option.test++; + break; + case 'v': printf(GPM_MESS_VERSION "\n"); + exit(0); + case '2': opt->three_button = -1; + break; + case '3': opt->three_button = 1; + break; + default: exit(usage("commandline")); } } + + validate_mouse(micelist, mouse_no); } diff -Nru a/src/headers/gpmInt.h b/src/headers/gpmInt.h --- a/src/headers/gpmInt.h 2004-08-10 01:17:58 -05:00 +++ b/src/headers/gpmInt.h 2004-08-10 01:17:58 -05:00 @@ -23,8 +23,6 @@ #ifndef _GPMINT_INCLUDED #define _GPMINT_INCLUDED -#include <sys/types.h> /* time_t */ /* for whom ???? FIXME */ - #include "gpm.h" #if !defined(__GNUC__) @@ -51,12 +49,10 @@ #define DEF_SCALE 10 #define DEF_TIME 250 /* time interval (ms) for multiple clicks */ #define DEF_THREE 0 /* have three buttons? */ -#define DEF_KERNEL 0 /* no kernel module, by default */ /* 10 on old computers (<=386), 0 on current machines */ #define DEF_CLUSTER 0 /* maximum number of clustered events */ -#define DEF_TEST 0 #define DEF_PTRDRAG 1 /* double or triple click */ #define DEF_GLIDEPOINT_TAP 0 /* tapping emulates no buttons by default */ @@ -74,11 +70,6 @@ #define GPM_PTS_CONSOLE "/dev/pts/0" #define GPM_OLD_CONSOLE "/dev/tty0" -/* for adding a mouse; add_mouse */ -#define GPM_ADD_DEVICE 0 -#define GPM_ADD_TYPE 1 -#define GPM_ADD_OPTIONS 2 - /*** mouse commands ***/ #define GPM_AUX_SEND_ID 0xF2 @@ -107,70 +98,49 @@ /*....................................... Structures */ +struct micedev { + int fd; + void *private; +}; + +struct miceopt { + char *sequence; + int baud; + int sample; + int delta; + int accel; + int scalex, scaley; + int time; + int cluster; + int three_button; + int glidepoint_tap; + char *text; /* extra textual options supplied via '-o text' */ +}; + /* * and this is the entry in the mouse-type table */ typedef struct Gpm_Type { - char *name; - char *desc; /* a descriptive line */ - char *synonyms; /* extra names (the XFree name etc) as a list */ - int (*fun)(Gpm_Event *state, unsigned char *data); - struct Gpm_Type *(*init)(int fd, unsigned short flags, struct Gpm_Type *type); - unsigned short flags; - unsigned char proto[4]; - int packetlen; - int howmany; /* how many bytes to read at a time */ - int getextra; /* does it get an extra byte? (only mouseman) */ - int absolute; /* flag indicating absolute pointing device */ + char *name; + char *desc; /* a descriptive line */ + char *synonyms; /* extra names (the XFree name etc) as a list */ + int (*fun)(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state); + int (*init)(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type); + unsigned short flags; + unsigned char proto[4]; + int packetlen; + int howmany; /* how many bytes to read at a time */ + int getextra; /* does it get an extra byte? (only mouseman) */ + int absolute; /* flag indicating absolute pointing device */ - int (*repeat_fun)(Gpm_Event *state, int fd); /* repeat this event into fd */ + int (*repeat_fun)(Gpm_Event *state, int fd); /* repeat this event into fd */ /* itz Mon Jan 11 23:27:54 PST 1999 */ } Gpm_Type; #define GPM_EXTRA_MAGIC_1 0xAA #define GPM_EXTRA_MAGIC_2 0x55 -/*....................................... Global variables */ - -/* this structure is used to hide the dual-mouse stuff */ - -struct mouse_features { - char *opt_type, *opt_dev, *opt_sequence; - int opt_baud,opt_sample,opt_delta, opt_accel, opt_scale, opt_scaley; - int opt_time, opt_cluster, opt_three, opt_glidepoint_tap; - char *opt_options; /* extra textual configuration */ - Gpm_Type *m_type; - int fd; -}; - -extern struct mouse_features mouse_table[3], *which_mouse; /*the current one*/ - -/* this is not very clean, actually, but it works fine */ -#define opt_type (which_mouse->opt_type) -#define opt_dev (which_mouse->opt_dev) -#define opt_sequence (which_mouse->opt_sequence) -#define opt_baud (which_mouse->opt_baud) -#define opt_sample (which_mouse->opt_sample) -#define opt_delta (which_mouse->opt_delta) -#define opt_accel (which_mouse->opt_accel) -#define opt_scale (which_mouse->opt_scale) -#define opt_scaley (which_mouse->opt_scaley) -#define opt_time (which_mouse->opt_time) -#define opt_cluster (which_mouse->opt_cluster) -#define opt_three (which_mouse->opt_three) -#define opt_glidepoint_tap (which_mouse->opt_glidepoint_tap) -#define opt_options (which_mouse->opt_options) - -#define m_type (which_mouse->m_type) - -/* the other variables */ - -extern int opt_test; -extern int opt_kill; -extern int opt_kernel, opt_explicittype; extern char *opt_special; -extern int opt_double; - extern Gpm_Type mice[]; /* where the hell are the descriptions...*/ /* new variables <CLEAN> */ @@ -185,30 +155,31 @@ /* contains all mice */ struct micetab { struct micetab *next; - char *device; - char *protocol; - char *options; + struct micedev dev; + struct miceopt options; + Gpm_Type *type; + char *device; }; struct options { int autodetect; /* -u [aUtodetect..'A' is not available] */ - int no_mice; /* number of mice */ + int test; int run_status; /* startup/daemon/debug */ char *progname; /* hopefully gpm ;) */ - struct micetab *micelist; /* mice and their options */ }; /* global variables */ struct options option; /* one should be enough for us */ extern struct repeater repeater; /* again, only one */ +extern struct micetab *micelist; /* new variables </CLEAN> */ /*....................................... Prototypes */ /* server_tools.c */ -void add_mouse (int type, char *value); -int init_mice (struct micetab *micelist); -int reset_mice(struct micetab *micelist); +struct micetab *add_mouse(void); +void init_mice(void); +void cleanup_mice(void); /* startup.c */ void startup(int argc, char **argv); @@ -218,16 +189,15 @@ /* gpn.c */ void cmdline(int argc, char **argv); -int giveInfo(int request, int fd); -int usage(char *whofailed); -struct Gpm_Type *find_mouse_by_name(char *name); +int giveInfo(int request, int fd); +int usage(char *whofailed); void check_uniqueness(void); -void check_kill(void); - +void kill_gpm(void); /* mice.c */ extern int M_listTypes(void); - /* special.c */ + + /* special.c */ int processSpecial(Gpm_Event *event); int twiddler_key(unsigned long message); int twiddler_key_init(void); diff -Nru a/src/headers/synaptics.h b/src/headers/synaptics.h --- a/src/headers/synaptics.h 2004-08-10 01:17:58 -05:00 +++ b/src/headers/synaptics.h 2004-08-10 01:17:58 -05:00 @@ -62,7 +62,7 @@ ** ** Process the touchpad 6/7/8 byte data. */ -void syn_process_serial_data (Gpm_Event *state, +void syn_process_serial_data (int fd, Gpm_Event *state, unsigned char *data); @@ -72,7 +72,7 @@ ** ** Process the touchpad 6 byte data. */ -void syn_process_ps2_data (Gpm_Event *state, +void syn_process_ps2_data (int fd, Gpm_Event *state, unsigned char *data); diff -Nru a/src/mice.c b/src/mice.c --- a/src/mice.c 2004-08-10 01:17:58 -05:00 +++ b/src/mice.c 2004-08-10 01:17:58 -05:00 @@ -46,15 +46,11 @@ #include <string.h> #include <stdlib.h> #include <termios.h> -#include <fcntl.h> -#include <termios.h> #include <errno.h> #include <unistd.h> #include <ctype.h> -#include <sys/types.h> #include <sys/stat.h> /* stat() */ -#include <sys/time.h> /* select() */ #include <linux/kdev_t.h> /* MAJOR */ #include <linux/keyboard.h> @@ -138,7 +134,7 @@ /*========================================================================*/ #ifdef HAVE_LINUX_INPUT_H -static int M_evdev (Gpm_Event * state, unsigned char *data) +static int M_evdev(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { struct input_event thisevent; (void) memcpy (&thisevent, data, sizeof (struct input_event)); @@ -159,7 +155,7 @@ } #endif /* HAVE_LINUX_INPUT_H */ -static int M_ms(Gpm_Event *state, unsigned char *data) +static int M_ms(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { /* * some devices report a change of middle-button state by @@ -178,7 +174,7 @@ return 0; } -static int M_ms_plus(Gpm_Event *state, unsigned char *data) +static int M_ms_plus(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { static unsigned char prev=0; @@ -198,7 +194,7 @@ return 0; } -static int M_ms_plus_lr(Gpm_Event *state, unsigned char *data) +static int M_ms_plus_lr(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { /* * Same as M_ms_plus but with an addition by Edmund GRIMLEY EVANS @@ -234,7 +230,7 @@ int SUMMA_BORDER=100; int summamaxx,summamaxy; char summaid=-1; -static int M_summa(Gpm_Event *state, unsigned char *data) +static int M_summa(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { int x, y; @@ -301,7 +297,7 @@ /* 'Genitizer' (kw@xxxxxxxxxxxxxxxx 11/12/97) */ -static int M_geni(Gpm_Event *state, unsigned char *data) +static int M_geni(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { /* this is a little confusing. If we use the stylus, we * have three buttons (tip, lower, upper), and if @@ -324,7 +320,7 @@ /* m$ 'Intellimouse' (steveb 20/7/97) */ -static int M_ms3(Gpm_Event *state, unsigned char *data) +static int M_ms3(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { state->wdx = state->wdy = 0; state->buttons= ((data[0] & 0x20) >> 3) /* left */ @@ -375,7 +371,7 @@ } /* M_brw is a variant of m$ 'Intellimouse' the middle button is different */ -static int M_brw(Gpm_Event *state, unsigned char *data) +static int M_brw(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { state->buttons= ((data[0] & 0x20) >> 3) /* left */ | ((data[3] & 0x20) >> 4) /* middle */ @@ -396,7 +392,7 @@ return 0; } -static int M_bare(Gpm_Event *state, unsigned char *data) +static int M_bare(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { /* a bare ms protocol */ state->buttons= ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4); @@ -405,7 +401,7 @@ return 0; } -static int M_sun(Gpm_Event *state, unsigned char *data) +static int M_sun(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { state->buttons= (~data[0]) & 0x07; state->dx= (signed char)(data[1]); @@ -413,7 +409,7 @@ return 0; } -static int M_msc(Gpm_Event *state, unsigned char *data) +static int M_msc(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { state->buttons= (~data[0]) & 0x07; state->dx= (signed char)(data[1]) + (signed char)(data[3]); @@ -465,7 +461,7 @@ return write(fd,buffer,4); } -static int M_logimsc(Gpm_Event *state, unsigned char *data) /* same as msc */ +static int M_logimsc(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { state->buttons= (~data[0]) & 0x07; state->dx= (signed char)(data[1]) + (signed char)(data[3]); @@ -473,7 +469,7 @@ return 0; } -static int M_mm(Gpm_Event *state, unsigned char *data) +static int M_mm(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { state->buttons= data[0] & 0x07; state->dx= (data[0] & 0x10) ? data[1] : - data[1]; @@ -481,7 +477,7 @@ return 0; } -static int M_logi(Gpm_Event *state, unsigned char *data) /* equal to mm */ +static int M_logi(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { state->buttons= data[0] & 0x07; state->dx= (data[0] & 0x10) ? data[1] : - data[1]; @@ -489,7 +485,7 @@ return 0; } -static int M_bm(Gpm_Event *state, unsigned char *data) /* equal to sun */ +static int M_bm(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { state->buttons= (~data[0]) & 0x07; state->dx= (signed char)data[1]; @@ -497,7 +493,7 @@ return 0; } -static int M_ps2(Gpm_Event *state, unsigned char *data) +static int M_ps2(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { static int tap_active=0; /* there exist glidepoint ps2 mice */ @@ -506,8 +502,8 @@ !!(data[0]&2) * GPM_B_RIGHT + !!(data[0]&4) * GPM_B_MIDDLE; - if (data[0]==0 && opt_glidepoint_tap) /* by default this is false */ - state->buttons = tap_active = opt_glidepoint_tap; + if (data[0]==0 && opt->glidepoint_tap) /* by default this is false */ + state->buttons = tap_active = opt->glidepoint_tap; else if (tap_active) { if (data[0]==8) state->buttons = tap_active = 0; @@ -530,10 +526,11 @@ state->dy= -((data[0] & 0x20) ? data[2]-256 : data[2]); else state->dy = 0; + return 0; } -static int M_imps2(Gpm_Event *state, unsigned char *data) +static int M_imps2(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { static int tap_active=0; /* there exist glidepoint ps2 mice */ @@ -543,8 +540,8 @@ state->buttons= ((data[0] & 1) << 2) /* left */ | ((data[0] & 6) >> 1); /* middle and right */ - if (data[0]==0 && opt_glidepoint_tap) // by default this is false - state->buttons = tap_active = opt_glidepoint_tap; + if (data[0]==0 && opt->glidepoint_tap) // by default this is false + state->buttons = tap_active = opt->glidepoint_tap; else if (tap_active) { if (data[0]==8) state->buttons = tap_active = 0; @@ -574,7 +571,7 @@ } -static int M_netmouse(Gpm_Event *state, unsigned char *data) +static int M_netmouse(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { /* Avoid these beasts if you can. They connect to normal PS/2 port, * but their protocol is one byte longer... So if you have notebook @@ -613,45 +610,45 @@ } /* standard ps2 */ -static Gpm_Type *I_ps2(int fd, unsigned short flags, struct Gpm_Type *type) +int I_ps2(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { static unsigned char s[] = { 246, 230, 244, 243, 100, 232, 3, }; - write (fd, s, sizeof (s)); + write(dev->fd, s, sizeof (s)); usleep (30000); - tcflush (fd, TCIFLUSH); - return type; + tcflush (dev->fd, TCIFLUSH); + return 0; } -static Gpm_Type *I_netmouse(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_netmouse(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { unsigned char magic[6] = { 0xe8, 0x03, 0xe6, 0xe6, 0xe6, 0xe9 }; int i; - if (!check_no_options(type->name, opt_options, ',')) return NULL; + if (!check_no_options(type->name, opt->text, ',')) return -1; for (i=0; i<6; i++) { unsigned char c = 0; - write( fd, magic+i, 1 ); - read( fd, &c, 1 ); + write(dev->fd, magic+i, 1 ); + read(dev->fd, &c, 1 ); if (c != 0xfa) { gpm_report(GPM_PR_ERR,GPM_MESS_NETM_NO_ACK,c); - return NULL; + return -1; } } { unsigned char rep[3] = { 0, 0, 0 }; - read( fd, rep, 1 ); - read( fd, rep+1, 1 ); - read( fd, rep+2, 1 ); + read( dev->fd, rep, 1 ); + read( dev->fd, rep+1, 1 ); + read( dev->fd, rep+2, 1 ); if (rep[0] || (rep[1] != 0x33) || (rep[2] != 0x55)) { gpm_report(GPM_PR_ERR,GPM_MESS_NETM_INV_MAGIC, rep[0], rep[1], rep[2]); - return NULL; + return -1; } } - return type; + return 0; } #define GPM_B_BOTH (GPM_B_LEFT|GPM_B_RIGHT) -static int M_mman(Gpm_Event *state, unsigned char *data) +static int M_mman(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { /* * the damned MouseMan has 3/4 bytes packets. The extra byte @@ -689,7 +686,7 @@ mytype->getextra=1; } else { if (b & 0x2) prev |= GPM_B_MIDDLE; - if (b & 0x1) prev |= opt_glidepoint_tap; + if (b & 0x1) prev |= opt->glidepoint_tap; } } state->buttons=prev; @@ -733,7 +730,7 @@ #define IsA(m) ((WacomModell==(-1))? 0:!strcmp(#m,wcmodell[WacomModell].name)) -static int M_wacom(Gpm_Event *state, unsigned char *data) +static int M_wacom(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { static int ox=-1, oy; int x, y; @@ -823,7 +820,7 @@ #define CAL_Y_MAX 0xF40 #define CAL_Y_SIZE (CAL_Y_MAX - CAL_Y_MIN) -static int M_calus(Gpm_Event *state, unsigned char *data) +static int M_calus(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { int x, y; @@ -855,7 +852,7 @@ return 0; } -static int M_calus_rel(Gpm_Event *state, unsigned char *data) +static int M_calus_rel(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { static int ox=-1, oy; int x, y; @@ -889,7 +886,7 @@ #define NCR_DELTA_X (NCR_RIGHT_X - NCR_LEFT_X) #define NCR_DELTA_Y (NCR_TOP_Y - NCR_BOTTOM_Y) -static int M_ncr(Gpm_Event *state, unsigned char *data) +static int M_ncr(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { int x,y; @@ -931,7 +928,7 @@ return 0; } -static int M_twid(Gpm_Event *state, unsigned char *data) +static int M_twid(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { unsigned long message=0UL; int i,h,v; static int lasth, lastv, lastkey, key, lock=0, autorepeat=0; @@ -1049,7 +1046,7 @@ #ifdef HAVE_LINUX_JOYSTICK_H /* Joystick mouse emulation (David Given) */ -static int M_js(Gpm_Event *state, unsigned char *data) +static int M_js(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { struct JS_DATA_TYPE *jdata = (void*)data; static int centerx = 0; @@ -1098,21 +1095,21 @@ #endif /* have joystick.h */ /* Synaptics TouchPad mouse emulation (Henry Davies) */ -static int M_synaptics_serial(Gpm_Event *state, unsigned char *data) +static int M_synaptics_serial(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { - syn_process_serial_data (state, data); + syn_process_serial_data(dev->fd, state, data); return 0; } /* Synaptics TouchPad mouse emulation (Henry Davies) */ -static int M_synaptics_ps2(Gpm_Event *state, unsigned char *data) +static int M_synaptics_ps2(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { - syn_process_ps2_data(state, data); + syn_process_ps2_data(dev->fd, state, data); return 0; } -static int M_mtouch(Gpm_Event *state, unsigned char *data) +static int M_mtouch(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { /* * This is a simple decoder for the MicroTouch touch screen @@ -1150,7 +1147,7 @@ if (avgx < 0) { /* press event */ GET_TIME(tv); - if (DIF_TIME(uptv, tv) < opt_time) { + if (DIF_TIME(uptv, tv) < opt->time) { /* count as button press placed at finger-up pixel */ state->buttons = GPM_B_LEFT; realposx = avgx = upx; state->x = REAL_TO_XCELL(realposx); @@ -1192,7 +1189,7 @@ static int gunze_calib[4]; /* x0,y0 x1,y1 (measured at 1/8 and 7/8) */ static int gunze_debounce = 100; /* milliseconds: ignore shorter taps */ -static int M_gunze(Gpm_Event *state, unsigned char *data) +static int M_gunze(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { /* * This generates button-1 events, by now. @@ -1255,7 +1252,7 @@ GET_TIME(tv); timediff = DIF_TIME(uptv, tv); released = 0; - if (timediff > gunze_debounce && timediff < opt_time) { + if (timediff > gunze_debounce && timediff < opt->time) { /* count as button press placed at finger-up pixel */ dragging = 1; state->buttons = GPM_B_LEFT; @@ -1304,7 +1301,7 @@ /* corresponding correction of the protocol identification */ /* mask) 2001/07/12 by Maciej W. Rozycki (macro@xxxxxxxxxxxxx) */ -static int M_vsxxx_aa(Gpm_Event *state, unsigned char *data) +static int M_vsxxx_aa(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { /* The mouse protocol is as follows: @@ -1354,7 +1351,7 @@ /* Genius Wizardpad tablet -- Matt Kimball (mkimball@xxxxxxxxxxxx) */ static int wizardpad_width = -1; static int wizardpad_height = -1; -static int M_wp(Gpm_Event *state, unsigned char *data) +static int M_wp(struct micedev *dev, struct miceopt *opt, unsigned char *data, Gpm_Event *state) { int x, y, pressure; @@ -1380,9 +1377,9 @@ /*========================================================================*/ /* Then, mice should be initialized */ -static Gpm_Type* I_empty(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_empty(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { - return check_no_options(type->name, opt_options, ',') ? type : NULL; + return check_no_options(type->name, opt->text, ',') ? 0 : -1; } static int setspeed(int fd,int old,int new,int needtowrite,unsigned short flags) @@ -1439,27 +1436,27 @@ {125,"Q"}, {1E9,"N"}, }; -static Gpm_Type* I_serial(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_serial(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { int i; unsigned char c; fd_set set; struct timeval timeout={0,0}; /* used when not debugging */ /* accept "-o dtr", "-o rts" and "-o both" */ - if (option_modem_lines(fd, type->name, opt_options)) return NULL; + if (option_modem_lines(dev->fd, type->name, opt->text)) return -1; #ifndef DEBUG /* flush any pending input (thanks, Miguel) */ FD_ZERO(&set); for(i=0; /* always */ ; i++) { - FD_SET(fd,&set); - switch(select(fd+1,&set,(fd_set *)NULL,(fd_set *)NULL,&timeout/*zero*/)){ - case 1: if (read(fd,&c,1)==0) break; + FD_SET(dev->fd,&set); + switch(select(dev->fd+1,&set,(fd_set *)NULL,(fd_set *)NULL,&timeout/*zero*/)){ + case 1: if (read(dev->fd,&c,1)==0) break; case -1: continue; } break; } - if (type->fun==M_logimsc) write(fd, "QU", 2 ); + if (type->fun==M_logimsc) write(dev->fd, "QU", 2 ); #if 0 /* Did this ever work? -- I don't know, but should we not remove it, * if it doesn't work ??? -- Nico */ @@ -1472,7 +1469,7 @@ /* Non mman: change from any available speed to the chosen one */ for (i=9600; i>=1200; i/=2) - setspeed(fd, i, opt_baud, (type->fun != M_mman) /* write */, flags); + setspeed(dev->fd, i, opt->baud, (type->fun != M_mman) /* write */, type->flags); /* * reset the MouseMan/TrackMan to use the 3/4 byte protocol @@ -1480,50 +1477,50 @@ * Changed after 1.14; why not having "I_mman" now? */ if (type->fun==M_mman) { - setspeed(fd, 1200, 1200, 0, flags); /* no write */ - write(fd, "*X", 2); - setspeed(fd, 1200, opt_baud, 0, flags); /* no write */ - return type; + setspeed(dev->fd, 1200, 1200, 0, type->flags); /* no write */ + write(dev->fd, "*X", 2); + setspeed(dev->fd, 1200, opt->baud, 0, type->flags); /* no write */ + return 0; } if(type->fun==M_geni) { gpm_report(GPM_PR_INFO,GPM_MESS_INIT_GENI); - setspeed(fd, 1200, 9600, 1, flags); /* write */ - write(fd, ":" ,1); - write(fd, "E" ,1); /* setup tablet. relative mode, resolution... */ - write(fd, "@" ,1); /* setup tablet. relative mode, resolution... */ + setspeed(dev->fd, 1200, 9600, 1, type->flags); /* write */ + write(dev->fd, ":" ,1); + write(dev->fd, "E" ,1); /* setup tablet. relative mode, resolution... */ + write(dev->fd, "@" ,1); /* setup tablet. relative mode, resolution... */ } if (type->fun==M_synaptics_serial) { int packet_length; - setspeed (fd, 1200, 1200, 1, flags); - packet_length = syn_serial_init (fd); - setspeed (fd, 1200, 9600, 1, flags); + setspeed (dev->fd, 1200, 1200, 1, type->flags); + packet_length = syn_serial_init (dev->fd); + setspeed (dev->fd, 1200, 9600, 1, type->flags); type->packetlen = packet_length; type->howmany = packet_length; } if (type->fun==M_vsxxx_aa) { - setspeed (fd, 4800, 4800, 0, flags); /* no write */ - write(fd, "R", 1); /* initialize a mouse; without getting an "R" */ + setspeed (dev->fd, 4800, 4800, 0, type->flags); /* no write */ + write(dev->fd, "R", 1); /* initialize a mouse; without getting an "R" */ /* a mouse does not send a bytestream */ } - return type; + return 0; } -static Gpm_Type* I_logi(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_logi(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { int i; struct stat buf; int busmouse; - if (!check_no_options(type->name, opt_options, ',')) return NULL; + if (!check_no_options(type->name, opt->text, ',')) return -1; /* is this a serial- or a bus- mouse? */ - if(fstat(fd,&buf)==-1) gpm_report(GPM_PR_OOPS,GPM_MESS_FSTAT); + if(fstat(dev->fd,&buf)==-1) gpm_report(GPM_PR_OOPS,GPM_MESS_FSTAT); i=MAJOR(buf.st_rdev); /* I don't know why this is herein, but I remove it. I don't think a @@ -1536,20 +1533,20 @@ type->howmany = busmouse ? 3 : 1; /* change from any available speed to the chosen one */ - for (i=9600; i>=1200; i/=2) setspeed(fd, i, opt_baud, 1 /* write */, flags); + for (i=9600; i>=1200; i/=2) setspeed(dev->fd, i, opt->baud, 1 /* write */, type->flags); /* this stuff is peculiar of logitech mice, also for the serial ones */ - write(fd, "S", 1); - setspeed(fd, opt_baud, opt_baud, 1 /* write */, + write(dev->fd, "S", 1); + setspeed(dev->fd, opt->baud, opt->baud, 1 /* write */, CS8 |PARENB |PARODD |CREAD |CLOCAL |HUPCL); /* configure the sample rate */ - for (i=0;opt_sample<=sampletab[i].sample;i++) ; - write(fd,sampletab[i].code,1); - return type; + for (i=0;opt->sample<=sampletab[i].sample;i++) ; + write(dev->fd,sampletab[i].code,1); + return 0; } -static Gpm_Type *I_wacom(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_wacom(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { /* wacom graphire tablet */ #define UD_RESETBAUD "\r$" /* reset baud rate to default (wacom V) */ @@ -1564,19 +1561,19 @@ { /* Init Wacom communication; this is modified from xf86Wacom.so module */ /* Set speed to 19200 */ - setspeed (fd, 1200, 19200, 0, B19200|CS8|CREAD|CLOCAL|HUPCL); + setspeed (dev->fd, 1200, 19200, 0, B19200|CS8|CREAD|CLOCAL|HUPCL); /* Send Reset Baudrate Command */ - write(fd, UD_RESETBAUD, strlen(UD_RESETBAUD)); + write(dev->fd, UD_RESETBAUD, strlen(UD_RESETBAUD)); usleep(250000); /* Send Reset Command */ - write(fd, UD_RESET, strlen(UD_RESET)); + write(dev->fd, UD_RESET, strlen(UD_RESET)); usleep(75000); /* Set speed to 9600bps */ - setspeed (fd, 1200, 9600, 0, B9600|CS8|CREAD|CLOCAL|HUPCL); + setspeed (dev->fd, 1200, 9600, 0, B9600|CS8|CREAD|CLOCAL|HUPCL); /* Send Reset Command */ - write(fd, UD_RESET, strlen(UD_RESET)); + write(dev->fd, UD_RESET, strlen(UD_RESET)); usleep(250000); - write(fd, UD_STOP, strlen(UD_STOP)); + write(dev->fd, UD_STOP, strlen(UD_STOP)); usleep(100000); } @@ -1590,7 +1587,7 @@ struct timeval timeout; fd_set readfds; int err; - FD_ZERO(&readfds); FD_SET(fd, &readfds); + FD_ZERO(&readfds); FD_SET(dev->fd, &readfds); timeout.tv_sec = 0; timeout.tv_usec = 200000; err = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout); return((err>0)?1:err); @@ -1606,11 +1603,11 @@ * Get Data to buffer until full or timeout. * Give back 0 for timeout and !0 for buffer full */ - if (cmd) write(fd,cmd,strlen(cmd)); + if (cmd) write(dev->fd,cmd,strlen(cmd)); memset(buffer,0,sizeof(buffer)); p=buffer; err=wait_wacom(); while (err != -1 && err && (p-buffer)<(sizeof(buffer)-1)) { - p+= read(fd,p,(sizeof(buffer)-1)-(p-buffer)); + p+= read(dev->fd,p,(sizeof(buffer)-1)-(p-buffer)); err=wait_wacom(); } /* return 1 for buffer full */ @@ -1634,7 +1631,7 @@ {"", OPT_END} }; - parse_options(type->name, opt_options, ',', optioninfo); + parse_options(type->name, opt->text, ',', optioninfo); type->absolute = WacomAbsoluteWanted; reset_wacom(); @@ -1668,23 +1665,23 @@ wmaxx = (wmaxx-wcmodell[WacomModell].border); wmaxy = (wmaxy-wcmodell[WacomModell].border); } - write(fd,UD_SENDCOORDS,4); + write(dev->fd,UD_SENDCOORDS,4); - return type; + return 0; } -static Gpm_Type *I_pnp(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_pnp(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { struct termios tty; /* accept "-o dtr", "-o rts" and "-o both" */ - if (option_modem_lines(fd, type->name, opt_options)) return NULL; + if (option_modem_lines(dev->fd, type->name, opt->text)) return -1; /* * Just put the device to 1200 baud. Thanks to Francois Chastrette * for his great help and debugging with his own pnp device. */ - tcgetattr(fd, &tty); + tcgetattr(dev->fd, &tty); tty.c_iflag = IGNBRK | IGNPAR; tty.c_oflag = 0; @@ -1692,15 +1689,15 @@ tty.c_line = 0; tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; - tty.c_cflag = flags | B1200; - tcsetattr(fd, TCSAFLUSH, &tty); /* set parameters */ + tty.c_cflag = type->flags | B1200; + tcsetattr(dev->fd, TCSAFLUSH, &tty); /* set parameters */ /* * Don't read the silly initialization string. I don't want to see * the vendor name: it is only propaganda, with no information. */ - return type; + return 0; } /* @@ -1748,7 +1745,7 @@ /* intellimouse, ps2 version: Ben Pfaff and Colin Plumb */ /* Autodetect: Steve Bennett */ -static Gpm_Type *I_imps2(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_imps2(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { int id; static unsigned char basic_init[] = { GPM_AUX_ENABLE_DEV, GPM_AUX_SET_SAMPLE, 100 }; @@ -1756,36 +1753,36 @@ static unsigned char ps2_init[] = { GPM_AUX_SET_SCALE11, GPM_AUX_ENABLE_DEV, GPM_AUX_SET_SAMPLE, 100, GPM_AUX_SET_RES, 3, }; /* Do a basic init in case the mouse is confused */ - write_to_mouse(fd, basic_init, sizeof (basic_init)); + write_to_mouse(dev->fd, basic_init, sizeof (basic_init)); /* Now try again and make sure we have a PS/2 mouse */ - if (write_to_mouse(fd, basic_init, sizeof (basic_init)) != 0) { + if (write_to_mouse(dev->fd, basic_init, sizeof (basic_init)) != 0) { gpm_report(GPM_PR_ERR,GPM_MESS_IMPS2_INIT); - return(NULL); + return -1; } /* Try to switch to 3 button mode */ - if (write_to_mouse(fd, imps2_init, sizeof (imps2_init)) != 0) { + if (write_to_mouse(dev->fd, imps2_init, sizeof (imps2_init)) != 0) { gpm_report(GPM_PR_ERR,GPM_MESS_IMPS2_FAILED); - return(NULL); + return -1; } /* Read the mouse id */ - id = read_mouse_id(fd); + id = read_mouse_id(dev->fd); if (id == GPM_AUX_ID_ERROR) { gpm_report(GPM_PR_ERR,GPM_MESS_IMPS2_MID_FAIL); id = GPM_AUX_ID_PS2; } /* And do the real initialisation */ - if (write_to_mouse(fd, ps2_init, sizeof (ps2_init)) != 0) { + if (write_to_mouse(dev->fd, ps2_init, sizeof (ps2_init)) != 0) { gpm_report(GPM_PR_ERR,GPM_MESS_IMPS2_SETUP_FAIL); } if (id == GPM_AUX_ID_IMPS2) { /* Really an intellipoint, so initialise 3 button mode (4 byte packets) */ gpm_report(GPM_PR_INFO,GPM_MESS_IMPS2_AUTO); - return type; + return 0; } if (id != GPM_AUX_ID_PS2) { gpm_report(GPM_PR_ERR,GPM_MESS_IMPS2_BAD_ID, id); @@ -1793,64 +1790,64 @@ else gpm_report(GPM_PR_INFO,GPM_MESS_IMPS2_PS2); for (type=mice; type->fun; type++) - if (strcmp(type->name, "ps2") == 0) return(type); + if (strcmp(type->name, "ps2") == 0) return 0; /* ps2 was not found!!! */ - return(NULL); + return -1; } /* * This works with Dexxa Optical Mouse, but because in X same initstring * is named ExplorerPS/2 so I named it in the same way. */ -static Gpm_Type *I_exps2(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_exps2(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { static unsigned char s1[] = { 243, 200, 243, 200, 243, 80, }; - if (!check_no_options(type->name, opt_options, ',')) return NULL; + if (!check_no_options(type->name, opt->text, ',')) return -1; - write (fd, s1, sizeof (s1)); + write (dev->fd, s1, sizeof (s1)); usleep (30000); - tcflush (fd, TCIFLUSH); - return type; + tcflush (dev->fd, TCIFLUSH); + return 0; } -static Gpm_Type *I_twid(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_twid(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { - if (!check_no_options(type->name, opt_options, ',')) return NULL; + if (!check_no_options(type->name, opt->text, ',')) return -1; - if (twiddler_key_init() != 0) return NULL; + if (twiddler_key_init() != 0) return -1; /* * the twiddler is a serial mouse: just drop dtr * and run at 2400 (unless specified differently) */ - if (opt_baud == DEF_BAUD) opt_baud = 2400; - opt_options = "dtr"; - return I_serial(fd, flags, type); + if (opt->baud == DEF_BAUD) opt->baud = 2400; + opt->text = "dtr"; + return I_serial(dev, opt, type); } -static Gpm_Type *I_calus(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_calus(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { - if (!check_no_options(type->name, opt_options, ',')) return NULL; + if (!check_no_options(type->name, opt->text, ',')) return -1; - if (opt_baud == 1200) opt_baud = 9600; /* default to 9600 */ - return I_serial(fd, flags, type); + if (opt->baud == 1200) opt->baud = 9600; /* default to 9600 */ + return I_serial(dev, opt, type); } /* synaptics touchpad, ps2 version: Henry Davies */ -static Gpm_Type *I_synps2(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_synps2(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { - syn_ps2_init (fd); - return type; + syn_ps2_init (dev->fd); + return 0; } -static Gpm_Type *I_summa(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_summa(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { void resetsumma() { - write(fd,0,1); /* Reset */ + write(dev->fd,0,1); /* Reset */ usleep(400000); /* wait */ } int waitsumma() @@ -1858,7 +1855,7 @@ struct timeval timeout; fd_set readfds; int err; - FD_ZERO(&readfds); FD_SET(fd, &readfds); + FD_ZERO(&readfds); FD_SET(dev->fd, &readfds); timeout.tv_sec = 0; timeout.tv_usec = 200000; err = select(FD_SETSIZE, &readfds, NULL, NULL, &timeout); return(err); @@ -1881,34 +1878,34 @@ char GEN_MODELL=0x7f; /* Set speed to 9600bps */ - setspeed (fd, 1200, 9600, 1, B9600|CS8|CREAD|CLOCAL|HUPCL|PARENB|PARODD); + setspeed (dev->fd, 1200, 9600, 1, B9600|CS8|CREAD|CLOCAL|HUPCL|PARENB|PARODD); resetsumma(); - write(fd, SS_PROMPT_MODE, strlen(SS_PROMPT_MODE)); + write(dev->fd, SS_PROMPT_MODE, strlen(SS_PROMPT_MODE)); if (strstr(type->name,"acecad")!=NULL) summaid=11; if (summaid<0) { /* Summagraphics test */ /* read the Summa Firm-ID */ - write(fd, SS_FIRMID, strlen(SS_FIRMID)); + write(dev->fd, SS_FIRMID, strlen(SS_FIRMID)); err=waitsumma(); if (!((err == -1) || (!err))) { summaid=10; /* Original Summagraphics */ - read(fd, buffer, 255); /* Read Firm-ID */ + read(dev->fd, buffer, 255); /* Read Firm-ID */ } } if (summaid<0) { /* Genius-test */ resetsumma(); - write(fd,GEN_MMSERIES,1); - write(fd,&GEN_MODELL,1); /* Read modell */ + write(dev->fd,GEN_MMSERIES,1); + write(dev->fd,&GEN_MODELL,1); /* Read modell */ err=waitsumma(); if (!((err == -1) || (!err))) { /* read Genius-ID */ err=waitsumma(); if (!((err == -1) || (!err))) { err=waitsumma(); if (!((err == -1) || (!err))) { - read(fd,&config,1); + read(dev->fd,&config,1); summaid=(config[0] & 224) >> 5; /* genius tablet-id (0-7)*/ } } @@ -1918,29 +1915,29 @@ /* unknown tablet ?*/ if ((summaid<0) || (summaid==11)) { resetsumma(); - write(fd, SS_BINARY_FMT SS_PROMPT_MODE, 3); + write(dev->fd, SS_BINARY_FMT SS_PROMPT_MODE, 3); } /* read tablet size */ err=waitsumma(); - if (!((err == -1) || (!err))) read(fd,buffer,sizeof(buffer)); - write(fd,SS_READCONFIG,1); - read(fd,&config,5); + if (!((err == -1) || (!err))) read(dev->fd,buffer,sizeof(buffer)); + write(dev->fd,SS_READCONFIG,1); + read(dev->fd,&config,5); summamaxx=(config[2]<<7 | config[1])-(SUMMA_BORDER*2); summamaxy=(config[4]<<7 | config[3])-(SUMMA_BORDER*2); - write(fd,SS_ABSOLUTE SS_STREAM_MODE SS_UPPER_ORIGIN,3); - if (summaid<0) write(fd,SS_500LPI SS_TABID0 SS_BINARY_FMT,4); + write(dev->fd,SS_ABSOLUTE SS_STREAM_MODE SS_UPPER_ORIGIN,3); + if (summaid<0) write(dev->fd,SS_500LPI SS_TABID0 SS_BINARY_FMT,4); - return type; + return 0; } -static Gpm_Type *I_mtouch(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_mtouch(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { struct termios tty; /* Set speed to 9600bps (copied from I_summa, above :) */ - tcgetattr(fd, &tty); + tcgetattr(dev->fd, &tty); tty.c_iflag = IGNBRK | IGNPAR; tty.c_oflag = 0; tty.c_lflag = 0; @@ -1948,17 +1945,17 @@ tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; tty.c_cflag = B9600|CS8|CREAD|CLOCAL|HUPCL; - tcsetattr(fd, TCSAFLUSH, &tty); + tcsetattr(dev->fd, TCSAFLUSH, &tty); /* Turn it to "format tablet" and "mode stream" */ - write(fd,"\001MS\r\n\001FT\r\n",10); + write(dev->fd,"\001MS\r\n\001FT\r\n",10); - return type; + return 0; } /* simple initialization for the gunze touchscreen */ -static Gpm_Type *I_gunze(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_gunze(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { struct termios tty; FILE *f; @@ -1973,23 +1970,23 @@ /* FIXME: add corner tapping */ {"", OPT_END} }; - parse_options(type->name, opt_options, ',', optioninfo); + parse_options(type->name, opt->text, ',', optioninfo); /* check that the baud rate is valid */ - if (opt_baud == DEF_BAUD) opt_baud = 19200; /* force 19200 as default */ - if (opt_baud != 9600 && opt_baud != 19200) { + if (opt->baud == DEF_BAUD) opt->baud = 19200; /* force 19200 as default */ + if (opt->baud != 9600 && opt->baud != 19200) { gpm_report(GPM_PR_ERR, GPM_MESS_GUNZE_WRONG_BAUD, option.progname, type->name); - opt_baud = 19200; + opt->baud = 19200; } - tcgetattr(fd, &tty); + tcgetattr(dev->fd, &tty); tty.c_iflag = IGNBRK | IGNPAR; tty.c_oflag = 0; tty.c_lflag = 0; tty.c_line = 0; tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; - tty.c_cflag = (opt_baud == 9600 ? B9600 : B19200) |CS8|CREAD|CLOCAL|HUPCL; - tcsetattr(fd, TCSAFLUSH, &tty); + tty.c_cflag = (opt->baud == 9600 ? B9600 : B19200) |CS8|CREAD|CLOCAL|HUPCL; + tcsetattr(dev->fd, TCSAFLUSH, &tty); /* FIXME: try to find some information about the device */ @@ -2012,18 +2009,18 @@ gunze_calib[0] = gunze_calib[1] = 128; /* 1/8 */ gunze_calib[2] = gunze_calib[3] = 896; /* 7/8 */ } - return type; + return 0; } /* Genius Wizardpad tablet -- Matt Kimball (mkimball@xxxxxxxxxxxx) */ -static Gpm_Type *I_wp(int fd, unsigned short flags, struct Gpm_Type *type) +static int I_wp(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type) { struct termios tty; char tablet_info[256]; int count, pos, size; /* Set speed to 9600bps (copied from I_summa, above :) */ - tcgetattr(fd, &tty); + tcgetattr(dev->fd, &tty); tty.c_iflag = IGNBRK | IGNPAR; tty.c_oflag = 0; tty.c_lflag = 0; @@ -2031,22 +2028,22 @@ tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; tty.c_cflag = B9600|CS8|CREAD|CLOCAL|HUPCL; - tcsetattr(fd, TCSAFLUSH, &tty); + tcsetattr(dev->fd, TCSAFLUSH, &tty); /* Reset the tablet (':') and put it in remote mode ('S') so that it isn't sending anything to us. */ - write(fd, ":S", 2); - tcsetattr(fd, TCSAFLUSH, &tty); + write(dev->fd, ":S", 2); + tcsetattr(dev->fd, TCSAFLUSH, &tty); /* Query the model of the tablet */ - write(fd, "T", 1); + write(dev->fd, "T", 1); sleep(1); - count = read(fd, tablet_info, 255); + count = read(dev->fd, tablet_info, 255); /* The tablet information should start with "KW" followed by the rest of the model number. If it isn't there, it probably isn't a WizardPad. */ - if(count < 2) return NULL; - if(tablet_info[0] != 'K' || tablet_info[1] != 'W') return NULL; + if(count < 2) return -1; + if(tablet_info[0] != 'K' || tablet_info[1] != 'W') return -1; /* Now, we want the width and height of the tablet. They should be of the form "X###" and "Y###" where ### is the number of units of @@ -2068,9 +2065,9 @@ } /* Set the tablet to stream mode with 180 updates per sec. ('O') */ - write(fd, "O", 1); + write(dev->fd, "O", 1); - return type; + return 0; } /*========================================================================*/ diff -Nru a/src/prog/mouse-test.c b/src/prog/mouse-test.c --- a/src/prog/mouse-test.c 2004-08-10 01:17:58 -05:00 +++ b/src/prog/mouse-test.c 2004-08-10 01:17:58 -05:00 @@ -50,22 +50,9 @@ #define max(a,b) ((a)>(b)?(a):(b)) #endif - -/* this material is needed to pass options to mice.c */ -struct mouse_features mymouse = { - DEF_TYPE, DEF_DEV, DEF_SEQUENCE, - DEF_BAUD, DEF_SAMPLE, DEF_DELTA, DEF_ACCEL, DEF_SCALE, DEF_SCALE /*scaley*/, - DEF_TIME, DEF_CLUSTER, DEF_THREE, DEF_GLIDEPOINT_TAP, - (char *)NULL /* extra */, - (Gpm_Type *)NULL, - -1 /* fd */ -}; - /* and this is a workaroud */ struct winsize win; -struct mouse_features *which_mouse=&mymouse; - char *progname; char *consolename; int devcount=0; @@ -78,9 +65,9 @@ struct device { char *name; - int fd; + struct micedev mdev; struct device *next; -}; +} *devlist; static int message(void) { @@ -148,46 +135,48 @@ /*----------------------------------------------------------------------------- Place the description here. -----------------------------------------------------------------------------*/ -struct device **gpm_makedev(struct device **current, char *name) +void gpm_makedev(char *name) { - int fd; int modes; + struct device *dev; + int fd; + int modes; + if ((fd=open(name,O_RDWR|O_NONBLOCK))==-1) { perror(name); - return current; - } - modes = fcntl(fd, F_GETFL); - if (0 > fcntl(fd, F_SETFL, modes & ~O_NONBLOCK)) { - close(fd); - perror(name); - return current; + } else { + modes = fcntl(fd, F_GETFL); + if (0 > fcntl(fd, F_SETFL, modes & ~O_NONBLOCK)) { + close(fd); + perror(name); + } else { + dev = malloc(sizeof(struct device)); + if (!dev) gpm_report(GPM_PR_OOPS,"malloc()"); + dev->name=strdup(name); + if (!dev->name) gpm_report(GPM_PR_OOPS,"malloc()"); + dev->mdev.fd=fd; + dev->mdev.private = NULL; + dev->next=devlist; + devlist = dev; + devcount++; + } } - - *current=malloc(sizeof(struct device)); - if (!*current) gpm_report(GPM_PR_OOPS,"malloc()"); - (*current)->name=strdup(name); - if (!(*current)->name) gpm_report(GPM_PR_OOPS,"malloc()"); - (*current)->fd=fd; - (*current)->next=NULL; - devcount++; - return &((*current)->next); } -Gpm_Type *(*I_serial)(int fd, unsigned short flags, struct Gpm_Type *type); +int (*I_serial)(struct micedev *dev, struct miceopt *opt, struct Gpm_Type *type); /*----------------------------------------------------------------------------- Place the description here. -----------------------------------------------------------------------------*/ -int mousereopen(int oldfd, char *name, Gpm_Type *type) +int mousereopen(struct micedev *dev, char *name, Gpm_Type *type, struct miceopt *opts) { - int fd; if (!type) type=mice+1; /* ms */ - close(oldfd); + close(dev->fd); usleep(100000); - fd=open(name,O_RDWR); - if (fd < 0) gpm_report(GPM_PR_OOPS,name); - (*I_serial)(fd,type->flags,type); /* ms initialization */ - return fd; + dev->fd=open(name,O_RDWR); + if (dev->fd < 0) gpm_report(GPM_PR_OOPS,name); + I_serial(dev, opts, type); /* ms initialization */ + return dev->fd; } int noneofthem(void) @@ -280,10 +269,9 @@ { struct item *list=NULL; struct item **nextitem; - struct device *devlist=NULL; - struct device **nextdev; + struct device *nextdev; Gpm_Type *cursor; - int i, mousefd; + int i; char *mousename; #define BUFLEN 512 char buf[BUFLEN]; @@ -293,6 +281,9 @@ int trial, readamount,packetsize,got; int baudtab[4]={1200,9600,4800,2400}; #define BAUD(i) (baudtab[(i)%4]) + struct miceopt opt = {0}; + struct micedev mdev = {0}; + consolename = Gpm_get_console(); if (!isatty(fileno(stdin))) { @@ -305,8 +296,8 @@ /* init the list of possible devices */ - for (nextdev=&devlist, i=1; i<argc; i++) - nextdev=gpm_makedev(nextdev,argv[i]); + for (i=1; i<argc; i++) + gpm_makedev(argv[i]); if (argc==1) { /* no cmdline, get all devices */ FILE *f; @@ -319,7 +310,7 @@ if (!f) gpm_report(GPM_PR_OOPS,"popen()"); while (fgets(s,64,f)) { s[strlen(s)-1]='\0'; /* trim '\n' */ - nextdev=gpm_makedev(nextdev,s); + gpm_makedev(s); } pclose(f); } @@ -344,18 +335,18 @@ /* BUG */ /* Logitech initialization is not performed */ - opt_baud=BAUD(trial); - printf("\r\nTrying with %i baud\r\n",opt_baud); + opt.baud=BAUD(trial); + printf("\r\nTrying with %i baud\r\n",opt.baud); trial++; FD_ZERO(&devSet); FD_ZERO(&gotSet); FD_SET(fileno(stdin),&devSet); maxfd=fileno(stdin); printf("\r\n The possible device nodes are:\r\n"); - for (nextdev=&devlist; *nextdev; nextdev=&((*nextdev)->next)) { - printf("\t%s\r\n", (*nextdev)->name); - FD_SET((*nextdev)->fd,&devSet); - maxfd=max((*nextdev)->fd,maxfd); - (*I_serial)((*nextdev)->fd,(mice+1)->flags,mice+1); /* try ms mode */ + for (nextdev=devlist; nextdev; nextdev=nextdev->next) { + printf("\t%s\r\n", nextdev->name); + FD_SET(nextdev->mdev.fd, &devSet); + maxfd=max(nextdev->mdev.fd,maxfd); + I_serial(&nextdev->mdev, &opt, mice+1); /* try ms mode */ } savSet=devSet; @@ -377,43 +368,43 @@ getchar(); break; } - for (nextdev=&devlist; *nextdev; nextdev=&((*nextdev)->next)) - if (FD_ISSET((*nextdev)->fd,&devSet)) { + for (nextdev=devlist; nextdev; nextdev=nextdev->next) + if (FD_ISSET(nextdev->mdev.fd,&devSet)) { gotthem++; - FD_CLR((*nextdev)->fd,&savSet); - FD_SET((*nextdev)->fd,&gotSet); + FD_CLR(nextdev->mdev.fd,&savSet); + FD_SET(nextdev->mdev.fd,&gotSet); } } - if (gotthem) for (nextdev=&devlist; *nextdev; /* nothing */ ) { - cur=*nextdev; - if (!FD_ISSET(cur->fd,&gotSet)) { + if (gotthem) for (nextdev=devlist; nextdev; /* nothing */ ) { + cur=nextdev; + if (!FD_ISSET(cur->mdev.fd,&gotSet)) { printf("removing \"%s\" from the list\r\n",cur->name); - *nextdev=cur->next; - close(cur->fd); + nextdev=cur->next; + close(cur->mdev.fd); free(cur->name); free(cur); devcount--; } else { - read(cur->fd,buf,80); /* flush */ - nextdev=&(cur->next); /* follow list */ + read(cur->mdev.fd,buf,80); /* flush */ + nextdev=cur->next; /* follow list */ } } } /* devcount>1 */ - mousefd=devlist->fd; + mdev=devlist->mdev; mousename=devlist->name; free(devlist); printf("\r\nOk, so your mouse device is \"%s\"\r\n",mousename); /* now close and reopen it, complete with initialization */ - opt_baud=BAUD(0); - mousefd=mousereopen(mousefd,mousename,NULL); - + opt.baud=BAUD(0); + mousereopen(&mdev, mousename, NULL,&opt); + FD_ZERO(&checkSet); - FD_SET(mousefd,&checkSet); + FD_SET(mdev.fd,&checkSet); FD_SET(fileno(stdin),&checkSet); - maxfd=max(mousefd,fileno(stdin)); + maxfd=max(mdev.fd, fileno(stdin)); /*====================================== Identify mouse type */ @@ -438,7 +429,7 @@ printf("\r\nNow please press and release your left mouse button,\r\n" "one time only\r\n\r\n"); - i=read(mousefd,buf,1); + i=read(mdev.fd, buf, 1); if (i==-1 && errno==EINVAL) readamount=3; else @@ -464,7 +455,7 @@ else nextitem=&(cur->next); } - read(mousefd,buf,BUFLEN); /* flush */ + read(mdev.fd, buf, BUFLEN); /* flush */ /*====================================== Packet size - second step */ @@ -482,12 +473,12 @@ while (packetsize==1) { int success3=0,success5=0; - opt_baud=BAUD(trial); - printf("\tBaud rate is %i\r\n",opt_baud); - mousefd=mousereopen(mousefd,mousename,NULL); + opt.baud=BAUD(trial); + printf("\tBaud rate is %i\r\n",opt.baud); + mousereopen(&mdev, mousename,NULL, &opt); printf("\r\n==> Detecting the packet size\r\n"); - got=eventlist(mousefd,buf,BUFLEN,GPM_B_LEFT,readamount); + got=eventlist(mdev.fd,buf,BUFLEN,GPM_B_LEFT,readamount); /* try three -- look at repeating arrays of 6 bytes */ for (i=0;i<got-12;i++) @@ -511,7 +502,6 @@ } /*====================================== Use that info to discard protocols */ - for (nextitem=&list; *nextitem; /* nothing */) { struct item *cur=*nextitem; int packetheads=0; @@ -528,7 +518,7 @@ if ( ((buf[i] &(cur->this->proto)[0]) == (cur->this->proto)[1]) && ((buf[i+1]&(cur->this->proto)[2]) == (cur->this->proto)[3]) ) { packetheads++; - if ((*(cur->this->fun))(&event,buf+i)==-1) { + if ((*(cur->this->fun))(&mdev, &opt, buf+i, &event)==-1) { packetheads--; continue; } @@ -592,7 +582,7 @@ * First trial: remove the "-t ms" extension if spurious buttons come in */ - got=eventlist(mousefd,buf,BUFLEN,0,readamount); + got=eventlist(mdev.fd,buf,BUFLEN,0,readamount); pending=0; for (nextitem=&list; *nextitem; /* nothing */) { struct item *cur=*nextitem; @@ -602,7 +592,7 @@ for (i=0;i<got;i++) { if ( ((buf[i] &(cur->this->proto)[0]) == (cur->this->proto)[1]) && ((buf[i+1]&(cur->this->proto)[2]) == (cur->this->proto)[3]) ) { - if ((*(cur->this->fun))(&event,buf+i)==-1) continue; + if ((*(cur->this->fun))(&mdev, &opt, buf+i, &event)==-1) continue; i+=packetsize-1; if (event.buttons) pending--; } @@ -622,8 +612,8 @@ */ printf("\r\n==> Looking for '-t mman'and enhanced ms\r\n"); - mousefd=mousereopen(mousefd,mousename, mice /* mman */); - got=eventlist(mousefd,buf,BUFLEN,GPM_B_MIDDLE,readamount); + mousereopen(&mdev, mousename, mice /* mman */, &opt); + got=eventlist(mdev.fd, buf, BUFLEN, GPM_B_MIDDLE, readamount); /* if it uses the 4-byte protocol, find it in a rude way */ for (pending=0,i=0;i<got-16;i++) @@ -644,7 +634,7 @@ for (i=0;i<got;i++) { if ( ((buf[i] &(cur->this->proto)[0]) == (cur->this->proto)[1]) && ((buf[i+1]&(cur->this->proto)[2]) == (cur->this->proto)[3]) ) { - if ((*(cur->this->fun))(&event,buf+i)==-1) continue; + if ((*(cur->this->fun))(&mdev,&opt,buf+i,&event)==-1) continue; i+=packetsize-1; if (event.buttons && event.buttons!=GPM_B_MIDDLE) pending--; if (event.buttons==GPM_B_MIDDLE) pending++; @@ -675,16 +665,16 @@ char *Xtognames[3]={"'ClearDTR' and 'ClearRTS'","'ClearDTR'","'ClearRTS'"}; int alllines,lines, index; - ioctl(mousefd, TIOCMGET, &alllines); + ioctl(mdev.fd, TIOCMGET, &alllines); printf("\r\nSome mice change protocol to three-buttons-aware if some\r\n" "\r\ncontrol lines are toggled after opening\r\n"); for (index=0;index<3;index++) { - mousereopen(mousefd,mousename,NULL); + mousereopen(&mdev, mousename, NULL, &opt); lines = alllines & ~toggle[index]; - ioctl(mousefd, TIOCMSET, &lines); + ioctl(mdev.fd, TIOCMSET, &lines); printf("\r\n==> Trying with '-o %s'\r\n",tognames[index]); - got=eventlist(mousefd,buf,BUFLEN,GPM_B_MIDDLE,readamount); + got=eventlist(mdev.fd, buf, BUFLEN, GPM_B_MIDDLE, readamount); /* if it uses the 5-byte protocol, find it in a rude way */ for (pending=0,i=0;i<got-20;i++) @@ -715,7 +705,7 @@ getchar(); - got=eventlist(mousefd,buf,BUFLEN,GPM_B_MIDDLE,readamount); + got=eventlist(mdev.fd,buf,BUFLEN,GPM_B_MIDDLE,readamount); /* if it uses the 5-byte protocol, find it in a rude way */ for (pending=0,i=0;i<got-20;i++) diff -Nru a/src/server_tools.c b/src/server_tools.c --- a/src/server_tools.c 2004-08-10 01:17:58 -05:00 +++ b/src/server_tools.c 2004-08-10 01:17:58 -05:00 @@ -21,151 +21,78 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ********/ +#include <string.h> +#include <stdlib.h> /* malloc() */ +#include <sys/fcntl.h> + #include "headers/gpmInt.h" #include "headers/message.h" -#include <stdlib.h> /* malloc() */ +struct micetab *micelist; -/* DESCR: add this to the list of mice. initialization follows later */ -/* RETURN: - */ +/* DESCR: allocate a new mouse and to the list of mice. initialization follows later */ +/* RETURN: new mouse structure */ /* COMMENT: does error handling and exiting itself */ -void add_mouse(int type, char *value) +struct micetab *add_mouse(void) { - struct micetab *tmp = option.micelist; + struct micetab *mouse; - /* PREAMBLE for all work: */ - /* -m /dev/misc/psaux -t ps2 [ -o options ] */ + gpm_report(GPM_PR_DEBUG, "adding mouse device"); + if (!(mouse = malloc(sizeof(struct micetab)))) + gpm_report(GPM_PR_OOPS, GPM_MESS_NO_MEM); + + memset(mouse, 0, sizeof(struct micetab)); + + mouse->options.sequence = NULL; + mouse->options.sample = DEF_SAMPLE; + mouse->options.delta = DEF_DELTA; + mouse->options.accel = DEF_ACCEL; + mouse->options.scalex = DEF_SCALE; + mouse->options.scaley = DEF_SCALE; + mouse->options.time = DEF_TIME; + mouse->options.cluster = DEF_CLUSTER; + mouse->options.three_button = DEF_THREE; + mouse->options.glidepoint_tap = DEF_GLIDEPOINT_TAP; + mouse->options.text = NULL; - switch(type) { + mouse->next = micelist; + micelist = mouse; - /*---------------------------------------------------------------------*/ - /********************** -m mousedevice *********************************/ - /*---------------------------------------------------------------------*/ - - case GPM_ADD_DEVICE: - - /* first invocation */ - if(option.micelist == NULL) { - gpm_report(GPM_PR_DEBUG,"adding mouse device: %s",value); - option.micelist = (struct micetab *) malloc(sizeof(struct micetab)); - if(!option.micelist) gpm_report(GPM_PR_OOPS,GPM_MESS_NO_MEM); - option.micelist->next = NULL; - option.micelist->device = value; - option.micelist->protocol = NULL; - option.micelist->options = NULL; - return; - } - - /* find actual mouse */ - while(tmp->device != NULL && tmp->protocol != NULL && tmp->next !=NULL) - tmp = tmp->next; - - gpm_report(GPM_PR_DEBUG,"finished searching"); - - /* found end of micelist, add new mouse */ - if(tmp->next == NULL && tmp->protocol != NULL) { - gpm_report(GPM_PR_DEBUG,"next mouse making"); - tmp->next = (struct micetab *) malloc(sizeof(struct micetab)); - if(!tmp) gpm_report(GPM_PR_OOPS,GPM_MESS_NO_MEM); - tmp->next = NULL; - tmp->device = value; - tmp->protocol = NULL; - tmp->options = NULL; - return; - } else gpm_report(GPM_PR_OOPS,GPM_MESS_FIRST_DEV); - - //} else if(tmp->device != NULL && tmp->protocol == NULL) - // gpm_report(GPM_PR_OOPS,GPM_MESS_FIRST_DEV); /* -m -m */ - - - break; - - /*---------------------------------------------------------------------*/ - /************************* -t type / protocol **************************/ - /*---------------------------------------------------------------------*/ - - case GPM_ADD_TYPE: - if(option.micelist == NULL) gpm_report(GPM_PR_OOPS,GPM_MESS_FIRST_DEV); - - /* skip to next mouse, where either device or protocol is missing */ - while(tmp->device != NULL && tmp->protocol != NULL && tmp->next !=NULL) - tmp = tmp->next; - - /* check whether device (-m) is there, if so, write protocol */ - if(tmp->device == NULL) gpm_report(GPM_PR_OOPS,GPM_MESS_FIRST_DEV); - else { - gpm_report(GPM_PR_DEBUG,"adding mouse type: %s",value); - tmp->protocol = value; - option.no_mice++; /* finally we got our mouse */ - } - - break; - - /*---------------------------------------------------------------------*/ - /*************************** -o options ********************************/ - /*---------------------------------------------------------------------*/ - - case GPM_ADD_OPTIONS: - if(option.micelist == NULL) gpm_report(GPM_PR_OOPS,GPM_MESS_FIRST_DEV); - - /* look for the last mouse */ - tmp = option.micelist; - while(tmp->next != NULL) tmp = tmp->next; - - /* if -m or -t are missing exit */ - if(tmp->device == NULL || tmp->protocol == NULL) - gpm_report(GPM_PR_OOPS,GPM_MESS_FIRST_DEV); - else { - gpm_report(GPM_PR_DEBUG,"adding mouse options: %s",value); - tmp->options = value; - } - break; - } + return mouse; } -/* DESCR: mice initialization. currently print mice. */ -/* RETURN: 0 - failed to init one or more devices - 1 - init was fine */ +/* DESCR: mice initialization. calls appropriate init functions. */ /* COMMENT: does error handling and exiting itself */ -int init_mice(struct micetab *micelist) +void init_mice(void) { - struct micetab *tmp = micelist; + struct micetab *mouse; + + for (mouse = micelist; mouse; mouse = mouse->next) { + if (!strcmp(mouse->device, "-")) + mouse->dev.fd = 0; /* use stdin */ + else if ((mouse->dev.fd = open(mouse->device, O_RDWR | O_NDELAY)) < 0) + gpm_report(GPM_PR_OOPS, GPM_MESS_OPEN, mouse->device); - while(tmp != NULL) { /* there are still mice to init */ - gpm_report(GPM_PR_DEBUG,"initialize %s with proto %s",tmp->device,tmp->protocol); - if(tmp->options != NULL) { - gpm_report(GPM_PR_DEBUG,"and options %s",tmp->options); - } - tmp = tmp->next; - } + /* and then reset the flag */ + fcntl(mouse->dev.fd, F_SETFL, fcntl(mouse->dev.fd, F_GETFL) & ~O_NDELAY); - gpm_report(GPM_PR_DEBUG,"finished initialization"); - return 1; + /* init the device, and use the return value as new mouse type */ + if (mouse->type->init) + if (mouse->type->init(&mouse->dev, &mouse->options, mouse->type)) + gpm_report(GPM_PR_OOPS, GPM_MESS_MOUSE_INIT); + } } /* DESCR: when leaving, we should reset mice to their normal state */ -/* RETURN: 0 - failed to reset one or more devices - 1 - reset was fine */ /* COMMENT: does error handling and exiting itself */ -int reset_mice(struct micetab *micelist) +void cleanup_mice(void) { - struct micetab *tmp = micelist; - struct micetab *end = tmp; + struct micetab *tmp; - while(tmp != NULL) { /* FIXME! I never get NULL, as free()d before */ - end = tmp; - while(tmp->next != NULL) { /* set end to the last mouse */ - end = tmp; - tmp = tmp->next; - } - - gpm_report(GPM_PR_DEBUG,"reset: %s with proto %s",end->device,end->protocol); - if(tmp->options != NULL) { - gpm_report(GPM_PR_DEBUG,"and options %s",end->options); - } - free(end); /* be clean() */ - tmp = micelist; /* reset to the first mice again */ + while ((tmp = micelist)) { + if (micelist->dev.private) + free(micelist->dev.private); + micelist = micelist->next; + free(tmp); } - - return 1; } diff -Nru a/src/startup.c b/src/startup.c --- a/src/startup.c 2004-08-10 01:17:58 -05:00 +++ b/src/startup.c 2004-08-10 01:17:58 -05:00 @@ -26,6 +26,7 @@ #include <string.h> /* strlen() */ #include <errno.h> /* errno */ #include <unistd.h> /* unlink,geteuid */ +#include <signal.h> #include <sys/types.h> /* geteuid, mknod */ #include <sys/stat.h> /* mknod */ #include <fcntl.h> /* mknod */ @@ -39,7 +40,7 @@ /* what todo atexit */ static void gpm_exited(void) { - gpm_report(GPM_PR_DEBUG,GPM_MESS_REMOVE_FILES, GPM_NODE_PID, GPM_NODE_CTL); + gpm_report(GPM_PR_DEBUG, GPM_MESS_REMOVE_FILES, GPM_NODE_PID, GPM_NODE_CTL); unlink(GPM_NODE_PID); unlink(GPM_NODE_CTL); } @@ -49,30 +50,12 @@ extern struct options option; extern int errno; - int i,opt; - - static struct { - char *in; - char *out; - } seq[] = { - {"123","01234567"}, - {"132","02134657"}, - {"213","01452367"}, /* warning: these must be readable as integers... */ - {"231","02461357"}, - {"312","04152637"}, - {"321","04261537"}, - {NULL,NULL} - }; - /* basic settings */ option.run_status = GPM_RUN_STARTUP; /* 10,9,8,... let's go */ option.autodetect = 0; /* no mouse autodection */ + option.test = 0; option.progname = argv[0]; /* who we are */ - /* basic2: are not necessary for oops()ing, if not root */ - option.no_mice = 0; /* counts -m + -t */ - option.micelist = NULL; /* no mice found yet */ - console.device = Gpm_get_console(); /* get consolename */ cmdline(argc, argv); /* parse command line */ @@ -97,29 +80,7 @@ gpm_report(GPM_PR_OOPS, GPM_MESS_OPEN, GPM_NODE_FIFO); } - /* duplicate initialization */ - for (i=1; i <= 1+opt_double; i++) { - which_mouse=mouse_table+i; /* used to access options */ - if (opt_accel < 1) exit(usage("acceleration")); - if (opt_delta < 2) exit(usage("delta")); - if (strlen(opt_sequence) != 3 || atoi(opt_sequence)<100) - exit(usage("sequence")); - if (opt_glidepoint_tap > 3) exit(usage("glidepoint tap button")); - if (opt_glidepoint_tap) - opt_glidepoint_tap=GPM_B_LEFT >> (opt_glidepoint_tap-1); - - /* choose the sequence */ - for (opt=0; seq[opt].in && strcmp(seq[opt].in,opt_sequence); opt++) ; - if(!seq[opt].in) exit(usage("button sequence")); - opt_sequence=strdup(seq[opt].out); /* I can rewrite on it */ - - /* look for the mouse type */ - m_type = find_mouse_by_name(opt_type); - if (!m_type) /* not found */ - exit(M_listTypes()); - } - - if(option.run_status == GPM_RUN_STARTUP ) { /* else is debugging */ + if(option.run_status == GPM_RUN_STARTUP) { /* else is debugging */ /* goto background and become a session leader (Stefan Giessler) */ switch(fork()) { case -1: gpm_report(GPM_PR_OOPS,GPM_MESS_FORK_FAILED); /* error */ @@ -137,13 +98,63 @@ /* is changing to root needed, because of relative paths ? or can we just * remove and ignore it ?? FIXME */ if (chdir("/") < 0) gpm_report(GPM_PR_OOPS,GPM_MESS_CHDIR_FAILED); - - //return mouse_table[1].fd; /* the second is handled in the main() */ + atexit(gpm_exited); /* call gpm_exited at the end */ +} - /****************** OLD CODE from gpn.c END ***********************/ +/* itz Sat Sep 12 10:30:05 PDT 1998 this function used to mix two + completely different things; opening a socket to a running daemon + and checking that a running daemon existed. Ugly. */ +/* rewritten mostly on 20th of February 2002 - nico */ +void check_uniqueness(void) +{ + FILE *fp = 0; + int old_pid = -1; - init_mice(option.micelist); /* reads option.micelist */ - atexit(gpm_exited); /* call gpm_exited at the end */ + if ((fp = fopen(GPM_NODE_PID, "r")) != NULL) { + fscanf(fp, "%d", &old_pid); + if (kill(old_pid, 0) == -1) { + gpm_report(GPM_PR_INFO,GPM_MESS_STALE_PID, GPM_NODE_PID); + unlink(GPM_NODE_PID); + } else /* we are really running, exit asap! */ + gpm_report(GPM_PR_OOPS, GPM_MESS_ALREADY_RUN, old_pid); + } + /* now try to sign ourself */ + if ((fp = fopen(GPM_NODE_PID,"w")) != NULL) { + fprintf(fp,"%d\n",getpid()); + fclose(fp); + } else { + gpm_report(GPM_PR_OOPS,GPM_MESS_NOTWRITE,GPM_NODE_PID); + } +} + +/* itz Sat Sep 12 10:55:51 PDT 1998 Added this as replacement for the + unwanted functionality in check_uniqueness. */ +void kill_gpm(void) +{ + int old_pid; + FILE* fp = fopen(GPM_NODE_PID, "r"); + /* if we cannot find the old pid file, leave */ + if (fp == NULL) gpm_report(GPM_PR_OOPS,GPM_MESS_OPEN, GPM_NODE_PID); + + /* else read the pid */ + if (fscanf(fp, "%d", &old_pid) != 1) + gpm_report(GPM_PR_OOPS, GPM_MESS_READ_PROB, GPM_NODE_PID); + fclose(fp); + + gpm_report(GPM_PR_DEBUG, GPM_MESS_KILLING, old_pid); + + /* first check if we run */ + if (kill(old_pid,0) == -1) { + gpm_report(GPM_PR_INFO, GPM_MESS_STALE_PID, GPM_NODE_PID); + unlink(GPM_NODE_PID); + } + /* then kill us (not directly, but the other instance ... ) */ + if (kill(old_pid, SIGTERM) == -1) + gpm_report(GPM_PR_OOPS, GPM_MESS_CANT_KILL, old_pid); + + gpm_report(GPM_PR_INFO, GPM_MESS_KILLED, old_pid); + exit(0); } + diff -Nru a/src/synaptics.c b/src/synaptics.c --- a/src/synaptics.c 2004-08-10 01:17:58 -05:00 +++ b/src/synaptics.c 2004-08-10 01:17:58 -05:00 @@ -867,7 +867,7 @@ static int scrolling_speed_timer = 0; static int scrolling_amount_left = 0; /* Tells how much to scroll up or down */ - +static int mouse_fd; @@ -1160,8 +1160,8 @@ status = GPM_B_NOT_SET; break; case Reset_Touchpad_Action: - syn_ps2_reset(which_mouse->fd); - syn_ps2_absolute_mode(which_mouse->fd); + syn_ps2_reset(mouse_fd); + syn_ps2_absolute_mode(mouse_fd); status = GPM_B_NOT_SET; break; case Toggle_Four_Way_Button_Action: @@ -2952,10 +2952,8 @@ data [0],data [1],data [2],data [3],data [4],data [5]); if (reset_on_error_enabled) { - /* Hack to get the fd: which_mouse is the current mouse, - and as the synaptic code is called, it is the current mouse. */ - syn_ps2_reset(which_mouse->fd); - syn_ps2_absolute_mode(which_mouse->fd); + syn_ps2_reset(mouse_fd); + syn_ps2_absolute_mode(mouse_fd); } report->left = 0; @@ -3110,7 +3108,7 @@ ** ** Process the touchpad 6 byte report. */ -void syn_process_serial_data (Gpm_Event *state, +void syn_process_serial_data (int fd, Gpm_Event *state, unsigned char *data) { /* initialize the state */ @@ -3118,6 +3116,8 @@ state->dx = 0; state->dy = 0; + mouse_fd = fd; /* cheat */ + syn_serial_translate_data (data, &cur_report); if (wmode_enabled){ syn_process_wmode_report(&cur_report); @@ -3198,7 +3198,7 @@ ** ** Process the touchpad 6 byte report. */ -void syn_process_ps2_data (Gpm_Event *state, +void syn_process_ps2_data (int fd, Gpm_Event *state, unsigned char *data) { /* gpm_report(GPM_PR_DEBUG,"Data %02x %02x %02x %02x %02x %02x",data[0],data[1],data[2],data[3],data[4],data[5]); */ @@ -3208,6 +3208,7 @@ state->dx = 0; state->dy = 0; + mouse_fd = fd; /* cheat */ if (wmode_enabled) { syn_ps2_translate_wmode_data (data, &cur_report); _______________________________________________ gpm mailing list gpm@xxxxxxxxxxxxxx http://lists.linux.it/listinfo/gpm