Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-261578

GUI elements stay focused after mouse click

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • None
    • 1.19.4
    • None
    • Unconfirmed
    • (Unassigned)

      A change has been made in ContainerEventHandler where upon mouse click, the child that is clicked is focused. This is not noticeable in most places because most buttons change the screen.

       

      However, in settings menus, it is prevalent, for example, changing a setting from OFF to ON leaves that button focused.

       

      Code analysis

      ContainerEventHandler.java - mojmap 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.

            Unassigned Unassigned
            isXander Xander Smith
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: