In linux, is it possible to get notifications when the currently focused GUI app changes? I\'m writing an app that tracks how long a user stays on each GUI app(per process, not
Example in JavaScript using node-x11:
var x11 = require('x11');
x11.createClient(function(err, display) {
var X = display.client;
X.ChangeWindowAttributes(display.screen[0].root, { eventMask: x11.eventMask.PropertyChange });
X.on('event', function(ev) {
if(ev.name == 'PropertyNotify') {
X.GetAtomName(ev.atom, function(err, name) {
if (name == '_NET_ACTIVE_WINDOW') {
X.GetProperty(0, ev.window, ev.atom, X.atoms.WINDOW, 0, 4, function(err, prop) {
console.log('New active window:' + prop.data.readUInt32LE(0));
});
}
});
}
});
});