是否有一个linux命令,以确定与一个给定的进程ID相关联的窗口的ID? [英] Is there a linux command to determine the window IDs associated with a given process ID?

查看:332
本文介绍了是否有一个linux命令,以确定与一个给定的进程ID相关联的窗口的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于XX的进程ID,我想有任何窗口的id,其中_NET_WM_PID = XX的列表。更妙的是最古老的仍然活跃窗口ID如果可能的话。

Given a process iD of XX, I'd like to have a list of any window id's where _NET_WM_PID = XX. Even better would be the oldest still active window id if possible.

我很新的Linux,但我想要做的就是创建一个脚本,将采取一个命令行,看看是否有一个窗口已经打开属于具有相同的命令行调用一个过程。如果是这样,只是将焦点设置到该窗口,否则执行命令行来获得一个新的进程去。我的目的是利用这个在我的Ubuntu桌面,在这里我就帮这个剧本到我easystroke的鼠标手势命令,这样一来,例如,每一次我的手势为gmail我没有得到一个全新的Gmail会话,我只是得到带给我现有的Gmail Chrome应用窗口。也许还有一个更简单的方法去了解这一切,但我没有发现我的方式呢。

I'm very new to linux, but what I'm trying to do is create a script that would take a command line, and see if there's a windows already open belonging to a process invoked with that same command line. If so, just set focus to that window, otherwise execute the command line to get a new process going. My intention is to use this in my ubuntu desktop, where I'll hook this script into my easystroke mouse gesture commands, so that, for example, every time I gesture for gmail I don't get a brand new gmail session, I just get brought to my existing gmail chrome app window. Perhaps there's a much easier way to go about all this, but I haven't found my way to it yet.

通过帮助下,我已经找到了如何找到一个PID与指派,以及如何将焦点设置与wmctrl窗口句柄的命令行,但我被困在得到从PID到窗口ID。

With help, I've figured out how find a PID for a command line with pgrep and how to set focus to a window handle with wmctrl, but I'm stuck on getting from PID to window ID.

推荐答案

xwininfo和xprop许可证获取你想要的东西,但它是一个有点棘手。

xwininfo and xprop permits to retrieve what you want, but it is a little tricky.

xwininfo许可证检索所有已知的窗户和xprop查询X有关您_NET_WM_PID参数一个窗口ID。

xwininfo permits to retrieve all known windows, and xprop to query X about a single window ID for your _NET_WM_PID parameter.

到目前为止,哈克的方式做这将是:

So far, a hacky way to do it would be:

#!/bin/sh

findpid=$1

known_windows=$(xwininfo -root -children|sed -e 's/^ *//'|grep -E "^0x"|awk '{ print $1 }')

for id in ${known_windows}
do
    xp=$(xprop -id $id _NET_WM_PID)
    if test $? -eq 0; then
        pid=$(xprop -id $id _NET_WM_PID|cut -d'=' -f2|tr -d ' ')

        if test "x${pid}" = x${findpid}
        then
            echo "Windows Id: $id"
        fi
    fi
done

结果:

mycroft:~ $ ./find_windows.sh 1919
Windows Id: 0x1800748
Windows Id: 0x181b221
Windows Id: 0x1803ad5
Windows Id: 0x181f681
Windows Id: 0x181f658
Windows Id: 0x180006d
Windows Id: 0x1800003
Windows Id: 0x1800001
Windows Id: 0x180001e

正如你所看到的,一个单一的过程中可能有一定数量知名的窗口,即使你只能看到一个在屏幕上。

As you will see, a single process may have a certain number of known windows, even if you see only one on your screen.

也许你应该为了让你想要什么让这些工具的来源。

Maybe you should get these tools sources in order to make what you want.

这篇关于是否有一个linux命令,以确定与一个给定的进程ID相关联的窗口的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆