fifo:ed mouse doesn't work properly, ExplorerPS/2

dgustafs at umsis.miami.edu dgustafs at umsis.miami.edu
Sat May 8 13:10:35 PDT 2004


I have a problem with the mouse in fd.o.
I have got an IBM Thinkapad with a "middle button" that allow for scrolling if I
pipe /dev/mouse though a small script to /dev/imouse

If I start xserver with -mouse /dev/mouse,7 I do have a working mouse but no
scrolling...

If I start with -mouse /dev/imouse,7 the mouse doesn't really work. it works to
the point that it somewhat changes position (fractions of an inch per minute and
not necessarily in the right direction).

Could someone please have a look at the enclosed script and tell me what might
be "fishy" and what to change... The output of the script should be ExplorerPS/2
and fd.o do detect it as such. (just doesn't work that great right now! :))

Cheers.


/*
AUTHOR:

Daniel Grobe Sachs <sachs at uiuc.edu>

LICENSE:  
The following is a standard BSD-style license.

Copyright (c) 2002, Daniel Grobe Sachs 
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.  

    * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#include <stdio.h>
#include <signal.h>
#include <math.h>

#define XY_ACCEL_EXP	1.6
#define Z_ACCEL_EXP	1.2
#define Z_ACCEL_MULT	0.02

main(int argc, char *argv[])
{
    FILE *in, *out;

    int state;
    int b, prev_b;
    signed char x, y;
    int scroll;

    double f;
    double x_scroll_accum;
    double y_scroll_accum;

    int c;

    if (argc < 3) {
	printf("%s: %s <in> <out>\n", argv[0], argv[0]);
	exit(3);
    }

    signal(SIGPIPE, SIG_IGN);

    while (1) {
	out = fopen(argv[2], "w");
	in = fopen(argv[1], "r");

	if ((in == NULL) || (out == NULL)) {
	    printf("%s: unable to open files\n", argv[0]);
	    exit(1);
	}

	state = 0;
	prev_b = 0;
	scroll = 0;

	while (!feof(in) && !feof(out)) {
	    state++;
	    c = getc(in);

	    if ((state == 1) & !(c & 0x08))
		state++;

	    if (state == 1)
		b = c;

	    if (!(b & 0x04)) {
		if ((prev_b & 0x04) && (!scroll)) {
		    putc(prev_b & 0xF, out);
		    putc(0, out);
		    putc(0, out);
		    putc(0, out);
		}

		scroll = 0;
		x_scroll_accum = 0;
		y_scroll_accum = 0;
		prev_b = b;

	        if( (state == 2) || (state == 3) )
		{
			x = (signed char)c;
			y = abs(x);

			f = pow( (double)y, (double)XY_ACCEL_EXP);

			f = (f > 127) ? 127 : f;

			if( x < 0 ) 
			    y = (signed char)(-f);
			else
		    	    y = (signed char) f;

#ifdef DEBUG
			printf("%2x %i %f %i %i\n",b,state,f,(int)x,(int)y);
#endif

			putc(y, out);
		}
		else
			putc(c, out);

		if (state == 3) {
		    putc(0, out);
		    state = 0;
		    fflush(out);
		}
	    } else {
		prev_b = b;

		x = getc(in);
		y = getc(in);
		state = 0;

		if( y != 0 )
		{
		    scroll = 1;

		    f = Z_ACCEL_MULT * pow( (double)(abs(y)), (double)Z_ACCEL_EXP);
#ifdef DEBUG
		    printf("y scroll %i %f accum %f\n",y,f,y_scroll_accum);
#endif
			
		    for( y_scroll_accum += f; y_scroll_accum > 1.0; y_scroll_accum -= 1.0 )
		    {
			putc(b & 0x0B, out);
			putc(0, out);
			putc(0, out);
		        y < 0 ? putc(0x01, out) : putc(0x0F, out);
		    }

		    fflush(out);
		}

		if( x != 0 )
		{
		    scroll = 1;

		    f = Z_ACCEL_MULT * pow( (double)(abs(x)), (double)Z_ACCEL_EXP);
#ifdef DEBUG
		    printf("x scroll %i %f accum %f\n",x,f,x_scroll_accum);
#endif
			
		    for( x_scroll_accum += f; x_scroll_accum > 1.0; x_scroll_accum -= 1.0 )
		    {
			putc(b & 0x0B, out);
			putc(0, out);
			putc(0, out);
			x < 0 ? putc(0x10, out) : putc(0x20, out);
			putc(b & 0x0B, out);
			putc(0, out);
			putc(0, out);
			putc(0, out);
		    }

		    fflush(out);
		}
	    }
	}
	fclose(in);
	fclose(out);
    }
}



More information about the xserver mailing list