From daced7a8974a1fb9b8b8758cf2c50ff0896226ac Mon Sep 17 00:00:00 2001 From: IoIxD Date: Tue, 5 May 2026 18:10:48 -0700 Subject: [PATCH] wayland: whatever it works on kde --- include/Mw/LowLevel/Wayland.h | 1 + src/backend/wayland/interfaces.c | 40 ++++++++++++++++---------------- src/backend/wayland/region.c | 1 + src/backend/wayland/wayland.c | 36 ++++++++++++++++++++++------ 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/include/Mw/LowLevel/Wayland.h b/include/Mw/LowLevel/Wayland.h index fdcc0a2..3babbaf 100644 --- a/include/Mw/LowLevel/Wayland.h +++ b/include/Mw/LowLevel/Wayland.h @@ -437,6 +437,7 @@ struct _MwLLWayland { enum _MwLLWaylandType type_to_be; MwRect clipping_rect; + MwBool no; MwBool detatching; MwPoint detach_point; diff --git a/src/backend/wayland/interfaces.c b/src/backend/wayland/interfaces.c index e382845..b9f089b 100644 --- a/src/backend/wayland/interfaces.c +++ b/src/backend/wayland/interfaces.c @@ -400,12 +400,12 @@ static void pointer_enter(void* data, struct wl_pointer* wl_pointer, MwU32 seria WAYLAND_EVENT_OP_START(self); while(topmost_parent->wayland.parent) topmost_parent = topmost_parent->wayland.parent; - curSurface = surface; - - self->wayland.pointer_serial = serial; - - wl_pointer_set_cursor(self->wayland.pointer, self->wayland.pointer_serial, topmost_parent->wayland.cursor.surface, 0, 0); + if(self->wayland.framebuffer.surface == surface) { + curSurface = surface; + self->wayland.pointer_serial = serial; + wl_pointer_set_cursor(self->wayland.pointer, self->wayland.pointer_serial, topmost_parent->wayland.cursor.surface, 0, 0); + } WAYLAND_EVENT_OP_END(self); }; @@ -506,14 +506,6 @@ static void pointer_motion(void* data, struct wl_pointer* wl_pointer, MwU32 time currentlyHeldWidget = topmost_parent->wayland.currentlyHeldWidget; - if(currentlyHeldWidget) { - currentlyHeldWidget->wayland.cur_mouse_pos.x = wl_fixed_to_int(surface_x); - currentlyHeldWidget->wayland.cur_mouse_pos.y = wl_fixed_to_int(surface_y); - p.point = currentlyHeldWidget->wayland.cur_mouse_pos; - MwLLDispatch(currentlyHeldWidget, move, &p); - h = MwTRUE; - } - if(self->wayland.framebuffer.surface) { inArea |= self->wayland.framebuffer.surface == curSurface; } @@ -521,15 +513,23 @@ static void pointer_motion(void* data, struct wl_pointer* wl_pointer, MwU32 time if(self->wayland.backbuffer.surface) { inArea |= self->wayland.backbuffer.surface == curSurface; } + + if(currentlyHeldWidget) { + currentlyHeldWidget->wayland.cur_mouse_pos.x = wl_fixed_to_int(surface_x); + currentlyHeldWidget->wayland.cur_mouse_pos.y = wl_fixed_to_int(surface_y); + p.point = currentlyHeldWidget->wayland.cur_mouse_pos; + MwLLDispatch(currentlyHeldWidget, down, &p); + h = MwTRUE; + } + if(inArea) { - if(h) { - self->wayland.cur_mouse_pos.x = wl_fixed_to_int(surface_x); - self->wayland.cur_mouse_pos.y = wl_fixed_to_int(surface_y); - p.point = self->wayland.cur_mouse_pos; - MwLLDispatch(self, move, &p); - } + self->wayland.cur_mouse_pos.x = wl_fixed_to_int(surface_x); + self->wayland.cur_mouse_pos.y = wl_fixed_to_int(surface_y); + p.point = self->wayland.cur_mouse_pos; + MwLLDispatch(self, move, &p); wl_pointer_set_cursor(self->wayland.pointer, self->wayland.pointer_serial, self->wayland.cursor.surface, 0, 0); } + WAYLAND_EVENT_OP_END(self); }; @@ -998,7 +998,7 @@ static wayland_protocol_t* xdg_wm_base_setup(MwU32 name, struct _MwLLWayland* wa ((struct xdg_wm_base_listener*)proto->listener)->ping = xdg_wm_base_ping; - proto->context = wl_registry_bind(wayland->registry, name, &xdg_wm_base_interface, 1); + proto->context = wl_registry_bind(wayland->registry, name, &xdg_wm_base_interface, 3); xdg_wm_base_add_listener(proto->context, proto->listener, wayland); return proto; diff --git a/src/backend/wayland/region.c b/src/backend/wayland/region.c index 4527d8e..8bd5337 100644 --- a/src/backend/wayland/region.c +++ b/src/backend/wayland/region.c @@ -23,6 +23,7 @@ void MwLLWaylandRegionSetup(MwLL handle) { } else { wl_region_subtract(handle->wayland.region, 0, 0, width + abs(handle->wayland.x), height + abs(handle->wayland.y)); wl_region_add(handle->wayland.region, handle->wayland.clipping_rect.x, handle->wayland.clipping_rect.y, handle->wayland.clipping_rect.width, handle->wayland.clipping_rect.height); + if(!handle->wayland.parent) wl_region_add(handle->wayland.region, 0, 0, width, height); } diff --git a/src/backend/wayland/wayland.c b/src/backend/wayland/wayland.c index 9711210..f3fc349 100644 --- a/src/backend/wayland/wayland.c +++ b/src/backend/wayland/wayland.c @@ -225,10 +225,12 @@ static void xdg_surface_configure( void MwLLWaylandBufferUpdate(MwLL self, struct _MwLLWaylandShmBuffer* buffer) { memcpy(buffer->buf, buffer->buf_back, buffer->buf_size); - // Yes this is needed every time, it's how we fix weston. - if(self->wayland.configured) - wl_surface_attach(buffer->surface, buffer->shm_buffer, 0, 0); - wl_surface_commit(buffer->surface); + if(buffer->surface) { + // Yes this is needed every time, it's how we fix weston. + if(self->wayland.configured) + wl_surface_attach(buffer->surface, buffer->shm_buffer, 0, 0); + wl_surface_commit(buffer->surface); + } } /* Toplevel setup function */ @@ -418,9 +420,19 @@ static void popup_done(void* data, (void)xdg_popup; }; +static void popup_repositioned(void* data, + struct xdg_popup* xdg_popup, + uint32_t token) { + MwLL self = data; + + xdg_surface_ack_configure(self->wayland.popup->xdg_surface, token); +}; + struct xdg_popup_listener popup_listener = { - .configure = popup_configure, - .popup_done = popup_done, + .configure = popup_configure, + .popup_done = popup_done, + .repositioned = popup_repositioned, + }; /* Popup setup function */ @@ -483,6 +495,8 @@ static void setup_popup(MwLL r, int x, int y, MwLL parent) { xdg_surface, r->wayland.popup->xdg_positioner); + uint32_t ver = wl_proxy_get_version((struct wl_proxy*)r->wayland.popup->xdg_popup); + xdg_popup_add_listener(r->wayland.popup->xdg_popup, &popup_listener, r); r->wayland.popup->xdg_surface_listener.configure = xdg_surface_configure; @@ -797,9 +811,16 @@ static void MwLLSetXYImpl(MwLL handle, int x, int y) { if(handle->wayland.type == MwLL_WAYLAND_SUBLEVEL) { wl_subsurface_set_position(handle->wayland.sublevel->subsurface, x, y); } + + if(handle->wayland.type == MwLL_WAYLAND_POPUP) { + xdg_positioner_set_anchor_rect(handle->wayland.popup->xdg_positioner, handle->wayland.parent->wayland.x, handle->wayland.parent->wayland.y, handle->wayland.ww, handle->wayland.wh); + xdg_positioner_set_offset(handle->wayland.popup->xdg_positioner, x, y); + xdg_popup_reposition(handle->wayland.popup->xdg_popup, handle->wayland.popup->xdg_positioner, 0); + xdg_surface_set_window_geometry(handle->wayland.popup->xdg_surface, 0, 0, handle->wayland.ww, handle->wayland.wh); + } MwLLWaylandRegionSetup(handle); - if(handle->wayland.type == MwLL_WAYLAND_SUBLEVEL) recursive_render(handle); + if(handle->wayland.type != MwLL_WAYLAND_TOPLEVEL) recursive_render(handle); MwLLDispatch(handle, draw, NULL); } @@ -1469,6 +1490,7 @@ static void MwLLMakeToolWindowImpl(MwLL handle) { static void MwLLGetCursorCoordImpl(MwLL handle, MwPoint* point) { MwLL topmost_parent = handle; + WIDGET_CHECK(handle); while(topmost_parent->wayland.parent) topmost_parent = topmost_parent->wayland.parent;