integer math

This commit is contained in:
Jorijn van der Graaf 2025-11-23 04:04:53 +01:00
commit 5ff43e240c
27 changed files with 922 additions and 1011 deletions

View file

@ -16,7 +16,6 @@ You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
module;
#ifdef CRAFTER_GRAPHICS_WAYLAND
@ -41,207 +40,139 @@ module;
export module Crafter.Graphics:Window;
import std;
import :WindowBase;
import :WindowKeyboard;
import :WindowMouse;
import :WindowTitle;
import :WindowFramebuffer;
import :Types;
import Crafter.Event;
export namespace Crafter {
template<bool Framebuffer, bool Title, bool Keyboard, bool Mouse>
class Window : public WindowBase {
class UiElement;
class Window {
public:
std::conditional_t<Framebuffer, WindowFramebuffer, std::monostate> framebuffer;
std::conditional_t<Title, WindowTitle, std::monostate> title;
std::conditional_t<Keyboard, WindowKeyboard, std::monostate> keyboard;
std::conditional_t<Mouse, WindowMouse, std::monostate> mouse;
Window() requires (Framebuffer && !Title && !Keyboard && !Mouse) : framebuffer(*this) {}
Window(std::uint_fast32_t width, std::uint_fast32_t height) requires (Framebuffer && !Title && !Keyboard && !Mouse) : framebuffer(*this, width, height) {}
Event<void> onClose;
Event<std::chrono::time_point<std::chrono::high_resolution_clock>> onUpdate;
bool open = true;
bool updating = false;
Window() = default;
Window(Window&) = delete;
Window(Window&&) = delete;
virtual ~Window() = default;
Window& operator=(const Window&) = delete;
virtual void StartSync() = 0;
virtual void StartUpdate() = 0;
virtual void StopUpdate() = 0;
ScaleData ScaleElement(const UiElement& element);
};
Window() requires (!Framebuffer &&!Title && !Keyboard && !Mouse) : title(*this) {}
Window(const std::string_view title) requires (!Framebuffer &&!Title && !Keyboard && !Mouse) : title(*this, title) {}
class WindowKeyboard {
public:
bool heldkeys[255] = {};
Event<void> onKeyDown[255];
Event<void> onKeyHold[255];
Event<void> onKeyUp[255];
Event<char> onAnyKeyDown;
Event<char> onAnyKeyHold;
Event<char> onAnyKeyUp;
};
Window(std::uint_fast32_t width, std::uint_fast32_t height, const std::string_view title) requires (Framebuffer && Title && !Keyboard && !Mouse) : framebuffer(*this, width, height), title(*this, title) {}
~Window() {
std::cout << "destr" << std::endl;
#ifdef CRAFTER_GRAPHICS_WAYLAND
xdg_toplevel_destroy(xdgToplevel);
xdg_surface_destroy(xdgSurface);
wl_surface_destroy(surface);
#endif
}
class UiElementMouse;
class WindowMouse {
public:
Event<MousePoint> onMouseRightClick;
Event<MousePoint> onMouseLeftClick;
Event<MousePoint> onMouseRightHold;
Event<MousePoint> onMouseLeftHold;
Event<MousePoint> onMouseRightRelease;
Event<MousePoint> onMouseLeftRelease;
Event<MouseMoveEvent> onMouseMove;
Event<MouseMoveEvent> onMouseEnter;
Event<MouseMoveEvent> onMouseLeave;
Event<std::uint_fast32_t> onMouseScroll;
MousePoint currentMousePos;
MousePoint lastMousePos;
MousePoint mouseDelta;
bool mouseLeftHeld = false;
bool mouseRightHeld = false;
std::vector<UiElementMouse*> mouseElements;
};
// template<bool Buffer, bool Mouse>
// UiElement<Buffer, Mouse>& AddElement(float anchorX, float anchorY, float relativeWidth, float relativeHeight, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false) requires(Buffer == true) {
class WindowTitle {
public:
virtual void SetTitle(const std::string_view title) = 0;
};
// }
template<bool UiBuffer, bool UiMouse>
UiElement<UiBuffer, UiMouse>& CreateElement(std::uint_fast32_t width, std::uint_fast32_t height, float anchorX, float anchorY, float relativeWidth, float relativeHeight, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false) requires(UiBuffer && Framebuffer) {
std::unique_ptr<UiElement<UiBuffer, UiMouse>> element = std::make_unique<UiElement<UiBuffer, UiMouse>>(width, height, anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling);
UiElement<UiBuffer, UiMouse>* ptr = element.get();
framebuffer.elements.push_back(&element->buffer);
if constexpr(UiMouse) {
mouse.elements.push_back(&element->mouse);
}
elements.emplace_back(std::move(element));
return *ptr;
}
template<bool UiBuffer, bool UiMouse>
void RemoveElement(UiElement<UiBuffer, UiMouse>& element) {
if constexpr(UiBuffer) {
framebuffer.elements.erase(std::find(framebuffer.elements.begin(), framebuffer.elements.end(), &element.buffer));
}
for(std::uint_fast32_t i = 0; i < elements.size(); i++) {
if(elements[i].get() == &element) {
elements.erase(elements.begin() + i);
break;
}
}
}
class WindowFramebuffer {
public:
std::uint_fast32_t width;
std::uint_fast32_t height;
WindowFramebuffer() = default;
WindowFramebuffer(std::uint_fast32_t width, std::uint_fast32_t height);
virtual void Resize(std::uint_fast32_t width, std::uint_fast32_t height) = 0;
virtual void Write(Pixel_BU8_GU8_RU8_AU8* pixels) = 0;
virtual void Write(std::uint_fast32_t x, std::uint_fast32_t y, Pixel_BU8_GU8_RU8_AU8 pixel) = 0;
virtual Pixel_BU8_GU8_RU8_AU8 Read(std::uint_fast32_t x, std::uint_fast32_t y) const = 0;
virtual const Pixel_BU8_GU8_RU8_AU8* Read() const = 0;
virtual Pixel_BU8_GU8_RU8_AU8* Get() = 0;
virtual void Store() = 0;
virtual void Render() = 0;
ScaleData ScaleElementAbsolute(const UiElement& element);
};
private:
#ifdef CRAFTER_GRAPHICS_WAYLAND
void InitWayland() {
std::cout << "bruh" << std::endl;
display = wl_display_connect(NULL);
if (display == NULL) {
std::cerr << "failed to create display" << std::endl;
}
wl_registry* registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener, this);
if (wl_display_roundtrip(display) == -1) {
exit(EXIT_FAILURE);
}
if (shm == NULL || compositor == NULL || xdgWmBase == NULL) {
std::cerr << "no wl_shm, wl_compositor or xdg_wm_base support" << std::endl;
exit(EXIT_FAILURE);
}
surface = wl_compositor_create_surface(compositor);
xdgSurface = xdg_wm_base_get_xdg_surface(xdgWmBase, surface);
xdgToplevel = xdg_surface_get_toplevel(xdgSurface);
cb = wl_surface_frame(surface);
//wl_callback_add_listener(cb, &surface_frame_listener, this);
xdg_surface_add_listener(xdgSurface, &xdg_surface_listener, this);
xdg_toplevel_add_listener(xdgToplevel, &xdg_toplevel_listener, this);
wl_surface_commit(surface);
while (wl_display_dispatch(display) != -1 && !configured) {}
wl_surface_commit(surface);
zxdg_toplevel_decoration_v1* decoration = zxdg_decoration_manager_v1_get_toplevel_decoration(manager, xdgToplevel);
zxdg_toplevel_decoration_v1_set_mode(decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
wl_surface_commit(surface);
std::cout << "bruh" << std::endl;
open = true;
}
static void wl_surface_frame_done(void* data, struct wl_callback *cb, uint32_t time) {
wl_callback_destroy(cb);
Window<Framebuffer, Title, Keyboard, Mouse>* window = reinterpret_cast<Window<Framebuffer, Title, Keyboard, Mouse>*>(data);
if(window->onUpdate.listeners.size() > 0) {
cb = wl_surface_frame(window->surface);
wl_callback_add_listener(cb, &WindowBase::surface_frame_listener, window);
}
}
constexpr static wl_callback_listener surface_frame_listener = {
.done = wl_surface_frame_done,
};
static void xdg_wm_base_handle_ping(void* data, xdg_wm_base* xdg_wm_base, std::uint32_t serial) {
xdg_wm_base_pong(xdg_wm_base, serial);
}
#ifdef CRAFTER_GRAPHICS_WAYLAND
class UiElementBufferBuffer;
class WindowWayland final: public Window, public WindowKeyboard, public WindowMouse, public WindowFramebuffer, public WindowTitle {
public:
Pixel_BU8_GU8_RU8_AU8* framebuffer = nullptr;
std::vector<UiElementBufferBuffer*> elements;
WindowWayland(std::uint_fast32_t width, std::uint_fast32_t height);
WindowWayland(std::uint_fast32_t width, std::uint_fast32_t height, const std::string_view title);
~WindowWayland();
bool configured = false;
wl_shm* shm = nullptr;
wl_seat* seat = nullptr;
xdg_toplevel* xdgToplevel = nullptr;
xdg_wm_base* xdgWmBase = nullptr;
zxdg_decoration_manager_v1* manager = nullptr;
wl_surface* surface = nullptr;
wl_buffer* buffer = nullptr;
wl_buffer* backBuffer = nullptr;
xdg_surface* xdgSurface = nullptr;
wl_display* display = nullptr;
wl_callback* cb = nullptr;
xkb_keymap* xkb_keymap;
xkb_context* xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
xkb_state* xkb_state;
void Render() override;
void StartSync() override;
void StartUpdate() override;
void StopUpdate() override;
void SetTitle(const std::string_view title) override;
void Resize(std::uint_fast32_t width, std::uint_fast32_t height) override;
void Write(Pixel_BU8_GU8_RU8_AU8* pixels) override;
void Write(std::uint_fast32_t x, std::uint_fast32_t y, Pixel_BU8_GU8_RU8_AU8 pixel) override;
Pixel_BU8_GU8_RU8_AU8 Read(std::uint_fast32_t x, std::uint_fast32_t y) const override;
const Pixel_BU8_GU8_RU8_AU8* Read() const override;
Pixel_BU8_GU8_RU8_AU8* Get() override;
void Store() override;
inline static wl_compositor* compositor = nullptr;
static void wl_surface_frame_done(void *data, wl_callback *cb, uint32_t time);
static void PointerListenerHandleMotion(void* data, wl_pointer* wl_pointer, uint time, wl_fixed_t surface_x, wl_fixed_t surface_y);
static void PointerListenerHandleAxis(void*, wl_pointer*, std::uint32_t, std::uint32_t, wl_fixed_t value);
static void PointerListenerHandleEnter(void* data, wl_pointer* wl_pointer, uint serial, wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y);
static void PointerListenerHandleLeave(void*, wl_pointer*, std::uint32_t, wl_surface*);
static void xdg_toplevel_handle_close(void* data, xdg_toplevel*);
static void handle_global(void* data, wl_registry* registry, std::uint32_t name, const char* interface, std::uint32_t version);
static void pointer_handle_button(void* data, wl_pointer* pointer, std::uint32_t serial, std::uint32_t time, std::uint32_t button, std::uint32_t state);
static void seat_handle_capabilities(void* data, wl_seat* seat, uint32_t capabilities);
static void xdg_surface_handle_configure(void* data, xdg_surface* xdg_surface, std::uint32_t serial);
static void xdg_wm_base_handle_ping(void* data, xdg_wm_base* xdg_wm_base, std::uint32_t serial);
static void keyboard_keymap(void* data, wl_keyboard* keyboard, uint32_t format, int fd, uint32_t size);
static void keyboard_enter(void *data, wl_keyboard *keyboard, uint32_t serial, wl_surface *surface, wl_array *keys);
static void keyboard_leave(void *data, wl_keyboard *keyboard, uint32_t serial, wl_surface *surface);
static void keyboard_key(void *data, wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state);
static void keyboard_modifiers(void *data, wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group);
static void keyboard_repeat_info(void *data, wl_keyboard *keyboard, int32_t rate, int32_t delay);
static void handle_global_remove(void* data, wl_registry* registry, uint32_t name);
static void xdg_toplevel_configure(void*, xdg_toplevel*, std::int32_t, std::int32_t, wl_array*);
constexpr static xdg_wm_base_listener xdgWmBaseListener = {
.ping = xdg_wm_base_handle_ping,
};
static void pointer_handle_button(void* data, wl_pointer* pointer, std::uint32_t serial, std::uint32_t time, std::uint32_t button, std::uint32_t state) {
Window<Framebuffer, Title, Keyboard, Mouse>* window = reinterpret_cast<<Window<Framebuffer, Title, Keyboard, Mouse>*>(data);
if (button == BTN_LEFT) {
if(state == WL_POINTER_BUTTON_STATE_PRESSED) {
window->mouseLeftHeld = true;
window->mouse.onMouseLeftClick.Invoke(window->mouse.currentMousePos);
if constexpr (Framebuffer) {
for(UiElementMouse& element : window->mouse.elements) {
ScaleData data = window->framebuffer.ScaleElement(element);
if(window->mouse.currentMousePos.x >= data.x && window->mouse.currentMousePos.x <= data.x+data.width && window->mouse.currentMousePos.y > data.y && window->mouse.currentMousePos.y < data.y+data.height) {
element.onMouseLeftClick.Invoke({window->mouse.currentMousePos.x-data.x, window->mouse.currentMousePos.y-data.y});
}
}
}
} else {
window->mouse.mouseLeftHeld = false;
window->mouse.onMouseLeftRelease.Invoke(window->mouse.currentMousePos);
for(UiElement& element : window->mouse.elements) {
ScaleData data = window->mouse.ScaleElement(element);
if(window->mouse.currentMousePos.x >= data.x && window->mouse.currentMousePos.x <= data.x+data.width && window->mouse.currentMousePos.y > data.y && window->mouse.currentMousePos.y < data.y+data.height) {
element.onMouseLeftRelease.Invoke({window->mouse.currentMousePos.x-data.x, window->mouse.currentMousePos.y-data.y});
}
}
}
} else if(button == BTN_RIGHT){
if(state == WL_POINTER_BUTTON_STATE_PRESSED) {
window->mouse.mouseRightHeld = true;
window->mouse.onMouseRightClick.Invoke(window->mouse.currentMousePos);
for(UiElement& element : window->mouse.elements) {
ScaleData data = window->mouse.ScaleElement(element);
if(window->mouse.currentMousePos.x >= data.x && window->mouse.currentMousePos.x <= data.x+data.width && window->mouse.currentMousePos.y > data.y && window->mouse.currentMousePos.y < data.y+data.height) {
element.onMouseRightClick.Invoke({window->mouse.currentMousePos.x-data.x, window->mouse.currentMousePos.y-data.y});
}
}
} else {
window->mouse.mouseRightHeld = true;
window->mouse.onMouseRightRelease.Invoke(window->mouse.currentMousePos);
for(UiElement& element : window->mouse.elements) {
ScaleData data = window->mouse.ScaleElement(element);
if(window->mouse.currentMousePos.x >= data.x && window->mouse.currentMousePos.x <= data.x+data.width && window->mouse.currentMousePos.y > data.y && window->mouse.currentMousePos.y < data.y+data.height) {
element.onMouseRightRelease.Invoke({window->mouse.currentMousePos.x-data.x, window->mouse.currentMousePos.y-data.y});
}
}
}
}
}
static void PointerListenerHandleMotion(void* data, wl_pointer* wl_pointer, uint time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
<Window<Framebuffer, Title, Keyboard, Mouse>* window = reinterpret_cast<<Window<Framebuffer, Title, Keyboard, Mouse>*>(data);
MousePoint pos = {wl_fixed_to_double(surface_x), wl_fixed_to_double(surface_y)};
window->mouse.lastMousePos = window->currentMousePos;
window->currentMousePos = pos;
window->mouseDelta = {window->currentMousePos.x-window->lastMousePos.x, window->currentMousePos.y-window->lastMousePos.y};
window->onMouseMove.Invoke({window->lastMousePos, window->currentMousePos, window->mouseDelta});
for(UiElement& element : window->elements) {
ScaleData data = window->ScaleElement(element);
if(window->currentMousePos.x >= data.x && window->currentMousePos.x <= data.x+data.width && window->currentMousePos.y > data.y && window->currentMousePos.y < data.y+data.height) {
element.onMouseMove.Invoke({window->currentMousePos.x-data.x, window->currentMousePos.y-data.y});
if(!(window->lastMousePos.x >= data.x && window->lastMousePos.x <= data.x+data.width && window->lastMousePos.y > data.y && window->lastMousePos.y < data.y+data.height)) {
element.onMouseEnter.Invoke({window->currentMousePos.x-data.x, window->currentMousePos.y-data.y});
}
} else if(window->lastMousePos.x >= data.x && window->lastMousePos.x <= data.x+data.width && window->lastMousePos.y > data.y && window->lastMousePos.y < data.y+data.height) {
element.onMouseLeave.Invoke({window->currentMousePos.x-data.x, window->currentMousePos.y-data.y});
}
}
}
static void PointerListenerHandleEnter(void* data, wl_pointer* wl_pointer, uint serial, wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
<Window<Framebuffer, Title, Keyboard, Mouse>* window = reinterpret_cast<<Window<Framebuffer, Title, Keyboard, Mouse>*>(data);
window->onMouseEnter.Invoke({window->lastMousePos, window->currentMousePos, window->mouseDelta});
}
static void PointerListenerHandleLeave(void* data, wl_pointer*, std::uint32_t, wl_surface*) {
<Window<Framebuffer, Title, Keyboard, Mouse>* window = reinterpret_cast<<Window<Framebuffer, Title, Keyboard, Mouse>*>(data);
window->onMouseEnter.Invoke({window->lastMousePos, window->currentMousePos, window->mouseDelta});
}
static void PointerListenerHandleAxis(void*, wl_pointer*, std::uint32_t, std::uint32_t, wl_fixed_t value) {
}
constexpr static wl_pointer_listener pointer_listener = {
.enter = PointerListenerHandleEnter,
.leave = PointerListenerHandleLeave,
@ -249,88 +180,6 @@ export namespace Crafter {
.button = pointer_handle_button,
.axis = PointerListenerHandleAxis,
};
xkb_keymap* xkb_keymap;
xkb_context* xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
xkb_state* xkb_state;
static void keyboard_keymap(void *data, wl_keyboard *keyboard, uint32_t format, int fd, uint32_t size) {
if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
close(fd);
fprintf(stderr, "Unsupported keymap format\n");
return;
}
void *map = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
if (map == MAP_FAILED) {
close(fd);
perror("mmap");
return;
}
xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
xkb_keymap = xkb_keymap_new_from_string(xkb_context, (const char *)map, XKB_KEYMAP_FORMAT_TEXT_V1,XKB_KEYMAP_COMPILE_NO_FLAGS);
munmap(map, size);
close(fd);
xkb_state = xkb_state_new(xkb_keymap);
}
static void keyboard_enter(void *data, wl_keyboard *keyboard, uint32_t serial, wl_surface *surface, wl_array *keys) {
}
static void keyboard_leave(void *data, wl_keyboard *keyboard, uint32_t serial, wl_surface *surface) {
}
static void keyboard_key(void *data, wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
if (!xkb_state) {
return;
}
Window<Framebuffer, Title, Keyboard, Mouse>* window = reinterpret_cast<Window<Framebuffer, Title, Keyboard, Mouse>*>(data);
xkb_keycode_t keycode = key + 8;
xkb_keysym_t keysym = xkb_state_key_get_one_sym(xkb_state, keycode);
char utf8[8] = {0};
int len = xkb_keysym_to_utf8(keysym, utf8, sizeof(utf8));
if (len != 0) {
char keypress = utf8[0];
if(state == WL_KEYBOARD_KEY_STATE_PRESSED) {
if(window->heldkeys[keypress]) {
window->onKeyHold[keypress].Invoke();
window->onAnyKeyHold.Invoke(keypress);
} else{
window->heldkeys[keypress] = true;
window->onKeyDown[keypress].Invoke();
window->onAnyKeyDown.Invoke(keypress);
}
} else{
window->heldkeys[keypress] = false;
window->onKeyUp[keypress].Invoke();
window->onAnyKeyUp.Invoke(keypress);
}
} else {
// // fallback for keys like Return, Escape, etc.
// char name[64];
// if (xkb_keysym_get_name(keysym, name, sizeof(name)) > 0) {
// printf("Key %s pressed (non-printable or multi-char)\n", name);
// }
}
}
static void keyboard_modifiers(void *data, wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) {
}
static void keyboard_repeat_info(void *data, wl_keyboard *keyboard, int32_t rate, int32_t delay) {
}
constexpr static wl_keyboard_listener keyboard_listener = {
.keymap = keyboard_keymap,
.enter = keyboard_enter,
@ -339,76 +188,26 @@ export namespace Crafter {
.modifiers = keyboard_modifiers,
.repeat_info = keyboard_repeat_info,
};
void seat_handle_capabilities(void* data, wl_seat* seat, uint32_t capabilities) {
Window<Framebuffer, Title, Keyboard, Mouse>* window = reinterpret_cast<Window<Framebuffer, Title, Keyboard, Mouse>*>(data);
window->seat = seat;
if constexpr(Mouse) {
wl_pointer* pointer = wl_seat_get_pointer(seat);
wl_pointer_add_listener(pointer, &pointer_listener, window);
}
if constexpr(Keyboard) {
wl_keyboard* keyboard = wl_seat_get_keyboard(seat);
wl_keyboard_add_listener(keyboard, &keyboard_listener, window);
}
}
constexpr static wl_seat_listener seat_listener = {
.capabilities = seat_handle_capabilities,
};
static void handle_global(void *data, wl_registry *registry, std::uint32_t name, const char *interface, std::uint32_t version) {
Window<Framebuffer, Title, Keyboard, Mouse>* window = reinterpret_cast<Window<Framebuffer, Title, Keyboard, Mouse>*>(data);
if (strcmp(interface, wl_shm_interface.name) == 0) {
window->shm = reinterpret_cast<wl_shm*>(wl_registry_bind(registry, name, &wl_shm_interface, 1));
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
if constexpr (Keyboard || Mouse) {
wl_seat* seat = reinterpret_cast<wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, 1));
wl_seat_add_listener(seat, &seat_listener, window);
}
} else if (compositor == NULL && strcmp(interface, wl_compositor_interface.name) == 0) {
compositor = reinterpret_cast<wl_compositor*>(wl_registry_bind(registry, name, &wl_compositor_interface, 1));
} else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
window->xdgWmBase = reinterpret_cast<xdg_wm_base*>(wl_registry_bind(registry, name, &xdg_wm_base_interface, 1));
xdg_wm_base_add_listener(window->xdgWmBase, &xdgWmBaseListener, NULL);
} else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) {
window->manager = reinterpret_cast<zxdg_decoration_manager_v1*>(wl_registry_bind(registry, name, &zxdg_decoration_manager_v1_interface, 1));
}
}
void handle_global_remove(void* data, wl_registry* registry, uint32_t name) {}
constexpr wl_registry_listener registry_listener = {
constexpr static wl_registry_listener registry_listener = {
.global = handle_global,
.global_remove = handle_global_remove,
};
static void xdg_surface_handle_configure(void* data, xdg_surface* xdg_surface, std::uint32_t serial) {
Window<Framebuffer, Title, Keyboard, Mouse>* window = reinterpret_cast<Window<Framebuffer, Title, Keyboard, Mouse>*>(data);
// The compositor configures our surface, acknowledge the configure event
xdg_surface_ack_configure(xdg_surface, serial);
if (window->configured) {
// If this isn't the first configure event we've received, we already
// have a buffer attached, so no need to do anything. Commit the
// surface to apply the configure acknowledgement.
wl_surface_commit(window->surface);
}
window->configured = true;
}
constexpr xdg_surface_listener xdg_surface_listener = {
constexpr static xdg_toplevel_listener xdg_toplevel_listener = {
.configure = xdg_toplevel_configure,
.close = xdg_toplevel_handle_close,
};
constexpr static wl_callback_listener wl_callback_listener = {
.done = wl_surface_frame_done,
};
constexpr static xdg_wm_base_listener xdgWmBaseListener = {
.ping = xdg_wm_base_handle_ping,
};
constexpr static xdg_surface_listener xdg_surface_listener = {
.configure = xdg_surface_handle_configure,
};
void noop5(void*, xdg_toplevel*, std::int32_t, std::int32_t, wl_array*){}
static void xdg_toplevel_handle_close(void* data, xdg_toplevel*) {
WindowBase* window = reinterpret_cast<WindowBase*>(data);
window->onClose.Invoke();
window->open = false;
}
constexpr xdg_toplevel_listener xdg_toplevel_listener = {
.configure = noop5,
.close = WindowBase::xdg_toplevel_handle_close,
};
#endif
};
#endif
}