diff --git a/include/Mw/LowLevel/Wayland.h b/include/Mw/LowLevel/Wayland.h index de63469..454de5c 100644 --- a/include/Mw/LowLevel/Wayland.h +++ b/include/Mw/LowLevel/Wayland.h @@ -87,7 +87,10 @@ struct _MwLLWayland { MwBool egl_setup; MwBool has_set_xy; - MwU32 x, y, ww, wh; + int resize_counter; + MwU32 x, y; + MwU32 ww, wh; + MwU32 lw, lh; MwPoint cur_mouse_pos; struct timeval timer; @@ -95,7 +98,9 @@ struct _MwLLWayland { MwU64 cooldown_timer; MwU64 cooldown_timer_epoch; - MwLL parent; + MwLL parent; + MwLL topmost_parent; + MwBool draw_recursively; GLuint fbo; unsigned int fbo_texture; diff --git a/src/backend/wayland.c b/src/backend/wayland.c index f6a0fe4..14cd116 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -428,6 +428,16 @@ static int event_loop(MwLL handle) { printf("error\n"); }; } + /* HACK: If the last known size is different, force a redraw */ + if(wayland->lw != wayland->ww || wayland->lh != wayland->wh) { + MwLLDispatch(handle, draw, 0); + wayland->resize_counter++; + if(wayland->resize_counter >= 5) { + wayland->lw = wayland->ww; + wayland->lh = wayland->wh; + wayland->resize_counter = 0; + } + } } } @@ -544,10 +554,13 @@ static void setup_sublevel(MwLL parent, MwLL r, int x, int y) { struct wl_subcompositor* subcompositor = parent->wayland.subcompositor; struct wl_surface* parent_surface = parent->wayland.surface; struct wl_region* region; - MwLL topmost_parent = parent; + { + MwLL topmost_parent = parent; - while(topmost_parent->wayland.type != MWLL_WAYLAND_TOPLEVEL) { - topmost_parent = topmost_parent->wayland.parent; + while(topmost_parent->wayland.type != MWLL_WAYLAND_TOPLEVEL) { + topmost_parent = topmost_parent->wayland.parent; + } + r->wayland.topmost_parent = topmost_parent; } r->wayland.type = MWLL_WAYLAND_SUBLEVEL; @@ -571,8 +584,8 @@ static void setup_sublevel(MwLL parent, MwLL r, int x, int y) { setup_callbacks(&r->wayland); - r->wayland.registry = wl_display_get_registry(topmost_parent->wayland.display); - r->wayland.display = topmost_parent->wayland.display; + r->wayland.registry = wl_display_get_registry(r->wayland.topmost_parent->wayland.display); + r->wayland.display = r->wayland.topmost_parent->wayland.display; wl_registry_add_listener(r->wayland.registry, &r->wayland.registry_listener, r); if(wl_display_roundtrip(r->wayland.display) == -1) { @@ -597,9 +610,9 @@ static void setup_sublevel(MwLL parent, MwLL r, int x, int y) { wl_surface_damage(parent->wayland.surface, 0, 0, parent->wayland.ww, parent->wayland.wh); - egl_resetup(topmost_parent); - MwLLDispatch(topmost_parent, draw, NULL); - recursive_draw(topmost_parent); + egl_resetup(r->wayland.topmost_parent); + MwLLDispatch(r->wayland.topmost_parent, draw, NULL); + recursive_draw(r->wayland.topmost_parent); } static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { @@ -628,6 +641,7 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { r->wayland.cooldown_timer = 0; r->wayland.has_set_xy = MwFALSE; + r->wayland.resize_counter = 0; r->wayland.force_redraw = MwFALSE; r->wayland.subwidgets = NULL; @@ -656,17 +670,11 @@ static void MwLLGetXYWHImpl(MwLL handle, int* x, int* y, unsigned int* w, unsign static void MwLLSetXYImpl(MwLL handle, int x, int y) { if(handle->wayland.type != MWLL_WAYLAND_TOPLEVEL) { - MwLL topmost_parent = handle->wayland.parent; - - while(topmost_parent->wayland.type != MWLL_WAYLAND_TOPLEVEL) { - topmost_parent = topmost_parent->wayland.parent; - } - handle->wayland.x = x; handle->wayland.y = y; if(handle->wayland.has_set_xy) { - timed_redraw_by_epoch(topmost_parent, 25); - recursive_draw(topmost_parent); + timed_redraw_by_epoch(handle->wayland.topmost_parent, 25); + recursive_draw(handle->wayland.topmost_parent); } else if(x != 0 && y != 0) { handle->wayland.has_set_xy = MwTRUE; } @@ -676,23 +684,18 @@ static void MwLLSetXYImpl(MwLL handle, int x, int y) { static void MwLLSetWHImpl(MwLL handle, int w, int h) { /* Prevent an integer underflow when the w/h is too low */ if((w < 10 || h < 10)) { - handle->wayland.ww = 10; - handle->wayland.wh = 10; + handle->wayland.ww = handle->wayland.lw = 10; + handle->wayland.wh = handle->wayland.lh = 10; return; } - handle->wayland.ww = w; - handle->wayland.wh = h; + handle->wayland.ww = handle->wayland.lw = w; + handle->wayland.wh = handle->wayland.lh = h; if(handle->wayland.type == MWLL_WAYLAND_TOPLEVEL) { xdg_surface_set_window_geometry(handle->wayland.toplevel->xdg_surface, 0, 0, handle->wayland.ww, handle->wayland.wh); } else { - MwLL topmost_parent = handle->wayland.parent; - - while(topmost_parent->wayland.type != MWLL_WAYLAND_TOPLEVEL) { - topmost_parent = topmost_parent->wayland.parent; - } - timed_redraw_by_epoch(topmost_parent, 25); - recursive_draw(topmost_parent); + timed_redraw_by_epoch(handle->wayland.topmost_parent, 25); + recursive_draw(handle->wayland.topmost_parent); } }