From 876c233ed33ae076632e6f623ef3766a59855c2f Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sun, 27 Jul 2025 09:47:34 +0800 Subject: [PATCH] opt: optimize handle xdg commit request --- src/maomao.c | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/src/maomao.c b/src/maomao.c index 157362f..78d50ae 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -2103,9 +2103,6 @@ void commitlayersurfacenotify(struct wl_listener *listener, void *data) { void commitnotify(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, commit); - if (!c->surface.xdg->initialized) - return; - if (c->surface.xdg->initial_commit) { // xdg client will first enter this before mapnotify applyrules(c); @@ -2114,12 +2111,18 @@ void commitnotify(struct wl_listener *listener, void *data) { } setmon(c, NULL, 0, true); /* Make sure to reapply rules in mapnotify() */ - wlr_xdg_toplevel_set_wm_capabilities( - c->surface.xdg->toplevel, - WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN); - wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, 0, 0); - client_set_tiled(c, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | - WLR_EDGE_RIGHT); + + uint32_t serial = wlr_xdg_surface_schedule_configure(c->surface.xdg); + if (serial > 0) { + c->configure_serial = serial; + } + + uint32_t wm_caps = WLR_XDG_TOPLEVEL_WM_CAPABILITIES_WINDOW_MENU | + WLR_XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE | + WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN | + WLR_XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE; + wlr_xdg_toplevel_set_wm_capabilities(c->surface.xdg->toplevel, wm_caps); + if (c->decoration) requestdecorationmode(&c->set_decoration_mode, c->decoration); return; @@ -2132,28 +2135,14 @@ void commitnotify(struct wl_listener *listener, void *data) { if (c == grabc) return; - if (client_is_unmanaged(c)) - return; + struct wlr_box *new_geo = &c->surface.xdg->geometry; + bool need_resize = new_geo->width != c->geom.width - 2 * c->bw || + new_geo->height != c->geom.height - 2 * c->bw || + new_geo->x != 0 || new_geo->y != 0; - unsigned int serial = c->surface.xdg->current.configure_serial; - if (!c->dirty || serial < c->configure_serial) - return; - - struct wlr_box geometry; - client_get_geometry(c, &geometry); - - if (geometry.width == c->geom.width - 2 * c->bw && - geometry.height == c->geom.height - 2 * c->bw) { - c->dirty = false; - return; + if (need_resize) { + resize(c, c->geom, 0); } - - if (geometry.width == c->animation.current.width - 2 * c->bw && - geometry.height == c->animation.current.height - 2 * c->bw) { - return; - } - - resize(c, c->geom, 0); } void destroydecoration(struct wl_listener *listener, void *data) {