Monitoring whether a window size changes in js

Mar 19, 2013 at 6:06am

Monitoring whether a window size changes in js

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

thx Lee

#67130
Mar 19, 2013 at 1:08pm

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..

#241561
Mar 19, 2013 at 1:31pm

excellent, thanks for the help :)

#241562

You must be logged in to reply to this topic.