local _, P = ... -- Notification space is reserved even when no toast is visible. Protected bars -- never chase a popup during combat. Blizzard still owns every alert's content, -- lifecycle, queue, click handler and bank transaction. local gap = P.layoutPolicy.gap local hudNames = { "MainActionBar", "MultiBarBottomLeft", "MultiBarBottomRight", "MultiBar5", "MultiBarLeft", "MultiBarRight", "MultiBar6", "MultiBar7", "BagsBar", "MicroMenuContainer", "DamageMeter", "BuffFrame", "DebuffFrame", "MirrorTimer1", "MirrorTimer2", "MirrorTimer3", "ChatFrame1", "ChatFrame1EditBox", "ChatFrame1Tab", "MinimapCluster", "ObjectiveTrackerFrame", "PartyFrame", "CompactRaidFrameContainer", "PlayerFrame", "PetFrame", "TargetFrame", "TargetFrameToT", "RuenTargetTargetTarget", "FocusFrame", "StanceBar", "PetActionBar", "MultiCastActionBarFrame", "PossessActionBar", "MainMenuBarVehicleLeaveButton", "PlayerCastingBarFrame", "RuenSwingTimers", "ExtraAbilityContainer", "BossTargetFrameContainer", "ArenaEnemyFrames", "CompactArenaFrame", "UIWidgetTopCenterContainerFrame", "UIWidgetBelowMinimapContainerFrame", "UIWidgetPowerBarContainerFrame", "PlayerPowerBarAlt", "TotemFrame", "ClassNameplateBarRogueFrame", "ClassNameplateBarDruidFrame", } local blockMembers = P.controlFrameSet local panels = P.layoutPolicy.panels local hooked, queued, placing = {}, false, false local place, edge, enabled, schedule local alertHooks={} local function rect(f, reserveHidden) if not f then return end if f.IsForbidden and f:IsForbidden() then return nil,true end if not reserveHidden then local shown=f:IsShown() if issecretvalue and issecretvalue(shown) then return nil,true end if not shown then return end end local l, r, b, t = edge(f,"GetLeft"), edge(f,"GetRight"), edge(f,"GetBottom"), edge(f,"GetTop") if not l or not r or not b or not t then return nil,true end if l and r and b and t and r>l and t>b then return {left=l,right=r,bottom=b,top=t,name=f.GetName and f:GetName()} end end local function overlaps(a,b,pad) return a.left < b.right+pad and a.right > b.left-pad and a.bottom < b.top+pad and a.top > b.bottom-pad end -- Pure geometry: choose the nearest free rectangle, considering obstacle edges -- rather than assuming that one fixed pixel offset works at every resolution. function P.FindOverlayPosition(width,height,x,y,obstacles,screenWidth,screenHeight) local maxX,maxY=screenWidth-gap-width,screenHeight-gap-height if maxX.001 then saved={base=current,applied=current};alertScales[f]=saved end local scale=f:GetEffectiveScale()/UIParent:GetEffectiveScale()*saved.base/current padding=padding or 0 local w,h=f:GetWidth()*scale+padding*2,f:GetHeight()*scale if w<=0 or h<=0 then return false end local target,fit for step=0,3 do fit=1-step*.05 target=P.FindOverlayPosition(w*fit,h*fit,x-padding,y,obstacles,UIParent:GetWidth(),UIParent:GetHeight()) if target then break end end if not target then return false end local nextScale=saved.base*fit if math.abs(current-nextScale)>.001 then (f.SetScaleBase or f.SetScale)(f,nextScale) end saved.applied=nextScale local old=rect(f) if not old or math.abs(old.left-target.left-padding*fit)>.5 or math.abs(old.bottom-target.bottom)>.5 then place(f,"BOTTOMLEFT",UIParent,"BOTTOMLEFT",target.left+padding*fit,target.bottom) end target.name=f.GetName and f:GetName() or "Alert" obstacles[#obstacles+1]=target return true end function P.PositionOverlayFrames() if placing or not enabled or not enabled() then return end placing=true local obstacles=P.OverlayObstacles(true) local bag=rect(ContainerFrameCombinedBags);if bag then obstacles[#obstacles+1]=bag end for _,name in ipairs({"GameTooltip","ShoppingTooltip1","ShoppingTooltip2"}) do local r=rect(_G[name]);if r then obstacles[#obstacles+1]=r end end P.overlayUnplaced={} P.overlayOverChat={} P.overlayOverOptional={} local alerts=collectAlerts() -- Place wide/tall alerts first so small loot notices do not fragment the -- remaining space. Stable names break ties between equal-size alerts. table.sort(alerts,function(a,b) local sa,sb=a:GetEffectiveScale(),b:GetEffectiveScale() local aa,ab=a:GetWidth()*a:GetHeight()*sa*sa,b:GetWidth()*b:GetHeight()*sb*sb if aa==ab then return (a:GetName() or tostring(a))<(b:GetName() or tostring(b)) end return aa>ab end) for _,f in ipairs(alerts) do if schedule and not alertHooks[f] then alertHooks[f]=true f:HookScript("OnHide",schedule) f:HookScript("OnSizeChanged",schedule) end local scale=f:GetEffectiveScale()/UIParent:GetEffectiveScale() -- Use the open upper field, clear of the combat HUD and minimap. -- The left bars occupy the middle of the screen, not this upper row. -- Let collision checks account for their actual height instead of -- excluding a full-height column; four roll cards can then wrap cleanly. local raidRight=CompactRaidFrameContainer and CompactRaidFrameContainer:IsShown() and edge(CompactRaidFrameContainer,"GetRight") or 20 local x=math.max(20,raidRight or 20)+gap local y=UIParent:GetHeight()-f:GetHeight()*scale-gap if not fitFrame(f,obstacles,x,y,alertPadding(f)) then -- Short-lived native notices may use chat's text area in a crowded -- raid. They still avoid social toasts, controls and other notices. local fallback={} for _,r in ipairs(obstacles) do if r.name~="ChatFrame1" then fallback[#fallback+1]=r end end if fitFrame(f,fallback,x,y,alertPadding(f)) then P.overlayOverChat[f]=true obstacles[#obstacles+1]=fallback[#fallback] else -- Interactive loot decisions outrank optional duplicate cooldown -- displays/meters. Health, casts, actions and social remain clear. local minimal={} for _,r in ipairs(fallback) do if not (r.name or ""):find("CooldownViewer") and not (r.name or ""):match("^DamageMeter") then minimal[#minimal+1]=r end end if fitFrame(f,minimal,x,y,alertPadding(f)) then P.overlayOverChat[f]=true;P.overlayOverOptional[f]=true obstacles[#obstacles+1]=minimal[#minimal] else P.overlayUnplaced[#P.overlayUnplaced+1]=f.GetName and f:GetName() or "Alert" end end end end placing=false end local tooltipPositions=setmetatable({},{__mode="k"}) function P.ResetTooltipPosition(tooltip) tooltipPositions[tooltip]=nil P.tooltipUnplaced=nil P.tooltipOverInventory=nil P.tooltipOverSocial=nil end function P.PositionTooltip(tooltip,settled) if not edge or not enabled() then return false end -- SetPoint alone does not release the tooltip engine's automatic owner- -- relative anchor. Bag refreshes reinstate ANCHOR_LEFT/RIGHT repeatedly; -- ANCHOR_NONE gives this tooltip one positioning authority without the -- hide/content-reset side effects of calling SetOwner again. if tooltip.GetAnchorType and tooltip.SetAnchorType and tooltip:GetAnchorType()~="ANCHOR_NONE" then tooltip:SetAnchorType("ANCHOR_NONE") end local screenW,screenH=UIParent:GetWidth(),UIParent:GetHeight() local uiScale=UIParent:GetEffectiveScale() local scale=tooltip:GetEffectiveScale()/uiScale local owner=tooltip:GetOwner() local pos=tooltipPositions[tooltip] if not pos or pos.owner~=owner or pos.screenW~=screenW or pos.screenH~=screenH or pos.uiScale~=uiScale or pos.scale~=scale then pos={owner=owner,screenW=screenW,screenH=screenH,uiScale=uiScale,scale=scale, right=edge(P.UtilityTop(),"GetRight") or screenW-22, bottom=(edge(P.UtilityTop(),"GetTop") or 250)+18,width=0,height=0,extraWidth=0} tooltipPositions[tooltip]=pos end local comparisons={} -- Fit comparison cards as one block; a correctly placed primary tooltip -- alone does not protect the bars from its secondary equipment tooltips. local extraWidth,extraHeight=0,0 if tooltip==GameTooltip and settled then for _,name in ipairs({"ShoppingTooltip1","ShoppingTooltip2"}) do local f=_G[name] if f and f:IsShown() then local ratio=f:GetEffectiveScale()/uiScale local w,h=f:GetWidth()*ratio,f:GetHeight()*ratio if w>0 and h>0 then comparisons[#comparisons+1]={frame=f,width=w,height=h} extraWidth=extraWidth+w+gap;extraHeight=math.max(extraHeight,h) end end end end -- DefaultAnchor runs before text is rebuilt. Only measure settled sizes and -- retain the high-water footprint until the mouse leaves this owner. if settled and tooltip:IsShown() then local w,h=tooltip:GetWidth()*scale,tooltip:GetHeight()*scale local needs=not pos.fitted or w>pos.width+1 or h>pos.height+1 or extraWidth>pos.extraWidth+1 or extraHeight>pos.height+1 or pos.revision~=(P.overlayRevision or 0) if w>0 and h>0 and needs then w,h=math.max(w,pos.width),math.max(h,pos.height,extraHeight) extraWidth=math.max(extraWidth,pos.extraWidth) local totalWidth=w+extraWidth local obstacles=P.OverlayObstacles(true) local bag=rect(ContainerFrameCombinedBags) local withoutBag=CopyTable(obstacles) -- In a packed small viewport, comparison cards may cover other bag -- contents, but must keep the hovered item and all controls clear. local hover=rect(owner);if hover then withoutBag[#withoutBag+1]=hover end if bag then obstacles[#obstacles+1]=bag end for _,f in ipairs(collectAlerts()) do local r=rect(f);if r then obstacles[#obstacles+1]=r end end local candidate={left=pos.right-w,right=pos.right+extraWidth,bottom=pos.bottom,top=pos.bottom+h} local free=candidate.left>=gap and candidate.right<=screenW-gap and candidate.bottom>=gap and candidate.top<=screenH-gap for _,o in ipairs(obstacles) do if overlaps(candidate,o,gap-0.1) then free=false;break end end P.tooltipOverInventory=nil P.tooltipOverSocial=nil if not free then local target=P.FindOverlayPosition(totalWidth,h,candidate.left,pos.bottom,obstacles,screenW,screenH) if not target and bag and extraWidth>0 then target=P.FindOverlayPosition(totalWidth,h,candidate.left,pos.bottom,withoutBag,screenW,screenH) P.tooltipOverInventory=target and true or nil end if not target then -- A full raid plus a long tooltip can saturate a laptop -- viewport. Temporarily cover chat/notification space only -- after proving no fully clear position exists. Never cover -- controls, health/cast bars, objectives or the hovered item. local fallback={} for _,o in ipairs(obstacles) do if o.name~="ChatFrame1" and o.name~="Social notifications" then fallback[#fallback+1]=o end end if hover then fallback[#fallback+1]=hover end target=P.FindOverlayPosition(totalWidth,h,candidate.left,pos.bottom,fallback,screenW,screenH) P.tooltipOverSocial=target and true or nil end if target then pos.right,pos.bottom=target.left+w,target.bottom;free=true end end P.tooltipUnplaced=not free pos.width,pos.height,pos.extraWidth,pos.fitted=w,h,extraWidth,true pos.revision=P.overlayRevision or 0 end end local point,relative,relativePoint,x,y if tooltip.GetPoint then point,relative,relativePoint,x,y=tooltip:GetPoint(1) end if point~="BOTTOMRIGHT" or relative~=UIParent or relativePoint~="BOTTOMLEFT" or not x or not y or math.abs(x-pos.right/scale)>.01 or math.abs(y-pos.bottom/scale)>.01 or (tooltip.GetNumPoints and tooltip:GetNumPoints()~=1) then place(tooltip,"BOTTOMRIGHT",UIParent,"BOTTOMLEFT",pos.right,pos.bottom) end local left=pos.right+gap for _,card in ipairs(comparisons) do if card.frame.GetAnchorType and card.frame.SetAnchorType and card.frame:GetAnchorType()~="ANCHOR_NONE" then card.frame:SetAnchorType("ANCHOR_NONE") end local r=rect(card.frame) if not r or math.abs(r.left-left)>.5 or math.abs(r.bottom-pos.bottom)>.5 then place(card.frame,"BOTTOMLEFT",UIParent,"BOTTOMLEFT",left,pos.bottom) end left=left+card.width+gap end return not P.tooltipUnplaced end function P.FindBagPosition(width,height,x,y) if not edge then return end local obstacles=P.OverlayObstacles(true) P.bagOverHUD=nil local screenW,screenH=UIParent:GetWidth(),UIParent:GetHeight() -- Prefer full readability; reduce only if the complete inventory does not -- fit. Never fall back to an anchor sitting on top of utility buttons. for step=0,10 do local scale=1-step*.035 local target=P.FindOverlayPosition(width*scale,height*scale,x,y,obstacles,screenW,screenH) if target then return target,scale end end -- An unusually tall inventory is a modal panel. Keep it on screen and -- preserve every action/chat/quest control; allow temporary HUD coverage -- only after the fully clear placements are exhausted. Report this fallback. local essential=P.ControlRegions() for _,o in ipairs(obstacles) do if o.name=="ChatFrame1" or o.name=="Social notifications" or o.name=="ObjectiveTrackerFrame" or o.name=="MinimapCluster" then essential[#essential+1]=o end end for _,name in ipairs(panels) do local r=rect(_G[name]);if r then essential[#essential+1]=r end end for step=0,10 do local scale=1-step*.035 local target=P.FindOverlayPosition(width*scale,height*scale,x,y,essential,screenW,screenH) if target then P.bagOverHUD=true;return target,scale end end end function P.OverlayAudit() local issues={} if not edge then return issues end for _,issue in ipairs(P.groupLayoutIssues or {}) do issues[#issues+1]=issue end for _,name in ipairs(RuenUICharacter.classAssistUnplaced or {}) do issues[#issues+1]=name.." has no free space" end if RuenUICharacter.classAssistError then issues[#issues+1]="Cooldown setup: "..RuenUICharacter.classAssistError end local social=P.SocialNotificationSpace(edge) for _,name in ipairs({"MultiBar6","MultiBar7","PartyFrame","CompactRaidFrameContainer"}) do local r=rect(_G[name]);if r and overlaps(r,social,0) then issues[#issues+1]=name.."/social notifications" end end local controls=P.ControlRegions() local chat=rect(ChatFrame1) if chat then for _,r in ipairs(controls) do if overlaps(chat,r,0) then issues[#issues+1]="ChatFrame1/"..r.name end end end local obstacles=P.OverlayObstacles(false) local bag=rect(ContainerFrameCombinedBags) if P.bagUnplaced then issues[#issues+1]="Inventory has no clear space at readable scale" end if P.tooltipUnplaced then issues[#issues+1]="Tooltip group has no clear space" end if bag then for _,o in ipairs(obstacles) do if overlaps(bag,o,0) then issues[#issues+1]="ContainerFrameCombinedBags/"..(o.name or "HUD") end end obstacles[#obstacles+1]=bag end for _,name in ipairs({"GameTooltip","ShoppingTooltip1","ShoppingTooltip2"}) do local t=rect(_G[name]) if t then for _,o in ipairs(obstacles) do if not (P.tooltipOverInventory and o.name=="ContainerFrameCombinedBags") and not (P.tooltipOverSocial and (o.name=="ChatFrame1" or o.name=="Social notifications")) and overlaps(t,o,0) then issues[#issues+1]=name.."/"..(o.name or "HUD") end end end end for _,name in ipairs(P.overlayUnplaced or {}) do issues[#issues+1]=name.." has no free space" end for _,f in ipairs(collectAlerts()) do local r=rect(f) if r then if r.left<0 or r.bottom<0 or r.right>UIParent:GetWidth()+1 or r.top>UIParent:GetHeight()+1 then issues[#issues+1]=(r.name or "Alert").." off screen" end for _,o in ipairs(obstacles) do if not (P.overlayOverChat and P.overlayOverChat[f] and o.name=="ChatFrame1") and not (P.overlayOverOptional and P.overlayOverOptional[f] and ((o.name or ""):find("CooldownViewer") or (o.name or ""):match("^DamageMeter"))) and overlaps(r,o,0) then issues[#issues+1]=(r.name or "Alert").."/"..(o.name or "HUD") end end obstacles[#obstacles+1]=r end end return issues end function P.InitializeOverlayLayout(placeFrame,frameEdge,owns) place,edge,enabled=placeFrame,frameEdge,owns if P.overlayListener then return end local listener=CreateFrame("Frame");P.overlayListener=listener local function queue() if placing or queued then return end queued=true C_Timer.After(0,function() queued=false;P.PositionOverlayFrames() end) end schedule=queue local function watch() for _,name in ipairs({"AlertFrame","GroupLootContainer","TalkingHeadFrame","ChatFrame1EditBox","ChatFrame1Tab"}) do local f=_G[name] if f and not hooked[f] then hooked[f]=true f:HookScript("OnShow",queue);f:HookScript("OnHide",queue);f:HookScript("OnSizeChanged",queue) hooksecurefunc(f,"SetPoint",queue) if f.UpdateAnchors then hooksecurefunc(f,"UpdateAnchors",queue) end end end end for _,event in ipairs({"ADDON_LOADED","DISPLAY_SIZE_CHANGED","UI_SCALE_CHANGED","PLAYER_REGEN_ENABLED"}) do listener:RegisterEvent(event) end listener:SetScript("OnEvent",function() watch();queue() end) if GroupLootContainer_Update then hooksecurefunc("GroupLootContainer_Update",queue) end watch();queue() end