Repository navigation
refactor: replace private access hacks with accessor pattern - #336
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
There was a problem hiding this comment.
Pull request overview
This PR replaces widespread #define private/protected public access hacks with a template-based “private accessor” pattern (explicit-instantiation trick) and updates build plumbing/CI to support the new header usage across XCB/Wayland codepaths.
Changes:
- Introduce
src/util/dprivateaccessor_p.hand migrate multiple call sites toD_PRIVATE_MEMBER/D_PRIVATE_CALLaccessors. - Remove
private/protectedmacro hacks from XCB/Wayland sources and adjust a few call sites to use public accessors where available. - Add CI workflows to build in Deepin (crimson) and Arch Linux containers; update CMake include paths to expose
src/headers where needed.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| xcb/xcbnativeeventfilter.cpp | Replace private member access with accessor tags/calls for QXcb connection internals. |
| xcb/xcb.cmake | Add ${CMAKE_SOURCE_DIR}/src include path for XCB build to find the new util header. |
| xcb/windoweventhook.cpp | Replace private/protected hacks with accessor tags for drag/keyboard internals and adjust usage sites. |
| xcb/dxcbwmsupport.cpp | Update compositing state write to use private member accessor. |
| xcb/dplatformwindowhook.h | Remove private macro hack from header include path usage. |
| xcb/dplatformwindowhelper.h | Remove private macro hack from header include path usage. |
| xcb/dplatformintegration.h | Remove private protected macro hack around Qt private header include. |
| xcb/dplatformintegration.cpp | Introduce multiple private accessor tags and migrate internal field accesses; adjust QGuiApplicationPrivate access. |
| xcb/dplatformbackingstorehelper.cpp | Replace backing store private member access with accessor. |
| xcb/dplatformbackingstore.h | Remove private macro hack around platform backing store include. |
| xcb/dnotitlebarwindowhelper.cpp | Replace protected QWindow::event hooking with accessor-based member pointer retrieval. |
| xcb/dforeignplatformwindow.h | Remove private macro hack around qxcbwindow include. |
| wayland/wayland-shell/main.cpp | Replace private access hack with accessor-based call to create shell integration. |
| wayland/wayland-shell/dwaylandshellmanager.h | Remove private macro hack around QtWayland private header includes. |
| wayland/wayland-shell/dwaylandshellmanager.cpp | Remove protected macro hack around QWindow include. |
| wayland/dwayland/dwaylandinterfacehook.cpp | Remove private macro hack around QtWayland native interface include. |
| wayland/dwayland/dwaylandintegration.cpp | Replace private field accesses for cursor theme internals with accessor tags/calls. |
| wayland/dwayland/dnotitlebarwindowhelper_wl.cpp | Replace protected QWindow::event hooking with accessor-based member pointer retrieval. |
| tests/src/ut_ddesktopinputselectioncontrol.cpp | Update unit test private-member access to use new accessor macros. |
| src/util/dprivateaccessor_p.h | Add the accessor pattern implementation and macro API used throughout the PR. |
| src/src.cmake | Register the new util header in the global headers list. |
| src/dnativesettings.h | Remove protected macro hack around qobject private header include. |
| src/dnativesettings.cpp | Replace call to QObject private method with accessor-based member pointer call. |
| .github/workflows/qt5platform-plugins-deepin-build.yml | Add Deepin crimson container build workflow producing deb artifacts. |
| .github/workflows/qt5platform-plugins-archlinux-build.yml | Add Arch Linux container build workflow producing install zip artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| namespace dtk_private_detail { | ||
| template<typename Tag> | ||
| inline constexpr typename Tag::MemberPtr access(Tag t) noexcept { return get(t); } | ||
|
|
||
| // For auto-type tags (D_DECLARE_AUTO_PRIVATE_MEMBER_TAG) that don't define MemberPtr. | ||
| template<typename Tag> | ||
| inline auto access_auto(Tag t) noexcept -> decltype(get(t)) { return get(t); } |
| #define D_DECLARE_AUTO_PRIVATE_MEMBER_TAG(TagName, ClassName, Member) \ | ||
| struct TagName { \ | ||
| friend auto get(TagName) noexcept; \ | ||
| }; \ | ||
| template<auto Ptr> \ | ||
| struct TagName##Impl { \ | ||
| friend auto get(TagName) noexcept { return Ptr; } \ | ||
| }; \ | ||
| template struct TagName##Impl<&ClassName::Member> |
| #include "dnotitlebarwindowhelper.h" | ||
| #include "util/dprivateaccessor_p.h" | ||
|
|
||
| D_DECLARE_PRIVATE_METHOD(QWindow_event, QWindow, event, bool, QEvent *); |
| #include <QWindow> | ||
| #undef protected | ||
| #include "util/dprivateaccessor_p.h" | ||
| D_DECLARE_PRIVATE_METHOD(QWindow_event, QWindow, event, bool, QEvent *); |
| D_DECLARE_PRIVATE_MEMBER(QXcbCursor_m_gtkCursorThemeInitialized, QXcbCursor, m_gtkCursorThemeInitialized, bool); | ||
| D_DECLARE_PRIVATE_MEMBER(QXcbCursor_m_callbackForPropertyRegistered, QXcbCursor, m_callbackForPropertyRegistered, bool); |
Replace all '#define private/protected public' access hacks with a proper C++ template-based private accessor pattern based on [temp.explicit]. Add src/util/dprivateaccessor_p.h with: - D_DECLARE_PRIVATE_MEMBER / D_DECLARE_PRIVATE_METHOD macros - D_DECLARE_AUTO_PRIVATE_MEMBER_TAG for members with private types - D_PRIVATE_MEMBER / D_PRIVATE_CALL helper macros
The KF5Wayland cmake module is provided by kwayland5, not kwayland (which is the KF6/Qt6 version). Fix the package name so that find_package(KF5Wayland REQUIRED) in wayland-shell.cmake succeeds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tar is always available in base system, no pacman install needed Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove pipe from cmake --install to properly propagate exit code. Add directory listing before tar to diagnose missing install dir. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Without set -o pipefail, cmake failures in piped commands are masked. This ensures the step fails properly if cmake configure or build fails. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
deepin pr auto review这份代码提交的核心目的是消除代码中广泛存在的 以下是对本次代码审查的详细意见,分为语法逻辑、代码质量、代码性能和代码安全四个方面: 一、 语法逻辑
二、 代码质量
三、 代码性能
四、 代码安全
总结这是一次非常出色的重构,从根本上解决了一直以来 Qt 私有 API 访问的脏乱差问题。代码逻辑严谨,对 C++ 模板机制的运用非常专业。只需注意宏展开的命名空间陷阱、C++17 |
Replace all '#define private/protected public' access hacks with a proper C++ template-based private accessor pattern based on [temp.explicit].
Add src/util/dprivateaccessor_p.h with: