Forums > Javascript

Monitoring whether a window size changes in js


Lee
March 19, 2013 | 6:06 am

Hi, is there a callback mechanism for this so that it’s possible to tell when windows have been resized, closes etc?

thx Lee


March 19, 2013 | 1:08 pm

you need to create a repeating task.

// 11oLsen, report changed window size

outlets = 2;
var	nowsize;
var lastsize;

var pollTsk = new Task(getsize, this);

function on()
{
	lastsize = -1;

	pollTsk.interval = 10; //set interval of polling in ms 

	pollTsk.repeat();
}

function off()
{
	pollTsk.cancel();
}

function getsize()
{	

	nowsize = this.patcher.wind.size;
	if (nowsize[0] != lastsize[0] || nowsize[1] != lastsize[1]) {
		//post(lastsize);
		//post(nowsize);
		outlet(1,nowsize[1]);
		outlet(0,nowsize[0]);
		lastsize = nowsize;

	}

}

btw: there’s a windowwatcher external in the sdk ready to compile, don’t ask me why they don’t add this to the standard object set..



Lee
March 19, 2013 | 1:31 pm

excellent, thanks for the help :)


Viewing 3 posts - 1 through 3 (of 3 total)