HumbleUI / JWM

Cross-platform window management and OS integration library for Java
Apache License 2.0
546 stars 44 forks source link

Wayland support #278

Open TheDrawingCoder-Gamer opened 7 months ago

TheDrawingCoder-Gamer commented 7 months ago

Untested (couldn't get javac to work) Highly expect something here to be extremely broken. Would not be surprised if there was an instant segfault. bc it's literally a new platform this touches a LOT of files. Will work on merging

dzaima commented 7 months ago

Changes I needed to make to have it build/run on my (X11) system (i.e. not running any of the actual wayland stuff):

diff --git a/linux/cc/ILayer.hh b/linux/cc/ILayer.hh
index f21346a..5b8ee03 100644
--- a/linux/cc/ILayer.hh
+++ b/linux/cc/ILayer.hh
@@ -15,7 +15,7 @@ public:
     virtual void makeCurrentForced();
     virtual void setVsyncMode(VSync v) = 0;
     virtual void close() = 0;
-    virtual void resize(int width, int height);
+    virtual void resize(int width, int height) = 0;

     static ILayer* _ourCurrentLayer;
diff --git a/wayland/cc/WindowWayland.cc b/wayland/cc/WindowWayland.cc
index ecbd2a9..ecb7c42 100644
--- a/wayland/cc/WindowWayland.cc
+++ b/wayland/cc/WindowWayland.cc
@@ -100,8 +100,10 @@ bool WindowWayland::init()
     wl_surface_listener surfaceListener = {
         .enter = WindowWayland::surfaceEnter,
         .leave = WindowWayland::surfaceLeave,
+#ifdef HAVE_WAYLAND_1_22
         .preferred_buffer_scale = WindowWayland::surfacePreferredBufferScale,
         .preferred_buffer_transform = WindowWayland::surfacePreferredBufferTransform
+#endif
     };
     wl_surface_add_listener(_waylandWindow, &surfaceListener, this);
dzaima commented 7 months ago

and here's a bunch of changes, ranging from fixes to hacks to debug utils (i.e. don't blindly copy everything here), to get ./script/run.py to not crash in Weston (doesn't render anything though):

that ```diff diff --git a/examples/dashboard/java/Example.java b/examples/dashboard/java/Example.java index f8a2ee2..fd3e29a 100644 --- a/examples/dashboard/java/Example.java +++ b/examples/dashboard/java/Example.java @@ -55,8 +55,9 @@ public class Example implements Consumer { var scale = window.getScreen().getScale(); int count = App._windows.size() - 1; - Screen screen = App.getScreens()[(count / 5) % App.getScreens().length]; - IRect bounds = screen.getWorkArea(); + // Screen screen = App.getScreens()[(count / 5) % App.getScreens().length]; + // IRect bounds = screen.getWorkArea(); + IRect bounds = new IRect(0, 0, 100, 100); window.setTitle("JWM Window #" + count); if (window instanceof WindowMac windowMac) { @@ -202,6 +203,7 @@ public class Example implements Consumer { } } } else if (e instanceof EventFrame) { + System.out.println("frame"); if (!paused) window.requestFrame(); } else if (e instanceof EventFrameSkija ee) { diff --git a/examples/dashboard/java/PanelRendering.java b/examples/dashboard/java/PanelRendering.java index 5ab882b..fde41f2 100644 --- a/examples/dashboard/java/PanelRendering.java +++ b/examples/dashboard/java/PanelRendering.java @@ -34,6 +34,8 @@ public class PanelRendering extends Panel { layers = new String[] { "LayerD3D12Skija", "LayerGLSkija", "SkijaLayerRaster" }; else if (Platform.CURRENT == Platform.X11) layers = new String[] { "LayerGLSkija", "LayerRasterSkija" }; + else if (Platform.CURRENT == Platform.WAYLAND) + layers = new String[] { "LayerRasterSkija", "LayerGLSkija" }; for (var layerName: layers) layersStatus.put(layerName, UNKNOWN); diff --git a/script/build.py b/script/build.py index 9954d82..589461f 100755 --- a/script/build.py +++ b/script/build.py @@ -4,7 +4,7 @@ import argparse, build_utils, common, glob, os, platform, subprocess, sys def build_native_system(system): os.chdir(common.basedir + "/" + system) subprocess.check_call(["cmake", - "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_BUILD_TYPE=Debug", "-B", "build", "-G", "Ninja", "-DJWM_ARCH=" + build_utils.arch, diff --git a/script/run.py b/script/run.py index 98f3c0e..e90cbe7 100755 --- a/script/run.py +++ b/script/run.py @@ -10,9 +10,10 @@ def main(): parser.add_argument('--skija-shared-jar', default=None) parser.add_argument('--skija-platform-jar', default=None) parser.add_argument('--types-dir', default=None) + parser.add_argument('--just-run', action='store_true') args = parser.parse_args() - if not args.jwm_version: + if not args.jwm_version and not args.just_run: build.main() if args.skija_dir: diff --git a/shared/java/App.java b/shared/java/App.java index 268ddc6..7a1c5a7 100644 --- a/shared/java/App.java +++ b/shared/java/App.java @@ -52,6 +52,8 @@ public class App { window = new WindowMac(); else if (Platform.CURRENT == Platform.X11) window = new WindowX11(); + else if (Platform.CURRENT == Platform.WAYLAND) + window = new WindowWayland(); else throw new RuntimeException("Unsupported platform: " + Platform.CURRENT); _windows.add(window); diff --git a/shared/java/impl/Library.java b/shared/java/impl/Library.java index 43fd5cb..29a5da5 100644 --- a/shared/java/impl/Library.java +++ b/shared/java/impl/Library.java @@ -46,10 +46,10 @@ public class Library { } else if (Platform.CURRENT == Platform.X11) { File library = _extract("/", "libjwm_x64.so", tempDir); System.load(library.getAbsolutePath()); - } /*else if (Platform.CURRENT == Platform.WAYLAND) { + } else if (Platform.CURRENT == Platform.WAYLAND) { File library = _extract("/", "libjwm_x64_wayland.so", tempDir); System.load(library.getAbsolutePath()); - }*/ + } if (tempDir.exists() && version == null) { Runtime.getRuntime().addShutdownHook(new Thread(() -> { diff --git a/wayland/CMakeLists.txt b/wayland/CMakeLists.txt index 95ca0ad..f13c700 100644 --- a/wayland/CMakeLists.txt +++ b/wayland/CMakeLists.txt @@ -15,6 +15,8 @@ if(NOT JWM_ARCH) endif() endif() +find_package(OpenGL REQUIRED) + file(GLOB SOURCES_CXX ${CMAKE_CURRENT_LIST_DIR}/../shared/cc/*.cc ${CMAKE_CURRENT_LIST_DIR}/../linux/cc/*.cc ${CMAKE_CURRENT_LIST_DIR}/cc/*.cc ) @@ -44,3 +46,4 @@ set_target_properties(jwm PROPERTIES OUTPUT_NAME "jwm_${JWM_ARCH}_wayland") target_link_libraries(jwm PRIVATE ${WAYLAND_CLIENT_LIB} ${DECOR_LIB} ${WAYLAND_CURSOR} ${XKBCOMMON}) target_link_libraries(jwm PRIVATE ${EGL} ${WAYLAND_EGL}) +target_link_libraries(jwm PRIVATE OpenGL::GL) diff --git a/wayland/cc/LayerRasterWayland.cc b/wayland/cc/LayerRasterWayland.cc index 0462940..2177fdf 100644 --- a/wayland/cc/LayerRasterWayland.cc +++ b/wayland/cc/LayerRasterWayland.cc @@ -36,7 +36,6 @@ namespace jwm { _pool->grow(bufSize); // LSBFirst means Little endian : ) auto buf = _pool->createBuffer(0, width, height, width * sizeof(uint32_t), WL_SHM_FORMAT_ABGR8888); - _buffer = buf.first; _imageData = buf.second; } diff --git a/wayland/cc/WindowManagerWayland.cc b/wayland/cc/WindowManagerWayland.cc index 2c62963..ee92779 100644 --- a/wayland/cc/WindowManagerWayland.cc +++ b/wayland/cc/WindowManagerWayland.cc @@ -75,7 +75,7 @@ WindowManagerWayland::WindowManagerWayland(): .leave = WindowManagerWayland::pointerHandleLeave, .motion = WindowManagerWayland::pointerHandleMotion, .button = WindowManagerWayland::pointerHandleButton, - .axis = WindowManagerWayland::pointerHandleAxis + // .axis = WindowManagerWayland::pointerHandleAxis }; wl_pointer_add_listener(pointer, &pointerListener, this); } @@ -112,7 +112,7 @@ void WindowManagerWayland::runLoop() { } if (myPoll.revents & POLLIN) { - while (read(pipes[0], buf, sizeof(buf) == sizeof(buf))) {} + while (read(pipes[0], buf, sizeof(buf)) == sizeof(buf)) {} } notifyBool.store(false); } @@ -166,7 +166,7 @@ void WindowManagerWayland::registryHandleGlobal(void* data, wl_registry *registr &wl_shm_interface, 1); } else if (strcmp(interface, "xdg_wm_base") == 0) { self->xdgShell = (xdg_wm_base*)wl_registry_bind(registry, name, - &xdg_wm_base_interface, 2); + &xdg_wm_base_interface, 1); } else if (strcmp(interface, "wl_data_device_manager") == 0) { self->deviceManager = (wl_data_device_manager*)wl_registry_bind(registry, name, &wl_data_device_manager_interface, 1); diff --git a/wayland/cc/xdg-shell.cc b/wayland/cc/xdg-shell.cc index 03826cd..4001974 100644 --- a/wayland/cc/xdg-shell.cc +++ b/wayland/cc/xdg-shell.cc @@ -28,16 +28,19 @@ * DEALINGS IN THE SOFTWARE. */ + #include #include #include "wayland-util.h" +extern "C" { + #ifndef __has_attribute # define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ #endif #if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) -#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) extern "C" #else #define WL_PRIVATE #endif @@ -181,3 +184,5 @@ WL_PRIVATE const struct wl_interface xdg_popup_interface = { 3, xdg_popup_events, }; + +} diff --git a/wayland/java/WindowWayland.java b/wayland/java/WindowWayland.java index 056f7f4..5c09dd5 100644 --- a/wayland/java/WindowWayland.java +++ b/wayland/java/WindowWayland.java @@ -32,14 +32,14 @@ public class WindowWayland extends Window { public IRect getWindowRect() { assert _onUIThread() : "Should be run on UI thread"; // very very bad! - return IRect.makeXYWH(0, 0, 0, 0); + return IRect.makeXYWH(0, 0, 100, 100); } @Override public IRect getContentRect() { assert _onUIThread() : "Should be run on UI thread"; // stop! - return IRect.makeXYWH(0, 0, 0, 0); + return IRect.makeXYWH(0, 0, 100, 100); } @Override ```
TheDrawingCoder-Gamer commented 7 months ago

sorry for the bad commit names. this is what I do when stuff DOESN'T WORK

TheDrawingCoder-Gamer commented 7 months ago

I have a question about what format the buffer is supposed to be in. I assumed ABGR8888 because of LSBFirst, but is it RGBA8888?

TheDrawingCoder-Gamer commented 7 months ago

updates ( i guess):

window does now open, but no rendering skija won't actually bind to LayerGL for some reason??? it can't find the egl context : /. idk what to do there LayerRaster currently memory leaks every resize because skija is holding on to a pointer. I get crashes when uncommenting out munmap in ShmPool::close.

I've made a surprising amount of progress which is nice. I want to get rendering working before I start hooking up the keyboard. Any help would be appreciated bc I don't fully understand C++ (multiple days were taken up because I didn't realize things were freed at the end of scope).

tonsky commented 7 months ago

skija won't actually bind to LayerGL for some reason??? it can't find the egl context

Sorry, I wish I could help, but I have no experience with Wayland

dzaima commented 7 months ago

ok here's some digging I've done on the GL issue - within Java_io_github_humbleui_jwm_LayerGL__1nAttachLayerGL::attachLayerGL::makeCurrentForcedeglMakeCurrent, some address is set to 1, which then Java_io_github_humbleui_skija_DirectContext__1nMakeGL → ... → GrGLMakeGLXInterfaceglXGetCurrentContext later doesn't like. My attempts at searching haven't ended up conclusive, but I think the "X" in "GLX" stands for X11, and thus shouldn't be used on Wayland (and/or be mixed with egl)? (I don't have much clue what I'm looking at, I'm primarily just having fun with debugging under https://rr-project.org/)

TheDrawingCoder-Gamer commented 7 months ago

I am not using glx though. I'm using egl, which SHOULD work on wayland.

TheDrawingCoder-Gamer commented 7 months ago

OH, you mean in skija. Yeah that is likely an upstream issue.

dzaima commented 7 months ago
#0  0x00007f22c3e5c9fe in glXGetCurrentContext () from /lib/x86_64-linux-gnu/libGLX.so.0
#1  0x00007f228af92132 in GrGLMakeGLXInterface() () from /tmp/skija_0.116.1_x64/libskija.so
#2  0x00007f228ae93d72 in GrGLMakeNativeInterface() () from /tmp/skija_0.116.1_x64/libskija.so
#3  0x00007f228aafe498 in GrGLGpu::Make(sk_sp<GrGLInterface const>, GrContextOptions const&, GrDirectContext*) () from /tmp/skija_0.116.1_x64/libskija.so
#4  0x00007f228a9e9a45 in GrDirectContext::MakeGL(sk_sp<GrGLInterface const>, GrContextOptions const&) () from /tmp/skija_0.116.1_x64/libskija.so
#5  0x00007f228a9e9ed7 in GrDirectContext::MakeGL() () from /tmp/skija_0.116.1_x64/libskija.so
#6  0x00007f228a4c2920 in Java_io_github_humbleui_skija_DirectContext__1nMakeGL () from /tmp/skija_0.116.1_x64/libskija.so
#7  0x00007f22b4356b11 in ?? ()
#8  0x00007f22cad16e10 in ?? ()
#9  0x0000000000000000 in ?? ()

the full gdb stacktrace of the fail fwiw

dzaima commented 7 months ago

oh, is skia in skija built with X11/GLX hard-coded? skia does have a thing that'd supposedly use EGL for GrGLMakeNativeInterface, but that's not present in the skija build afaict

dzaima commented 7 months ago

perhaps a skia_use_egl=true in like here or something?

gonna try building that, probably gonna take a while though

TheDrawingCoder-Gamer commented 7 months ago

X11 could also be possibly rewritten to use EGL too - it would ensure that all linux targets would work with EGL.

(or we could just add an if statement to the constructor of LayerGLSkija : ) )

dzaima commented 7 months ago

Got a skia build with that to load (ended up ln -sing SkiaBuild's output unzipped to Skija's platform/Skia-m116-f44dbc40d8-linux-Release-x64/ and doing a clean rebuild); gives this now:

Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/skija_369211854708109/libskija.so: /tmp/skija_369211854708109/libskija.so: undefined symbol: eglQueryString
    at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
    at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:331)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:197)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:139)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2404)
    at java.base/java.lang.Runtime.load0(Runtime.java:785)
    at java.base/java.lang.System.load(System.java:2011)
    at io.github.humbleui.skija.impl.Library._loadFromFile(Library.java:147)
    at io.github.humbleui.skija.impl.Library.load(Library.java:122)
    at io.github.humbleui.skija.impl.Library.staticLoad(Library.java:20)
    at io.github.humbleui.skija.Font.<clinit>(Font.java:9)
    at io.github.humbleui.jwm.examples.Example.<clinit>(Example.java:18)

should be easy enough to fix once I find where

dzaima commented 7 months ago

and with a

diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt
index 6b352fe..23afd7e 100644
--- a/platform/CMakeLists.txt
+++ b/platform/CMakeLists.txt
@@ -84,4 +84,4 @@ endif()

 list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
 include(FindSkia)
-target_link_libraries(skija skottie sksg svg skparagraph skshaper skunicode skresources skia ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES})
+target_link_libraries(skija skottie sksg svg skparagraph skshaper skunicode skresources skia EGL ${FREETYPE_LIBRARIES} ${HARFBUZZ_LIBRARIES})

in Skija, JWM now doesn't crash with LayerGLSkija! Doesn't show any window though; presumably just unfinished?

dzaima commented 7 months ago

(here's a Skija linux x64 jar file of that; usable for JWM's example thing with ./script/run.py --skija-platform-jar /path/to/that/target/skija-linux-x64-0.0.0-SNAPSHOT.jar)

dzaima commented 7 months ago

Seems with this EGL build JWM & Skija still work on X11 with no extra changes? So that's nice (assuming that's correct and not me having forgotten to do something)

TheDrawingCoder-Gamer commented 7 months ago

Yeah just unfinished - needs more work. Will make a PR to skia build and skija to include EGL.

TheDrawingCoder-Gamer commented 7 months ago

You did test X11, correct? this doesn't break X11 if I change skija?

dzaima commented 7 months ago

yeah, said that in my last comment; running the exact same command works both in my native X11, and within Weston, both using LayerGLSkija (with X11 properly rendering things as usual, and Weston quietly doing nothing). There could be some implications I'm not aware of, but ¯\_(ツ)_/¯

TheDrawingCoder-Gamer commented 7 months ago

I think I will have to add an if statement in JWM and add an "MakeEGL" thing for it, as MakeGL is currently platform specific (thus can't really differ on different installs of linux).

TheDrawingCoder-Gamer commented 7 months ago

While the window is infact showing, it's incapable of actually rendering anything. It can't actually make the DirectContext (it errors out, because GrDirectContext::MakeGL().release() returns nullptr only on wayland : /)

dzaima commented 7 months ago

Huh? For me, GrDirectContext::MakeGL().release() gave nullptr before the SkiaBuild change, but the entire purpose of the Skia change was to make GrDirectContext::MakeGL() work, and it does appear to for me; i.e. adjusting Skija's DirectContext::makeGL to

    public static DirectContext makeGL() {
        Stats.onNativeCall();
        System.out.println("pre-_nMakeGL in Java");
        long ptr = _nMakeGL();
        System.out.println("post-_nMakeGL in Java: got "+ptr);
        new Exception().printStackTrace();
        return new DirectContext(ptr);
    }

results in logging of

pre-_nMakeGL in Java
post-_nMakeGL in Java: got 140025466978336
java.lang.Exception
  at io.github.humbleui.skija.DirectContext.makeGL(DirectContext.java:15)
  at io.github.humbleui.jwm.skija.LayerGLSkija.frame(LayerGLSkija.java:27)
  at io.github.humbleui.jwm.Window.accept(Window.java:412)
  at io.github.humbleui.jwm.Window.accept(Window.java:427)
  at io.github.humbleui.jwm.Window.accept(Window.java:425)
  at io.github.humbleui.jwm.Window.setLayer(Window.java:66)
  at io.github.humbleui.jwm.examples.PanelRendering.changeLayer(PanelRendering.java:57)
  at io.github.humbleui.jwm.examples.PanelRendering.<init>(PanelRendering.java:44)
  at io.github.humbleui.jwm.examples.Example.<init>(Example.java:51)
  at io.github.humbleui.jwm.examples.Example.lambda$main$0(Example.java:229)
  at io.github.humbleui.jwm.App.lambda$start$1(App.java:35)
  at io.github.humbleui.jwm.App._nStart(Native Method)
  at io.github.humbleui.jwm.App.start(App.java:28)
  at io.github.humbleui.jwm.examples.Example.main(Example.java:228)
pre-_nMakeGL in Java
post-_nMakeGL in Java: got 140025466978336
java.lang.Exception
  at io.github.humbleui.skija.DirectContext.makeGL(DirectContext.java:15)
  at io.github.humbleui.jwm.skija.LayerGLSkija.frame(LayerGLSkija.java:27)
  at io.github.humbleui.jwm.Window.accept(Window.java:412)
  at io.github.humbleui.jwm.Window.accept(Window.java:427)
  at io.github.humbleui.jwm.Window.accept(Window.java:425)
  at io.github.humbleui.jwm.Window.setVisible(Window.java:280)
  at io.github.humbleui.jwm.WindowWayland.setVisible(WindowWayland.java:92)
  at io.github.humbleui.jwm.examples.Example.<init>(Example.java:88)
  at io.github.humbleui.jwm.examples.Example.lambda$main$0(Example.java:229)
  at io.github.humbleui.jwm.App.lambda$start$1(App.java:35)
  at io.github.humbleui.jwm.App._nStart(Native Method)
  at io.github.humbleui.jwm.App.start(App.java:28)
  at io.github.humbleui.jwm.examples.Example.main(Example.java:228)
TheDrawingCoder-Gamer commented 7 months ago

hm, I must have messed up my local build. Did you do anything other than just add skia_use_egl?

TheDrawingCoder-Gamer commented 7 months ago

Something must be different in our environments : / Adding that same code it still returns null under wayland, but works fine under x11.

What I'm more worried about at the moment is that Raster isn't showing anything.

dzaima commented 7 months ago

this is my SkiaBuild diff (the compiler diffs are just because I don't have gcc-9 installed; shouldn't affect anything), and this in Skija (all that matters is the platform/CMakeLists.txt; ignore the syscall(-1), I abuse that as a "checkpoint" for debugging).

After doing SkiaBuild script/checkout.py --version m116-f44dbc40d8, script/build.py, and script/archive.py, I unzipped the Skia-m116-f44dbc40d8-linux-Release-x64.zip to a folder in Skija under platform/Skia-m116-f44dbc40d8-linux-Release-x64, removing what was there before. Then within Skija I ran ./script/clean.py and then ./script/build.py && ./script/package_platform.py and then for JWM's --skija-platform-jar used the output in Skija's target/skija-linux-x64-0.0.0-SNAPSHOT.jar.

In Weston I do have raster rendering the window (although it is somewhat broken, only redrawing whenever the window is unfocused & refocused).

TheDrawingCoder-Gamer commented 7 months ago

Wayland also either forces you to draw window frames, or use a library like libdecor to ask the compositor nicely to draw it for you. I opted to use libdecor, but it crashes on mouse hover under weston (swaywm doesn't crash, but I assume that's because it doesn't actually draw anything)

It seems to be an error in JNI from mouse movement, more likely due to dispatching, which is kind of odd considering OTHER dispatches work?

dzaima commented 7 months ago

here's a random stacktrace of a random segfault from making PanelRendering switch from raster to GL on a mouse button press (doesn't error always, sometimes it does manage to switch from raster to rendering nothing on GL; this is before the libdecor change):

#0  0x00007f583a3efe43 in jwm::Window::dispatch(_jobject*) () from /mnt/linux2/git/jwm-wayland/target/classes/libjwm_x64_wayland.so
#1  0x00007f583a3f27c6 in jwm::WindowManagerWayland::mouseUpdate(jwm::WindowWayland*, unsigned int, unsigned int, unsigned int) () from /mnt/linux2/git/jwm-wayland/target/classes/libjwm_x64_wayland.so
#2  0x00007f583a327e2e in ?? () from /lib/x86_64-linux-gnu/libffi.so.8
#3  0x00007f583a324493 in ?? () from /lib/x86_64-linux-gnu/libffi.so.8
#4  0x00007f583a632ad0 in ?? () from /lib/x86_64-linux-gnu/libwayland-client.so.0
#5  0x00007f583a633243 in ?? () from /lib/x86_64-linux-gnu/libwayland-client.so.0
#6  0x00007f583a63343c in wl_display_dispatch_queue_pending () from /lib/x86_64-linux-gnu/libwayland-client.so.0
#7  0x00007f583a3f21dd in jwm::WindowManagerWayland::runLoop() () from /mnt/linux2/git/jwm-wayland/target/classes/libjwm_x64_wayland.so

not a worry for now, but noting regardless (error is from myWindow being null, presumably pointerHandleMotion of the old surface running after we've switched to the new one?)

will look at what the libdecor change looks like

edit: oh that's handled in the latest commit!

dzaima commented 7 months ago

ok with that last commit GL crashes with my "OH NO SAD", and raster doesn't render anything

TheDrawingCoder-Gamer commented 7 months ago

It breaking may have been caused by me switching from glext api to glplatform. Unsure why that breaks stuff

edit: nvm, doesn't change anything. how peculiar

dzaima commented 7 months ago

with this, GL not crashing is restored:

diff --git a/wayland/cc/LayerGLWayland.cc b/wayland/cc/LayerGLWayland.cc
index 27f6c93..abc8aa9 100644
--- a/wayland/cc/LayerGLWayland.cc
+++ b/wayland/cc/LayerGLWayland.cc
@@ -73,6 +73,7 @@ namespace jwm {
                     throw std::runtime_error("Couldn't make context");
                 }
             }
+            makeCurrentForced();

         }
dzaima commented 7 months ago

:o while undoing random parts of your changes, I now have a GL rendering the window in weston, and with proper refreshing too unlike raster! (those undoed changes include undoing all of libdecor though)

TheDrawingCoder-Gamer commented 7 months ago

Unsure how makeCurrentForced works considering that you should have to have a surface first

TheDrawingCoder-Gamer commented 7 months ago

For me the whole compositor must lose focus and be refocused for window to be visible. For SwayWM i am doing this by switching ttys, so something god awful is going on

dzaima commented 7 months ago

Adding a libdecor_dispatch(_windowManager.decorCtx, -1); right after libdecor_decorate does Something (and results in some segfaulting too; looking into that)

TheDrawingCoder-Gamer commented 7 months ago

Try adding libdecor_frame_map(_frame) at the end of show, I'm not segfaulting with that at the end

and move the dispatch to after the map

TheDrawingCoder-Gamer commented 7 months ago

nvm, pointer will still crash. Again, only in weston?

TheDrawingCoder-Gamer commented 7 months ago

I don't think I actually commited the change where I commented out the pointer listener, but you seem to be getting something, which is confusing.

Is it possible it doesn't like WHERE I'm calling dispatch from? I don't really understand the difference

dzaima commented 7 months ago

I'm getting a decorated window in Weston, but it only appears after changing the weston window size. And it's of course still segfaulting. I have a very slight guess that there might be some memory corruption, am investigating

dzaima commented 7 months ago

printing fWindow in jwm::Window::dispatch does give a different value on the crashing iteration. Honestly I have no clue what's happening (rr is breaking on me repeatedly), but potentially libdecor_decorate and/or libdecor in general is writing over it for some reason..?

TheDrawingCoder-Gamer commented 7 months ago

Is it possible it's losing all references for some reason?

dzaima commented 7 months ago

the window object? maybe, though the ~Window isn't called (libdecor specifically messing with it seems unlikely now; xoring the this argument of the data pointers of libdecor_decorate and wl_surface_add_listener leads it to still failing)

TheDrawingCoder-Gamer commented 7 months ago

Layers call jwm::unref, which removes one reference to it - but idk why this would do anything, unless close was being called multiple times

TheDrawingCoder-Gamer commented 7 months ago

????? the WHOLE this? wouldn't that extend to WindowWayland as well?

dzaima commented 7 months ago

(ignore me there, I did a stupid)

TheDrawingCoder-Gamer commented 7 months ago

If libdecor changes the user data on the surface, then YES it would cause issues.

dzaima commented 7 months ago

libdecor does in fact not touch the user data pointer in any way other than passing it where it should

TheDrawingCoder-Gamer commented 7 months ago

It adds listeners though, which also sets userdata. Only for cursor surface though??

dzaima commented 7 months ago

ok the issue might be quite simple - the window derived in pointerHandleMotion is invalid (added a field of int sanityCheck = 31415926; in WindowWayland, and added if (window->sanityCheck != 31415926) { printf("NOT WINDOW\n"); __builtin_trap(); } in pointerHandleMotion)

TheDrawingCoder-Gamer commented 7 months ago

I'll revert to finding in native : /. Bad optimization on my part