Is there a way to assign a keyboard shortcut to move the window-in-focus between monitors?

Hi, I’m new to qubes and I’ve gone through some discussions and made qubes more keyboard friendly using scripts… Now it would be handy if I could move the window in focus between monitors… Has anyone done it yet or can anyone help me with it…?
I think the challenge here is to figure out “which monitor the window is on”…

System Settings → Windows Manager → Move window to left/right workspace

1 Like

Workspaces are not the same as monitors, though…I don’t think there’s a readily available Xfce mechanism to move a window onto a different monitor (if used in expand mode), but you could write a script that makes use of xdotool windowmove x y (see man xdotool in dom0) to achieve this for your default setup.

To get the window’s current coordinates use xdotool getwindowgeometry --shell windowID, which will store x and y coordinates in $X and $Y automatically. You can get the windowID of the window in focus by executing xdotool getwindowfocus in the same script.

2 Likes

You can use wmctrl and xdotool to do it, you use window=$(printf '0x0%x' $(xdotool getwindowfocus)) to get the focused window, and then you move it with wmctrl.

Here is some info on how to work with the window
https://forum.qubes-os.org/t/controlling-xfce-windows-with-wmctrl/22299
https://forum.qubes-os.org/t/tiling-xfce-windows-with-shortcut-keys/22840

3 Likes

Thanks…
xdotool windowmove is indeed what I’ve been looking for …

3 Likes

There is no way to move windows between monitors until Xfce Xfce4 4.17.2 (2022 Dec)

But you could move windows between workspaces with default xfce4 window manager.

Check this script:

#!/usr/bin/env bash

########################################################################
# File Name    : shortcuts-setup-wm-qubes.sh
# Description  : Script to add custom window manager shortcuts using
#                xfconf-query in dom0 of Qubes Xfce. It makes a backup
#                before reset previous rules. Note: copying content
#                from others qubes compromises the Qubes OS security
#                model.
# Dependencies : Xfce
# Usage        : • Transfer this script from appvm to dom0 with:
#                [user@dom0 ~]$ qvm-run --pass-io appvm 'cat ~/shortcuts-setup-wm-qubes.sh' > ~/shortcuts-setup-wm-qubes.sh
#                • Make the script executable with:
#                [user@dom0 ~]$ chmod +x shortcuts-setup-wm-qubes.sh
#                • Run the script with:
#                [user@dom0 ~]$ bash shortcuts-setup-wm-qubes.sh
# Author       : Me and the bois
# License      : Free of charge, no warranty
# Reference    : https://docs.xfce.org/xfce/xfwm4/keyboard_shortcuts
########################################################################

# Verify dom0
if [ "$(hostname)" != "dom0" ]; then
    echo "ERROR: This script should only run in dom0!" >&2
    exit 1
fi

# Check if xfconf-query is available
if ! command -v xfconf-query > /dev/null; then
    echo "ERROR: xfconf-query is not installed. This script requires Xfce." >&2
    exit 1
fi

# Backup current settings
backup_shortcuts() {
    local backup_file="$HOME/keyboard_shortcuts_backup_$(date +%Y%m%d_%H%M%S).xml"
    echo "Backing up current keyboard shortcuts to $backup_file..."
    xfconf-query -c xfce4-keyboard-shortcuts -lv > "$backup_file"
    echo "Backup created successfully."
}

# Reset existing keyboard shortcuts
reset_shortcuts() {
    echo "Resetting ALL keyboard shortcuts to empty state..."

    # Completely reset the entire channel
    xfconf-query -c xfce4-keyboard-shortcuts -p / -rR 2>/dev/null

    # Ensure basic structure exists (optional)
    xfconf-query -c xfce4-keyboard-shortcuts -p / -n -t string -s "" 2>/dev/null

    echo "Keyboard shortcuts have been reset to empty state."
}

# Create shortcuts with xfconf-query
create_shortcut() {
    local path="$1"
    local value="$2"
    local type="${3:-string}"

    # Delete existing property if it exists
    xfconf-query -c xfce4-keyboard-shortcuts -p "$path" -r 2>/dev/null

    # Create new property with specified type
    xfconf-query -c xfce4-keyboard-shortcuts -p "$path" -n -t "$type" -s "$value"
}

# Function flow
backup_shortcuts  # Keep your backup function
reset_shortcuts    # Wipe all existing shortcuts

echo "Configuring keyboard shortcuts for Qubes Xfce..."

# Qubes-specific shortcuts
create_shortcut "/commands/custom/<Primary><Alt>Escape" "qvm-xkill" "string"
create_shortcut "/commands/custom/<Primary><Alt>l" "xflock4" "string"

# Boolean properties (override and startup-notify)
create_shortcut "/xfwm4/custom/override" "true" "bool"
create_shortcut "/commands/custom/<Super>r/startup-notify" "true" "bool"

# Window management shortcuts
create_shortcut "/xfwm4/custom/<Primary>q" "close_window_key" "string"
create_shortcut "/xfwm4/custom/<Alt>Tab" "cycle_windows_key" "string"
create_shortcut "/xfwm4/custom/<Shift><Alt>Tab" "cycle_reverse_windows_key" "string"
create_shortcut "/xfwm4/custom/<Alt><Super>space" "resize_window_key" "string"
create_shortcut "/xfwm4/custom/<Alt><Super>Control_L" "move_window_key" "string"
create_shortcut "/xfwm4/custom/<Super>d" "show_desktop_key" "string"
create_shortcut "/xfwm4/custom/<Super>m" "hide_window_key" "string"
create_shortcut "/xfwm4/custom/<Shift><Super>m" "maximize_window_key" "string"
create_shortcut "/xfwm4/custom/<Alt>space" "popup_menu_key" "string"
create_shortcut "/xfwm4/custom/Escape" "cancel_key" "string"

# Navigation shortcuts
create_shortcut "/xfwm4/custom/Up" "up_key" "string"
create_shortcut "/xfwm4/custom/Down" "down_key" "string"
create_shortcut "/xfwm4/custom/Left" "left_key" "string"
create_shortcut "/xfwm4/custom/Right" "right_key" "string"

# Window tiling shortcuts (using Ctrl+Super)
create_shortcut "/xfwm4/custom/<Primary><Super>1" "tile_up_left_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Super>2" "tile_up_right_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Super>3" "tile_down_left_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Super>4" "tile_down_right_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Super>Down" "tile_down_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Super>Left" "tile_left_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Super>Right" "tile_right_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Super>Up" "tile_up_key" "string"

# Window movement
create_shortcut "/xfwm4/custom/<Primary><Shift>exclam" "move_window_workspace_1_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Shift>at" "move_window_workspace_2_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Shift>numbersign" "move_window_workspace_3_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Shift>dollar" "move_window_workspace_4_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Shift><Alt>Left" "move_window_prev_workspace_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Shift><Alt>Right" "move_window_next_workspace_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Shift><Alt>Up" "move_window_up_workspace_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Shift><Alt>Down" "move_window_down_workspace_key" "string"

# Workspace movement
create_shortcut "/xfwm4/custom/<Shift><Alt>exclam" "workspace_1_key" "string"
create_shortcut "/xfwm4/custom/<Shift><Alt>at" "workspace_2_key" "string"
create_shortcut "/xfwm4/custom/<Shift><Alt>numbersign" "workspace_3_key" "string"
create_shortcut "/xfwm4/custom/<Shift><Alt>dollar" "workspace_4_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Alt>Right" "next_workspace_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Alt>Left" "prev_workspace_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Alt>Down" "down_workspace_key" "string"
create_shortcut "/xfwm4/custom/<Primary><Alt>Up" "up_workspace_key" "string"

# Application switching
create_shortcut "/xfwm4/custom/<Alt>Escape" "switch_application_key" "string"
create_shortcut "/xfwm4/custom/<Shift><Alt>Escape" "switch_window_key" "string"

echo "Keyboard shortcuts configuration complete."
echo "Note: Some shortcuts may require restarting xfwm4 to take effect."
echo "You may need to log out and back in for all changes to apply."

KDE has long had shortcuts for moving windows to next screen.

I never presume to speak for the Qubes team.
When I comment in the Forum I speak for myself.