Repository navigation
feat(dock): approve a window for mirror mode from its preview - #1851
justforlxz wants to merge 1 commit into
Conversation
The mirror mode switch decides whether the other outputs show the desktop, and KWin lets the user override that decision per window. The dock now offers it where the window itself is: the preview that pops up when the task icon is hovered carries a lock button next to the close button of every approvable window. The approval is read and written through KWin's D-Bus interface, and the button reflects the state KWin publishes, so the same window shows the same state in every preview and in every panel. The button belongs to the item it is drawn on: it carries the window id it writes, so a click can never be applied to another window, and it is refreshed from the window lists and the mode property rather than from the click, which keeps a slow or refused write from leaving a state the user did not ask for. The policy that maps the mode and the listed flag to an approval is a pure function in mirrormodepolicy.h, covered by a unit test, because KWin and the dock have to agree on it: what the button shows is what the window does. PMS: TASK-394957
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: justforlxz 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 |
|
Reviewer's GuideData structuresDefine the mirror-mode policy values and pure helpers that map KWin’s listed flag to approval state.
APIAdd the asynchronous KWin mirror-mode client that reads the published policy and window lists and requests per-window approval changes.
Uses of the APIWire the mirror-mode client into the X11 preview container and refresh its state as window lists or the mode property change.
UIAdd a per-preview lock button that reflects policy-derived approval and toggles the listed flag for the preview’s window.
ConfigurationInclude the mirror-mode client and policy files in the X11 task manager build.
TestsTest the root-property mapping, approvable policies, approval semantics, and listed-flag round trips.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 7 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="panels/dock/taskmanager/mirrormodeclient.cpp" line_range="44" />
<code_context>
+
+ const xcb_get_property_cookie_t cookie =
+ xcb_get_property(connection, false, utils->getRootWindow(), atom, XCB_ATOM_CARDINAL, 0, 1);
+ std::unique_ptr<xcb_get_property_reply_t> reply(xcb_get_property_reply(connection, cookie, nullptr));
+ if (!reply || reply->type == XCB_ATOM_NONE || reply->format != 32
+ || xcb_get_property_value_length(reply.get()) < static_cast<int>(sizeof(uint32_t))) {
</code_context>
<issue_to_address>
**Preview refresh mismatches allocator**
When `fetchPolicy()` receives a non-null XCB reply, `std::unique_ptr` uses its default `delete` deleter for the reply returned by XCB, which must be released with `free`; destroying the reply therefore invokes mismatched deallocation and undefined behavior during policy refreshes, potentially corrupting the heap or crashing the dock.
Give the `unique_ptr` a deleter that calls `free`, or use an equivalent XCB-aware RAII wrapper.
</issue_to_address>
### Comment 2
<location path="panels/dock/taskmanager/mirrormodeclient.cpp" line_range="42-44" />
<code_context>
+ return MirrorModePolicy::Off;
+ }
+
+ const xcb_get_property_cookie_t cookie =
+ xcb_get_property(connection, false, utils->getRootWindow(), atom, XCB_ATOM_CARDINAL, 0, 1);
+ std::unique_ptr<xcb_get_property_reply_t> reply(xcb_get_property_reply(connection, cookie, nullptr));
+ if (!reply || reply->type == XCB_ATOM_NONE || reply->format != 32
+ || xcb_get_property_value_length(reply.get()) < static_cast<int>(sizeof(uint32_t))) {
</code_context>
<issue_to_address>
**Dock freezes on X replies**
When the X server is slow or stops responding to the property query, `refresh()` calls `fetchPolicy()` on the UI thread, where `xcb_get_property_reply()` waits for the server response and stalls painting and input until it responds or the connection fails.
Make the property query nonblocking on the UI thread and handle its reply asynchronously.
</issue_to_address>
### Comment 3
<location path="panels/dock/taskmanager/x11preview.cpp" line_range="409-410" />
<code_context>
+ mirrorButton->setPalette(palette);
+ mirrorButton->setIconSize(QSize(16, 16));
+ mirrorButton->setFixedSize(PREVIEW_TITLE_HEIGHT, PREVIEW_TITLE_HEIGHT);
+ mirrorButton->move(option.rect.topRight()
+ - QPoint(PREVIEW_TITLE_HEIGHT * 2 + MIRROR_BUTTON_INSET * 2, -5));
+ updateMirrorButton(mirrorButton, m_parent->mirrorModeClient());
+
</code_context>
<issue_to_address>
**Approval button targets wrong row**
When preview rows are inserted, removed, or otherwise move while the preview is open, `QListView` repositions the persistent `closeButton` editor but not the sibling `mirrorButton`, which is positioned only once and retains its original window ID; the lock appears beside a different row and toggles the wrong window.
Keep the mirror button positioned with its row whenever the view updates the persistent editor’s geometry.
</issue_to_address>
### Comment 4
<location path="panels/dock/taskmanager/mirrormodeclient.cpp" line_range="79-86" />
<code_context>
+
+void MirrorModeClient::refresh()
+{
+ m_policy = fetchPolicy();
+
+ // Supersede whatever is still on the wire: only this generation's answers are
+ // applied, and changed() is emitted when both lists are in.
+ const quint64 generation = ++m_generation;
+ m_pendingLists = 0;
+ requestWindowList(QStringLiteral("primaryWindows"), generation);
+ requestWindowList(QStringLiteral("mirrorWindows"), generation);
+}
+
</code_context>
<issue_to_address>
**Clicks combine new policy with old lists**
When the mirror-mode policy changes and the user clicks before both list reads complete, `refresh()` publishes the new policy while retaining the old lists and button state, so the click handler combines the new policy with the old listed flag and submits the action opposite to the state the button shows.
Publish the policy and refreshed lists together, or prevent approval clicks until the lists are refreshed.
Also at `panels/dock/taskmanager/x11preview.cpp:436-442`.
</issue_to_address>
### Comment 5
<location path="panels/dock/taskmanager/mirrormodeclient.cpp" line_range="109-110" />
<code_context>
+ const QDBusMessage reply = call->reply();
+ if (reply.type() != QDBusMessage::ReplyMessage || reply.arguments().isEmpty()) {
+ // Keep the lists read last time: a failed read must not look like
+ // "KWin publishes no windows".
+ qCWarning(mirrorModeLog) << "failed to read" << name << ":" << reply.errorMessage();
+ } else {
+ applyWindowList(name, reply.arguments().constFirst().value<QDBusVariant>().variant().toStringList());
</code_context>
<issue_to_address>
**Failed reads leave stale approval**
When a window-list read fails while the other list succeeds or KWin’s lists have changed, `requestWindowList()` preserves the failed read’s previous value, then emits `changed()` after the reads complete; the preview uses a mixed or stale snapshot for approval controls, and no retry occurs to correct it until another refresh trigger.
Do not expose approval controls from a mixed snapshot; invalidate the failed list and retry or refresh it before publishing the state.
</issue_to_address>
### Comment 6
<location path="panels/dock/taskmanager/mirrormodeclient.cpp" line_range="174" />
<code_context>
+ QString::fromLatin1(kInterface),
+ listed ? QStringLiteral("approveWindow")
+ : QStringLiteral("removeWindow"));
+ message << QVariant::fromValue<qulonglong>(winId);
+
+ m_pendingWrites.insert(winId);
</code_context>
<issue_to_address>
**Approval calls use the wrong integer width**
When KWin exports `approveWindow` and `removeWindow` with a 32-bit window-ID argument, the call marshals `winId` as a 64-bit D-Bus integer, so KWin rejects it with an argument-signature error when `approveWindow` and `removeWindow` take the 32-bit X11 window ID; every approval click then fails.
Send the window ID using the exact integer type declared by KWin's D-Bus interface.
</issue_to_address>
### Comment 7
<location path="panels/dock/taskmanager/mirrormodeclient.cpp" line_range="45-46" />
<code_context>
+ const xcb_get_property_cookie_t cookie =
+ xcb_get_property(connection, false, utils->getRootWindow(), atom, XCB_ATOM_CARDINAL, 0, 1);
+ std::unique_ptr<xcb_get_property_reply_t> reply(xcb_get_property_reply(connection, cookie, nullptr));
+ if (!reply || reply->type == XCB_ATOM_NONE || reply->format != 32
+ || xcb_get_property_value_length(reply.get()) < static_cast<int>(sizeof(uint32_t))) {
+ return MirrorModePolicy::Off;
+ }
</code_context>
<issue_to_address>
**Wrong property types enable controls**
When the root property has a 32-bit non-`CARDINAL` type and its value is 1, 2, or 3, the 32-bit value is interpreted as a mirror policy even though its X property type is not `CARDINAL`; a mismatched property containing a recognized value can expose approval controls with the wrong policy and make the button report or write the wrong state.
Require `reply->type == XCB_ATOM_CARDINAL` before interpreting the property value.
</issue_to_address>|
|
||
| const xcb_get_property_cookie_t cookie = | ||
| xcb_get_property(connection, false, utils->getRootWindow(), atom, XCB_ATOM_CARDINAL, 0, 1); | ||
| std::unique_ptr<xcb_get_property_reply_t> reply(xcb_get_property_reply(connection, cookie, nullptr)); |
There was a problem hiding this comment.
🟡 Medium · Preview refresh mismatches allocator
When fetchPolicy() receives a non-null XCB reply, std::unique_ptr uses its default delete deleter for the reply returned by XCB, which must be released with free; destroying the reply therefore invokes mismatched deallocation and undefined behavior during policy refreshes, potentially corrupting the heap or crashing the dock.
Give the unique_ptr a deleter that calls free, or use an equivalent XCB-aware RAII wrapper.
Prompt for AI agents
In `panels/dock/taskmanager/mirrormodeclient.cpp` at line 44:
**Preview refresh mismatches allocator**
When `fetchPolicy()` receives a non-null XCB reply, `std::unique_ptr` uses its default `delete` deleter for the reply returned by XCB, which must be released with `free`; destroying the reply therefore invokes mismatched deallocation and undefined behavior during policy refreshes, potentially corrupting the heap or crashing the dock.
Give the `unique_ptr` a deleter that calls `free`, or use an equivalent XCB-aware RAII wrapper.| const xcb_get_property_cookie_t cookie = | ||
| xcb_get_property(connection, false, utils->getRootWindow(), atom, XCB_ATOM_CARDINAL, 0, 1); | ||
| std::unique_ptr<xcb_get_property_reply_t> reply(xcb_get_property_reply(connection, cookie, nullptr)); |
There was a problem hiding this comment.
🟡 Medium · Dock freezes on X replies
When the X server is slow or stops responding to the property query, refresh() calls fetchPolicy() on the UI thread, where xcb_get_property_reply() waits for the server response and stalls painting and input until it responds or the connection fails.
Make the property query nonblocking on the UI thread and handle its reply asynchronously.
Prompt for AI agents
In `panels/dock/taskmanager/mirrormodeclient.cpp` at lines 42-44:
**Dock freezes on X replies**
When the X server is slow or stops responding to the property query, `refresh()` calls `fetchPolicy()` on the UI thread, where `xcb_get_property_reply()` waits for the server response and stalls painting and input until it responds or the connection fails.
Make the property query nonblocking on the UI thread and handle its reply asynchronously.| mirrorButton->move(option.rect.topRight() | ||
| - QPoint(PREVIEW_TITLE_HEIGHT * 2 + MIRROR_BUTTON_INSET * 2, -5)); |
There was a problem hiding this comment.
🟠 High · Approval button targets wrong row
When preview rows are inserted, removed, or otherwise move while the preview is open, QListView repositions the persistent closeButton editor but not the sibling mirrorButton, which is positioned only once and retains its original window ID; the lock appears beside a different row and toggles the wrong window.
Keep the mirror button positioned with its row whenever the view updates the persistent editor’s geometry.
Prompt for AI agents
In `panels/dock/taskmanager/x11preview.cpp` at lines 409-410:
**Approval button targets wrong row**
When preview rows are inserted, removed, or otherwise move while the preview is open, `QListView` repositions the persistent `closeButton` editor but not the sibling `mirrorButton`, which is positioned only once and retains its original window ID; the lock appears beside a different row and toggles the wrong window.
Keep the mirror button positioned with its row whenever the view updates the persistent editor’s geometry.| m_policy = fetchPolicy(); | ||
|
|
||
| // Supersede whatever is still on the wire: only this generation's answers are | ||
| // applied, and changed() is emitted when both lists are in. | ||
| const quint64 generation = ++m_generation; | ||
| m_pendingLists = 0; | ||
| requestWindowList(QStringLiteral("primaryWindows"), generation); | ||
| requestWindowList(QStringLiteral("mirrorWindows"), generation); |
There was a problem hiding this comment.
🟡 Medium · Clicks combine new policy with old lists
When the mirror-mode policy changes and the user clicks before both list reads complete, refresh() publishes the new policy while retaining the old lists and button state, so the click handler combines the new policy with the old listed flag and submits the action opposite to the state the button shows.
Publish the policy and refreshed lists together, or prevent approval clicks until the lists are refreshed.
Also at panels/dock/taskmanager/x11preview.cpp:436-442.
Prompt for AI agents
In `panels/dock/taskmanager/mirrormodeclient.cpp` at lines 79-86:
**Clicks combine new policy with old lists**
When the mirror-mode policy changes and the user clicks before both list reads complete, `refresh()` publishes the new policy while retaining the old lists and button state, so the click handler combines the new policy with the old listed flag and submits the action opposite to the state the button shows.
Publish the policy and refreshed lists together, or prevent approval clicks until the lists are refreshed.
Also at `panels/dock/taskmanager/x11preview.cpp:436-442`.| // "KWin publishes no windows". | ||
| qCWarning(mirrorModeLog) << "failed to read" << name << ":" << reply.errorMessage(); |
There was a problem hiding this comment.
🟡 Medium · Failed reads leave stale approval
When a window-list read fails while the other list succeeds or KWin’s lists have changed, requestWindowList() preserves the failed read’s previous value, then emits changed() after the reads complete; the preview uses a mixed or stale snapshot for approval controls, and no retry occurs to correct it until another refresh trigger.
Do not expose approval controls from a mixed snapshot; invalidate the failed list and retry or refresh it before publishing the state.
Prompt for AI agents
In `panels/dock/taskmanager/mirrormodeclient.cpp` at lines 109-110:
**Failed reads leave stale approval**
When a window-list read fails while the other list succeeds or KWin’s lists have changed, `requestWindowList()` preserves the failed read’s previous value, then emits `changed()` after the reads complete; the preview uses a mixed or stale snapshot for approval controls, and no retry occurs to correct it until another refresh trigger.
Do not expose approval controls from a mixed snapshot; invalidate the failed list and retry or refresh it before publishing the state.| QString::fromLatin1(kInterface), | ||
| listed ? QStringLiteral("approveWindow") | ||
| : QStringLiteral("removeWindow")); | ||
| message << QVariant::fromValue<qulonglong>(winId); |
There was a problem hiding this comment.
🟠 High · Approval calls use the wrong integer width
When KWin exports approveWindow and removeWindow with a 32-bit window-ID argument, the call marshals winId as a 64-bit D-Bus integer, so KWin rejects it with an argument-signature error when approveWindow and removeWindow take the 32-bit X11 window ID; every approval click then fails.
Send the window ID using the exact integer type declared by KWin's D-Bus interface.
Prompt for AI agents
In `panels/dock/taskmanager/mirrormodeclient.cpp` at line 174:
**Approval calls use the wrong integer width**
When KWin exports `approveWindow` and `removeWindow` with a 32-bit window-ID argument, the call marshals `winId` as a 64-bit D-Bus integer, so KWin rejects it with an argument-signature error when `approveWindow` and `removeWindow` take the 32-bit X11 window ID; every approval click then fails.
Send the window ID using the exact integer type declared by KWin's D-Bus interface.| if (!reply || reply->type == XCB_ATOM_NONE || reply->format != 32 | ||
| || xcb_get_property_value_length(reply.get()) < static_cast<int>(sizeof(uint32_t))) { |
There was a problem hiding this comment.
🟡 Medium · Wrong property types enable controls
When the root property has a 32-bit non-CARDINAL type and its value is 1, 2, or 3, the 32-bit value is interpreted as a mirror policy even though its X property type is not CARDINAL; a mismatched property containing a recognized value can expose approval controls with the wrong policy and make the button report or write the wrong state.
Require reply->type == XCB_ATOM_CARDINAL before interpreting the property value.
Prompt for AI agents
In `panels/dock/taskmanager/mirrormodeclient.cpp` at lines 45-46:
**Wrong property types enable controls**
When the root property has a 32-bit non-`CARDINAL` type and its value is 1, 2, or 3, the 32-bit value is interpreted as a mirror policy even though its X property type is not `CARDINAL`; a mismatched property containing a recognized value can expose approval controls with the wrong policy and make the button report or write the wrong state.
Require `reply->type == XCB_ATOM_CARDINAL` before interpreting the property value.
The mirror mode switch decides whether the other outputs show the desktop, and KWin lets the user override that decision per window. The dock now offers it where the window itself is: the preview that pops up when the task icon is hovered carries a lock button next to the close button of every approvable window.
The approval is read and written through KWin's D-Bus interface, and the button reflects the state KWin publishes, so the same window shows the same state in every preview and in every panel. The button belongs to the item it is drawn on: it carries the window id it writes, so a click can never be applied to another window, and it is refreshed from the window lists and the mode property rather than from the click, which keeps a slow or refused write from leaving a state the user did not ask for.
The policy that maps the mode and the listed flag to an approval is a pure function in mirrormodepolicy.h, covered by a unit test, because KWin and the dock have to agree on it: what the button shows is what the window does.
PMS: TASK-394957
Summary by Sourcery
Add window-level mirror-mode approval controls to task previews and keep their state synchronized with KWin.
New Features:
Enhancements:
Tests: