如何仅放置/调整*第一个*匹配的窗口的大小?

如何仅放置/调整*第一个*匹配的窗口的大小?

使用带有 Unity 界面和 Compiz 3D 的 11.04,通过 CompizConfig 设置管理器(ccsm,默认情况下未安装,但非常有用),我可以使用“放置窗口”插件来设置窗口的默认位置,使用“窗口规则”插件来设置窗口的默认大小,这非常方便。(如果我不必重复规则就好了,但是嘿,*nix 就是关于小部件协同工作的......)

有什么方法可以设置这些规则,使它们仅在打开的窗口与它们唯一匹配时才适用?例如,不适用于我打开的第二个或第三个匹配窗口?(例如:第一次打开 Chrome 时,我希望它在 X、Y 处,大小为 W、H,但如果我按 Ctrl+N,我希望第二个窗口按照一般规则放置,而不是我的固定规则。)或者我必须回退到wmctrlDevil's Pie 脚本来实现这种事情?

答案1

好吧,答案似乎是否定的,您无法使用“放置窗口”和“窗口规则”插件来实现这一点。相反,您必须使用wmctrl和/或魔鬼派

在我的例子中,仅作为示例,我删除了 Chrome 的所有“放置窗口”/“窗口规则”内容,并wmctrl通过使用一些脚本创建自定义google-chrome.desktop文件来使用:

  1. 复制常用google-chrome.desktop文件:

    cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications
    
  2. 编辑~/.local/share/applications/google-chrome.desktop

  3. 找到该Exec=行并将其更改为指向方便位置的脚本:

    Exec=/home/tjc/bin/runchrome %U
    

我的runchrome脚本只是runandmove使用我想要用于 Chrome 的参数调用我的通用脚本:

#!/bin/bash

# For 1440x900:
runandmove "Google Chrome" 0 246 0 1025 875 /opt/google/chrome/google-chrome $*

这些数字是workspace x y width height

我的runandmove剧本并不漂亮,但内容如下:

#!/bin/bash
#
# runandmove looks to see if a program with a given title is already running. If so,
# it raises that program (brings it to the foreground). If not, it runs the program
# in the background (eating all output) and tries to move it to the given position.

# Check we have enough args
if [ $# -lt 7 ]; then
    echo "ERROR: Please supply at least seven arguments."
    echo
    echo "Usage:"
    echo
    echo "    runandmove \"program title\" workspace x y width height \"run command\" {args for command}"
    echo
    echo "Be sure to use quotes around the program title and the run command if they include"
    echo "any spaces (no need if they don't)."
    exit -1
fi

# Get the args
program_title=$1
program_ws=$2
program_x=$3
program_y=$4
program_width=$5
program_height=$6
program_cmd=$7
shift 7

# If the program is already running, bring it to the foreground. If it wasn't, wmctrl will
# return 1 and we'll use that as a flag telling us that we just started it.
wmctrl -a "$program_title"
just_started=$?

# If it isn't running, run it and put it in the right place
if [ $just_started -gt 0 ]; then
    "$program_cmd" $* &> /dev/null &
    wmctrlretry -r "$program_title" -e $program_ws,$program_x,$program_y,$program_width,$program_height
fi

由于我们发出程序命令后它才会显示在窗口管理器中,因此请注意上面使用wmctrlretry是否启动程序,这只是一个简单的重试包装器wmctrl

#!/bin/bash

# wmctrl with up to 100 retries; we use this when we've just launched a program
# and it takes a moment to show up in the window manager's list.
counter=0
wmctrl $*
while [ $? -gt 0 ]; do
    counter=$[$counter+1]
    if [ $counter -gt 19 ]; then
        exit -1
    fi
    sleep 0.125
    wmctrl $*
done

相关内容