Bug 416093 - client screen property now readonly?
Summary: client screen property now readonly?
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: scripting (show other bugs)
Version: 5.17.5
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL: https://phabricator.kde.org/D26988
Keywords: multiscreen
Depends on:
Blocks:
 
Reported: 2020-01-10 17:00 UTC by LinG
Modified: 2020-01-29 17:47 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 5.18.0
Sentry Crash Report:
vlad.zahorodnii: ReviewRequest+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description LinG 2020-01-10 17:00:12 UTC
The screen property of a client is now readonly? I'm pretty sure it used to be read and write, thus allowing me to change the screen on which a client resides but now I can't? How do I change the screen on which a client resides through the scripting API now?

Additional question regarding the documentation (https://techbase.kde.org/Development/Tutorials/KWin/Scripting/API_4.9):

the desktop property has the description to prefer the use of `isOnDesktop()` method over accessing this variable directly, however this method is not documented in the kwin scripting documentation.

Latest packages on ArchLinux
Comment 1 LinG 2020-01-12 10:38:31 UTC
Here is a MWE

var clients = workspace.clientList();
for (var i = 0; i < clients.length; i++)
{
  if (clients[i] === null) {continue;}
  if (clients[i].resourceName.toString() === 'konsole') // or any other client that you have open
  {
    var pre = clients[i].screen;
    clients[i].screen = 1;
    var post = clients[i].screen;
    print(pre, post, workspace.numScreens); // output: 0 0 2, expected output 0 1 2
  }
}
Comment 2 Lo 2020-01-21 23:25:34 UTC
There seems to be a sendToScreen method ( https://github.com/KDE/kwin/blob/fbfd1ac705212892f417aa5cc9df5fcd9ce9cb52/abstract_client.h#L453 ) however it's not accessible to scripts.

using `workspace.activeScreen = 1` doesn't work either, since it's readonly too and it doesn't seem possible to activate a client either.

Finally, https://api.kde.org doesn't seem to contain any scripting docs for KWin 5+
Comment 3 Vlad Zahorodnii 2020-01-29 13:26:46 UTC
(In reply to LinG from comment #0)
> The screen property of a client is now readonly? I'm pretty sure it used to
> be read and write, thus allowing me to change the screen on which a client
> resides but now I can't? How do I change the screen on which a client
> resides through the scripting API now?
As far as I know, it has always been read-only.

(In reply to Lo from comment #2)
> There seems to be a sendToScreen method (
> https://github.com/KDE/kwin/blob/fbfd1ac705212892f417aa5cc9df5fcd9ce9cb52/
> abstract_client.h#L453 ) however it's not accessible to scripts.
No, what you need is Workspace::sendClientToScreen(), which is not exposed to scripting API unfortunately.
Comment 4 Lo 2020-01-29 13:32:31 UTC
So how does one move a client from a screen to another?
Comment 5 Vlad Zahorodnii 2020-01-29 13:43:35 UTC
(In reply to Lo from comment #4)
> So how does one move a client from a screen to another?
See https://phabricator.kde.org/D26988.

You would do `workspace.sendClientToScreen(client, screen);` or something.
Comment 6 Vlad Zahorodnii 2020-01-29 13:44:00 UTC
It would be great if you could test my patch. ;-)
Comment 7 LinG 2020-01-29 14:20:24 UTC
(In reply to Vlad Zahorodnii from comment #3)
> (In reply to LinG from comment #0)
> > The screen property of a client is now readonly? I'm pretty sure it used to
> > be read and write, thus allowing me to change the screen on which a client
> > resides but now I can't? How do I change the screen on which a client
> > resides through the scripting API now?
> As far as I know, it has always been read-only.

I've always used this screen property of the client the same way as I have been using the desktop property and am still using. So it's interesting to me that you say that this property has never been writable.

Question 1: What would be the reason to not make the screen property writable like the desktop property on a client? I'm fine with using your proposed method as well, but isn't the former more in line with the rest of the API?
Comment 8 Vlad Zahorodnii 2020-01-29 15:24:18 UTC
(In reply to LinG from comment #7)
> I've always used this screen property of the client the same way as I have
> been using the desktop property and am still using. So it's interesting to
> me that you say that this property has never been writable.
You shouldn't actually use that property, it's deprecated.

> Question 1: What would be the reason to not make the screen property
> writable like the desktop property on a client? I'm fine with using your
> proposed method as well, but isn't the former more in line with the rest of
> the API?
It matches what KWin is doing whenever it needs to send a client to another screen.
Comment 9 Vlad Zahorodnii 2020-01-29 15:24:45 UTC
Git commit 76297196e898c838ed89d21f44e8a8560cd7391f by Vlad Zahorodnii.
Committed on 29/01/2020 at 15:14.
Pushed by vladz into branch 'Plasma/5.18'.

[scripting] Expose Workspace::sendClientToDesktop()

Summary:
FIXED-IN: 5.18.0

Test Plan: Only compile-time check.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D26988

M  +8    -0    scripting/workspace_wrapper.cpp
M  +5    -0    scripting/workspace_wrapper.h

https://commits.kde.org/kwin/76297196e898c838ed89d21f44e8a8560cd7391f
Comment 10 LinG 2020-01-29 15:34:29 UTC
(In reply to Vlad Zahorodnii from comment #8)
> (In reply to LinG from comment #7)
> > I've always used this screen property of the client the same way as I have
> > been using the desktop property and am still using. So it's interesting to
> > me that you say that this property has never been writable.
> You shouldn't actually use that property, it's deprecated.

Alright, where can I find the most recent documentation about the methods and properties that I should use?

(What method should I use to send clients to different desktops and is there also something available to send clients to different activities?)

> 
> > Question 1: What would be the reason to not make the screen property
> > writable like the desktop property on a client? I'm fine with using your
> > proposed method as well, but isn't the former more in line with the rest of
> > the API?
> It matches what KWin is doing whenever it needs to send a client to another
> screen.

That's fair, keeping the API as close to the internals seems like the best way to me as well.
Comment 11 Vlad Zahorodnii 2020-01-29 15:52:58 UTC
(In reply to LinG from comment #10)
> Alright, where can I find the most recent documentation about the methods
> and properties that I should use?
Unfortunately, only source code. API dox is not generated for KWin since KDE Plasma 5.

> (What method should I use to send clients to different desktops and is there
> also something available to send clients to different activities?)
So, with the new virtual desktop model, a client can enter and leave more than just one desktop. On X11, a client can be either only on one or on all desktops, though. The relevant AbstractClient property I'm talking about is x11DesktopsIds.

It seems like scripts can modify only legacy `desktop` property. :/
Comment 12 LinG 2020-01-29 17:47:36 UTC
(In reply to Vlad Zahorodnii from comment #11)
> (In reply to LinG from comment #10)
> > Alright, where can I find the most recent documentation about the methods
> > and properties that I should use?
> Unfortunately, only source code. API dox is not generated for KWin since KDE
> Plasma 5.

Alright, could you point out to me where I can find the code that is related to the KWin::client and KWin::toplevel (assuming client still inherits from toplevel as in 4.9). The scripting/workspace_wrapper.h is very readable so I'm fine with working with that but I didn't find a client_wrapper.h or something in this directory