c++ - 在 linux 中,如何在 bash 或 c 或 c++ 中观察窗口创建事件

标签 c++ c linux bash

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”,所以我想存在某种方式来观察窗口创建事件 enter image description here

最佳答案

这是我的 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/

相关文章:

c - 按降序显示列表

linux - 在 linux 命令行上反向目录搜索

linux - 如何在 linux 脚本中更改函数参数的值?

c++ - 运算符 + 和 float 参数

c - 如何动态更改c中i/o流中的字符串

c++ - 施工中的 self 引用

c - C 中将数组和数组指针传递给函数的区别

linux - 读取文件(列和循环)和 ssh

c++ - 捕获自定义 UART 类信号

c++ - 当函数有特定大小的数组参数时,为什么要用指针替换它?