kwin-scripts / kwin-tiling

Tiling script for kwin
GNU General Public License v2.0
1.1k stars 68 forks source link

Wayland/Xorg differences #117

Closed TRPB closed 5 years ago

TRPB commented 5 years ago

For some reason on Wayland some windows that are tiled under Xorg are not tiled using Wayland. While Thunderbird and Firefox tile correctly, Konsole and Dolphin are not tiled at all. Is there a setting I can change to fix this?

edit: In fact, I don't think any KDE applications are tiled. I just tried Kate and System settings, no tiling.

faho commented 5 years ago

Kwin does not expose wayland clients to scripts. That needs to be changed in kwin upstream.

TRPB commented 5 years ago

Did this ever get resolved upstream? I was hoping with 5.15 it might have been fixed.

faho commented 5 years ago

https://bugs.kde.org/show_bug.cgi?id=401309, which is stuck in review (https://phabricator.kde.org/D17097), because apparently there are security concerns.

TL;DR: Don't hold your breath.

abenz1267 commented 4 years ago

I didn't wanna necro, but I just thought about it since I love this script and KDE seems to be pushing Wayland a lot. I looked at the review you linked and it seems to be resolved? Or did I misinterpret something?

Tried Wayland quickly today and f.e. the System Settings window didn't get tiled.

Regards

TRPB commented 4 years ago

I'm hoping that the change will appear in Plasma 5.17 which is due to ship on Tuesday.

laloch commented 4 years ago

I'm running Plasma 5.16.90 (5.17 beta) for some time now. I'm sorry to say that scripting only works in nested XWayland session. In native wayland session scripting is completely broken (KWin JavaScript object is not exported to script engine).

TRPB commented 4 years ago

The grid-tiling extension https://github.com/lingtjien/Grid-Tiling-Kwin works for detecting and tiling windows. However, the author made some rather strange design decisions (all windows transparent, horrible gaps, no window decorations, odd tiling order, very poor mutli monitor support, can't drag and drop to rearrange, etc). It'd be interesting to see what happens differently in that script and why that works.

laloch commented 4 years ago

That's right. Grid-Tiling-Kwin is much simpler and does not need the interfaces we use.

TRPB commented 4 years ago

But surely if that script can detect and position the windows under Wayland, Kwin-Tiling can use the same approach and at least get basic functionality working.

Looking through the code it looks like the KWin object is only used for reading configuration options and registering shortcuts. Grid-Tiling-Kwin manages to register shortcuts, the only thing it doesn't seem to do is have configuration options.

TRPB commented 4 years ago

I have a partial fix.

If you change clientAdded to clientActivated in tilielist.js, Wayland windows work after they have been minimized then unminimized. It's buggy and I keep ending up with phantom windows, but it does sort of work.

TRPB commented 4 years ago

This patch mostly fixes the issues:

diff --git a/contents/code/tilelist.js b/contents/code/tilelist.js
index a4b43fa..c511a60 100644
--- a/contents/code/tilelist.js
+++ b/contents/code/tilelist.js
@@ -64,7 +64,7 @@ function TileList(timer) {
     // clients are added in order to be able to keep track of the
     // new tiles
     var self = this;
-    workspace.clientAdded.connect(function(client) {
+    workspace.clientActivated.connect(function(client) {
         // TODO: When compositing is on,
         // we need to delay first tiling until the window is shown
         // otherwise we end up with artifacts.
@@ -74,13 +74,8 @@ function TileList(timer) {
         // - "compositingMode"
         // - "compositingInitialized"
         // change when it is disabled/enabled.
-        if (options.useCompositing) {
-            client.windowShown.connect(function(client) {
-                self.addClient(client);
-            });
-        } else {
-            self.addClient(client);
-        }
+
+        self.addClient(client);
         // NOTE: When a new client is added, activeChanged will be called before it even appears
         // in workspace.clientList(), so we need to keep track of the focus change here as well.
         self.trackFocusChanges(client);
laloch commented 4 years ago

clientAdded now works on Wayland in Plasma 5.17. The scriptengine is however severely broken and I'm not going to work it around in our script.

laloch commented 4 years ago

I'll rather try to fix KWin and push the fix for the next release.

TRPB commented 4 years ago

the above patch gets Kwin-tiling to a useable state on Wayland 5.16+. The config options are unavailable but the script's basic behaviour works fine and the keyboard shortcuts are registered. I didn't try every keyboard option but for what I need it seems to be working fine.

laloch commented 4 years ago

OK, what I wrote above was complete BS. The global objects are only missing if the script is reloaded. The following patch makes kwin-tiling work on Plasma>=5.16.90. We are, however, really bad in detecting clients to be ignored on Wayland, so we tile almost everything.

  diff --git a/contents/code/tilelist.js b/contents/code/tilelist.js
  index a4b43fa..0835bbd 100644
  --- a/contents/code/tilelist.js
  +++ b/contents/code/tilelist.js
  @@ -65,22 +65,7 @@ function TileList(timer) {
       // new tiles
       var self = this;
       workspace.clientAdded.connect(function(client) {
  -        // TODO: When compositing is on,
  -        // we need to delay first tiling until the window is shown
  -        // otherwise we end up with artifacts.
  -        // However, we can only determine what the option is set to on start
  -        // neither of (options.):
  -        // - "useCompositing"
  -        // - "compositingMode"
  -        // - "compositingInitialized"
  -        // change when it is disabled/enabled.
  -        if (options.useCompositing) {
  -            client.windowShown.connect(function(client) {
  -                self.addClient(client);
  -            });
  -        } else {
  -            self.addClient(client);
  -        }
  +        self.addClient(client);
           // NOTE: When a new client is added, activeChanged will be called before it even appears
           // in workspace.clientList(), so we need to keep track of the focus change here as well.
           self.trackFocusChanges(client);
TRPB commented 4 years ago

I've found I get quite a few phantom windows and issues with clientAdded. clientActivated seems to give a much less buggy experience, I'm not sure why as I'm not sure what the differences are supposed to be.

In addition, here's a few classes which need adding to ignored.js's _blacklist array:

I also can't fullscreen windows in MPV as of 0.30, which is strange because I'm fairly sure it worked before. vlc works fine.

With these changes, Wayland is actually a better experience with this script than on X because X has the problem of frozen windows (try maximising google chrome, or opening a VM in Virtualbox) where you have to move the window to a different tile before it's drawn. This rather annoying bug doesn't happen on Wayland.

TRPB commented 4 years ago

There's a weird issue where some applications keep getting resized. Try opening Lutris on a Wayland session. It starts off the correct size and keeps getting made full size then 1px less. It's like it animates getting smaller. Really strange.

WillPower3309 commented 4 years ago

@TRPB any updates on this? I'm not super experienced with low level linux programming but I'd love to lend a helping hand in any way that I can

TRPB commented 4 years ago

take a look at my fork here: https://github.com/TRPB/kwin-tiling

There are a few tweaks but nothing major, mostly just adding wayland windows to the ignore list.

WillPower3309 commented 4 years ago

Ah, okay thanks! Despite https://phabricator.kde.org/R108:4bbef8d128ce339b4fa08816780c42c40bdd909e, it looks like wayland clients still aren't tiled, tried with your fork and with the main project

TRPB commented 4 years ago

Should work with my fork, this commit fixes it: https://github.com/TRPB/kwin-tiling/commit/1fd493bc99b280ae1010d73e6d4030079b8c82ca