Skip to content

Commit 545f4d0

Browse files
TimMenu: secodnary atemtp to fix the race conditionms 9in click consumbtion
1 parent e508b5d commit 545f4d0

5 files changed

Lines changed: 25 additions & 1 deletion

File tree

TimMenu/Globals.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ Globals.LayersPerGroup = 10
129129
-- Popup layer that's always on top (above all sectors)
130130
Globals.POPUP_LAYER_BASE = 1000
131131

132+
-- Global click consumption flag to prevent race conditions
133+
-- When true, indicates a widget has already handled the click
134+
-- Window manager should respect this and not change focus
135+
Globals.isClickConsumed = false
136+
132137
-- Preload interactive widget images
133138
local ImgDecoder = require("TimMenu.images.imageDecoder")
134139
Globals.Images = Globals.Images or {}

TimMenu/Main.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,13 @@ local function _TimMenu_GlobalDraw()
321321
)
322322

323323
-- Only change focus if window allows it (prevents popup focus stealing)
324-
if isFocused and input.IsButtonPressed(MOUSE_LEFT) and win:ShouldChangeFocus(mouseX, mouseY) then
324+
-- AND no widget has consumed the click
325+
if
326+
isFocused
327+
and input.IsButtonPressed(MOUSE_LEFT)
328+
and win:ShouldChangeFocus(mouseX, mouseY)
329+
and not Globals.isClickConsumed
330+
then
325331
if TimMenuGlobal.order[#TimMenuGlobal.order] ~= key then
326332
for j, v_key in ipairs(TimMenuGlobal.order) do
327333
if v_key == key then
@@ -352,6 +358,9 @@ local function _TimMenu_GlobalDraw()
352358
end
353359
end
354360

361+
-- Reset click consumption flag at end of frame
362+
Globals.isClickConsumed = false
363+
355364
if not reRegistered then
356365
callbacks.Unregister("Draw", "zTimMenu_GlobalDraw")
357366
callbacks.Register("Draw", "zTimMenu_GlobalDraw", _TimMenu_GlobalDraw)

TimMenu/WidgetBase.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,10 @@ function WidgetBase.MeasureText(text)
111111
return draw.GetTextSize(text)
112112
end
113113

114+
--- Mark the current click as consumed by a widget
115+
--- This prevents the window manager from changing focus
116+
function WidgetBase.ConsumeClick()
117+
Globals.isClickConsumed = true
118+
end
119+
114120
return WidgetBase

TimMenu/Widgets/Combo.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ local function Combo(win, label, selected, options)
164164
local idx = math.floor((input.GetMousePos()[2] - popupBounds.y) / height) + 1
165165
if idx >= 1 and idx <= #options then
166166
entry.selected[idx] = not entry.selected[idx]
167+
-- Consume the click to prevent window focus changes
168+
WidgetBase.ConsumeClick()
167169
end
168170
else
169171
entry.open = false

TimMenu/Widgets/Dropdown.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ local function Dropdown(win, label, selectedIndex, options)
155155
entry.selected = idx
156156
entry.open = false
157157
win._widgetBlockedRegions = {}
158+
-- Consume the click to prevent window focus changes
159+
WidgetBase.ConsumeClick()
158160
end
159161
else
160162
entry.open = false

0 commit comments

Comments
 (0)