feat: expose a method to move XWayland window position relative to wl_surface#683
feat: expose a method to move XWayland window position relative to wl_surface#683zccrs merged 1 commit intolinuxdeepin:masterfrom
Conversation
Reviewer's GuideAdds a Helper API and Wayland DDE shell protocol entry point to move an XWayland window to a position relative to a given wl_surface, and wires it to return a completion callback to the client. Sequence diagram for moving an XWayland surface relative to a wl_surfacesequenceDiagram
actor DDEClient
participant WlClient as wl_client
participant DDEShellMgr as DDEShellManagerInterfaceV1Private
participant Helper as Helper
participant RootContainer as RootSurfaceContainer
participant Wrapper as SurfaceWrapper
participant XWaylandSurf as qw_xwayland_surface
DDEClient->>WlClient: treeland_dde_shell_manager_v1_move_xwayland_surface(callback_id, wid, anchor, dx, dy)
WlClient->>DDEShellMgr: treeland_dde_shell_manager_v1_move_xwayland_surface(resource, callback, wid, anchor, dx, dy)
DDEShellMgr->>DDEShellMgr: WSurface::fromHandle(qw_surface::from_resource(anchor))
DDEShellMgr->>Helper: moveXWaylandSurface(wid, wsurface, dx, dy)
activate Helper
Helper->>RootContainer: rootSurfaceContainer()->getSurface(anchor)
RootContainer-->>Helper: SurfaceWrapper for anchor
Helper->>Helper: pos = wrapper->position().toPoint()
loop iterate_root_surfaces
Helper->>RootContainer: rootSurfaceContainer()->surfaces()
RootContainer-->>Helper: SurfaceWrapper list
Helper->>Wrapper: type()
alt wrapper_is_XWayland
Helper->>Wrapper: surface()->handle()->handle()
Helper->>XWaylandSurf: try_from_wlr_surface(wlr_surface)
alt window_id_matches_wid
Helper-->>Helper: select surface
Helper-->>Helper: break
end
end
end
alt surface_found
Helper->>XWaylandSurf: configure(clamped_x, clamped_y, width, height)
Helper-->>DDEShellMgr: true
else surface_not_found
Helper-->>DDEShellMgr: false
end
deactivate Helper
DDEShellMgr->>DDEShellMgr: wl_resource_create(callback)
DDEShellMgr->>DDEClient: wl_callback_send_done(ok)
DDEShellMgr->>DDEShellMgr: wl_resource_destroy(callback)
Updated class diagram for Helper XWayland movement and DDE shell managerclassDiagram
class Helper {
+static Helper* instance()
+bool moveXWaylandSurface(uint wid, WSurface* anchor, int dx, int dy)
-RootSurfaceContainer* m_rootSurfaceContainer
}
class RootSurfaceContainer {
+SurfaceWrapper* getSurface(WSurface* surface)
+QList~SurfaceWrapper*~ surfaces()
}
class SurfaceWrapper {
<<enumeration>> Type
+Type type()
+WSurface* surface()
+QPointF position()
Type XWayland
}
class qw_xwayland_surface {
+static qw_xwayland_surface* try_from_wlr_surface(wlr_surface* surface)
+void configure(int x, int y, int width, int height)
+qw_xwayland_surface_handle* handle()
}
class qw_xwayland_surface_handle {
+int16_t width
+int16_t height
+xcb_window_t window_id
}
class DDEShellManagerInterfaceV1Private {
+void treeland_dde_shell_manager_v1_move_xwayland_surface(Resource* resource, uint32_t callback, uint32_t wid, wl_resource* anchor, int32_t dx, int32_t dy)
}
class WSurface {
+static WSurface* fromHandle(qw_surface* surface)
}
class qw_surface {
+static qw_surface* from_resource(wl_resource* resource)
}
Helper --> RootSurfaceContainer : uses
RootSurfaceContainer --> SurfaceWrapper : returns
SurfaceWrapper --> qw_xwayland_surface : converted via wlr_surface
qw_xwayland_surface --> qw_xwayland_surface_handle : has
DDEShellManagerInterfaceV1Private --> Helper : calls_moveXWaylandSurface
DDEShellManagerInterfaceV1Private --> WSurface : uses_fromHandle
WSurface --> qw_surface : constructed_from
qw_surface --> wl_resource : wraps
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Related with linuxdeepin/treeland-protocols#36 |
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In Helper::moveXWaylandSurface, several pointer dereferences assume non-null (e.g., m_rootSurfaceContainer->getSurface(anchor), wrapper->surface()->handle()->handle(), xwaylandSurface->handle()); consider adding null checks so that a missing or mismatched surface can’t cause a crash.
- treeland_dde_shell_manager_v1_move_xwayland_surface assumes the passed wl_resource* anchor is valid and corresponds to a WSurface; adding validation (including handling a null/invalid resource and fromHandle() failures) would make the protocol handler more robust against misbehaving clients.
- The wl_callback used to return the status sends the raw ok value as the done timestamp; if the protocol intends this as a status code rather than a time, consider documenting this or using a more conventional success/error signaling mechanism to avoid confusion with standard wl_callback semantics.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In Helper::moveXWaylandSurface, several pointer dereferences assume non-null (e.g., m_rootSurfaceContainer->getSurface(anchor), wrapper->surface()->handle()->handle(), xwaylandSurface->handle()); consider adding null checks so that a missing or mismatched surface can’t cause a crash.
- treeland_dde_shell_manager_v1_move_xwayland_surface assumes the passed wl_resource* anchor is valid and corresponds to a WSurface; adding validation (including handling a null/invalid resource and fromHandle() failures) would make the protocol handler more robust against misbehaving clients.
- The wl_callback used to return the status sends the raw ok value as the done timestamp; if the protocol intends this as a status code rather than a time, consider documenting this or using a more conventional success/error signaling mechanism to avoid confusion with standard wl_callback semantics.
## Individual Comments
### Comment 1
<location> `src/seat/helper.cpp:2902` </location>
<code_context>
+ */
+bool Helper::moveXWaylandSurface(uint wid, WSurface *anchor, int dx, int dy)
+{
+ QPoint pos = m_rootSurfaceContainer->getSurface(anchor)->position().toPoint();
+ qw_xwayland_surface *surface = nullptr;
+ for (SurfaceWrapper *wrapper : std::as_const(rootSurfaceContainer()->surfaces())) {
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against a missing surface for the given anchor to avoid potential null dereference.
If `getSurface(anchor)` can return `nullptr` (e.g. when the anchor is destroyed or not in `m_rootSurfaceContainer`), this will dereference a null pointer and crash. Store the result of `getSurface(anchor)` in a local variable, check it for null, and return early or log instead of calling `position()` unconditionally.
</issue_to_address>
### Comment 2
<location> `src/seat/helper.cpp:2907-2908` </location>
<code_context>
+ for (SurfaceWrapper *wrapper : std::as_const(rootSurfaceContainer()->surfaces())) {
+ if (wrapper->type() == SurfaceWrapper::Type::XWayland) {
+ wlr_surface *wlrSurface = wrapper->surface()->handle()->handle();
+ qw_xwayland_surface *xwaylandSurface = qw_xwayland_surface::try_from_wlr_surface(wlrSurface);
+ if (xwaylandSurface->handle()->window_id == static_cast<xcb_window_t>(wid)) {
+ surface = xwaylandSurface;
+ break;
</code_context>
<issue_to_address>
**issue (bug_risk):** Check the result of `try_from_wlr_surface` before dereferencing its handle.
If `try_from_wlr_surface` returns `nullptr`, dereferencing `xwaylandSurface->handle()` will crash. Add a null check (e.g. `if (!xwaylandSurface) continue;`) before accessing `window_id`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Pull request overview
This pull request adds functionality to move XWayland windows to positions relative to Wayland surfaces, as required by the DDE (Deepin Desktop Environment) project.
Changes:
- Adds
Helper::moveXWaylandSurfaceAPI that repositions an XWayland window based on an anchor WSurface and x/y offset - Extends the
treeland_dde_shell_manager_v1protocol with amove_xwayland_surfacerequest that invokes the helper and returns completion status via a wl_callback
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/seat/helper.h | Adds declaration for the new moveXWaylandSurface method |
| src/seat/helper.cpp | Implements the logic to find XWayland surfaces by window ID and reposition them relative to an anchor surface |
| src/modules/dde-shell/ddeshellmanagerinterfacev1.cpp | Adds protocol handler for the new move_xwayland_surface request and returns status via wl_callback |
|
TAG Bot New tag: 0.8.1 |
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
…_surface For the requirement of DDE.
c5328f7 to
4663444
Compare
1d0a521 to
9ea3f44
Compare
d676c1c to
8b97b93
Compare
c2b3b59 to
9cb7f0b
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: calsys456, zccrs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
For the requirement of DDE.
Summary by Sourcery
Expose a compositor helper and DDE shell protocol request to move an XWayland window relative to a given Wayland surface.
New Features: