Macro to hide/show action bars?

I’d like to have a macro to show/hide my action bars. I don’t need a full UI overhaul mod, a simple script should suffice.

I tried using this:

/script MainMenuBar:SetShown(not MainMenuBar:IsShown())

But it doesn’t work as expected. Mounting shows the action bar and it can’t seem to be toggled in combat.

Any suggestions?

MainMenuBar contains action buttons which are secure/protected. Since Dec 5 2006 we’ve not been able to toggle them in combat with a SetShown. (This is in part to prevent addons/macros from making choices of what to cast instead of the player.)

When buttons are secure, you need to use the secure environment to toggle them properly. In a secure environment you “program” behavior and let the client handle the behavior you’ve defined.

The simplest method if you want something shown/hidden based on a macro [condition] is with a visibility state driver. You can run this once (either copy/paste to chat after /run or make a small addon of it at https://addon.bool.no/

RegisterStateDriver(MainMenuBar,"visibility","[mod:ctrl] show; hide")

For the rest of the session, MainMenuBar will only be shown while ctrl is down.

In your case you want a macro which you can hit to toggle it. This is one way, again as a small addon:

local f = CreateFrame("Button", "ToggleMainMenuBar", UIParent, "SecureHandlerClickTemplate")
f:SetFrameRef("mainmenubar",MainMenuBar)
f:SetAttribute("_onclick",[[
  local bar = self:GetFrameRef("mainmenubar")
  if bar:IsVisible() then
    bar:Hide()
  else
    bar:Show()
  end
]])

(Note that SetShown is not usable in the above snippet which has a heavily-restricted API.)

When that runs on login (technically before PLAYER_LOGIN which is fine here) it creates a button named ToggleMainMenuBar. You can use this macro to toggle MainMenuBar now, in combat or out:

/click ToggleMainMenuBar

But the client will occasionally show MainMenuBar since it manages its frames. Like when you enter a pet battle the bar will hide, and when you leave battle it will show. (Zoning might show them too.) Fighting the client that wants to show/hide secure frames is usually a losing battle that will end with taint or a broken UI. There have been ways to get through this but with the mass of taint issues in Dragonflight I don’t know what would still work.

All that said, setting the alpha of secure frames is not protected. You can macro this:

/run MainMenuBar:SetAlpha(1-MainMenuBar:GetAlpha())

In combat or out it will make the MainMenuBar invisible. It will still be there and intercept the mouse, it will just not be seen. And as a bonus the default UI probably isn’t going to mess with the alpha so when it shows the bar it will still appear invisible.

But if you have your bars in the middle of the screen then alpha is probably not a practical solution.

2 Likes

Wonderful, thank-you for the thorough reply.

1 more quick question, what’s the name of the stance bar?

StanceBar

You can use /fstack to find the name of named stuff under the mouse

Thank-you.