Lua UI widget mousePress event generates an additional focus state, persisting even with mouse out of focus
I noticed that after clicking on a custom Lua UI widget element the game keeps calling focus events alongside mouse press events on every click even if the mouse is well away from the problematic element.
Reproducing the problem using the mod I made
I created a mod with a player Lua script which helps to reproduce the problem. It replaces the Morrowind journal window with a custom window. There are two buttons in that window -- I added debug logs to focusGain/focusLoss/mousePress/mouseRelease events for both buttons to see when each event is called exactly. The mod is available here:
trav5/openmw-widget-troubleshooting@a4ede152
or just the player script:
Steps
When I say "a debug log should appear", I mean in the the openmw.log / F10 Log Viewer. Here are the steps:
- [OK] Open the Morrowind journal in-game -- a custom window with buttons [click me] and [Close] should appear
- [OK] Hover the mouse over [click me] -- a debug log
onEvent focusGain for: [click me]
should appear, indicating the focusGain event was called - [NOT OK] Press the mouse button but don't release it. Two debug logs appear - one for focusGain, another for mousePress. Why is the focusGain called again when the element under mouse cursor was already in focus?
- [OK] Release the mouse button -- Debug log for mouseRelease should appear. This seems okay.
- [OK] Move the cursor away from [click me] -- Debug log for focusLoss should appear. This seems okay.
- [NOT OK] Click on anything (you don't even have to release the mouse press) except the two buttons -- every mouse press now generates two debug logs for [click me]: one for focusLoss, one for focusGain.
- [NOT OK] Closing the journal generates one last focusLoss debug log for [click me] - most likely because the last 'state' for [click me] was focus gain.
OpenMW version
I'm running a compiled openmw on Windows:
$ git log
commit b5b6744321e11332870f9d17a25aae41a420bc55 (HEAD -> master, origin/master)
Merge: 0557a649ce eba4ae94b0
Author: psi29a <psi29a@gmail.com>
Date: Mon Mar 11 11:14:26 2024 +0000