如何为 Ubuntu 使用窗口捕捉?

Dou*_*oug 15 gnome window-manager

可能的重复:
如何模拟 winkey+arrow Windows 7 的最大化快捷键?

我正在尝试 Ubuntu,当我使用热键 Window Key + Arrow 时,我想让我的窗口像 Windows 7 一样左右对齐。我怎样才能做到这一点?

小智 19

这很容易从 CompizConfig 设置管理器启用。(安装它,如果你还没有)。

然后在窗口管理下,启用网格。我保留了 CTRL+ALT+NumPad 的默认绑定,但您可以根据需要轻松更改 Super + Arrow。


小智 4

转到此处,获取来自 Mike 的 Ubuntu 的人类可读形式的完整说明(谢谢 Mike),这里是原始的 Ubuntu 论坛帖子(感谢 Gotsanity)。我已经在我的系统上检查过这个,所以它应该适合你。我还添加和编辑了一些内容,以使其更容易理解。

我对他的指示所做的唯一更改是,您首先检查是否安装了 compiz(最简单的方法是使用软件管理器并将“compiz”放入搜索窗口中。

如果您这样做,请在终端中输入以下内容:-

sudo apt-get install compizconfig-settings-manager wmctrl

否则,compiz 设置管理器将不会出现在您的系统上。

打开终端并输入:

xinput list
Run Code Online (Sandbox Code Playgroud)

它将显示一个列表。找到您的鼠标的 ID 号。您在后续步骤中将需要此号码。我的是 10。你的很可能会有所不同。
接下来的命令会在您的主文件夹中创建一个新的隐藏文件夹来保存所需的脚本,并将您移入其中。

mkdir .scripts

cd .scripts
Run Code Online (Sandbox Code Playgroud)

然后输入

gedit compizsnap-left.sh    
Run Code Online (Sandbox Code Playgroud)

将弹出一个文本编辑器。粘贴此内容,然后将鼠标 ID从 11 更改为“xinput list”命令输出中的数字。完成此操作后,保存文件。

#!/bin/sh
#
# CompizSnap is a collaborative project from ubuntuforums.org and is free software.
# This script adds window snapping functionality to compiz using the commands plugin.
#
# Directions: run "xinput list" to find your mouse's ID# and then edit the MOUSE variable below:
#

MOUSE="11"

# ----- Don't edit below this line unless you know what you are doing.
WIDTH=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x'` && HALF=$(($WIDTH/2-10))

echo $WIDTH
TEMPWIDTH=$(($WIDTH-10))
echo $TEMPWIDTH
if /usr/bin/X11/xinput --query-state $MOUSE | grep down
then
    while (/usr/bin/X11/xinput --query-state $MOUSE | grep down)
    do
        echo 'button pressed'
    done

    if [ "$(/usr/bin/X11/xinput --query-state $MOUSE | grep "valuator\[0\]=." | sed s/"valuator\[0\]="//)" -le 10 ]
    then

        wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,0,0,$HALF,-10

    else
        echo "exiting without matching"
        exit 1
    fi
else
        echo "exiting because button isnt "
        exit 1
fi    
Run Code Online (Sandbox Code Playgroud)

然后,对其他两个脚本执行相同的操作。(不要忘记更改鼠标ID)

compizsnap-right.sh

代码:

#!/bin/sh
#
# CompizSnap is a collaborative project from ubuntuforums.org and is free software.
# This script adds window snapping functionality to compiz using the commands plugin.
#
# Directions: run "xinput list" to find your mouse's ID# and then edit the MOUSE variable below:
#

MOUSE="11"

# ----- Don't edit below this line unless you know what you are doing.
WIDTH=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x'` && HALF=$(($WIDTH/2))

echo $WIDTH
TEMPWIDTH=$(($WIDTH-10))
echo $TEMPWIDTH
if /usr/bin/X11/xinput --query-state $MOUSE | grep down
then
    while (/usr/bin/X11/xinput --query-state $MOUSE | grep down)
    do
        echo 'button pressed'
    done

    if [ "$(/usr/bin/X11/xinput --query-state $MOUSE | grep "valuator\[0\]=." | sed s/"valuator\[0\]="//)" -ge $TEMPWIDTH ]
    then

        wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$HALF,0,$HALF,-1

    else
        echo "exiting without matching"
        exit 1
    fi
else
        echo "exiting because button isnt "
        exit 1
fi    
Run Code Online (Sandbox Code Playgroud)

compizsnap-max.sh

代码:

#!/bin/sh
#
# CompizSnap is a collaborative project from ubuntuforums.org and is free software.
# This script adds window snapping functionality to compiz using the commands plugin.
#
# Directions: run "xinput list" to find your mouse's ID# and then edit the MOUSE variable below:
#

MOUSE="11"

# ----- Don't edit below this line unless you know what you are doing.
if /usr/bin/X11/xinput --query-state $MOUSE | grep down
then
    while (/usr/bin/X11/xinput --query-state $MOUSE | grep down)
    do
        echo 'button pressed'
    done
    if [ "$(/usr/bin/X11/xinput --query-state $MOUSE | grep "valuator\[1\]=." | sed s/"valuator\[1\]="//)" -le 10 ]
    then

        wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz

    else
        echo "exiting without matching"
        exit 1
    fi
else
        echo "exiting because button isnt "
        exit 1
fi    
Run Code Online (Sandbox Code Playgroud)

(你记得更改鼠标ID吗)

现在我们需要告诉 compiz 当鼠标移动到屏幕的右侧、顶部和左侧时如何表现。

运行系统 > 首选项 > CompizConfig 设置管理器。转到命令部分。设置以下内容:
在命令 0 字段中:

sh ~/.scripts/compizsnap-left.sh
Run Code Online (Sandbox Code Playgroud)

在命令 1 字段中:

sh ~/.scripts/compizsnap-right.sh
Run Code Online (Sandbox Code Playgroud)

在命令 2 字段中:

sh ~/.scripts/compizsnap-max.sh
Run Code Online (Sandbox Code Playgroud)

最后,转到边缘绑定选项卡,将命令 0 设置为左​​侧,将命令 1 设置为右侧,将命令 2 设置为顶部。

NB Compiz 可能会抱怨已经有函数设置为您想要使用的边缘绑定 - 将它们替换为您的。


小智 2

大多数 Unix 窗口管理器和 Windows 之间的区别之一是,大多数 Unix 窗口管理器对屏幕边缘的窗口移动提供阻力。因此,您不需要任何特殊命令来将窗口移动到屏幕的左边缘或右边缘;只需将其中一个拖向边缘,它就会在到达那里时停止。我不知道有任何 Gnome(目前标准的 Ubuntu 窗口管理器)键盘快捷键可以移动窗口。