glfw
glfw copied to clipboard
Implement focus callback
Resolves #12.
This uses the browser's focus and blur events to implement the focus callback, which is informed when the browser window is in focus (active window) or not.
Depending on whether or not we want to consider multiple tabs as "all focused" or if each is focused individually, we may need to change the listener to attach to the document instead of the window. I have not explored browser functionality related to that.
Just did some tests with:
window.addEventListener('focus', () => console.log('window focus'))
window.addEventListener('blur', () => console.log('window blur'))
document.addEventListener('focus', () => console.log('document focus'))
document.addEventListener('blur', () => console.log('document blur'))
The second two event handlers did not execute at all, which indicates to me that the former two are the correct mechanism for this to be implemented, as I have done in this PR.
Thanks for the new PR. I'll able to test and review it about a week from now, sorry about the delay (busy time for me). Feel free to ping in case I forget.
Thanks @meyerzinn. Merged as commit a8743c0d1829b17a0e654d08c6be66f46adf5144.