Bug 386021 - Can not adjust the geometry of applications consistently inside clientAdded() signal
Summary: Can not adjust the geometry of applications consistently inside clientAdded()...
Status: RESOLVED NOT A BUG
Alias: None
Product: kwin
Classification: Plasma
Component: scripting (show other bugs)
Version: 5.11.1
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-21 11:48 UTC by LinG
Modified: 2017-10-21 20:03 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description LinG 2017-10-21 11:48:26 UTC
Using the kwin scripting interface, I can change the client.geometry property of Kate and if I check the geometry afterward it has been correctly set.

But for some reason Kate does not want to take on the new geometry you assign to it. It works fine for every other application I use (from konsole to texstudio etc...) only for Kate is it not possible to let it take on the new geometry that you assign to it.
Comment 1 Martin Flöser 2017-10-21 11:54:43 UTC
That would be a problem in Kate then. Geometry is handled in truth by the application. The window manager just tells the window "please take this geometry". The window is allowed to just change it back.

Windows support a min size. You can check with xprop and xwininfo for the minimum size and other constraints on the window. Maybe the geometry you want to use just violates the constraints.
Comment 2 LinG 2017-10-21 13:26:47 UTC
But there are two different scenarios in which the application behaves differently. Allow me to provide two small examples which illustrate what I'm experiencing to be weird

case 1.

- open application: kate
- execute this piece of code in Kwin

var clients = workspace.clientList(); 
for (var i=0; i<clients.length; i++) {
  if (clients[i].resourceClass.toString() === "kate") {kate = clients[i];};
}
kate.geometry = {x: 5, y: 100, width: 400, height: 800};

- succes, kate now takes on this geometry

case 2.

- close application: kate
- execute this piece of code

workspace.clientAdded.connect
(
  function(client)
  {
    client.geometry = {x: 100, y: 5, width: 800, height: 400};
    return 0;
  }
);

- open application: kate
- fail, kate takes on some random geometry

I don't understand why these two cases generate different results, but as you said this may be kate related... In which case I report it in the kate section I suppose? (Just checking to be sure that it is kate related and not kwin.)
Comment 3 Martin Flöser 2017-10-21 16:36:12 UTC
just saying: your second script part has x/y and width/height swapped compared to the working one.
Comment 4 LinG 2017-10-21 17:03:43 UTC
that was intentional in this example, if I had not done that and the second script would work (which it doesn't) then you would not notice a difference in the geometries.

Anyways, while trying out other applications I noticed that kate is by far not the only application that does not listen to the settings that you apply (spotify, inkscape, etc...)

My observation is that whatever you do inside the workspace.clientAdded function does not always work, for a lot of applications they just ignore whatever you tell them to do and create a geometry set by the application. 

This only happends during the startup of the application once it has already been started up you can do whatever you want with the geometry using the API that kwin provides. 

Shouldn't the clientAdded function overrule whatever the application itself tries to achieve in terms of geometry and what not? Right now creating a Kwin script that manages my newly added applications *consistently* is simply impossible because most applications have their own predefined geometries.

Or is there a way to force the applications to adjust to the settings you apply to it, that I'm unaware of?
Comment 5 LinG 2017-10-21 17:06:18 UTC
Also the workspace.getClient() function does not work for newly added clients until the workspace.clientAdded() routine is finished, the client is not added internally to the workspace. Which means that kwin does not manage newly added applications yet until they are started up?
Comment 6 LinG 2017-10-21 17:11:13 UTC
Or is there a way to call clientAdded() after the application has started up instead of before?

Right now it goes:
- apply settings in kwin
- startup application -> applies settings from applications

result = applied settings in kwin are overwritten by application itself

Shouldn't it be?
- startup application -> applies settings from applications
- apply settings in kwin
Comment 7 LinG 2017-10-21 17:20:23 UTC
my main problem is that you're basically setting up default settings for the application in kwin and then you pray to god the application does not define its own settings which override your default settings.

A more expected behavior would be that you let the application decide on the default behavior and then you can adjust these settings using kwin.

(settings = geometries, minimized, etc...)
Comment 8 Martin Flöser 2017-10-21 18:18:56 UTC
Please note that there are also window rules which support setting values for windows when they open. This might be a better solution than scripting.
Comment 9 LinG 2017-10-21 20:03:40 UTC
I've taken a look at those at first but they did not satisfy my needs.

Regardless of that, don't you think that a window manager API that is not able to change the geometry of applications that are started kinda defeats the purpose of a "window manager"?

Basically, one of the simplest things one could do is:

- Set the geometry of an application that is started to some geometry

But right now that only works for a handful of applications that don't set their own geometry... Feels like I don't even have control of my own window manager... (If only there was a "force" option...)