From 931cff0f6dd1f0a776b943811286d3b6c0f74713 Mon Sep 17 00:00:00 2001 From: IoI_xD Date: Thu, 23 Apr 2026 14:39:38 -0700 Subject: [PATCH] wayland: only recreate buffers on SetWH when Pending rolls around --- include/Mw/LowLevel/Wayland.h | 1 + src/backend/wayland.c | 35 ++++++++++++++++++++++++----------- src/widget/listbox.c | 6 +++--- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/include/Mw/LowLevel/Wayland.h b/include/Mw/LowLevel/Wayland.h index dbf9b74..d06119d 100644 --- a/include/Mw/LowLevel/Wayland.h +++ b/include/Mw/LowLevel/Wayland.h @@ -507,6 +507,7 @@ struct _MwLLWayland { MwPoint cur_mouse_pos; /* Currently known mouse position */ int resizing; + int setting_wh; MwU32 mw, mh; /* Monitor width and height as advertised by wl_output.mode */ diff --git a/src/backend/wayland.c b/src/backend/wayland.c index c88f490..6065d5f 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -2075,19 +2075,9 @@ static void MwLLSetXYImpl(MwLL handle, int x, int y) { MwLLDispatch(handle, draw, NULL); } -static void MwLLSetWHImpl(MwLL handle, int w, int h) { - WIDGET_CHECK(handle); +static void actually_set_wh(MwLL handle) { region_invalidate(handle); - /* Prevent an integer underflow when the w/h is too low */ - if((w < 2 || h < 2)) { - handle->wayland.ww = 2; - handle->wayland.wh = 2; - } else { - handle->wayland.ww = w; - handle->wayland.wh = h; - } - if(handle->wayland.type == MwLL_WAYLAND_TOPLEVEL && handle->wayland.configured) { xdg_surface_set_window_geometry(handle->wayland.toplevel->xdg_surface, 0, 0, handle->wayland.ww, handle->wayland.wh); } @@ -2112,6 +2102,24 @@ static void MwLLSetWHImpl(MwLL handle, int w, int h) { backbuffer_destroy(&handle->wayland); backbuffer_setup(&handle->wayland); MwLLDispatch(handle, draw, NULL); +} + +static void MwLLSetWHImpl(MwLL handle, int w, int h) { + WIDGET_CHECK(handle); + + /* Prevent an integer underflow when the w/h is too low */ + if((w < 2 || h < 2)) { + handle->wayland.ww = 2; + handle->wayland.wh = 2; + } else { + handle->wayland.ww = w; + handle->wayland.wh = h; + } + + if(!handle->wayland.setting_wh) { + handle->wayland.setting_wh = 1; + } + handle->wayland.events_pending = 1; } @@ -2309,6 +2317,11 @@ static int MwLLPendingImpl(MwLL handle) { handle->wayland.resizing = 0; + if(handle->wayland.setting_wh) { + actually_set_wh(handle); + handle->wayland.setting_wh = 0; + } + #ifdef USE_DBUS if(wl_call_tbl.has_dbus) { if(handle->wayland.dark_theme_detection) { diff --git a/src/widget/listbox.c b/src/widget/listbox.c index fbfb514..78114c6 100644 --- a/src/widget/listbox.c +++ b/src/widget/listbox.c @@ -410,8 +410,8 @@ static void redrawIfNeeded(MwWidget handle, int row) { static int mwListBoxSetImpl(MwWidget handle, int row, int col, const char* text) { MwListBox lb = handle->internal; MwListBoxEntry entry; - char* t = text == NULL ? NULL : MwStringDuplicate(text); - int new = 0; + char* t = text == NULL ? NULL : MwStringDuplicate(text); + int new = 0; if(row == -1) row = arrlen(lb->list); entry.name = NULL; @@ -439,7 +439,7 @@ static int mwListBoxSetImpl(MwWidget handle, int row, int col, const char* text) static void mwListBoxSetIconImpl(MwWidget handle, int index, MwLLPixmap icon) { MwListBox lb = handle->internal; MwListBoxEntry entry; - int new = 0; + int new = 0; if(index == -1) index = arrlen(lb->list); entry.name = NULL;