Bug 449181 - kwin scripting client signal argument undefined
Summary: kwin scripting client signal argument undefined
Status: RESOLVED UNMAINTAINED
Alias: None
Product: kwin
Classification: Plasma
Component: scripting (show other bugs)
Version: 5.23.5
Platform: Other Linux
: NOR minor
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-01-26 04:11 UTC by Peifeng Yu
Modified: 2023-09-06 10:38 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peifeng Yu 2022-01-26 04:11:09 UTC
SUMMARY

According to the documentation[1] and code[2], the KWin::Toplevel::windowClosed signal should be usable from the js script, and have two parameters. However, on the js side, the handler gets nothing.

[1]: https://develop.kde.org/docs/extend/plasma/kwin/api/#signals-2
[2]: https://invent.kde.org/plasma/kwin/-/blob/master/src/toplevel.h#L578

STEPS TO REPRODUCE
1. Start the scripting console: `plasma-interactiveconsole --kwin`
2. Enter the following test script and execute it

```js
function closedHandler() {
    console.log('all args in closed handler are ', JSON.stringify(arguments));
}

workspace.clientMaximizeSet.connect(function(client) {
    console.log('client is ', client);
    client.windowClosed.connect(closedHandler);
});
```
3. Create a new window, i.e. konsole
4. Maximize the konsole window
5. Directly close the konsole window

OBSERVED RESULT

The kwin output:
```
js: client is  KWin::X11Client(0x555f1610a7f0)
js: all args in closed handler are  {}
```
The closed handler was correctly installed, but didn't get any argument.

EXPECTED RESULT

The closed handler gets 2 arguments as documented.


SOFTWARE/OS VERSIONS
Operating System: Arch Linux
KDE Plasma Version: 5.23.5
KDE Frameworks Version: 5.90.0
Qt Version: 5.15.2
Kernel Version: 5.16.1-zen1-1-zen (64-bit)
Graphics Platform: X11
Processors: 12 × Intel® Core™ i7-10750H CPU @ 2.60GHz
Memory: 31.1 GiB of RAM
Graphics Processor: Mesa Intel® UHD Graphics

ADDITIONAL INFORMATION

First reported here: https://github.com/Aetf/kwin-maxmize-to-new-desktop/issues/14
Comment 1 Vlad Zahorodnii 2022-01-26 10:19:28 UTC
Most likely, QJSEngine doesn't know about KWin::Deleted so it refuses passing both signal arguments. `Deleted` is an implementation detail that generally should not be exposed to scripts. Not sure what to do about it other than ask script developers not to use the Toplevel argument and instead do something like

  client.windowClosed.connect(() => console.log(client.caption, "has been closed"));
Comment 2 Peifeng Yu 2022-01-26 23:43:41 UTC
That's indeed what I'm doing in my script to work around this.

Maybe creating a wrapper class to expose X11Clients to scripts is a better way to move forward in the long term.
Comment 3 David Edmundson 2023-09-06 10:38:37 UTC
This bug was reported against an outdated version of KWin. We have made many changes since the. 
If the issue persists in newer versions can you reopen the bug report updating the version number.