Targeting windows/apps to activity-desktop-screen combos in Plasma 6.x

I would like to run several programs on startup, targeting them to specific display-virtual desktop-activity combinations. I’ve never tried making a Kwin script before, but that seems like the way to do it. As Plasma 6 brought a bunch of breaking changes, I would just like to make it for Plasma 6.x and not bother with 5.x.

I asked ChatGPT for some help, it gave me commands to get the IDs of activities, and this works:

for uuid in $(qdbus6 org.kde.ActivityManager /ActivityManager/Activities ListActivities); do
    name=$(qdbus6 org.kde.ActivityManager /ActivityManager/Activities ActivityName "$uuid")
    name2=$(echo $name | sed 's/\.//g')
    echo "activity$name2=$name" >> ~/.config/kwin-scripts/activity_ids.conf
done

Unfortunately, it suggested saving them to a file, and it seems that Kwin scripts cannot read variables from a file. It also suggested some ways to run dbus commands from within the kwin script js, but those did not work.

I was under the impression that I should be able to see it listed by running qdbus6 org.kde.KWin /KWin | grep -i ListActivities, but it was not there, in spite of the above qdbus command working.

So if someone has a full working solution for my objective, that would be wonderful. If not, perhaps I can get some guidance about obtaining activityIDs from activity names inside a kwin script?

You can do both with window rules, have you tried that?

Or if you need a more complex setup you may want to try this kwin script GitHub - juienpro/kwin-multiconf: A KDE6 KWin script to bind windows placement to keybindings or monitor events

1 Like

I would prefer to simply open a specified program on a specified activity-desktop-display combo once on startup rather than have a rule that windows from that program are forced to afterwards. Am I correct that I would need a Kwin script to do this?

I will look more into window rules though, I probably should have given them more consideration without assuming the above.

Edit: OK great, I see that “Window Rules” has options for whether to force it or not. Now I just need to figure out how to get window class names under Wayland.

Sounds like a KWin script is indeed needed for that if you want the rule to only trigger on boot when you auto-start your apps.

The KWin script I linked seems to be able to do that with a Shortcuts instead so it may serve this purpose.

The alternative (though advanced) would be changing the rules on boot using a script, by adding your windows and then removing them but risk breaking the rules if something goes wrong editing the file example changing titlebar color scheme for specific window class names in python

You can use qdbus6 org.kde.KWin /KWin org.kde.KWin.queryWindowInfo, the qdbus6 might have a different name depending on the distro.