Observable to detect tool window in foreground or background?

To build a window tool, it is sometimes necessary to know if the tool window is in the foreground or in the background, being able to toggle between the main Renoise window and the tool window with an observable or notifier.

Is there an observable that detects the change of state of the tool window, in the background or in the foreground?

In the following documentation there are “similar” observables, but not the foreground and background state of the tool. I’m missing something?


-- Invoked when the tool finished loading/initializing and no errors happened. When
-- the tool has preferences, they are loaded here as well when the notification fires,
-- but 'renoise.song()' may not yet be available.
-- See also 'renoise.tool().app_new_document_observable'.
  -> [renoise.Document.Observable object]

-- Invoked right before a tool gets unloaded: either because it got disabled, reloaded
-- or the application exists. You can cleanup resources or connections to other devices
-- here if necessary.
  -> [renoise.Document.Observable object]

-- Invoked as soon as the application becomes the foreground window.
-- For example, when you ATL-TAB to it, or activate it with the mouse
-- from another app to Renoise.
  -> [renoise.Document.Observable object]

-- Invoked as soon as the application looses focus and another app
-- becomes the foreground window.
  -> [renoise.Document.Observable object]

-- Invoked periodically in the background, more often when the work load
-- is low, less often when Renoise's work load is high.
-- The exact interval is undefined and can not be relied on, but will be
-- around 10 times per sec.
-- You can do stuff in the background without blocking the application here.
-- Be gentle and don't do CPU heavy stuff please!
  -> [renoise.Document.Observable object]

-- Invoked each time before a new document gets created or loaded: this is the
-- last time renoise.song() still points to the old song before a new one arrives.
-- You can explicitly release notifiers to the old document here, or do your own
-- housekeeping. Also called right before the application exits.
  -> [renoise.Document.Observable object]

-- Invoked each time a new document (song) is created or loaded. In other words:
-- each time the result of renoise.song() is changed. Also called when the script
-- gets reloaded (only happens with the auto_reload debugging tools), in order
-- to connect the new script instance to the already running document.
  -> [renoise.Document.Observable object]

-- invoked each time the app's document (song) is successfully saved.
-- renoise.song().file_name will point to the filename that it was saved to.
  -> [renoise.Document.Observable object]

This would be especially useful when using modifier key commands, so that the tool could change the state of these key commands depending on the state of the tool window, whether it is in the foreground or in the background.

Any trick to do this?

The specific scenario I am looking for is the following:
The window tool could detect when it is in the background. In this case you could deactivate certain features and reactivate them when the window is back in the foreground, especially useful for controlling the state of keyboard commands, preventing certain commands from remaining pressed when the window tool changes state to the background.

The point is to be able to switch between the Renoise window and the tool window and to be able to detect it to trigger a function.

Not possible AFAIK. Would be handy to have though for your scenario.

There is something that can effect focus state which I use. A hacky way to always put the tool window in the background when keyboard is used, but it’s limited to just that.

-By toggling it keeps the users original setting:

  --key Handler
  local function my_keyhandler_func(dialog,key)

     --toggle lock focus hack, allows pattern ed to get key input
     renoise.app().window.lock_keyboard_focus = not renoise.app().window.lock_keyboard_focus
     renoise.app().window.lock_keyboard_focus = not renoise.app().window.lock_keyboard_focus
     return key

Yes, I am aware of this trick and use it in some of my tools to save setting custom keyboard commands.

However, I need to know the status of the window. The problem is the following… If the window tool is in the foreground and you press and hold an “X” key, it will remain pressed if you place the Renoise window in the foreground with the mouse, even after releasing the “X” key. This is a control problem. I should be able to disable those pressed keys in some way.

I have not found a way to do it.

Like I say, no way to check that at mo - unless someone else can correct.