首页 > 解决方案 > 在虚拟 X 显示器上启动并检查窗口名称

问题描述

我正在 Ubuntu 18.04 上编写测试。我想创建一个虚拟显示器,在其上启动一个窗口,然后检查窗口名称。在三个单独的外壳中,我正在运行:

Xvfb :4 -screen 0 1920x1080x24+32 -fbdir /var/tmp 

然后

DISPLAY=:4 xterm

然后

DISPLAY=:4 xdotool getwindowfocus getwindowname

最后一个命令返回

XGetInputFocus returned the focused window of 1. This is likely a bug in the X server.
X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  20 (X_GetProperty)
  Resource id in failed request:  0x1
  Serial number of failed request:  20
  Current serial number in output stream:  20

该错误似乎来自xdotool

int xdo_get_focused_window(const xdo_t *xdo, Window *window_ret) {
  int ret = 0;
  int unused_revert_ret;

  ret = XGetInputFocus(xdo->xdpy, window_ret, &unused_revert_ret);

  /* Xvfb with no window manager and given otherwise no input, with 
   * a single client, will return the current focused window as '1'
   * I think this is a bug, so let's alert the user. */
  if (*window_ret == 1) {
    fprintf(stderr, 
            "XGetInputFocus returned the focused window of %ld. "
            "This is likely a bug in the X server.\n", *window_ret);
  }
  return _is_success("XGetInputFocus", ret == 0, xdo);
}

我只想做最简单的事情来获得虚拟显示器,在其上启动一个窗口,然后检查窗口名称。

我应该怎么办?

标签: pythonxlibxorgxdotool

解决方案


推荐阅读