您想要的实际命令是这样的
wmctrl -r :ACTIVE: -b add,maximized_vert &&
wmctrl -r :ACTIVE: -e 0,0,0,$HALF,-1
这将使当前窗口占据屏幕的一半(更改$HALF
为屏幕的尺寸)并对齐到左侧。要向右对齐,请使用
wmctrl -r :ACTIVE: -b add,maximized_vert &&
wmctrl -r :ACTIVE: -e 0,$HALF,0,$HALF,-1
您也可以使用wmctrl
来获取感兴趣的窗口的ID,而不是使用:ACTIVE:
。不过,我对此无能为力,因为这取决于所讨论的窗户。看看man wmctrl
更多。
我为此写了一个脚本。我不使用Unity,因此无法保证它可以与Unity一起使用,但是我看不出为什么不这样做。它需要wmctrl
,xdpyinfo
并且disper
要安装:
sudo apt-get install wmctrl x11-utils disper
然后,将以下脚本另存为~/bin/snap_windows.sh
,使其可以执行,chmod a+x ~/bin/snap_windows.sh
然后可以运行
snap_windows.sh r
捕捉到右侧。l
用于左侧,不使用任何参数来最大化窗口。请注意,它在当前窗口上运行,因此,如果您希望它在终端以外的任何设备上运行,则需要为其分配快捷方式。
该脚本比您要的要复杂一些,因为我已将其编写为可在单显示器和双显示器设置中使用。
#!/usr/bin/env bash
## If no side has been given, maximize the current window and exit
if [ ! $1 ]
then
wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz
exit
fi
## If a side has been given, continue
side=$1;
## How many screens are there?
screens=`disper -l | grep -c display`
## Get screen dimensions
WIDTH=`xdpyinfo | grep 'dimensions:' | cut -f 2 -d ':' | cut -f 1 -d 'x'`;
HALF=$(($WIDTH/2));
## If we are running on one screen, snap to edge of screen
if [ $screens == '1' ]
then
## Snap to the left hand side
if [ $side == 'l' ]
then
## wmctrl format: gravity,posx,posy,width,height
wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,0,0,$HALF,-1
## Snap to the right hand side
else
wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$HALF,0,$HALF,-1
fi
## If we are running on two screens, snap to edge of right hand screen
## I use 1600 because I know it is the size of my laptop display
## and that it is not the same as that of my 2nd monitor.
else
LAPTOP=1600; ## Change this as approrpiate for your setup.
let "WIDTH-=LAPTOP";
SCREEN=$LAPTOP;
HALF=$(($WIDTH/2));
if [ $side == 'l' ]
then
wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$LAPTOP,0,$HALF,-1
else
let "SCREEN += HALF+2";
wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,$SCREEN,0,$HALF,-1;
fi
fi