簡體   English   中英

在Linux中,如何觀看Bash或C或C ++中的窗口創建事件

[英]In linux, how to watch window creating event in bash or c or c++

即使我當前的窗口不是unity編輯器,Unity Linux編輯器也會始終彈出“ Hold On”,因此我希望在創建此Win時最小化“ Hold On”贏,這是我的代碼:

#!/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中,“窗口管理器”>“自動將焦點移到新創建的窗口”,因此我想存在一些監視窗口創建事件的方法 在此處輸入圖片說明

這是我的紅寶石解決方案:我緩存最小化的窗口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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM