#!/usr/bin/env bash
[[ "$#" -lt 2 ]] && {
echo "Usage: $0 <desktop> <command> [arg] ..."
exit 1
}
getWinIdList(){
wmctrl -l | sed 's/\s.*//'
}
DESKTOP=$1
shift
WL="$(getWinIdList)"
#run the process
"$@" &
# Loop up to 20 seconds and wait for new window apperence
i=0
while [[ "$((i++))" -lt 200 ]]; do
newWL="$(getWinIdList)"
# check if there are new windows
wins=$(diff <(echo -n "$WL") <(echo -n "$newWL") | sed -n '/^>/p')
[[ -n "$wins" ]] && break
sleep 0.1 || break
done
# if new windows were detected, move them.
if [[ -n "$wins" ]]; then
for w in $wins; do
wmctrl -ir "$w" -t "$DESKTOP"
done
else
echo "The timeout expired no new windows detected."
fi
如果你 ssh 进入并运行
然后应用程序将在监视器上打开,如果有的话,
我想你的问题也可以这样说。
在大多数 WM 中管理桌面上的窗口位置是根据这个freesesktop 的高规范实现的。在此规范的基础上,有一个控制台实用程序
wmctrl。规范本身的 API 不包含“在桌面 N 上启动 X”之类的内容,所以我看到了两个选项:切换到桌面 # 1并运行应用程序:
记住窗口列表→运行应用程序→出现新窗口时,转移到桌面N;如果应用程序创建多个窗口或欢迎窗口,这将需要一个小脚本并且不是很可靠。
⚠小心,耙拐杖分散得更远。
发射:
一般来说,我认为没有一种方法(DE/WM/平台特定与否)以某种方式可靠地使任意应用程序在某个表上运行其所有窗口,这仅仅是基于进程交互增加了三倍的事实,窗口管理器和 X11。
¹ 台式机从零开始计数