shithub: 9intro

ref: 2b99422480d596ebc26921c87c6bb81a07949f3e
dir: /progs/resize.c.ms/

View raw version
.P1
.ps -1
.ti -1i
.B
.BX resize.c
.ps +1
.CW
.ps -2
.vs .15i
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <draw.h>
#include <mouse.h>

void
blank(void)
{
	draw(screen, screen->r, display->black, nil, ZP);
	flushimage(display, 1);
}

void
resizethread(void* arg)
{
	Mousectl*mctl = arg;
	for(;;){
		recvul(mctl->resizec);
		if (getwindow(display, Refnone) < 0)
			sysfatal("getwindow: %r");
		blank();
	}
}

void
mousethread(void* arg)
{
	Mousectl*mctl = arg;
	Mouse	m;
	for(;;){
		recv(mctl->c, &m);
		if(m.buttons){
			do {
				recv(mctl->c, &m);
			} while(m.buttons);
			closedisplay(display);
			closemouse(mctl);
			threadexitsall(nil);
		}
	}
}

.ps +2
.P2
.P1
.ps -2
void
threadmain(int, char*argv[])
{
	Mousectl*mctl;
	Mouse	m;

	mctl = initmouse("/dev/mouse", nil);
	if (mctl == nil)
		sysfatal("initmouse: %r");
	if(initdraw(nil, nil, argv[0]) < 0)
		sysfatal("initdraw: %r");
	threadcreate(resizethread, mctl, 8*1024);
	threadcreate(mousethread, mctl, 8*1024);
	blank();
	threadexits(nil);
}
.ps +2
.P2