Switching Window to Active Screen Programmatically

Hello there!

I’m using two monitors, and I’m looking for a way to programmatically move a window to the currently active screen, meaning the monitor my mouse is currently on.

I’ve been using GitHub - noctuid/tdrop: A Glorified WM-Independent Dropdown Creator for a while to create a dropdown terminal, and it works great - moving the terminal to whichever is my active screen. However, it doesn’t fully support Wayland.

I couldn’t find a direct alternative for Wayland, but I did find GitHub - jinliu/kdotool: xdotool-like for KDE Wayland which allows me to achieve a similar effect with some small bit of shell scripting. Here’s the script I’m currently using (activated via a Plasma hotkey):

#!/usr/bin/env bash

export STATE=/home/tk/.local/state/alacritty-dropdown
export KDOTOOL=/path/to/kdetool
export ALACRITTY=alacritty

if [ -z "$($KDOTOOL search --class alacritty)" ]; then
        $ALACRITTY &
        sleep 0.5

        $KDOTOOL search --class alacritty windowstate --add SKIP_TASKBAR windowstate --add FULLSCREEN --toggle ABOVE
        echo 1 >$STATE
fi

echo "State is: $STATE"
if [[ $(<$STATE) == 1 ]]; then
        echo "Setting Window Below"
        $KDOTOOL search --class alacritty windowstate --toggle BELOW
        echo 0 >$STATE
else
        echo "Setting Window Above"
        $KDOTOOL search --class alacritty windowstate --add SKIP_TASKBAR windowstate --add FULLSCREEN --toggle ABOVE
        echo 1 >$STATE
fi

I managed to achieve most of what I wanted, but kdotool doesn’t yet seem to support getting/setting the active screen of a window.

Does anyone know if there is a cli application which can get/set the active screen for an application window in KDE Plasma 6? Failing that, how can I otherwise programmatically get/set the active screen for a window?

Not sure it’s relevant for this question, but my current KDE Plasma 6 version is 6.3.6

Thank you kindly for reading!

Came here with the same question.

Sometimes a window is “lost” i.e. it’s not on the active screen but on some other one which you don’t see (this can happen with remote access for instance). In such a case it would be handy to have „Bring to active screen” feature.

Actually I think such an action should be present among other actions in the following menu:

I forgot to leave kind of a workaround. In the menu shown in my previous post, if you choose “Move” option and move your cursor the window “snaps” to the cursor. This way one can bring any window do the current screen (one with the cursor on it).