Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ read_globals = {
-- Namespaces
"C_AddOns", "C_CVar", "C_DamageMeter", "C_EditMode", "C_EventUtils", "C_InputInterfaceStyle", "C_Timer", "C_UI", "Settings", "Enum", "EventRegistry",
-- Frames and UI (AutoSetupReloadPopup* are named in FrameXML/AutoSetup_ReloadPopup.xml)
"CreateFrame", "UIParent", "EditModeManagerFrame", "InterfaceOptionsFrame",
"InterfaceOptionsFrame_OpenToCategory", "InterfaceOptions_AddCategory",
"CreateFrame", "UIParent", "EditModeManagerFrame",
"AutoSetupReloadPopup", "AutoSetupReloadPopupMessage",
-- Addons
"DisableAddOn", "EnableAddOn", "GetAddOnInfo", "GetNumAddOns",
Expand Down
71 changes: 51 additions & 20 deletions AutoSetup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ local debugLog = {} -- rolling in‑memory log for /autosetup deb
local lastResolution = nil -- last resolution string we evaluated
local initDone = false -- the one verbose evaluation per login/reload has run (see RunInitialEvaluation)
local applyAfterCombat = false -- the last full evaluation ran in combat; run it again once combat ends
local lastAppliedControllerSupport = nil -- last native-controller-support state we actually applied
local controllerSupportChangedThisSession = false -- true once our SetCVar took this session; Edit Mode won't offer the new mode's layouts until the next reload
local lastAppliedControllerSupport = nil -- the controller support state the last evaluation saw the profile want; a mismatch is reported once per state
local controllerSupportChangedThisSession = false -- our SetCVar took this session; Edit Mode won't offer the new mode's layouts until the next reload
local controllerSupportSetAtLogin = false -- our SetCVar took at PLAYER_LOGIN; the initial evaluation asks for the follow-up reload
local controllerSupportBlocked = false -- the game refused our SetCVar at PLAYER_LOGIN
local controllerAutoReloadAllowed = false -- set at ADDON_LOADED; false right after an automatic reload (TakeControllerReloadMark)

-- Native controller support (WoW Forever): confirmed by diffing config-cache.wtf before/after
-- toggling the setting in Forever's Options menu -- the only line that changed was
-- InputDeviceInterfaceStyle going from unset (default 0) to "1".
local CONTROLLER_SUPPORT_CVAR = "InputDeviceInterfaceStyle"

-- CVars are written through the C API, not the game's Lua SetCVar wrapper around it: a Blizzard Lua
-- function called from addon code runs tainted.
local GetCVarValue = (C_CVar and C_CVar.GetCVar) or GetCVar
local SetCVarValue = (C_CVar and C_CVar.SetCVar) or SetCVar

-- Native controller support needs the game's controller interface: on Forever, not on Retail.
-- Checked by capability, not flavor, so a client that adds it later gets the option too. The
-- C_InputInterfaceStyle namespace alone isn't enough:
Expand Down Expand Up @@ -162,6 +168,22 @@ local function LoadDB()
end
end

-- AutoSetupDB.reloadedForController marks that the last session ended with the automatic reload
-- after a controller support change (RunInitialEvaluation), so a change that doesn't survive the
-- reload can't reload forever: the session after one never reloads by itself. Optional, absent
-- means false, so no DB_VERSION bump. Only saved data of this version carries it; without it
-- (a newer file, unreadable data) there is no automatic reload at all.
local function TakeControllerReloadMark()
if type(AutoSetupDB) ~= "table" or AutoSetupDB.version ~= DB_VERSION then return true end
local marked = AutoSetupDB.reloadedForController == true
AutoSetupDB.reloadedForController = nil
return marked
end

local function SetControllerReloadMark()
AutoSetupDB.reloadedForController = true
end

local function GetProfileForResolution(resolution)
return profiles[resolution]
end
Expand Down Expand Up @@ -520,8 +542,8 @@ local function ApplyScale(profile, verbose)

if math.abs(currentScale - targetScale) > 0.001 then
if verbose then Debug("Setting UI Scale to " .. tostring(profile.scale)) end
SetCVar("useUiScale", "1")
SetCVar("uiScale", tostring(profile.scale))
SetCVarValue("useUiScale", "1")
SetCVarValue("uiScale", tostring(profile.scale))
elseif verbose then
Debug("UI Scale already matches profile (" .. tostring(currentScale) .. ")")
end
Expand All @@ -530,8 +552,6 @@ end
-- The game's real on/off for the Damage Meter; its frame listens for the CVar, so no reload is needed.
-- Edit Mode's ShowDamageMeter setting only controls the preview and is never read or written here.
local DAMAGE_METER_CVAR = "damageMeterEnabled"
local GetCVarValue = (C_CVar and C_CVar.GetCVar) or GetCVar
local SetCVarValue = (C_CVar and C_CVar.SetCVar) or SetCVar

-- nil (Leave alone) changes nothing, and nothing restores an earlier value. Only a client without
-- C_DamageMeter is skipped: IsDamageMeterAvailable() can change by character and the game's frame
Expand All @@ -553,22 +573,24 @@ local function ApplyDamageMeter(profile, verbose)
end

-- True when Edit Mode should be left alone because the input mode (keyboard/mouse vs. controller)
-- isn't confirmed settled yet -- either we changed it ourselves this session (Edit Mode won't offer
-- the new mode's layouts until the next reload), or we're blocked from changing it live and it
-- still doesn't match the profile.
-- isn't settled: either we changed controller support this session (Edit Mode won't offer the
-- new mode's layouts until the next reload), or it doesn't match the profile, whose layouts belong
-- to the other mode.
local function IsInputModeUnsettled(profile)
if not AutoSetup.hasControllerInterface then return false end
local desired = profile.nativeControllerSupport or false
return controllerSupportChangedThisSession or desired ~= (GetCVar(CONTROLLER_SUPPORT_CVAR) == "1")
end

-- InputDeviceInterfaceStyle is a protected CVar, and this is the only place that sets it. Confirmed
-- in-game: an addon's SetCVar on it from EDIT_MODE_LAYOUTS_UPDATED or later in a session can be
-- blocked with ADDON_ACTION_BLOCKED, and it's not known why, so nothing after PLAYER_LOGIN tries.
-- This can pass without acting and the value still differ by the initial evaluation (cause unknown:
-- it may arrive after PLAYER_LOGIN on a first login, or the attempt was skipped), so
-- ApplyControllerSupport asks for a reload, which comes back through here. Read it back: a blocked
-- SetCVar doesn't stop the caller.
-- InputDeviceInterfaceStyle is a protected CVar, and this is the only place that sets it. The game
-- answers an addon's SetCVar on it with ADDON_ACTION_BLOCKED, at PLAYER_LOGIN too (taint.log,
-- 2026-11-10: the addon's own call, nothing tainted before it; seen with the controller interface on
-- and a profile that wants it off). The call is made anyway, on purpose: the value still changes
-- and the switch works after a reload, which is worth the logged error. Likely why: the game's own
-- checkbox reloads the UI when toggled, with no reload in its Lua, so the client does that inside
-- the CVar change and refuses only that part to an addon (not confirmed).
-- Later in a session nothing tries: seen blocked there with the value left as it was. Read it back
-- to tell the two apart.
local function ApplyControllerSupportAtLogin()
if not AutoSetup.hasControllerInterface or InCombatLockdown() then return end
local res = GetCurrentResolution()
Expand All @@ -582,7 +604,7 @@ local function ApplyControllerSupportAtLogin()
if desired == (current == "1") then return end

Debug("Setting " .. CONTROLLER_SUPPORT_CVAR .. " to " .. (desired and "1" or "0"))
SetCVar(CONTROLLER_SUPPORT_CVAR, desired and "1" or "0")
SetCVarValue(CONTROLLER_SUPPORT_CVAR, desired and "1" or "0")
if (GetCVar(CONTROLLER_SUPPORT_CVAR) == "1") == desired then
controllerSupportChangedThisSession = true
controllerSupportSetAtLogin = true
Expand All @@ -594,7 +616,7 @@ end

-- Reports the result; only ApplyControllerSupportAtLogin changes it. Setting the CVar alone doesn't
-- make it take functional effect -- confirmed in-game that a reload is still needed afterwards.
local function ApplyControllerSupport(profile)
local function ReportControllerSupport(profile)
if not profile or not AutoSetup.hasControllerInterface then return end

local desired = profile.nativeControllerSupport or false
Expand Down Expand Up @@ -690,7 +712,7 @@ end

-- Listen to the target events only while a target layout applies, so without one AutoSetup does
-- next to nothing during play. Recomputed on every full evaluation, after CacheProfileLayouts and
-- ApplyControllerSupport (an unsettled input mode leaves Edit Mode alone until the next reload).
-- ReportControllerSupport (an unsettled input mode leaves Edit Mode alone).
local function UpdateTargetEventRegistration()
local wanted = targetLayoutClean ~= nil and not IsInputModeUnsettled(layoutProfile)
if wanted == targetEventsRegistered then return end
Expand Down Expand Up @@ -727,7 +749,7 @@ local function EvaluateProfileState(verbose)
end

ApplyScale(profile, verbose)
ApplyControllerSupport(profile)
ReportControllerSupport(profile)
UpdateTargetEventRegistration()
UpdateLayout(verbose)
ApplyAddonSet(profile, verbose)
Expand All @@ -745,6 +767,14 @@ local function RunInitialEvaluation()
if initDone then return end
initDone = true
eventFrame:UnregisterEvent("EDIT_MODE_LAYOUTS_UPDATED")
-- Controller support changed at login takes effect with a reload, like the game's own checkbox
-- does it. Reload now, before applying a profile the reload would apply again. In combat, or
-- right after such a reload, the evaluation shows the reload popup for it.
if controllerSupportSetAtLogin and controllerAutoReloadAllowed and not InCombatLockdown() then
SetControllerReloadMark()
AutoSetup.ExecuteReload()
return
end
EvaluateProfileState(true)
end

Expand Down Expand Up @@ -814,6 +844,7 @@ eventFrame:SetScript("OnEvent", function(self, event, arg1)
if arg1 ~= addonName then return end
self:UnregisterEvent("ADDON_LOADED")
LoadDB()
controllerAutoReloadAllowed = not TakeControllerReloadMark()
Debug("AutoSetup loaded.")

-- Safety net: DISPLAY_SIZE_CHANGED/UI_SCALE_CHANGED catch most changes, but some
Expand Down
47 changes: 14 additions & 33 deletions FrameXML/AutoSetup_Options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,14 @@ local function BuildAddonsString(...)
return table.concat(parts, ", ")
end

local function ASP(msg)
if AutoSetup and AutoSetup.Print then
AutoSetup.Print(msg)
else
print("AutoSetup: " .. tostring(msg))
end
end
local ASP = AutoSetup.Print

-- Find the installed addon matching a user-entered name or title (case-insensitive).
-- Returns its folder name, or nil.
local function ResolveAddonName(userName)
local lowerUser = string.lower(userName)
local getCount = AutoSetup.GetAddOnCount
local getInfo = AutoSetup.GetAddOnNameAndTitle
local numAddOns = getCount and getCount() or ((GetNumAddOns and GetNumAddOns()) or 0)

for i = 1, numAddOns do
local name, title
if getInfo then
name, title = getInfo(i)
else
name, title = GetAddOnInfo(i)
end
for i = 1, AutoSetup.GetAddOnCount() do
local name, title = AutoSetup.GetAddOnNameAndTitle(i)
if name then
local lowerTitle = title and string.lower(title) or nil
if lowerUser == string.lower(name) or (lowerTitle and lowerUser == lowerTitle) then
Expand Down Expand Up @@ -387,14 +372,8 @@ local function RefreshProfileList(panel)
end

function AutoSetup_OpenOptionsPanel()
if Settings and Settings.OpenToCategory and AutoSetup.optionsCategory then
if AutoSetup.optionsCategory then
Settings.OpenToCategory(AutoSetup.optionsCategory:GetID())
return
end

if InterfaceOptionsFrame then
InterfaceOptionsFrame_OpenToCategory("AutoSetup")
InterfaceOptionsFrame_OpenToCategory("AutoSetup")
end
end

Expand Down Expand Up @@ -487,7 +466,8 @@ function AutoSetup_OptionsPanel_OnLoad(panel)
if panel.saveButton then
panel.saveButton:SetScript("OnClick", function()
local name = panel.nameInput:GetText() or ""
local res = panel.resInput:GetText() or ""
-- Profiles are looked up by the exact "WIDTHxHEIGHT" key GetCurrentResolution builds.
local res = (panel.resInput:GetText() or ""):gsub("%s+", ""):lower()
local baseLayout = panel.baseLayoutInput:GetText() or ""
local targetLayout = panel.targetLayoutInput:GetText() or ""
local scale = panel.scaleCheck:GetChecked()
Expand All @@ -502,6 +482,11 @@ function AutoSetup_OptionsPanel_OnLoad(panel)
ASP("Please enter a resolution.")
return
end
if not res:match("^%d+x%d+$") then
ASP("Please enter the resolution as WIDTHxHEIGHT, e.g. 1920x1080.")
return
end
panel.resInput:SetText(res)
if baseLayout == "" and not controllerSupport then
ASP(AutoSetup.hasControllerInterface
and "Please enter a base Edit Mode layout name, or enable native controller support."
Expand Down Expand Up @@ -555,13 +540,9 @@ function AutoSetup_OptionsPanel_OnLoad(panel)
panel.scaleSliderText:SetText(string.format("UI Scale: %.2f", panel.scaleSlider:GetValue()))
end

if Settings and Settings.RegisterCanvasLayoutCategory then
local category = Settings.RegisterCanvasLayoutCategory(panel, "AutoSetup")
Settings.RegisterAddOnCategory(category)
AutoSetup.optionsCategory = category
elseif InterfaceOptions_AddCategory then
InterfaceOptions_AddCategory(panel)
end
local category = Settings.RegisterCanvasLayoutCategory(panel, "AutoSetup")
Settings.RegisterAddOnCategory(category)
AutoSetup.optionsCategory = category

AutoSetup.optionsPanel = panel

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ AutoSetup removes that friction: once profiles are configured, you log in and ju
- **Native controller support per profile (WoW Forever only)**
- Optional flag marking whether a profile expects WoW Forever's built-in native controller support to be on or off (e.g. on for a Steam Deck/couch profile, off for a mouse-and-keyboard profile).
- This setting doesn't exist on any other flavor, so the checkbox is hidden entirely unless AutoSetup detects it's running on Forever.
- The underlying setting is a protected CVar that Blizzard only allows addons to change during the initial evaluation right after login/reload, so switching it takes **two reloads**: the first login/reload where AutoSetup detects the mismatch applies the CVar and asks you to reload again; the second reload is where it actually takes functional effect. AutoSetup shows the same "reload required" popup used for AddOn changes at each step (with wording specific to which step you're on), and leaves Edit Mode untouched the whole time until the mode switch is fully confirmed.
- AutoSetup switches it at login/reload and then **reloads the UI once by itself**, which is when the switch takes effect (the game's own checkbox reloads too). The game logs an "action blocked" error for AutoSetup when this happens; the switch works regardless.
- The game doesn't let addons change it later in a session (e.g. right when you switch resolutions), and AutoSetup never reloads by itself in combat or twice in a row. In those cases it shows the "reload required" popup instead. Edit Mode is left untouched until the setting matches the profile.

- **Non‑intrusive behavior**
- Never changes your actual resolution; it only **observes** it.
Expand Down Expand Up @@ -99,7 +100,7 @@ In the options panel:
- On and Off apply whenever the profile is applied. In combat the change waits until combat ends.
7. **Enable native controller support** (only shown on WoW Forever)
- Check this if the profile expects WoW Forever's native controller support to be on (leave unchecked for keyboard/mouse profiles).
- Takes two reloads to fully apply: AutoSetup sets the CVar as soon as it can (on the next login/reload after a mismatch is detected) and asks you to reload once more for it to actually take effect. Blizzard also blocks addons from changing this setting live mid-session (e.g. right when you switch resolutions), so in that case AutoSetup shows the reload popup first to get that initial reload going. Edit Mode is left alone the whole time until the mode switch is fully confirmed.
- AutoSetup switches it at the next login/reload and reloads the UI once by itself to finish. Mid-session (e.g. right after you save the profile or switch resolutions) it shows the reload popup first. Edit Mode is left alone until the setting matches the profile.
8. **AddOns**
- Comma/semicolon‑separated list of addons to enable/disable:
- `WeakAuras, Details, Midnight Viewport`
Expand Down Expand Up @@ -133,7 +134,7 @@ Saved profiles are listed in the scrollable list at the bottom:
- AutoSetup re‑evaluates whether to be on the **base** or **target** layout and switches only if needed. Scale, addons, features and the Damage Meter are left alone.
- While Edit Mode is open it doesn't switch layouts; it catches up when you close Edit Mode.

If AutoSetup detects that addons or native controller support need to change for a profile, it shows a popup with **Reload UI** and **Later** buttons so you can apply those changes when it's convenient. If more than one thing needs a reload at the same time, the popup lists each reason on its own line rather than showing them one at a time.
If AutoSetup detects that addons need to change for a profile, or that native controller support needs a reload it won't do by itself, it shows a popup with **Reload UI** and **Later** buttons so you can apply those changes when it's convenient. If more than one thing needs a reload at the same time, the popup lists each reason on its own line rather than showing them one at a time.

---

Expand Down
Loading