Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Native Wayland Support #102

Closed
ByPaco10 opened this issue Jun 20, 2024 · 3 comments
Closed

Feature: Native Wayland Support #102

ByPaco10 opened this issue Jun 20, 2024 · 3 comments

Comments

@ByPaco10
Copy link

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:

  • Jun 20, 2024 9:51:24 AM sun.awt.wl.WLToolkit getSystemClipboard
    INFO: Not implemented: WLToolkit.getSystemClipboard()

  • Jun 20, 2024 9:51:25 AM sun.awt.wl.WLToolkit lazilyLoadDesktopProperty
    INFO: Not implemented: WLToolkit.lazilyLoadDesktopProperty()

  • Jun 20, 2024 9:51:25 AM sun.awt.wl.WLToolkit addPropertyChangeListener
    INFO: Not implemented: WLToolkit.addPropertyChangeListener()

  • Jun 20, 2024 9:51:25 AM sun.awt.wl.WLToolkit useBufferPerWindow
    INFO: Not implemented: WLToolkit.useBufferPerWindow()

  • Jun 20, 2024 9:51:25 AM sun.awt.wl.WLToolkit isWindowOpacitySupported
    INFO: Not implemented: WLToolkit.isWindowOpacitySupported()

  • Jun 20, 2024 9:51:25 AM sun.awt.wl.WLToolkit isWindowShapingSupported
    INFO: Not implemented: WLToolkit.isWindowShapingSupported()

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: JetBrains/JetBrainsRuntime#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 #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
Copy link
Author

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
Copy link
Author

ByPaco10 commented Jul 6, 2024

Update:

  • Managed to fix clipboard
  • Window doesn't move
  • Buttons are still broken
  • Window is not on focus
  • Window is not always active

@ByPaco10 ByPaco10 changed the title Native Wayland Support Feature: Native Wayland Support Jul 6, 2024
@ByPaco10
Copy link
Author

Not needed anymore. I can upload my changes to a branch if someone wants to try to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant