SUMMARY *** I noticed that in Wayland protocol, when I perform a copy operation in a program, the protocol performs some data operations through `SetSelection` function.But when I set `Qt::WindowDoesNotAcceptFocus` via Qt in this program and write data via `setText` operation in `QClipboard`, the function `updateSelection` in Wayland will not send the `setSelection` signal. I found that the following code is causing the signal not to be sent. `*globalKeyboard.focus.surface->client() == dataDevice->client()`. *** STEPS TO REPRODUCE 1. Create a Qt window, set the `Qt::WindowDoesNotAcceptFocus` property 2. Create a button in which the button function is to set a value to the QClipboard 3. Clicked the button and found it impossible to paste in other apps OBSERVED RESULT Write values cannot be pasted by other applications EXPECTED RESULT Write values that can be pasted by other applications may i ask why this judgment is necessary, and if I want my app to write clipboard data without getting focus, is there an alternative way I can do it? SOFTWARE/OS VERSIONS Linux/KDE Plasma: (available in About System) KDE Plasma Version: KDE Frameworks Version: Qt Version: 5.11.3 ADDITIONAL INFORMATION
It's a lazy way to determine that the passed serial is valid. Only focused client is going to have a serial that can be used to set the selection. > Create a Qt window, set the `Qt::WindowDoesNotAcceptFocus` property As far as I know, an xdg_toplevel cannot influence whether it should accept focus or not. It can only change the input shape, but it's controlled by a different flag.
(In reply to Vlad Zahorodnii from comment #1) > It's a lazy way to determine that the passed serial is valid. Only focused > client is going to have a serial that can be used to set the selection. > > > Create a Qt window, set the `Qt::WindowDoesNotAcceptFocus` property > > As far as I know, an xdg_toplevel cannot influence whether it should accept > focus or not. It can only change the input shape, but it's controlled by a > different flag. yes, i found that `Only focusedclient is going to have a serial that can be used to set the selection`. But I don't really understand what you mean by this, so let me describe my problem in detail. I have written a program through which I want to click a button to enter data for another application. The way it works now is: create a window set the `Qt::WindowStaysOnTopHint |Qt::WindowDoesNotAcceptFocus` property so that the window stays on top and the input focus is retained in the other program, then click the button and via `QClipboard->setText` put the data into the `selection` in the system by `QClipboard->setText`. However, I find that the following code in `kwayland` does not work at this point. `QObject::connect(dataDevice, &DataDeviceInterface::selectionChanged, q, [this, dataDevice]], [this, dataDevice]]. [this, dataDevice] { if(keys.focus.surface && dataDevice && dataDevice->client() == keys.focus.surface->client()) { updateSelection(dataDevice->selection(), true); } } );` When I call `setText` in my Qt app, `setSelection` is called in wayland, which then triggers Kwayland's callback function, but at this point, the source of the data is the program I've written, but keys.focus.surface is another app, causing the selection not to be updated. Maybe the kwin in my system has been modified, resulting in a difference from the original design. I will also try to test this on a native KDE system, and if necessary, I'll attach a demo I've written!
Created attachment 161774 [details] demo Run the demo, let the input focus on any application, click the button in the demo, it will output an "ok" at the other application's focus. But it won't actually
Kwin now allows any app to change clipboard without focus.