Skip to content

Commit

Permalink
Make multiwindow work
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDrawingCoder-Gamer committed Dec 12, 2023
1 parent 952c76c commit ebafae5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion script/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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,
Expand Down
1 change: 1 addition & 0 deletions shared/cc/Window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

jwm::Window::~Window() {
fEnv->DeleteGlobalRef(fWindow);
fWindow = nullptr;
}

void jwm::Window::dispatch(jobject event) {
Expand Down
32 changes: 21 additions & 11 deletions wayland/cc/LayerGLWayland.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,32 @@ namespace jwm {
EGLDisplay _display = nullptr;
EGLSurface _surface = nullptr;
EGLConfig _config = nullptr;
bool _firstAttach = true;
bool _closed = false;

LayerGL() = default;
virtual ~LayerGL() = default;

void attach(WindowWayland* window) {
// no idea why you would reopen it???
_closed = false;
fWindow = jwm::ref(window);
fWindow->setLayer(this);
// HACK: reopen
bool visible = fWindow->_visible;
if (visible) {
fWindow->hide();
}
if (_display == nullptr) {
_display = eglGetDisplay(window->_windowManager.display);
if (fWindow->_windowManager._eglDisplay == EGL_NO_DISPLAY) {
fWindow->_windowManager._eglDisplay = eglGetDisplay(window->_windowManager.display);

eglInitialize(_display, nullptr, nullptr);
eglInitialize(fWindow->_windowManager._eglDisplay, nullptr, nullptr);

}
if (_firstAttach) {
_firstAttach = false;
}
_display = fWindow->_windowManager._eglDisplay;
if ( eglBindAPI(EGL_OPENGL_API) == EGL_FALSE) {
throw new std::runtime_error("Cannot bind EGL Api");
}
Expand Down Expand Up @@ -71,6 +79,7 @@ namespace jwm {
throw std::runtime_error("Couldn't make context");
}
// Don't block on swap
// Blocking here will freeze the app on sway.
eglSwapInterval(_display, 0);
}
if (visible)
Expand All @@ -84,7 +93,7 @@ namespace jwm {

void resize(int width, int height) override {
// Make current to avoid artifacts in other windows
makeCurrentForced();
makeCurrent();
glClearStencil(0);
glClearColor(0, 0, 0, 255);
glStencilMask(0xffffffff);
Expand All @@ -98,17 +107,19 @@ namespace jwm {
}

void swapBuffers() override {
printf("before swap\n");
eglSwapBuffers(_display, _surface);
printf("after swap\n");
}

void close() override {
if (_closed)
return;
_closed = true;
detach();
eglDestroyContext(_display, _context);
eglTerminate(_display);


_firstAttach = true;
jwm::unref(&fWindow);
fWindow = nullptr;
}

void makeCurrentForced() override {
Expand All @@ -121,9 +132,6 @@ namespace jwm {
void attachBuffer() override {
if (fWindow && fWindow->_waylandWindow) {
if (!_eglWindow) {
// _region = wl_compositor_create_region(fWindow->_windowManager.compositor);
// wl_region_add(_region, 0, 0, fWindow->getWidth(), fWindow->getHeight());
// wl_surface_set_opaque_region(fWindow->_waylandWindow, _region);
_eglWindow = wl_egl_window_create(fWindow->_waylandWindow, fWindow->getWidth(), fWindow->getHeight());
_surface = eglCreateWindowSurface(_display, _config, _eglWindow, nullptr);

Expand Down Expand Up @@ -181,6 +189,8 @@ extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_LayerGL__1nResize

extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_LayerGL__1nMakeCurrent
(JNIEnv* env, jobject obj) {
jwm::LayerGL* instance = reinterpret_cast<jwm::LayerGL*>(jwm::classes::Native::fromJava(env, obj));
instance->makeCurrent();
}

extern "C" JNIEXPORT void JNICALL Java_io_github_humbleui_jwm_LayerGL__1nSwapBuffers
Expand Down
4 changes: 3 additions & 1 deletion wayland/cc/WindowManagerWayland.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <GL/glx.h>
#include <atomic>
#include <map>
#include <memory>
Expand All @@ -17,6 +16,8 @@
#include "Output.hh"
#include <libdecor-0/libdecor.h>
#include <xkbcommon/xkbcommon.h>
#include <wayland-egl.h>
#include <EGL/egl.h>

namespace jwm {
class WindowWayland;
Expand Down Expand Up @@ -123,6 +124,7 @@ namespace jwm {
libdecor* decorCtx = nullptr;
xkb_context* _xkbContext = nullptr;
xkb_state* _xkbState = nullptr;
EGLDisplay _eglDisplay = EGL_NO_DISPLAY;
std::list<Output*> outputs;

bool _runLoop;
Expand Down
10 changes: 6 additions & 4 deletions wayland/cc/WindowWayland.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ WindowWayland::WindowWayland(JNIEnv* env, WindowManagerWayland& windowManager):
}

WindowWayland::~WindowWayland() {
close();
// TODO: close gets called twice?
// close();
}


Expand All @@ -64,12 +65,12 @@ void WindowWayland::setTitlebarVisible(bool isVisible) {
}

void WindowWayland::close() {
_windowManager.unregisterWindow(this);
hide();
if (_waylandWindow) {
_windowManager.unregisterWindow(this);
wl_surface_destroy(_waylandWindow);
}
_waylandWindow = nullptr;
hide();
// TODO: more destruction!
}
void WindowWayland::hide() {
Expand Down Expand Up @@ -264,7 +265,8 @@ void jwm::WindowWayland::outputDone(void* data, wl_output* output) {}
void jwm::WindowWayland::outputScale(void* data, wl_output* output, int factor) {
WindowWayland* self = reinterpret_cast<WindowWayland*>(data);
self->_scale = factor;
self->dispatch(classes::EventWindowScreenChange::kInstance);
if (self->_waylandWindow)
self->dispatch(classes::EventWindowScreenChange::kInstance);
}
void jwm::WindowWayland::outputName(void* data, wl_output* output, const char* name) {}
void jwm::WindowWayland::outputDescription(void* data, wl_output* output, const char* desc) {}
Expand Down
1 change: 0 additions & 1 deletion wayland/cc/WindowWayland.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ namespace jwm {
void setCursor(jwm::MouseCursor cursor);
void setLayer(ILayerWayland* layer);


ScreenInfo getScreen();

static void surfaceEnter(void* data, wl_surface* surface, wl_output* output);
Expand Down

0 comments on commit ebafae5

Please sign in to comment.