Bug 436498 - WindowSystem::window(WId wid) returns the wrong window
Summary: WindowSystem::window(WId wid) returns the wrong window
Alias: None
Product: kwayland-integration
Classification: Plasma
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
Depends on:
Reported: 2021-05-02 19:10 UTC by Fabian Vogt
Modified: 2021-05-03 10:49 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Note You need to log in before you can comment on or make changes to this bug.
Description Fabian Vogt 2021-05-02 19:10:19 UTC
It does this:

    const auto &windows = WaylandIntegration::self()->plasmaWindowManagement()->windows();
    auto it = std::find_if(windows.begin(), windows.end(), [wid] (PlasmaWindow *w) { return w->internalId() == wid; } );

wid is the internally generated window id in the client process, while internalId() returns the internally generated window id from the compositor.

Those do not match, which essentially means that any KWindowSystem functions on wayland which take a WId act on a random window instead.

krunner for instance calls KWindowSystem::forceActiveWindow(winId()); after the window is shown, but actually activates the desktop (plasmashell) instead.
krunner's View is the first QWaylandWindow instance and gets winId 1, while plasmashell is the first window created by kwayland-server.
Comment 1 David Edmundson 2021-05-02 19:40:24 UTC
At least it's found. 

As for this bug - we definitely need to fix krunner. 
Super worst case, we just if guard round that call.

As for this bug, I think the right call is to strip all plasmaWindowManagement  from kwayland-integration to leave only things that meddle with our windows not 3rd party windows. It's a broken concept to try and retroactively fit into our old API.

Only plasma should meddle with other windows, and we have native API for that so should have no regressions.
Comment 2 Bug Janitor Service 2021-05-03 09:13:00 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwayland-integration/-/merge_requests/6
Comment 3 Fabian Vogt 2021-05-03 10:49:29 UTC
Git commit 9058eff75d11e112ccf35f723199dd458fa7b02e by Fabian Vogt.
Committed on 03/05/2021 at 09:01.
Pushed by fvogt into branch 'master'.

Drop functions which rely on PlasmaWindow::internalId()

While that returns a WinId, those are from the compositor and not related to
the internal WinIds from the calling application itself. Most uses of
KWindowSystem rely on that though, and so acted on a random other window

M  +0    -21   src/windowsystem/waylandintegration.cpp
M  +19   -85   src/windowsystem/windowsystem.cpp
M  +0    -4    src/windowsystem/windowsystem.h