Old 05-20-2019, 05:22 PM   #1
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default Hide dockers individually

Hey guys,

I've been working on a script that will hide/show dockers individually.

My approach is:

- get the screen dimensions of Reaper's main window
- search for all docker windows (= REAPER_dock) and also get their screen dimensions
- now to get the right docker, I compare the right value with the width value of the screen

And that's where I'm stuck, now.

The logical step to show/hide the docker was to use reaper.JS_Window_Show().
However, when using this method, the windows inside the docker get hidden, but not the docker itself, as shown here:
https://imgur.com/ppLEWBj

The goal is NOT to terminate running scripts, therefore reaper.JS_Window_Destroy() is no option.

View: Show docker 40279, perfectly shows, that it's possible to hide dockers without terminating the running scripts.
I checked the child windows when using this action (all dockers hidden).
reaper.JS_Window_IsVisible() gave me a false for all the child windows.
The same thing, that I achieved by using JS_Window_Show().
But apparently there is another mechanism involed, that will update the arrange or the docker windows. Otherwise it would look like my screenshot from above.

Maybe someone can help?

Here's my code:

Code:

dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")


hwnd = reaper.GetMainHwnd() -- get Reaper main
retval, width, height = reaper.JS_Window_GetClientSize(hwnd) -- get window dimensions
retval, docker_list = reaper.JS_Window_ListFind("REAPER_dock", false) -- find all windows called REAPER_dock

docker_count, docker_array = ultraschall.CSV2IndividualLinesAsArray(docker_list) -- create docker array from list


for i=1, docker_count do

    docker_hwnd = reaper.JS_Window_HandleFromAddress(docker_array[i]) -- convert address to hwnd
    retval, left, top, right, bottom = reaper.JS_Window_GetRect(docker_hwnd) -- get docker dimensions
    
    if right == width then -- get right docker
        
        if reaper.JS_Window_IsVisible(docker_hwnd) then
            reaper.JS_Window_Show(docker_hwnd, "HIDE") -- hide all children of right docker
        else 
            reaper.JS_Window_Show(docker_hwnd, "SHOW") -- hide all children of right docker
        end
    end
end
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...

Last edited by _Stevie_; 05-20-2019 at 05:35 PM.
_Stevie_ is online now   Reply With Quote
Old 05-27-2019, 03:36 AM   #2
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

bumpy bump
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 06-12-2019, 04:43 PM   #3
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

Sigh, I guess there's no hope?
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 06-12-2019, 04:58 PM   #4
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 635
Default

I wonder if the proper way to hide/show the dockers would be reaper.DockWindowAdd() and reaper.DockWindowRemove() rather than the JS functions?
tack is offline   Reply With Quote
Old 06-12-2019, 05:01 PM   #5
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

Yes, I tried that, too. The problem is to add the undocked window to the same docker as before.

Let me check with my code...
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 06-12-2019, 05:07 PM   #6
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

I indeed created a script for hiding the Track Inspector with the method you mentioned. But it doesn't dock back to the correct docker.
Maybe I'm also missing something...

Code:
hwnd = reaper.JS_Window_Find("Track Inspector", false)

if hwnd then
    title = reaper.JS_Window_GetTitle(hwnd)

    if reaper.JS_Window_IsVisible(hwnd) then
        reaper.DockWindowRemove(hwnd)
    else
        reaper.DockWindowAdd(hwnd, title, 0, true)
    end
else
    reaper.ShowConsoleMsg("Track Inspector is not running!")
end

EDIT: actually! How do you dock the Reaticulate script back to where it was, when we undock it?
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 06-12-2019, 05:14 PM   #7
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 635
Default

Do different values of the third argument to DockWindowAdd() affect which docker it attaches to?

Although even if it does, I don't know how to get the current value before undocking.
tack is offline   Reply With Quote
Old 06-12-2019, 05:20 PM   #8
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

Well, it almost looks like it wouldn't.
What method do you use to redock the Reaticulate window?
It always docks to the same position, where it was before.
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 06-12-2019, 05:23 PM   #9
tack
Human being with feelings
 
tack's Avatar
 
Join Date: Jan 2014
Location: Ontario, Canada
Posts: 635
Default

Quote:
Originally Posted by _Stevie_ View Post
Well, it almost looks like it wouldn't.
What method do you use to redock the Reaticulate window?
It always docks to the same position, where it was before.
It's a lot easier there because I control the gfx context (having created it). All I need to do is call gfx.dock().

What you're trying to do is different, since you're trying to manipulate the dock states from the outside.
tack is offline   Reply With Quote
Old 06-12-2019, 05:26 PM   #10
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

Oh... ok that is different indeed.
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 06-13-2019, 04:05 AM   #11
heda
Human being with feelings
 
heda's Avatar
 
Join Date: Jun 2012
Location: Spain
Posts: 5,190
Default

I can make Track inspector to be hidden but running in the background. This would help to make the tag actions work without having Track Inspector visible.
Like the Region Tracks script that it has a minimize button that sends the script to background without gfx window but still running to manage the regions etc.
__________________
HeDaScripts for REAPER
heda is offline   Reply With Quote
Old 06-13-2019, 06:33 AM   #12
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

Hey Heda! That would actually be a great idea. But there is a problem...
This will only work, if only one script is running in the dock. As soon as I add another script to
the docker, where TI is located, it won’t work anymore, because only TI will be hidden but not the whole docker.

So, my plan is to do the following:

- identify the docker by a script that will always be there (like TI).
- cycle thru all the scripts running in the docker and hide them
- save the dock ID via SetExState
- save all the script names, that are running inside the docker via SetExState

When toggling that action again:

- check if docker is visible
- if it isn’t, get the dock ID from GetExtState
- also retrieve all the other scripts names that are in the same dock as TI
- add all the scripts to the dock

Not sure, if I’m missing something, but in theory this should work.
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...

Last edited by _Stevie_; 06-13-2019 at 07:26 AM.
_Stevie_ is online now   Reply With Quote
Old 06-13-2019, 08:04 AM   #13
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

I think, I solved it, even without using ExState.
Code coming shortly...
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 06-13-2019, 11:44 AM   #14
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

Here you go. Not sure, if it can be done even more efficiently. But give it a spin, if you think so.

What puzzled me a bit was the use of arrays and tables. The difference didn't seem obvious to me. I took a code snippet from Edgemeal and adjusted it to my needs.
Another thing is: although my functions are local, arrays are global. Is this normal and if so, should I localize them? I always thought that everything in a "local function" is localized anyway?


Okay, but now back to the script. Once you put the title of a window in "known_window" (here Track Inspector), the script will toggle all windows that are docked in the same docker. That means, if TI is docked in the left docker, the script will toggle show the left docker. If you want to toggle show the right docker, you have to pick the title of a known_window that is docked there and put it in the script.

Code:
local function GetDocker(known_window)
    
    known_hwnd = reaper.JS_Window_Find(known_window, false) -- get hwnd of known docked window
    docker_hwnd = reaper.JS_Window_GetParent(known_hwnd) -- get (parent) docker hwnd
    
    docker_id = reaper.DockIsChildOfDock(known_hwnd) -- dock id is retained, if even window is removed from dock!
    docker_visible = reaper.JS_Window_IsVisible(docker_hwnd) -- get visible state of dock
    
    if docker_id ~= -1 then
        return docker_visible, docker_hwnd, docker_id
    else
        reaper.ShowMessageBox("The window with the title "..known_window.." does not exist", "Error", 0)
    end
end


local function GetChildren(docker_hwnd)
   
    child_array = reaper.new_array({},100) -- create array
    retval = reaper.JS_Window_ArrayAllChild(docker_hwnd, child_array) -- store all children in array
    table = child_array.table()

end


local function ToggleDocker(docker_visible, docker_id)
    
    for t = 1, #table do
        
        address = table[t] -- iterate thru table and get window address
        child_hwnd = reaper.JS_Window_HandleFromAddress(address) -- convert address to hwnd
        child_title = reaper.JS_Window_GetTitle(child_hwnd) -- get full title of window
        
     
        
        if docker_visible then -- if docker is visible: hide
            if child_title ~= "Custom1" then -- ignore Custom1 window
                reaper.DockWindowRemove(child_hwnd)
            end
        else -- if docker is visible: show
            if child_title ~= "Custom1" then -- ignore Custom1 window
                reaper.DockWindowAdd(child_hwnd, child_title, docker_id, true)
            end
        end
    end
end


local known_window = "Track Inspector" -- enter your known window title here
local docker_visible, docker_hwnd, docker_id = GetDocker(known_window)

GetChildren(docker_hwnd)
ToggleDocker(docker_visible, docker_id)
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 06-14-2019, 09:40 AM   #15
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 14,504
Default

Stevie... love the idea... just was trying it but either I don't get it or something is missing... here's my tale:

I have at the right of the arrange a docker with three tabs
1-performance
2-HeDa Track Inspector VIP
3-FX Browser

and at the right of the TCP I have the reaper MCP docked to use as a track inspector also...

OK so I ran you script as is, thinking it would hide and also restore the dock at the right side that holds the three tabs listed above.

...and it indeed hides them but then running it again does not restore them ... instead it puts that dock along with a slew of tabs to the left of the TCP...
...the slew of tabs seem to be each of the FX Browser folders, each one on a tab... wtf???
not at all what I expected and really a mess

...it does seem close though
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 06-14-2019, 10:24 AM   #16
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

Yeah, I noticed this as well. There’s really something going wrong. I yet have to find out what’s causing this.
When toggling the docker twice, it changes the docker ID. In my case, the first iteration is docker ID 0 and on the second iteration it switches to ID 5. This goes back and forth. I think that’s the culprit. I’ll dig deeper.
Maybe the devs can also shed some light if they are reading this.
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Old 06-14-2019, 10:34 AM   #17
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 14,504
Default

ah I see... well that changing ID certainly describes what I see happen...

this will be a kewl tool if you get it working

I was just thinking but have tried it... that in my case I might be able to get the same [desired] result with just another screen set
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva/angel-rain
hopi is online now   Reply With Quote
Old 06-24-2019, 06:28 AM   #18
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,226
Default

Quote:
Originally Posted by _Stevie_ View Post
Yeah, I noticed this as well. There’s really something going wrong. I yet have to find out what’s causing this.
When toggling the docker twice, it changes the docker ID. In my case, the first iteration is docker ID 0 and on the second iteration it switches to ID 5. This goes back and forth. I think that’s the culprit. I’ll dig deeper.
Maybe the devs can also shed some light if they are reading this.
This changing of the docker ID is due the fact, that Reaper has 16 of them (0 to 15).

Usually, you don't use all of them, leading to some of them being "hidden" at the same position.
So when you add a window to a docker, which is at a position where numerous "hidden" dockers are positioned, it will simply take anyone of them(dunno what kind of "pattern" Reaper is using for the selection-process).

Still investigating into that more, but that's my current state of understanding.

@all
BTW: You might want to add a +1 to the following FR-thread, where I added some docker-related function-requests:
https://forum.cockos.com/showthread.php?t=222314
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote
Old 06-24-2019, 07:41 AM   #19
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Posts: 2,386
Default

Hey mespo!

Thanks for chiming in. I have found a pattern but it doesn’t make sense to me.
Please keep us posted if you find anything!
__________________
My Reascripts forum thread | My Reascripts on GitHub | Stephan Römer - film composer
If you wish to donate for my scripts: please consider an organization like: animal shelter, doctors without borders, UNICEF, etc...
_Stevie_ is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.