Ninjabrain1 / Ninjabrain-Bot

Accurate stronghold calculator for Minecraft speedrunning.
307 stars 42 forks source link

Feature: Native Wayland Support #102

Open ByPaco10 opened 2 weeks ago

ByPaco10 commented 2 weeks ago

Right now Ninjabrainbot works using Xwayland compatibility layer. This causes some issues with Native Wayland Minecraft windows. Example: Ninjabrainbot Window doesn't update until you click on it or you focus on it. This is not an easy fix and it would require 1 of 2 things:

This is NOT a priority as Wakefield and Swingland are early in development and are not easy to work I already tried to compile current code with Wakefield WLToolkit and this is currently unimplemented:

Currently the crash lies on PERPIXEL_TRANSPARENT translucency as it is not supported at all, but probably if you try to make the code work without it, any other random function will crash, it would be wise to try to implement them in the toolkit (I do think that if we ignore exceptions we can at least render the Window).

Trying to open with compiled latest version of Swingland gives: [SwingWrapper]:java.lang.reflect.InvocationTargetException. Not really useful at all. Didn't do any further testing as I am in touch with Swingland dev and this Friday I will ask him if he can help.

Useful link for trying to compile Ninjabrainbot on Wakefield: https://github.com/JetBrains/JetBrainsRuntime/issues/242. Didn't research much, but it seems like Jetbrains made theirs runtime work natively under a custom Wakefield with their own WLToolkit, could be good insight.

While compiling Swingland is easy enough (and also running it, java -jar <path to/>swingland.jar <target application jar> <target application arguments>). If you want to give Wakefield a try you need to compile the branch mentioned above with java 21 or 22 and run ../wakefield/build/linux-x86_64-server-release/jdk/bin/java -Dawt.toolkit.name=WLToolkit -jar (Ninjabrainbot.jar). My compilation tests failed a lot and I needed to change clang for GCC compiler.

Also. To run tests for Wakefield it is needed to compile jtreg https://github.com/openjdk/jtreg, and to provide a jtreg path when you compile Wakefield --with-jtreg=<path>

This issue is a "continuation" of https://github.com/Ninjabrain1/Ninjabrain-Bot/pull/80.

You can close this issue if you don't want to work in this, as future Java versions will (probably) make Native Wayland support. If I manage to compile a custom Ninjabrainbot I will make my own branch for Wayland users.

ByPaco10 commented 2 weeks ago

Update: Managed to open Ninjabrainbot on Wayland using a modified Jetbrains jbr21 and a heavy modified Ninjabrainbot without any translucency. Window doesn't move, I broke button icons (my fault), hotkeys, the window still doesn't stand focused until I click on it (strange) and the font is terrible, but this is progress. Implementing in the WLToolkit clipboard support and shaping support seems fundamental right now, As I Needed to manually remove public void applyShape(Region shape) { throw new UnsupportedOperationException(); } from JetBrainsRuntime/src/java.desktop/unix/classes/sun/awt/wl/WLComponentPeer.java (line 966) and add a catch for NullPointerException in Ninjabrain-Bot/src/main/java/ninjabrainbot/io/ClipboardReader.java (line 58)

Even if you remove translucency the program will still crash with PERPIXEL_TRANSPARENT translucency not supported. To get rid of this annoying crash I manually removed from JetBrainsRuntime/src/java.desktop/share/classes/java/awt/Window.java line 3801 to 3806.

Now we need a programmer understanding in Wayland protocol and Java to help us implement those two features (Shaping and Clipboard, as translucency is no longer needed), then to fix focus.

Even Having the custom Wayland Toolkit of jbr21 it seems like clipboard is broken. This is the current state:

Exception in thread "Clipboard reader" java.lang.NullPointerException: Cannot read the array length because "formats" is null at java.desktop/sun.awt.datatransfer.DataTransferer.getFlavorsForFormats(DataTransferer.java:412) at java.desktop/sun.awt.datatransfer.SunClipboard.getData(SunClipboard.java:212) at ninjabrainbot.io.ClipboardReader.run(ClipboardReader.java:57) at java.base/java.lang.Thread.run(Thread.java:1583)

image image

ByPaco10 commented 1 day ago

Update: