sindresorhus / get-windows

Get metadata about the active window and open windows (title, id, bounds, owner, etc)
MIT License
800 stars 167 forks source link

Trigger an event when focus changes #1

Open sindresorhus opened 8 years ago

sindresorhus commented 8 years ago

I imagine it would be something like:

const activeWin  = require('active-win');

activeWin.on('change', win => {
    console.log(win.title);
});

With win being the same as activeWin() returns.

No idea how to achieve this though as it would have to communicate with the binary somehow. Maybe spawn the native binary when someone subscribes to the events, and have the binary push to stdout for each event.

PR welcome 😀

bencevans commented 8 years ago

Not ideal but I ended up polling and emitting an event if the data changed from the previously cached data... https://github.com/bencevans/active-app-watcher#readme

bencevans commented 8 years ago

Python implementation https://stackoverflow.com/questions/23786289/how-to-correctly-detect-application-name-when-changing-focus-event-occurs-with for linux using xlib

sindresorhus commented 7 years ago

Some more resources:

Pandakls commented 4 years ago

That kind of event emitter would be awesome.

sindresorhus commented 4 years ago

@Pandakls Your comment doesn't add anything to the conversation. In the future, please use GitHub reactions instead.