unity linux 编辑器总是弹出“Hold On”即使我当前的窗口不是 unity editor,所以我希望在创建这个 win 时最小化“Hold On”win,这是我的代码:
#!/bin/bash
# regex for extracting hex id's
grep_id='0[xX][a-zA-Z0-9]\{7\}'
xprop -spy -root _NET_ACTIVE_WINDOW | grep --line-buffered -o $grep_id |
while read -r id; do
class="`xprop -id $id WM_CLASS | grep Unity`"
win_title="`xprop -id $id WM_NAME | grep Hold\ On`"
if [ -n "$class" ] && [ -n "$win_title" ]; then
xdotool windowminimize $id
fi
done
但是上面的代码有问题,每次激活“Hold On”时都会触发_NET_ACTIVE_WINDOW,我只需要在创建窗口时最小化“Hold On”,我该怎么办?
在 linux xfce 中,“Window Manager” > “automatically give focus to new created window”,所以我想存在某种方式来观察窗口创建事件
最佳答案
这是我的 ruby 解决方案:我缓存最小化的窗口 ID,一个窗口只最小化一次
system %Q(notify-send "auto hide Unity 'Hold On' popup, conf: #{__FILE__}")
# bash_script = File.expand_path("../../sh/auto_hide_unity_hold_on_popup.sh", __FILE__)
# system "bash #{bash_script}"
pipe = IO.popen("xprop -spy -root _NET_ACTIVE_WINDOW")
wids = []
while (line = pipe.gets)
wid = line.match(%r{0x[\da-z]{2,}})
kls = `xprop -id #{wid} WM_CLASS | grep Unity`
win_title = `xprop -id #{wid} WM_NAME | grep "Hold On"`
if !wids.include?(wid) && kls != "" && win_title != ""
wids << wid
if (wids.size > 20)
wids = wids[-20..-1]
end
`xdotool windowminimize #{wid}`
end
end
关于c++ - 在 linux 中,如何在 bash 或 c 或 c++ 中观察窗口创建事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52583791/