XFCE - 击键时将窗口发送到其他监视器

bof*_*fin 35 keyboard-shortcuts xfce multi-monitor xubuntu

我正在使用双显示器设置运行 Xubuntu 11.10。我期待创造一个按键(也许CTRL+ ALT+ SPACE,这将让我选择的窗口发送到下一个监视器。

在 GNOME 中有一个名为的包swapmonitor,它能够将窗口发送到其他监视器。用按键调用这个程序也能达到同样的效果。

这是如何在 XFCE/Xubuntu 中完成的?

小智 35

这是不久前发布的,我相信您已经得到了答案,但对于那些还没有得到的人。

运行这些命令

sudo apt-get install xdotool
sudo apt-get install wmctrl
Run Code Online (Sandbox Code Playgroud)

然后从以下链接下载 bash 脚本(归功于 jc00ke) https://github.com/jc00ke/move-to-next-monitor

就我个人而言,我的根目录中有一个目录,用于存储我所有的个人脚本。然而,你在哪里下载它真的取决于你。将其更改为具有权限,以便您可以执行。例如,将脚本保存为move-to-next-monitor.sh,然后执行以下命令

chmod 755 move-to-next-monitor.sh
Run Code Online (Sandbox Code Playgroud)
  1. 设置管理器 -> 键盘 -> 应用程序快捷方式
  2. 点击添加
  3. 单击打开并将其定向到您的脚本
  4. 为其分配一个键盘快捷键,瞧!

您现在有一个键盘快捷键可以将窗口从一个屏幕切换到另一个屏幕。我不确定它是如何处理超过 2 个屏幕的。


jbr*_*ock 12

我对上面提到的脚本做了一些更改,最初由 jc00ke 编写。

  • 我的设置为三个显示器。
  • 它维护窗口是否最大化。
  • 它用于分别使用script-name -l和向左或向右移动窗口script-name -r
  • 如果您有两台显示器,您将使用script-name -a.
  • 我添加了一个修复程序,其中最小化时 Chromium 应用程序非常小,并且不会在新显示器上再次最大化。
    我与 jc00ke 通信。虽然这在 Xfce 上效果很好,但他说他在 Unity 中的脚本有问题。当然,其他桌面环境(例如 Unity)不需要此脚本,因为此类选项已内置于窗口管理器中。
    要使用脚本使其可执行chmod +x script-name并安装以下两个程序,sudo apt install xdotool wmctrl.
#!/bin/bash
#
# Move the current window to the next monitor.
#
# Also works only on one X screen (which is the most common case).
#
# Props to
# http://icyrock.com/blog/2012/05/xubuntu-moving-windows-between-monitors/
#
# Unfortunately, both "xdotool getwindowgeometry --shell $window_id" and
# checking "-geometry" of "xwininfo -id $window_id" are not sufficient, as
# the first command does not respect panel/decoration offsets and the second
# will sometimes give a "-0-0" geometry. This is why we resort to "xwininfo".

screen_width=$(xdpyinfo | awk -F" |x" '/dimensions:/ { print $7 }')
screen_height=$(xdpyinfo | awk -F" |x" '/dimensions:/ { print $8 }')
window_id=$(xdotool getactivewindow)

case $1 in
    -l )
        display_width=$((screen_width / 3 * 2))
        ;;
    -r )
        display_width=$((screen_width / 3))
        ;;
    -a )
        display_width=$((screen_width / 2))
        ;;
esac

# Remember if it was maximized.
window_state=$(xprop -id $window_id _NET_WM_STATE | awk '{ print $3 }')

# Un-maximize current window so that we can move it
wmctrl -ir $window_id -b remove,maximized_vert,maximized_horz

# Read window position
x=$(xwininfo -id $window_id | awk '/Absolute upper-left X:/ { print $4 }')
y=$(xwininfo -id $window_id | awk '/Absolute upper-left Y:/ { print $4 }')

# Subtract any offsets caused by window decorations and panels
x_offset=$(xwininfo -id $window_id | awk '/Relative upper-left X:/ { print $4 }')
y_offset=$(xwininfo -id $window_id | awk '/Relative upper-left Y:/ { print $4 }')
x=$((x - x_offset))
y=$((y - y_offset))

# Fix Chromium app view issue of small un-maximized size
width=$(xdotool getwindowgeometry $window_id | awk -F" |x" '/Geometry:/ { print $4 }')
if [ "$width" -lt "150" ]; then
  display_width=$((display_width + 150))
fi

# Compute new X position
new_x=$((x + display_width))
# Compute new Y position
new_y=$((y + screen_height))

# If we would move off the right-most monitor, we set it to the left one.
# We also respect the window's width here: moving a window off more than half its width won't happen.
if [ $((new_x + width / 2)) -gt $screen_width ]; then
  new_x=$((new_x - screen_width))
fi

height=$(xdotool getwindowgeometry $window_id | awk -F" |x" '/Geometry:/ { print $5 }')
if [ $((new_y + height / 2)) -gt $screen_height ]; then
  new_y=$((new_y - screen_height))
fi

# Don't move off the left side.
if [ $new_x -lt 0 ]; then
  new_x=0
fi

# Don't move off the bottom
if [ $new_y -lt 0 ]; then
  new_y=0
fi

# Move the window
xdotool windowmove $window_id $new_x $new_y

# Maintain if window was maximized or not
if [[ "${window_state}" == _NET_WM_STATE_MAXIMIZED* ]]; then
    wmctrl -ir $window_id -b add,maximized_vert,maximized_horz
fi
Run Code Online (Sandbox Code Playgroud)


cal*_*doa 8

我还创建了自己的 python 脚本来跨显示器移动窗口。

https://github.com/calandoa/movescreen

用法:

movescreen.py <up|down|left|right>

有趣的功能:

  • 处理4个方向
  • 处理一些特殊情况,例如在多个显示器上重叠的窗口
  • 恢复独立全屏最大化水平垂直状态
  • 使用python轻松调试或添加新功能。