Skip to content

Commit

Permalink
IT SURE DOES OPEN
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDrawingCoder-Gamer committed Dec 6, 2023
1 parent cc7f892 commit 9c35576
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 73 deletions.
4 changes: 2 additions & 2 deletions wayland/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ file(GLOB SOURCES_CXX ${CMAKE_CURRENT_LIST_DIR}/../shared/cc/*.cc
${CMAKE_CURRENT_LIST_DIR}/../linux/cc/*.cc
${CMAKE_CURRENT_LIST_DIR}/cc/*.cc )
file(GLOB SOURCES_CXX_IMPL ${CMAKE_CURRENT_LIST_DIR}/../shared/cc/impl/*.cc)
file(GLOB SOURCES_C ${CMAKE_CURRENT_LIST_DIR}/cc/*.c)
add_library(xdgShell STATIC ${SOURCES_C})
file(GLOB SOURCES_XDG ${CMAKE_CURRENT_LIST_DIR}/cc/xdg-shell/*.c)
add_library(xdgShell STATIC ${SOURCES_XDG})
add_library(jwm SHARED ${SOURCES_OBJC} ${SOURCES_CXX} ${SOURCES_CXX_IMPL})
find_library(WAYLAND_CLIENT_LIB wayland-client)
find_library(DECOR_LIB decor-0)
Expand Down
52 changes: 25 additions & 27 deletions wayland/cc/WindowManagerWayland.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,30 @@
#include <algorithm>
#include <system_error>
#include "Log.hh"
#include "xdg-shell.hh"
#include <cstring>
#include <cerrno>

using namespace jwm;

wl_registry_listener WindowManagerWayland::_registryListener = {
.global = WindowManagerWayland::registryHandleGlobal,
.global_remove = WindowManagerWayland::registryHandleGlobalRemove
};
wl_pointer_listener WindowManagerWayland::_pointerListener = {
.enter = WindowManagerWayland::pointerHandleEnter,
.leave = WindowManagerWayland::pointerHandleLeave,
.motion = WindowManagerWayland::pointerHandleMotion,
.button = WindowManagerWayland::pointerHandleButton,
.axis = WindowManagerWayland::pointerHandleAxis
};
xdg_wm_base_listener WindowManagerWayland::_xdgWmBaseListener = {
.ping = WindowManagerWayland::xdgWmBasePing
};

WindowManagerWayland::WindowManagerWayland():
display(wl_display_connect(nullptr)) {
registry = wl_display_get_registry(display);
wl_registry_listener registry_listener = {
.global = WindowManagerWayland::registryHandleGlobal,
.global_remove = WindowManagerWayland::registryHandleGlobalRemove
};
wl_registry_add_listener(registry, &registry_listener, this);
wl_registry_add_listener(registry, &_registryListener, this);

wl_display_roundtrip(display);

Expand All @@ -40,13 +49,11 @@ WindowManagerWayland::WindowManagerWayland():
throw std::system_error(ENOTSUP, std::generic_category(), "Unsupported compositor");
}

struct xdg_wm_base_listener xdgListener = {
.ping = WindowManagerWayland::xdgWmBasePing
};


// frankly `this` is not needed here, but it needs a pointer anyway and it's
// good to have consistentcy.
// xdg_wm_base_add_listener(xdgShell, &xdgListener, this);
xdg_wm_base_add_listener(xdgShell, &_xdgWmBaseListener, this);
{
wl_cursor_theme* cursor_theme = wl_cursor_theme_load(nullptr, 24, shm);
// TODO: what about if missing : (
Expand Down Expand Up @@ -77,14 +84,8 @@ WindowManagerWayland::WindowManagerWayland():

{
pointer = wl_seat_get_pointer(seat);
struct wl_pointer_listener pointerListener = {
.enter = WindowManagerWayland::pointerHandleEnter,
.leave = WindowManagerWayland::pointerHandleLeave,
.motion = WindowManagerWayland::pointerHandleMotion,
.button = WindowManagerWayland::pointerHandleButton,
.axis = WindowManagerWayland::pointerHandleAxis
};
wl_pointer_add_listener(pointer, &pointerListener, this);

wl_pointer_add_listener(pointer, &_pointerListener, this);
}


Expand All @@ -109,7 +110,6 @@ void WindowManagerWayland::runLoop() {
struct pollfd ps[] = {{.fd=wl_display_get_fd(display), .events=POLLIN}, {.fd=pipes[0], .events=POLLIN}};
// who be out here running they loop
while (_runLoop) {
printf(": (\n");
if (jwm::classes::Throwable::exceptionThrown(app.getJniEnv()))
_runLoop = false;
_processCallbacks();
Expand Down Expand Up @@ -142,7 +142,6 @@ void WindowManagerWayland::runLoop() {
printf("error with pipe\n");
break;
}
printf(": |\n");
if (ps[1].revents & POLLIN) {
while (read(pipes[0], buf, sizeof(buf)) == sizeof(buf)) { }
}
Expand All @@ -154,7 +153,6 @@ void WindowManagerWayland::runLoop() {
}
wl_display_dispatch_pending(display);
notifyBool.store(false);
printf(": )\n");
}

notifyFD = -1;
Expand Down Expand Up @@ -198,20 +196,20 @@ void WindowManagerWayland::_processCallbacks() {
void WindowManagerWayland::registryHandleGlobal(void* data, wl_registry *registry,
uint32_t name, const char* interface, uint32_t version) {
WindowManagerWayland* self = reinterpret_cast<WindowManagerWayland*>(data);
if (strcmp(interface, "wl_compositor") == 0) {
if (strcmp(interface, wl_compositor_interface.name) == 0) {
// EGL apparently requires at least a version of 4 here : )
self->compositor = (wl_compositor*)wl_registry_bind(registry, name,
&wl_compositor_interface, 4);
} else if (strcmp(interface, "wl_shm") == 0) {
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
self->shm = (wl_shm*)wl_registry_bind(registry, name,
&wl_shm_interface, 1);
} else if (strcmp(interface, "xdg_wm_base") == 0) {
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
self->xdgShell = (xdg_wm_base*)wl_registry_bind(registry, name,
&xdg_wm_base_interface, 2);
} else if (strcmp(interface, "wl_data_device_manager") == 0) {
&xdg_wm_base_interface, 1);
} else if (strcmp(interface, wl_data_device_manager_interface.name) == 0) {
self->deviceManager = (wl_data_device_manager*)wl_registry_bind(registry, name,
&wl_data_device_manager_interface, 1);
} else if (strcmp(interface, "wl_seat") == 0) {
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
self->seat = (wl_seat*)wl_registry_bind(registry, name,
&wl_seat_interface, 1);
}
Expand Down
7 changes: 6 additions & 1 deletion wayland/cc/WindowManagerWayland.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "MouseCursor.hh"
#include <wayland-client.h>
#include <wayland-cursor.h>
#include "xdg-shell.hh"
#include "xdg-shell/xdg-shell.h"

namespace jwm {
class WindowWayland;
Expand Down Expand Up @@ -52,11 +52,15 @@ namespace jwm {
void notifyLoop();
void enqueueTask(const std::function<void()>& task);

static wl_registry_listener _registryListener;

static void registryHandleGlobal(void* data, wl_registry *registry,
uint32_t name, const char* interface, uint32_t version);
static void registryHandleGlobalRemove(void* data, wl_registry *registry,
uint32_t name);

static wl_pointer_listener _pointerListener;

static void pointerHandleEnter(void* data, wl_pointer *pointer,
uint32_t serial, wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y);
static void pointerHandleLeave(void* data, wl_pointer *pointer,
Expand All @@ -69,6 +73,7 @@ namespace jwm {
static void pointerHandleAxis(void* data, wl_pointer *pointer,
uint32_t time, uint32_t axis, wl_fixed_t value);

static xdg_wm_base_listener _xdgWmBaseListener;
static void xdgWmBasePing(void* data, xdg_wm_base* base, uint32_t serial);


Expand Down
56 changes: 29 additions & 27 deletions wayland/cc/WindowWayland.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@
using namespace jwm;


wl_surface_listener WindowWayland::_surfaceListener = {
.enter = WindowWayland::surfaceEnter,
.leave = WindowWayland::surfaceLeave,
.preferred_buffer_scale = WindowWayland::surfacePreferredBufferScale,
.preferred_buffer_transform = WindowWayland::surfacePreferredBufferTransform
};
xdg_surface_listener WindowWayland::_xdgSurfaceListener = {
.configure = WindowWayland::xdgSurfaceConfigure
};

xdg_toplevel_listener WindowWayland::_xdgToplevelListener = {
.configure = WindowWayland::xdgToplevelConfigure,
.close = WindowWayland::xdgToplevelClose,
.configure_bounds = WindowWayland::xdgToplevelConfigureBounds,
.wm_capabilities = WindowWayland::xdgToplevelWmCapabilities
};

wl_output_listener WindowWayland::_outputListener = {
.geometry = WindowWayland::outputGeometry,
.mode = WindowWayland::outputMode,
.done = WindowWayland::outputDone,
.scale = WindowWayland::outputScale,
.name = WindowWayland::outputName,
.description = WindowWayland::outputDescription
};
WindowWayland::WindowWayland(JNIEnv* env, WindowManagerWayland& windowManager):
jwm::Window(env),
_windowManager(windowManager),
Expand Down Expand Up @@ -113,28 +138,13 @@ bool WindowWayland::init() {
void WindowWayland::show()
{
_waylandWindow = wl_compositor_create_surface(_windowManager.compositor);
wl_surface_listener surfaceListener = {
.enter = WindowWayland::surfaceEnter,
.leave = WindowWayland::surfaceLeave,
.preferred_buffer_scale = WindowWayland::surfacePreferredBufferScale,
.preferred_buffer_transform = WindowWayland::surfacePreferredBufferTransform
};
wl_surface_add_listener(_waylandWindow, &surfaceListener, this);
wl_surface_add_listener(_waylandWindow, &_surfaceListener, this);

xdgSurface = xdg_wm_base_get_xdg_surface(_windowManager.xdgShell, _waylandWindow);
xdg_surface_listener xdgSurfaceListener = {
.configure = WindowWayland::xdgSurfaceConfigure
};
xdg_surface_add_listener(xdgSurface, &xdgSurfaceListener, this);
xdg_surface_add_listener(xdgSurface, &_xdgSurfaceListener, this);

xdgToplevel = xdg_surface_get_toplevel(xdgSurface);
xdg_toplevel_listener xdgToplevelListener = {
.configure = WindowWayland::xdgToplevelConfigure,
.close = WindowWayland::xdgToplevelClose,
.configure_bounds = WindowWayland::xdgToplevelConfigureBounds,
.wm_capabilities = WindowWayland::xdgToplevelWmCapabilities
};
xdg_toplevel_add_listener(xdgToplevel, &xdgToplevelListener, this);
xdg_toplevel_add_listener(xdgToplevel, &_xdgToplevelListener, this);
_windowManager.registerWindow(this);
wl_surface_commit(_waylandWindow);
}
Expand Down Expand Up @@ -175,15 +185,7 @@ void jwm::WindowWayland::setCursor(jwm::MouseCursor cursor) {
// what do???
void jwm::WindowWayland::surfaceEnter(void* data, wl_surface* surface, wl_output* output) {
// doesn't crash : )
wl_output_listener listener = {
.geometry = WindowWayland::outputGeometry,
.mode = WindowWayland::outputMode,
.done = WindowWayland::outputDone,
.scale = WindowWayland::outputScale,
.name = WindowWayland::outputName,
.description = WindowWayland::outputDescription
};
wl_output_add_listener(output, &listener, data);
wl_output_add_listener(output, &_outputListener, data);
}
void jwm::WindowWayland::surfaceLeave(void* data, wl_surface* surface, wl_output* output) {}
void jwm::WindowWayland::surfacePreferredBufferScale(void* data, wl_surface* surface, int factor) {
Expand Down
9 changes: 8 additions & 1 deletion wayland/cc/WindowWayland.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "WindowManagerWayland.hh"
#include "ILayerWayland.hh"
#include "ScreenInfo.hh"
#include "xdg-shell.hh"
#include "xdg-shell/xdg-shell.h"
#include <libdecor-0/libdecor.h>
namespace jwm {
class WindowWayland: public jwm::Window {
Expand Down Expand Up @@ -100,5 +100,12 @@ namespace jwm {
xdg_surface* xdgSurface = nullptr;
xdg_toplevel* xdgToplevel = nullptr;
libdecor_frame* _frame = nullptr;

static wl_surface_listener _surfaceListener;
static xdg_surface_listener _xdgSurfaceListener;
static xdg_toplevel_listener _xdgToplevelListener;

static wl_output_listener _outputListener;

};
}
21 changes: 6 additions & 15 deletions wayland/cc/xdg-shell.c → wayland/cc/xdg-shell/xdg-shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@
#include <stdint.h>
#include "wayland-util.h"

#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")))
#else
#define WL_PRIVATE
#endif

extern const struct wl_interface wl_output_interface;
extern const struct wl_interface wl_seat_interface;
extern const struct wl_interface wl_surface_interface;
Expand Down Expand Up @@ -90,7 +80,7 @@ static const struct wl_message xdg_wm_base_events[] = {
{ "ping", "u", xdg_shell_types + 0 },
};

WL_PRIVATE const struct wl_interface xdg_wm_base_interface = {
WL_EXPORT const struct wl_interface xdg_wm_base_interface = {
"xdg_wm_base", 6,
4, xdg_wm_base_requests,
1, xdg_wm_base_events,
Expand All @@ -109,7 +99,7 @@ static const struct wl_message xdg_positioner_requests[] = {
{ "set_parent_configure", "3u", xdg_shell_types + 0 },
};

WL_PRIVATE const struct wl_interface xdg_positioner_interface = {
WL_EXPORT const struct wl_interface xdg_positioner_interface = {
"xdg_positioner", 6,
10, xdg_positioner_requests,
0, NULL,
Expand All @@ -127,7 +117,7 @@ static const struct wl_message xdg_surface_events[] = {
{ "configure", "u", xdg_shell_types + 0 },
};

WL_PRIVATE const struct wl_interface xdg_surface_interface = {
WL_EXPORT const struct wl_interface xdg_surface_interface = {
"xdg_surface", 6,
5, xdg_surface_requests,
1, xdg_surface_events,
Expand Down Expand Up @@ -157,7 +147,7 @@ static const struct wl_message xdg_toplevel_events[] = {
{ "wm_capabilities", "5a", xdg_shell_types + 0 },
};

WL_PRIVATE const struct wl_interface xdg_toplevel_interface = {
WL_EXPORT const struct wl_interface xdg_toplevel_interface = {
"xdg_toplevel", 6,
14, xdg_toplevel_requests,
4, xdg_toplevel_events,
Expand All @@ -175,8 +165,9 @@ static const struct wl_message xdg_popup_events[] = {
{ "repositioned", "3u", xdg_shell_types + 0 },
};

WL_PRIVATE const struct wl_interface xdg_popup_interface = {
WL_EXPORT const struct wl_interface xdg_popup_interface = {
"xdg_popup", 6,
3, xdg_popup_requests,
3, xdg_popup_events,
};

File renamed without changes.

0 comments on commit 9c35576

Please sign in to comment.