Can't get output from KWin script

Hello,

I’m trying to get started with KWin script development. The first thing I want to do is, of course, a simple “Hello World.”

I followed everything mentioned in the output section of the KWin Scripting official tutorial.

In KDebugSetting, I set KWin Scripting to full debug. I added these environment variables:

export QT_LOGGING_RULES="kwin_*.debug=true"

to both ~/.bash_profile and /etc/environment. However, whatever I do, I can’t see the output of my print statements.

I get some outputs from my script, like undefined symbols and variables errors, but no print output.

I’m checking the journalctl output with this command:

journalctl -f QT_CATEGORY=js QT_CATEGORY=kwin_scripting

I’m on Fedora 40 Kinoite, Plasma version 6.1.3, Framework version 6.4.0, and Qt version 6.7.2.

Any help would be really appreciated. Thanks a lot.

Can you show us those errors, the code you are running and how are you running it?

Sure, I’m using Kwin interactive console to run my code.

I took screenshots but since this is a new account, it didn’t allow me to upload them.

Basically on KWin interactive console, I’m executing this erroneous code snippet:

print("hello world");

workspace.clientMaximizeSet.connect(manageKeepAbove);

This is the output on my terminal:

❯ journalctl -f QT_CATEGORY=js QT_CATEGORY=kwin_scripting
Jul 28 13:26:38 fedora kwin_wayland[2037]: kwin_scripting: /home/m1lex4r/.local/share/plasma-interactiveconsole/interactiveconsoleautosave.js:3: error: manageKeepAbove is not defined

You should put the complete code of the example including the manageKeepAbove function.

But it will still not work because the API has changed with Plasma 6

Here’s a working script I put together that does the same on Plasma 6, not sure if it’s the best way but works.

var keepAboveMaximized = new Array();

function setup(window) {
  if (!window.normalWindow) return
    console.error("setting up window", window.caption)
    // here we connect our function to the maximizedChanged signal
    // we need to know if our window is maximized so we also pass that
    window.maximizedChanged.connect(() => {
      toggleKeepAbove(window)
    });
}

function toggleKeepAbove(window) {
  // the size the window would have if it was maximized
  const maximizedArea = workspace.clientArea(KWin.MaximizeArea, window)
  // check if it's actually maximized
  let maximized = window.height === maximizedArea.height && window.width === maximizedArea.width
  console.error(window.caption, "maximized: ", maximized)
    if (maximized) {
      // if it had keep above add it to our keepAboveMaximized and remove keepAbove
      if (window.keepAbove) {
        console.log("saved and removed keepAbove")
        keepAboveMaximized[keepAboveMaximized.length] = window;
        window.keepAbove = false;
      }
    } else {
      // no longer maximized
      console.log("no longer maximized")
      var found = keepAboveMaximized.indexOf(window);
      // if the de-maximized window was previously set to keep above make it stay above again
      if (found != -1) {
        console.log("removed and restored keepAbove")
        window.keepAbove = true;
        keepAboveMaximized.splice(found, 1);
      }
  }
  console.error("keep above now", window.keepAbove)
}

console.log("init")

// handle any new window
workspace.windowAdded.connect(setup)

Thank you, but you got me wrong. That’s the whole snippet, it is intentionally broken.
What I’m trying to show is that I can see the error messages just fine but I can’t see any print() outputs.

My bad, did you set the QT_LOGGING_RULES="kwin_*.debug=true" environment variable as instructed in the Output section?

If I run your snippet I do see the print on the terminal along with the error

Yep, I tried to add that environment variable both in .bash_profile and /etc/environment also put it before the journalctl command

 QT_LOGGING_RULES="kwin_*.debug=true"  journalctl -f QT_CATEGORY=js QT_CATEGORY=kwin_scripting

but no luck, on some other forum someone said it is a Fedora problem. Maybe related to SELinux?

Maybe you need this?

Depending on your distribution and graphics platform, it may also be necessary to have Plasma systemd boot enabled (this is the default since Plasma 5.25).