linux查看正在运行的窗口,获取linux中打开的应用程序窗口的数量

我想检测由窗口管理器管理的特定应用程序的实例数量.目前,我有这个:

#!/bin/bash

# wmctrl required

pids=$(pidof $1)

IFS=' ' read -a pid_arr <<< "$pids"

matches=0

for pid in "${pid_arr[@]}"

do

matching_lines=$(wmctrl -l -p | egrep -c "^.+\b.+\b$pid\b")

matches=$((matches + $matching_lines))

done

echo $matches

假设我有三次打开firefox并且我将firefox作为参数传递,如果没有打开“子窗口”(例如首选项窗口),该函数将只返回正确的数字.否则,该函数也将计算这些窗口.

我想获得没有“子窗口”的窗口数量.

P.S.:做了一些改变.要计算没有对话窗口的窗口数,这是我目前的解决方案:

#!/bin/bash

pids=$(pidof $1)

IFS=' ' read -r -a pid_arr <<< "$pids"

matches=0

for pid in "${pid_arr[@]}"

do

ids=$(wmctrl -l -p | awk '$3=='$pid'{printf $1" "}')

IFS=' ' read -r -a id_arr <<< "$ids"

for id in "${id_arr[@]}"

do

if ! xprop -id "$id" |

egrep -q '(WM_TRANSIENT_FOR|_NET_WM_WINDOW_TYPE_DIALOG)'

then

((matches++))

fi

done

done

echo $matches

但是在firefox的情况下,脚本无法区分浏览器窗口及其首选项窗口,因为它们都不是对话框窗口.

上面的脚本对我来说已经足够了,因为我用它来弄清楚xfce4-appfinder有多少个窗口(没有对话窗口).对于xfce4-appfinder,脚本可以正常工作,因为它的首选项窗口很容易被识别为对话框窗口.在firefox中,甚至可以通过调用firefox -preferences独立打开首选项窗口.将这样的窗口识别为某种“子窗口”可能是不可能的.

以下是我对firefox的浏览器和首选项窗口的xprop和xwininfo的结果:

xwininfo(浏览器):

xwininfo: Window id: 0x1c0007f "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"

Root window id: 0xa1 (the root window) (has no name)

Parent window id: 0x1400048 (has no name)

1 child:

0x1c00080 (has no name): () 1x1+-1+-1 +1+37

Absolute upper-left X: 2

Absolute upper-left Y: 38

Relative upper-left X: 0

Relative upper-left Y: 14

Width: 956

Height: 511

Depth: 24

Visual: 0x20

Visual Class: TrueColor

Border width: 0

Class: InputOutput

Colormap: 0x22 (installed)

Bit Gravity State: NorthWestGravity

Window Gravity State: NorthWestGravity

Backing Store State: NotUseful

Save Under State: no

Map State: IsViewable

Override Redirect State: no

Corners: +2+38 -962+38 -962-531 +2-531

-geometry 956x511+0+22

Bit gravity: NorthWestGravity

Window gravity: NorthWestGravity

Backing-store hint: NotUseful

Backing-planes to be preserved: 0xffffffff

Backing pixel: 0

Save-unders: No

Someone wants these events:

KeyPress

KeyRelease

ButtonPress

ButtonRelease

EnterWindow

LeaveWindow

PointerMotion

Exposure

VisibilityChange

StructureNotify

FocusChange

PropertyChange

Do not propagate these events:

Override redirection?: No

Window manager hints:

Client accepts input or input focus: Yes

Initial state is Normal State

Displayed on desktop 0

Window type:

Normal

Process id: 792 on host T530

Normal window size hints:

Program supplied minimum size: 300 by 71

Program supplied maximum size: 32767 by 32767

Program supplied window gravity: NorthWestGravity

No zoom window size hints defined

No window shape defined

No border shape defined

xwininfo(首选项):

xwininfo: Window id: 0x1c046ef "Firefox Preferences"

Root window id: 0xa1 (the root window) (has no name)

Parent window id: 0x1400060 (has no name)

1 child:

0x1c046f0 (has no name): () 1x1+-1+-1 +961+37

Absolute upper-left X: 962

Absolute upper-left Y: 38

Relative upper-left X: 0

Relative upper-left Y: 14

Width: 956

Height: 1040

Depth: 24

Visual: 0x20

Visual Class: TrueColor

Border width: 0

Class: InputOutput

Colormap: 0x22 (installed)

Bit Gravity State: NorthWestGravity

Window Gravity State: NorthWestGravity

Backing Store State: NotUseful

Save Under State: no0x1c00001

Map State: IsViewable

Override Redirect State: no

Corners: +962+38 -2+38 -2-2 +962-2

-geometry 956x1040-0-0

Bit gravity: NorthWestGravity

Window gravity: NorthWestGravity

Backing-store hint: NotUseful

Backing-planes to be preserved: 0xffffffff

Backing pixel: 0

Save-unders: No

Someone wants these events:

KeyPress

KeyRelease

ButtonPress

ButtonRelease

EnterWindow

LeaveWindow

PointerMotion

Exposure

VisibilityChange

StructureNotify

FocusChange

PropertyChange

Do not propagate these events:

Override redirection?: No

Window manager hints:

Client accepts input or input focus: Yes

Initial state is Normal State

Displayed on desktop 0

Window type:

Normal

Process id: 792 on host T530

Normal window size hints:

Program supplied location: 0, 0

Program supplied minimum size: 604 by 594

Program supplied maximum size: 32767 by 32767

Program supplied window gravity: NorthWestGravity

No zoom window size hints defined

No window shape defined

No border shape defined

xprop(浏览器):

_DESKTOP(CARDINAL) = 0

WM_STATE(WM_STATE):

window state: Normal

icon window: 0x0

WM_HINTS(WM_HINTS):

Client accepts input or input focus: True

Initial state is Normal State.

bitmap id # to use for icon: 0x1c00082

bitmap id # of mask for icon: 0x1c00083

window id # of group leader: 0x1c00001

_NET_STARTUP_ID(UTF8_STRING) = "xfce4-appfinder/|usr|lib|firefox|firefox/756-0-T530_TIME21351"

WM_WINDOW_ROLE(STRING) = "browser"

XdndAware(ATOM) = BITMAP

_MOTIF_DRAG_RECEIVER_INFO(_MOTIF_DRAG_RECEIVER_INFO) = 0x6c, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0

_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 29360257

_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL

_NET_WM_USER_TIME(CARDINAL) = 1758669

_NET_WM_USER_TIME_WINDOW(WINDOW): window id # 0x1c00080

WM_CLIENT_LEADER(WINDOW): window id # 0x1c00001

_NET_WM_PID(CARDINAL) = 792

WM_LOCALE_NAME(STRING) = "en_US.UTF-8"

WM_CLIENT_MACHINE(STRING) = "T530"

WM_NORMAL_HINTS(WM_SIZE_HINTS):

program specified minimum size: 300 by 71

program specified maximum size: 32767 by 32767

window gravity: NorthWest

WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST

WM_CLASS(STRING) = "Navigator", "Firefox"

WM_ICON_NAME(STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"

_NET_WM_ICON_NAME(UTF8_STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"

WM_NAME(STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"

_NET_WM_NAME(UTF8_STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"

xprop(首选项)

_NET_WM_DESKTOP(CARDINAL) = 0

WM_STATE(WM_STATE):

window state: Normal

icon window: 0x0

WM_HINTS(WM_HINTS):

Client accepts input or input focus: True

Initial state is Normal State.

bitmap id # to use for icon: 0x1c046f2

bitmap id # of mask for icon: 0x1c046f3

window id # of group leader: 0x1c00001

WM_WINDOW_ROLE(STRING) = "Preferences"

XdndAware(ATOM) = BITMAP

_MOTIF_DRAG_RECEIVER_INFO(_MOTIF_DRAG_RECEIVER_INFO) = 0x6c, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0

_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 29378289

_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL

_NET_WM_USER_TIME(CARDINAL) = 1456410

_NET_WM_USER_TIME_WINDOW(WINDOW): window id # 0x1c046f0

WM_CLIENT_LEADER(WINDOW): window id # 0x1c00001

_NET_WM_PID(CARDINAL) = 792

WM_LOCALE_NAME(STRING) = "en_US.UTF-8"

WM_CLIENT_MACHINE(STRING) = "T530"

WM_NORMAL_HINTS(WM_SIZE_HINTS):

program specified location: 0, 0

program specified minimum size: 604 by 594

program specified maximum size: 32767 by 32767

window gravity: NorthWest

WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST

WM_CLASS(STRING) = "Browser", "Firefox"

WM_ICON_NAME(STRING) = "Firefox Preferences"

_NET_WM_ICON_NAME(UTF8_STRING) = "Firefox Preferences"

WM_NAME(STRING) = "Firefox Preferences"

_NET_WM_NAME(UTF8_STRING) = "Firefox Preferences"

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/554899.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

TortoiseGit的使用详解

Git是什么&#xff0c;相信大家都很清楚。Git不就是分布式版本控制系统嘛&#xff1f;那你知道TortoiseGit是什么吗&#xff1f;下面我们就介绍一下TortoiseGit它是什么&#xff1f;如何使用&#xff1f;   TortoiseGit其实是一款开源的git的版本控制系统&#xff0c;也叫海龟…

linux gpt分区看不到,Linux无法看到我的任何分区 – 备份GPT表不在磁盘的末尾

我正在尝试在HP Pavilion 14英寸超极本上安装Linux,但没有任何成功.起初我尝试在其上安装Ubuntu;一切都很顺利,我进入了Live DVD(是的,我就像那样老了),然后去我的磁盘上安装系统.发生的第一个奇怪的事情是,我没有被提示选择在Windows旁边安装Ubuntu,而是直接用分区表抛入窗口.…

将项目上传到Gitee上(命令方式使用TortoiseGit方式)

如何将项目上传到Gitee上&#xff08;命令方式&#xff09; 目录 将项目上传到Gitee是我们经常需要使用到的操作&#xff0c;因此我们要熟悉这些步骤 一、首先保证本机已经安装了Git git官网安装完成之后&#xff0c;鼠标右键会出现Git GUI Here和Git Bash Here 二、上传代…

linux自动重新启动,linux 系统自动重新启动,请帮忙看看

在查了一下,的确有这个log其中有一段之后系统开始重新启动&#xff0c;请帮忙看看是什么原因&#xff1a;谢谢[2011-01-25 11:33:36 xend.XendDomainInfo 2990] DEBUG (XendDomainInfo:228) XendDomainInfo.recreate({paused: 0, cpu_time: 41195236230L, ssidref: 0, hvm: 0, …

java.awt.Color类

Color类概述 Color是用来封装颜色的&#xff0c;支持多种颜色空间&#xff0c;默认为RGB颜色空间。每个Color对象都有一个alpha通道&#xff0c;值为0到255&#xff0c;代表透明度&#xff0c;当alpha通道值为255时&#xff0c;表示完全不透明&#xff1b;当alpha通道值为0时&…

BufferedImage类、Image类、Graphics类

BufferedImage Image是一个抽象类&#xff0c;BufferedImage是其实现类&#xff0c;是一个带缓冲区图像类&#xff0c;主要作用是将一幅图片加载到内存中&#xff08;BufferedImage生成的图片在内存里有一个图像缓冲区&#xff0c;利用这个缓冲区我们可以很方便地操作这个图片&…

linux远程连接最大数是多少,Linux Shell 脚本限制ssh最大用户登录数

我撰写本文原来的意图是想把“复制SSH渠道”和"copy SSH Session"这样的功能从远程ssh客户端中剔除掉.因此想到可以在SSH服务端设置一下&#xff0c;但查阅了sshd_config的man手册,发现里面的看起来限制ssh连接数量的参数(MaxSessions &#xff0c;ClientAliveCountM…

linux 文件名带特殊符号,Linux删除含有特殊符号文件名的文件

Web前端面试题目及答案汇总HTML/CSS部分 1.什么是盒子模型? 在网页中,一个元素占有空间的大小由几个部分构成,其中包括元素的内容(content),元素的内边距(padding),元素的边框(border),元素的外边 ...Delphi中滚动文字的应用1.添加一个Timer控件,Interval属性设置为20. 2.添加…

Vue this.$refs的作用

案例一、ref 写在标签上时 <!-- ref 写在标签上时&#xff1a;this.$refs.名字 获取的是标签对应的dom元素ref 写在组件上时&#xff1a;这时候获取到的是 子组件&#xff08;比如counter&#xff09;的引用--><div id"root"><!-- ref hello&#…

linux电脑合盖后卡住了,解决ubuntu合盖后无法唤醒

解决办法&#xff1a;安装laptop-mode-tools工具包。1.检查是否安装了grep laptop-mode-tools 工具包$ dpkg -l | grep laptop-mode-tools如果执行命令无结果输出&#xff0c;表示未安装(如果已安装&#xff0c;忽略第2步)2.安装laptop-mode执行命令&#xff1a;$ sudo apt-get…

三列布局 css

实现如下图的三列布局&#xff1a; .box {width:1400px;margin:0 auto;padding-bottom:40px;> .left {float:left;width:180px;margin-top:100px;text-align:center;}> .center {float:left;margin-top:100px;margin-left:130px;item-box {float:left;text-align:left;…

axios和ajax的区别是什么

axios和ajax的区别&#xff1a; 1、axios是一个基于Promise的HTTP库&#xff0c;而ajax是对原生XHR的封装&#xff1b; 2、ajax技术实现了局部数据的刷新&#xff0c;而axios实现了对ajax的封装。 axios和ajax的区别是什么? axios和ajax的区别及优缺点: ajax&#xff1a; 1…

telnet linux 命令详解,解析Linux Telnet命令

不少系统中&#xff0c;都有Telnet的相关涉及和使用。那么今天我们就来讲解一下Linux Telnet命令的相关使用和操作。这里我们针对一些重点的内容和命令进行讲解。希望对大家有所帮助。用户使用Telnet命令进行远程登录。该命令允许用户使用Telnet协议在远程计算机之间进行通信&a…

VUE学习笔记详细

VUE学习笔记 本文章以vue3来记录的&#xff0c;但并非记录vue3所有变化&#xff01; 1、ES6语法 1.1、let变量声明 let用于声明变量有局部作用域let声明的变量不会提升&#xff08;只能先定义后使用&#xff09; 1.2、const变量声明 const用于声明常量const声明的常量也不会…

C语言2020年作业,2020年c语言上机报告范文【四篇】

《2020年c语言上机报告范文【四篇】》由会员分享&#xff0c;可在线阅读&#xff0c;更多相关《2020年c语言上机报告范文【四篇】(7页珍藏版)》请在人人文库网上搜索。1、2020 年 c 语言上机报告范文【四篇】2020 年 c 语言上机报告范文一说到我学习 C 语言时&#xff0c;真是用…

Centos7配置gitlab服务器

Centos7配置gitlab服务器 1、安装SSH yum install -y curl policycoreutils-pythonopenssh-server设置开机自启 sudo systemctl enable sshd启动服务 sudo systemctl start sshd2、安装postfix 邮件服务 sudo yum install postfix设置开机自启 sudo systemctl enable po…

湖南工大11级C语言网上作业,湖南工大11级C语言网上作业之《最简单的程序设计》.docx...

《程序设计语言 C1》随机作业题做作业时间&#xff1a;2012-3-9 8:00:00至2012-5-29 23:30:00?1、以下程序的输出结果是 main() { char cz; printf("%c",c-25); } (3分)A、B、C、D、A、aB、ZC、z-25D、y?2、以下程序段的输出结果是 char s[]"\\141\141abc\t&q…

Jenkins学习笔记详细

最近接触了jenkins这个东西&#xff0c;所以花点时间了解了下。它可以在代码上传仓库&#xff08;如github,gitee&#xff0c;gitlab&#xff09;后&#xff0c;在jenkins&#xff08;一个网站界面&#xff09;中通过获取代码仓库中最新代码&#xff0c;进行自动化部署&#xf…

c语言程序设计华北电力大学,2016年华北电力大学电气与电子工程学院C语言程序设计(同等学力加试)考研复试题库...

一、选择题1&#xff0e; 有以下程序程序运行后的输出结果是( )。A.24B.44C.22D.46答:B【解析】p 是int 类型的指针&#xff0c;指向数组a 的首元素&#xff1b;k 的int*类型的指针&#xff0c;指向int*变量先执行p&#xff0c;p 指向a 中第二个元素&#xff0c;然后取值&#…

Form Data与Request Payload,你真的了解吗?

前言 做过前后端联调的小伙伴&#xff0c;可能有时会遇到一些问题。例如&#xff0c;我明明传递数据给后端了&#xff0c;后端为什么说没收到呢&#xff1f;这时候可能就会就会有小伙伴陷入迷茫&#xff0c;本文从chrome-dev-tools&#xff08;F12调试器&#xff09;中看到的F…