[sharing] Knowing if a device is visible
Sometimes when a device has a CPU-intensive UI, it is useful to know whether the device is visible at all. If not, drawing can be turned off. Here is a script that does that.
"use strict";
/*
Outputs a bang when it becomes visible. Only passes on incoming bangs when visible.
Note that to be visible for a device in presentation mode, this object must be included in presentation.
*/
mgraphics.init()
function paint() {
outlet(0, "bang")
}
function bang() {
mgraphics.redraw()
}
I also tried to find something to get visible state of a device in js. Only thing I found is that this.patcher.getattr('rect') reports 0 for x and y if device is hidden..
Using C sdk it's easy to detect (and observe) device visibillity.