From 96b5f053e3b1a176252a685ed4bfc06482694611 Mon Sep 17 00:00:00 2001 From: guolin Date: Tue, 29 Sep 2026 17:29:03 +0800 Subject: [PATCH] refactor(modules): drop redundant wl_resource type checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Remove the unreachable strcmp(wl_resource_get_class()) checks in the decoration, active-notify, region-watch and xwindow-control request handlers. 2. libwayland already validates object arguments before a handler runs: non-nullable object args are never NULL, and unknown ids or type mismatches fail dispatch with WL_DISPLAY_ERROR_INVALID_METHOD. 3. Drop the now-unused / includes; keep the real checks (cross-client ownership, inert resources, missing wrappers). Log: Remove redundant wl_resource type checks already done by libwayland dispatch Influence: 1. Build treeland and confirm it compiles and links. 2. Start treeland, run a client that drives decoration, active-notify, region-watch and xwindow-control requests, and confirm normal behavior. 3. Send a request with an invalid object id from a client and verify the compositor reports a protocol error instead of crashing. refactor(modules): 清理冗余的 wl_resource 类型检查 1. 删除 decoration、active-notify、region-watch、xwindow-control 请求处理函数中不可达的 strcmp(wl_resource_get_class()) 类型检查。 2. libwayland 分发层在调用处理函数前已完成校验:不可空对象参数不会为 NULL,未知对象 id 或类型不匹配会以 WL_DISPLAY_ERROR_INVALID_METHOD 分发失败。 3. 顺带删除不再使用的 / 头文件;保留跨客户端归属、inert resource 判空与缺失包装对象等必要检查。 Log: 清理请求处理函数中冗余的 wl_resource 类型检查,libwayland 分发层已校验对象类型 Influence: 1. 编译 treeland 确认通过。 2. 启动 treeland,运行客户端遍历 decoration、active-notify、region-watch、xwindow-control 相关请求,确认功能正常。 3. 客户端传入非法对象 id 时,确认合成器返回协议错误而非崩溃。 PMS: TASK-390751 Multica Issue: WM-558 --- .../activenotifymanagerinterfacev1.cpp | 7 ------- .../decoration/decorationmanagerinterfacev1.cpp | 16 ---------------- .../regionwatchmanagerinterfacev1.cpp | 14 -------------- .../xwindowcontrolinterfacev1.cpp | 7 ++----- 4 files changed, 2 insertions(+), 42 deletions(-) diff --git a/src/modules/active-notify/activenotifymanagerinterfacev1.cpp b/src/modules/active-notify/activenotifymanagerinterfacev1.cpp index 2fb3b5cd7..6bcae59b8 100644 --- a/src/modules/active-notify/activenotifymanagerinterfacev1.cpp +++ b/src/modules/active-notify/activenotifymanagerinterfacev1.cpp @@ -5,8 +5,6 @@ #include "qwayland-server-treeland-active-notify-unstable-v1.h" -#include - static QList s_notifies; struct TreelandActiveNotifyManagerInterfaceV1Private @@ -46,11 +44,6 @@ void TreelandActiveNotifyManagerInterfaceV1Private::get_active_notify(Resource * uint32_t id, struct ::wl_resource *seat) { - if (!seat || strcmp(wl_resource_get_class(seat), "wl_seat") != 0) { - wl_resource_post_error(resource->handle, 0, "seat resource is NULL or not a wl_seat!"); - return; - } - struct wlr_seat_client *seat_client = wlr_seat_client_from_resource(seat); if (!seat_client) { wl_resource_post_error(resource->handle, 0, "seat resource is inert!"); diff --git a/src/modules/decoration/decorationmanagerinterfacev1.cpp b/src/modules/decoration/decorationmanagerinterfacev1.cpp index 063a490f3..a1a4f025e 100644 --- a/src/modules/decoration/decorationmanagerinterfacev1.cpp +++ b/src/modules/decoration/decorationmanagerinterfacev1.cpp @@ -13,8 +13,6 @@ #include -#include - // --------------------------------------------------------------------------- // Helpers // --------------------------------------------------------------------------- @@ -309,13 +307,6 @@ void DecorationManagerInterfaceV1Private::get_decoration_context(Resource *resou uint32_t id, struct ::wl_resource *surface) { - if (!surface) { - wl_resource_post_error(resource->handle, - TREELAND_DECORATION_MANAGER_V1_ERROR_INVALID_SURFACE, - "surface resource is NULL!"); - return; - } - // The surface must be owned by the requesting client. if (wl_resource_get_client(surface) != resource->client()) { wl_resource_post_error(resource->handle, @@ -324,13 +315,6 @@ void DecorationManagerInterfaceV1Private::get_decoration_context(Resource *resou return; } - if (strcmp(wl_resource_get_class(surface), "wl_surface") != 0) { - wl_resource_post_error(resource->handle, - TREELAND_DECORATION_MANAGER_V1_ERROR_INVALID_SURFACE, - "invalid surface!"); - return; - } - auto *wlrSurface = wlr_surface_from_resource(surface); // At most one active decoration context per surface. diff --git a/src/modules/region-watch/regionwatchmanagerinterfacev1.cpp b/src/modules/region-watch/regionwatchmanagerinterfacev1.cpp index 758cf3be0..b9ca75133 100644 --- a/src/modules/region-watch/regionwatchmanagerinterfacev1.cpp +++ b/src/modules/region-watch/regionwatchmanagerinterfacev1.cpp @@ -9,8 +9,6 @@ #include -#include - #include #include @@ -120,18 +118,6 @@ void RegionWatchV1Private::set_region(Resource *resource, return; } - // wlr_output_from_resource() asserts that the resource is a genuine - // wl_output; a client may pass any live object id (or an inert one), - // which would abort the compositor before the checks below. Validate - // the object class first and route invalid references to the error path. - if (!outputResource - || strcmp(wl_resource_get_class(outputResource), wl_output_interface.name) != 0) { - wl_resource_post_error(resource->handle, - InvalidAnchor, - "set_region requires a valid wl_output resource"); - return; - } - struct wlr_output *output = wlr_output_from_resource(outputResource); auto *wOutput = output ? WOutput::fromHandle(output) : nullptr; if (!wOutput) { diff --git a/src/modules/xwindow-control/xwindowcontrolinterfacev1.cpp b/src/modules/xwindow-control/xwindowcontrolinterfacev1.cpp index 14227636b..1e2dc69ab 100644 --- a/src/modules/xwindow-control/xwindowcontrolinterfacev1.cpp +++ b/src/modules/xwindow-control/xwindowcontrolinterfacev1.cpp @@ -11,8 +11,6 @@ #include -#include - class XWindowControlInterfaceV1Private : public QtWaylandServer::treeland_xwindow_control_v1 { public: @@ -50,9 +48,8 @@ void XWindowControlInterfaceV1Private::set_xwindow_position_relative(Resource *r wl_fixed_t dx, wl_fixed_t dy) { - WSurface *wsurface = nullptr; - if (anchor && strcmp(wl_resource_get_class(anchor), "wl_surface") == 0) - wsurface = WSurface::fromHandle(wlr_surface_from_resource(anchor)); + // libwayland dispatch already guarantees a genuine wl_surface. + auto *wsurface = WSurface::fromHandle(wlr_surface_from_resource(anchor)); uint32_t ok = (wsurface && Helper::instance()->setXWindowPositionRelative(wid, wsurface, dx, dy)) ? 0 : 1; wl_resource *cb = wl_resource_create(resource->client(), &wl_callback_interface, 1, callback); if (!cb) {