From 287aedc57a75e36864206a80c0bf4e7bc31790ff Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 16 Dec 1995 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1995-12-16 --- carrera/kbd.c | 5 +++++ pc/kbd.c | 6 ++++++ port/devmouse.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++- port/portfns.h | 1 + 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/carrera/kbd.c b/carrera/kbd.c index 6020b22c9882976ad5dfd961062630c7116851e6..daabfe594995067ebb818deb89f9b6a36daff4b4 100644 --- a/carrera/kbd.c +++ b/carrera/kbd.c @@ -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); } diff --git a/pc/kbd.c b/pc/kbd.c index 55f046fb04dcb2e5575cc29616fdbc5e408d2c10..405b6b706d8cba7412370e54d7b9a89807ed229c 100644 --- a/pc/kbd.c +++ b/pc/kbd.c @@ -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) diff --git a/port/devmouse.c b/port/devmouse.c index ddda7bcec6c5be48d37a65ac60c972a9000a3da6..8ab06424fd32aa327bc2ebac5bfc43bb61a1bbb6 100644 --- a/port/devmouse.c +++ b/port/devmouse.c @@ -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; +} diff --git a/port/portfns.h b/port/portfns.h index 0170884534e66388c2f179fe4fcf5a21c61270d4..5ab08f43963fb066b5388538a90fe3bc5f52603c 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -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*);