searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

X窗口调试

2023-05-22 09:39:47
48
0

0 前言

 《KWin窗口管理器》中介绍了KWin相关的一些调试方法,本文重点介绍X窗口本身的调试工具及方法。

1 窗口信息

1.1 详细信息

sudo apt-get install -y x11-utils
xwininfo                                        # 鼠标选择窗口并打印其信息
xwininfo -id <window_id>                        # 打印指定窗口ID的信息
xwininfo -root -children                        # 打印根窗口及其子窗口信息

    例如UOS Pro V20的终端窗口信息如下:

xwininfo: Window id: 0x7200006 "终端"

  Absolute upper-left X:  215
  Absolute upper-left Y:  186
  Relative upper-left X:  0
  Relative upper-left Y:  0
  Width: 1054
  Height: 651
  Depth: 32
  Visual: 0x392
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x7200005 (not 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:  +215+186  -651+186  -651-179  +215-179
  -geometry 1054x651+214+185

1.2 窗口大小

    上面方法已经包含了窗口大小信息,此外还可以通过下面方法存粹的查看窗口大小:

sudo apt-get install -y xdotool 		# 注:若已安装请忽略
xdotool getwindowgeometry <window_id>
xdotool getwindowgeometry `xdotool selectwindow` # 鼠标选择窗口并打印其位置和大小

    例如

Window 119537670
  Position: 215,186 (screen: 0)
  Geometry: 1054x651

:TTY或SSH远程登录需设置DISPLAY环境变量,例如:

export DISPLAY=:0

1.3 窗口进程

xdotool getwindowpid <window_id> 	               # 通过窗口ID获得该窗口的进程ID
xdotool getwindowpid `xdotool selectwindow` | xargs ps # 鼠标选择窗口并查看其对应进程

用途:发现异常窗体时(白屏、黑屏、卡死),可通过上述命令确认它对应的进程PID。

2 当前窗口

xdotool getactivewindow                                 # 当前活动窗口ID
xdotool getwindowfocus                                  # 当前焦点窗口ID

:通常情况下活动窗口和焦点窗口都是相同的,但据说比焦点窗口的命令更加可靠[1]

 

    拿到窗口ID并非最终目的,可和其它命令组合使用:

(1)活动窗口名称、详情

xdotool getwindowname `xdotool getactivewindow`        # 只显示活动窗口名称,只有一行,例如“deepin20 on QEMU/KVM”
xwininfo -id `xdotool getactivewindow`                 # 显示活动窗口详情

:SSH远程登录执行上述命令自然可以获得不同的焦点窗口,但直接在图形终端中执行上述命令只能得到终端窗口的信息(因为当前焦点必然在终端窗口上),需稍作优化以获得其它焦点窗口信息:

sleep 3; xdotool getwindowname `xdotool getwindowfocus` # 3s内鼠标点击其它应用窗口,然后等待该命令的输出

用途:确认焦点窗口是否可以正常切换来排查键盘输入无响应的问题。

 

(2)聚焦窗口名称、详情

xdotool getwindowname `xdotool getwindowfocus`         # 只显示焦点窗口名称,只有一行,例如“deepin20 on QEMU/KVM”
xwininfo -id `xdotool getwindowfocus`                  # 显示焦点窗口详情

 

2 杀死窗口

xkill                    # 鼠标选择窗口并将其进程杀死[2]
xkill -id <window_id>    # 可通过xwininfo查看窗口的id[2]

用途:可用于杀掉哪些卡死无响应的窗口。

3 dump窗口

    可分别通过xwd命令将窗口dump到文件中,然后通过xwud将其重现出来(类似于截图功能):

(1)dump

xwd -out <file> 				# 然后鼠标点击要dump的窗口
xwd -frame -out <file>			# 同时将窗管增加的外框都包含进来
xwd -d <window_id> -out <file> 	# dump指定窗口 
xwd -root -out <file>			# dump所有窗口

(2)display

xwud -in <file>

 

4 性能测试

sudo apt-get install -y x11-apps
x11perf --help
x11perf -all            # 做所有测试!
x11perf -minpixwin10    # 只做其中一项测试

    上述测试工具在左上角显示一个固定大小区域,不受窗口管理器控制,不能移动或缩放,会遮挡该区域的其它所有窗口:

图4.1

5 卡死确认

    卡死有可能是输入的问题,也有可能是显示问题,因此都需要确认。

5.1 evtest

sudo apt-get install -y evtest
sudo evtest

    通过序号选择要测试的输入设备,例如选择鼠标输入设备后,正常情况下移动鼠标会在终端打印相关事件,例如:

Event: time 1684746463.771410, -------------- SYN_REPORT ------------
Event: time 1684746463.789126, type 3 (EV_ABS), code 1 (ABS_Y), value 619
Event: time 1684746463.789126, -------------- SYN_REPORT ------------
Event: time 1684746463.855432, type 3 (EV_ABS), code 0 (ABS_X), value 1006
Event: time 1684746463.855432, -------------- SYN_REPORT ------------
Event: time 1684746463.890909, type 3 (EV_ABS), code 0 (ABS_X), value 1005
Event: time 1684746463.890909, -------------- SYN_REPORT ------------
Event: time 1684746463.940603, type 3 (EV_ABS), code 1 (ABS_Y), value 618
Event: time 1684746463.940603, -------------- SYN_REPORT ------------
Event: time 1684746464.040009, type 3 (EV_ABS), code 0 (ABS_X), value 1004
Event: time 1684746464.040009, -------------- SYN_REPORT ------------

    若没有上述打印输出,则说明鼠标输入有异常。

5.2 xeyes

sudo apt-get install -y x11-apps
xeyes

    显示一对眼睛,眼珠跟随着鼠标光标位置:

图5.1

用途:可同时确认输入和图形是否异常。

参考资料

[1]man xdotool

[2]杀掉关不掉的XWin程序

0条评论
0 / 1000
李****海
14文章数
0粉丝数
李****海
14 文章 | 0 粉丝