I'm searching for a solution in my firefox addon to detect when the user workspace has locked/released. In google chrome there is an easy API chrome.idle.onStateChanged.addListener
for it, is there something similar in firefox or any possibility to do that, platform independent?
By the way, I use the addon sdk.
I've already tried the idle service:
Cc["@mozilla.org/widget/idleservice;1"].getService(Ci.nsIIdleService)
but I just gives me access to some idle timeout or system when go to sleep and not to just workspace locked.
Edit: With "workspace locked" I mean the user lock the workspace with ctrl + alt + delete. I don't know how this exactly work on OSX or linux.
Edit2: I working in Windows 8.1 currently, but I guess the chrome.idle
handler works cross platform.
Edit3: What i currently get out of current answers is
1. That there not exist a cross-platform solution, neither in chrome nor in firefox.
chrome.idle.onStateChanged
seems to work different on windows, linux and osx. Only windows can handle that "locked" behaviour as expected. I can't test OSX, on ubuntu 14 it doesn't work for me.
2. For firefox there some in-depth code things to try to make it working - see answer bellow from Noitidart in this topic.
Edit4: Noitidart have found a solution for windows - github link.
I don't know how to detect screen lock but there are these observer notifications:
https://developer.mozilla.org/en-US/docs/Observer_Notifications#Idle_Service
Also the computer sleep wake notifications. ill ask around for lock screen thats an interesting one.
Some useful chat about the subject, looking at how google chrome does it:
maybe they arent polling.
check this out:
http://mxr.mozilla.org/chromium/source/src/chrome/browser/extensions/api/idle/idle_manager.cc#246
leads to: http://mxr.mozilla.org/chromium/source/src/chrome/browser/idle_win.cc#52
so this leads us to test if screensaver running or workstation locked
leads to:
http://mxr.mozilla.org/chromium/search?string=IsWorkstationLocked
we see just one implementation (its curious because there is no linux support but it doesnt say so on the chrome docs page, so maybe i couldnt find it)
Windows
http://mxr.mozilla.org/chromium/source/src/ui/base/win/lock_state.cc#11
http://mxr.mozilla.org/chromium/search?string=IsScreensaverRunning&find=&findi=&filter=^%5B^\0%5D*%24&hitlimit=&tree=chromium
we see in this search results 2 implementations, mac and windows it looks like no support for linux, which is curious because the chrome.idle page doesnt mention this on docs, maybe i just couldnt find it
windows implementation: http://mxr.mozilla.org/chromium/source/src/chrome/browser/idle_win.cc#39
mac implementation: http://mxr.mozilla.org/chromium/source/src/chrome/browser/idle_mac.mm#28
so to sum this all up:
edit: actually i found the linux implementation. back from the search results of:
CheckIdleStateLocked
: http://mxr.mozilla.org/chromium/search?string=CheckIdleStateIsLockedhttp://mxr.mozilla.org/chromium/source/src/chrome/browser/idle_linux.cc#24
Leads to ask how is
ScreensaverWindowExists
we find this: http://mxr.mozilla.org/chromium/source/src/chrome/browser/screensaver_window_finder_x11.ccLeads to what is
EnumerateTopLevelWindows
http://mxr.mozilla.org/chromium/source/src/ui/base/x/x11_util.cc#1059:We say they call
delegate->ShouldStopIterating
which was seen in same file asScreensaverWindowExists
: http://mxr.mozilla.org/chromium/source/src/chrome/browser/screensaver_window_finder_x11.ccLeads to ask what is
IsWindowVisible
andIsScreensaverWindow
*
IsScreensaverWindow
, in same file ofScreensaverWindowExists
: http://mxr.mozilla.org/chromium/source/src/chrome/browser/screensaver_window_finder_x11.ccIsWindowVisible
: http://mxr.mozilla.org/chromium/source/src/ui/base/x/x11_util.cc#546