window focus

7 views
Skip to first unread message

Anatoly Pashin

unread,
Oct 11, 2013, 1:43:53 AM10/11/13
to node-...@googlegroups.com
Is there way to determine is window focused? Like Window.isFullscreen or Window.isKioskMode

--
Пашин Анатолий,
эникейщик.

Anthony Ettinger

unread,
Oct 11, 2013, 1:58:44 AM10/11/13
to node-...@googlegroups.com

i don't see anything obvious...but you could set a flag on the focus() and enter-fullscreen events.

Anatoly Pashin

unread,
Oct 11, 2013, 2:17:01 AM10/11/13
to node-...@googlegroups.com
That's what i tryed already. Focus event is fired ok, but there is problems with blur event: it's fired only when you switch between windows of your app. If you focus on any system window, blur event is not fired.


2013/10/11 Anthony Ettinger <etti...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Пашин Анатолий,
эникейщик.

Chris Price

unread,
Oct 13, 2013, 12:23:06 AM10/13/13
to node-...@googlegroups.com
Hi Anatoly--

I came over to node-webkit from AppJS which had the properties you mention. I wrote a generic windowing script for node-webkit to mimic most of its features from the window.frame object in AppJS. For window focus, in order to catch all events, I had to watch two different places.

1 - The node-webkit window object
2 - The global javascript window object

--------------

//Window Controls
window.frame = gui.Window.get();

//Additional properties for the window frame to match AppJS' window.frame.state
window.frame.state = 'normal';

<snip>

//Manage window active state for styling...
window.frame.on('blur', function(e){window.frame.active = false; jQuery(document.body).addClass('inactive');});

window.frame.on('focus', function(e){window.frame.active = true; jQuery(document.body).removeClass('inactive');});

window.addEventListener('blur', function(e){window.frame.active = false; jQuery(document.body).addClass('inactive');});

window.addEventListener('focus', function(e){window.frame.active = true; jQuery(document.body).removeClass('inactive');});

-------------

With this, I can check window.frame.active to see if the window is focused or not. I have not done extensive testing with it, but checking as I write this post on a frameless app, the window chrome I've created with HTML/CSS is being styled appropriately for what the active/inactive state should be when switching between both system windows and windows in my app.

Anatoly Pashin

unread,
Oct 13, 2013, 9:17:42 PM10/13/13
to node-...@googlegroups.com
Ty Chris, will test soon.


2013/10/13 Chris Price <studioc...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Пашин Анатолий,
эникейщик.

dansc...@gmail.com

unread,
Mar 28, 2014, 3:37:07 PM3/28/14
to node-...@googlegroups.com
I've come across a requirement for this, too. Was there overall luck with this approach?

It would be nice if node-webkit's Window API had a getter to determine focus state, instead of tracking it in javascript. 

s...@konjekt.com

unread,
Oct 15, 2014, 5:55:56 PM10/15/14
to node-...@googlegroups.com, dansc...@gmail.com
I was able to make this approach work on osx. It seems to be pretty reliable. Thanks Chris Price for figuring this out. I only use one window, so it might behave differently if you introduce multiple windows.

I made the following to keep track of my focus-state:

(coffee script example. )
window.gui = require('nw.gui')
window.win = window.gui.Window.get()
window.win.on 'focus', ->
window.is_in_focus = true
window.win.on 'blur', ->
window.is_in_focus = false

If syntax throws you off: http://js2coffee.org/
Reply all
Reply to author
Forward
0 new messages