The Bug:
Buttons and sliders remain selected after clicking on them.
This issue did not occur in 1.19.3. It first appeared in 23w03a.
Steps to Reproduce:
Navigate to your video settings.
Click on the "Graphics" button and then move your mouse cursor away from it.
Take note as to whether or not buttons and sliders remain selected after clicking on them.
Observed Behavior:
Buttons and sliders remain selected.
Expected Behavior:
Buttons and sliders would not remain selected, just like how they didn't in 1.19.3.
Code Analysis:
Code analysis by @unknown can be found in the duplicate MC-261578:
ContainerEventHandler.java (Mojang mappings, 1.19.4)
@Override
default public boolean mouseClicked(double mouseX, double mouseY, int button) {
for (GuiEventListener guiEventListener : this.children()) {
if (!guiEventListener.mouseClicked(mouseX, mouseY, button)) continue;
this.setFocused(guiEventListener);
if (button == 0) {
this.setDragging(true);
}
return true;
}
return false;
}
Here you can see this.setFocused(guiEventListener)
is being invoked on every mouse click. Remember, both Screen
and ObjectSelectionList.Entry
both implement this interface.
This could be fixed with the following code:
@Override
default public boolean mouseClicked(double mouseX, double mouseY, int button) {
for (GuiEventListener child : this.children()) {
if (child.mouseClicked(mouseX, mouseY, button)) {
if (button == InputConstants.MOUSE_BUTTON_LEFT)
this.setDragging(true);
return true;
}
}
return false;
}
However, this would break dragging code as mouseDragged
is only passed to the focused element. This could be solved by just iterating through the children like usual, as most mouseDragged
implementation have a boolean to check if they are dragging anyway.
Linked issues
causes 1
is duplicated by 19
relates to 5
Attachments
Comments 11
also the reason i keep coming back is because this bug drives me crazy, and i wish it gets fixed before 1.20.2
Edit: 2 updates later and it still wasn't fixed
Also appears to affect the Open Pack Folder button (23w06a).
Previously (1.19.3) the button would be deselected when moving the mouse away.