Plan 9 from Bell Labs’s /usr/web/sources/contrib/aiju/mouse.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <bio.h>

Biobuf *tablet;
int mouseout;

int
main()
{
	int curx, cury;

	curx = cury = 0;
	mouseout = open("/dev/mousein", OWRITE);
	if(mouseout < 0) sysfatal("%r");
	tablet = Bopen("/dev/tablet", OREAD);
	if(tablet == nil) sysfatal("%r");
	while(1) {
		char *line, *p;
		int x, y, b;
		
		line = Brdline(tablet, 10);
		p = line;
		if(*p++ != 'm') continue;
		if(*p++ != ' ') continue;
		x = strtol(p, &p, 10);
		if(*p++ != ' ') continue;
		y = strtol(p, &p, 10);
		if(*p++ != ' ') continue;
		b = strtol(p, &p, 10);
		if(*p++ != ' ') continue;
		fprint(mouseout, "m %d %d %d\n", x - curx, y - cury, b);
		curx = x;
		cury = y;
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].