-
Notifications
You must be signed in to change notification settings - Fork 55
fix: improve window identity and tracking order #1310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideEnhance window identity uniqueness by incorporating desktop file IDs into identity generation and adjust the window tracking sequence by emitting the addition signal before actual tracking to avoid race conditions. Sequence diagram for updated window tracking order in X11WindowMonitorsequenceDiagram
participant X11WindowMonitor
participant "AbstractWindowMonitor"
participant Window
X11WindowMonitor->>Window: Create window object
X11WindowMonitor->>"AbstractWindowMonitor": Emit windowAdded signal
X11WindowMonitor->>Window: trackWindow(window)
Class diagram for updated window identity generation in X11WindowclassDiagram
class X11Window {
+QStringList identity()
-m_identity: QStringList
-m_windowID: xcb_window_t
+pid(): int
+getAppItem(): AppItem*
}
class AppItem {
+desktopfileID(): QString
}
X11Window --> AppItem: uses
X11Window : identity() now appends getAppItem()->desktopfileID()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deepin pr auto review我来对这段代码进行审查,从语法逻辑、代码质量、性能和安全几个方面进行分析:
改进建议:
QStringList X11Window::identity()
{
if (m_identity.isEmpty()) {
m_identity = X11->getWindowWMClass(m_windowID);
if (auto appItem = getAppItem()) { // 添加空指针检查
m_identity.append(appItem->desktopfileID());
}
m_identity.append(QString::number(pid()));
}
return m_identity;
}
void X11WindowMonitor::onWindowMapped(xcb_window_t xcb_window)
{
auto window = std::make_unique<X11Window>(xcb_window);
if (!window) {
return;
}
uint32_t value_list[] = { XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_VISIBILITY_CHANGE};
xcb_change_window_attributes(X11->getXcbConnection(), xcb_window, XCB_CW_EVENT_MASK, value_list);
// 先添加到跟踪列表,确保不会丢失
trackWindow(window.get());
// 然后发送信号
Q_EMIT AbstractWindowMonitor::windowAdded(static_cast<QPointer<AbstractWindow>>(window.get()));
}
void X11WindowMonitor::onWindowMapped(xcb_window_t xcb_window)
{
try {
auto window = std::make_unique<X11Window>(xcb_window);
if (!window) {
qWarning() << "Failed to create X11Window for xcb_window:" << xcb_window;
return;
}
uint32_t value_list[] = { XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_VISIBILITY_CHANGE};
xcb_change_window_attributes(X11->getXcbConnection(), xcb_window, XCB_CW_EVENT_MASK, value_list);
trackWindow(window.get());
Q_EMIT AbstractWindowMonitor::windowAdded(static_cast<QPointer<AbstractWindow>>(window.get()));
} catch (const std::exception& e) {
qCritical() << "Error in onWindowMapped:" << e.what();
}
}这些改进可以提高代码的健壮性和可维护性,同时保持原有功能不变。 |
| { | ||
| if (m_identity.isEmpty()) { | ||
| m_identity = X11->getWindowWMClass(m_windowID); | ||
| m_identity.append(getAppItem()->desktopfileID()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
判断下是否为空吧,加个日志,
加个更新identity接口是不是更好,第一次就缓存,之后可能有问题,
1. Add desktop file ID to window identity for better uniqueness 2. Include AppItem desktopfileID in identity generation 3. Change window tracking order to emit signal before tracking 4. This prevents potential race conditions in window management fix: 改进窗口标识和跟踪顺序 1. 添加桌面文件ID到窗口标识以提高唯一性 2. 在身份生成中包含AppItem的desktopfileID 3. 更改窗口跟踪顺序,在跟踪前发出信号 4. 这可以防止窗口管理中的潜在竞争条件 PMS: BUG-335801
d27c1b1 to
be25a00
Compare
|
@wjyrich: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, wjyrich 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 |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tsic404 如果要加 am 应用识别的话,合理的加法是加到哪里?现在已经有一个来自 dde-apps 的 DesktopIdRole 了,是建议塞一个新 role 吗(比如... WindowMatchedDesktopId 什么的)?
| xcb_change_window_attributes(X11->getXcbConnection(), xcb_window, XCB_CW_EVENT_MASK, value_list); | ||
| trackWindow(window.get()); | ||
| Q_EMIT AbstractWindowMonitor::windowAdded(static_cast<QPointer<AbstractWindow>>(window.get())); | ||
| trackWindow(window.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个顺序应该不能调,先track后发信号,不然可能信号接收到后尝试获取会拿不到(size不对)导致崩溃。
| if (auto appItem = getAppItem()) { | ||
| m_identity.append(appItem->desktopfileID()); | ||
| } else { | ||
| qCWarning(x11windowLog) << "identify not found appitem." << id(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppItem 是要废弃的,应当规避使用。
fix: 改进窗口标识和跟踪顺序
PMS: BUG-335801
Summary by Sourcery
Improve window identity uniqueness by appending desktop file identifiers and adjust the window tracking order to emit signals before tracking to avoid potential race conditions
Enhancements: