~kris/9p

9hist

287aedc57a75e36864206a80c0bf4e7bc31790ff — David du Colombier 30 years ago 500be37
Plan 9 from Bell Labs 1995-12-16
4 files changed, 62 insertions(+), 1 deletions(-)

M carrera/kbd.c
M pc/kbd.c
M port/devmouse.c
M port/portfns.h
M carrera/kbd.c => carrera/kbd.c +5 -0
@@ 406,6 406,11 @@ mousectl(char *cmd)
		mousecmd(0xF4);	/* enabled */
		splx(s);
	}
	else if(strcmp(cmd, "accelerated") == 0){
		s = splhi();
		mousecmd(0xE7);
		splx(s);
	}
	else
		error(Ebadctl);
}

M pc/kbd.c => pc/kbd.c +6 -0
@@ 574,6 574,9 @@ mousectl(char *arg)
			mousecmd(0xE7);
			splx(x);
			break;
		default:
			mouseaccelerate(field[1]);
			break;
		}
	} else if(strcmp(field[0], "linear") == 0){
		switch(mousetype){


@@ 582,6 585,9 @@ mousectl(char *arg)
			mousecmd(0xE6);
			splx(x);
			break;
		default:
			mouseaccelerate("0");
			break;
		}
	} else if(strcmp(field[0], "res") == 0){
		if(n < 2)

M port/devmouse.c => port/devmouse.c +50 -1
@@ 27,6 27,8 @@ struct Mouseinfo
	Ref;
	QLock;
	int	open;
	int	acceleration;
	int	maxacc;
};

Mouseinfo	mouse;


@@ 272,7 274,10 @@ mousewrite(Chan *c, void *va, long n, ulong)
		if(n >= sizeof(buf))
			n = sizeof(buf)-1;
		strncpy(buf, va, n);
		buf[n] = 0;
		if(buf[n - 1] == '\n')
			buf[n-1] = 0;
		else
			buf[n] = 0;
		mousectl(buf);
		return n;



@@ 338,6 343,34 @@ mouseclock(void)
	graphicsactive(0);
}

static int
scale(int x)
{
	int sign = 1;

	if(x < 0){
		sign = -1;
		x = -x;
	}
	switch(x){
	case 0:
	case 1:
	case 2:
	case 3:
		break;
	case 4:
		x = 6 + (mouse.acceleration>>2);
		break;
	case 5:
		x = 9 + (mouse.acceleration>>1);
		break;
	default:
		x *= mouse.maxacc;
		break;
	}
	return sign*x;
}

/*
 *  called at interrupt level to update the structure and
 *  awaken any waiting procs.


@@ 347,6 380,10 @@ mousetrack(int b, int dx, int dy)
{
	int x, y;

	if(mouse.acceleration){
		dx = scale(dx);
		dy = scale(dy);
	}
	x = mouse.xy.x + dx;
	if(x < gscreen.r.min.x)
		x = gscreen.r.min.x;


@@ 449,3 486,15 @@ mousexy(void)
{
	return mouse.xy;
}

void
mouseaccelerate(char *x)
{
	if(x == 0)
		x = "1";
	mouse.acceleration = atoi(x);
	if(mouse.acceleration < 3)
		mouse.maxacc = 2;
	else
		mouse.maxacc = mouse.acceleration;
}

M port/portfns.h => port/portfns.h +1 -0
@@ 142,6 142,7 @@ void		mntrepl(char*);
long		mntwrite9p(Chan*, void*, long, ulong);
int		mount(Chan*, Chan*, int, char*);
void		mountfree(Mount*);
void		mouseaccelerate(char*);
void		mousebuttons(int);
void		mouseclock(void);
void		mousectl(char*);