Xorg 中的全屏 window 不会导致键盘事件

Fullscreen window in Xorg causes no keyboard events

我正在为 Xorg(X11,Linux)编写一个简单的应用程序,它应该有一个全屏 window。

它似乎工作得很好,window 管理器忽略了 window 所以它被正确定位为全屏。但是有一个问题,事件循环永远不会获取任何 KeyPress 事件。鼠标事件被正确接收,但没有按键。

// assuming some variables are already defined as global here, like display etc.
void main()
{
   unsigned long valuemask = CWOverrideRedirect;
   XSetWindowAttributes attributes;
   Window window;

   window = XCreateSimpleWindow(display, XDefaultRootWindow(display), 0, 0,
              (DisplayWidth(display, screen)), (DisplayHeight(display, screen)), 0, 0, 0);
   attributes.override_redirect = True;
   XChangeWindowAttributes(display, window, valuemask, &attributes);

   for (;;)
   {
       XNextEvent(display, &ev);
       switch (ev.type)
       {
           case KeyPress:
             ... this gets never called if override_redirect = True
       }

       // ... the rest of code
   }
}

如果我设置 attributes.override_redirect = False;,则 window 不再是全屏,但可以正确接收键盘事件。

如何使 window 全屏显示并同时接收正确的键盘事件?

;-)

你为什么不试试 XSetInputFocus(disp, win, RevertToNone, CurrentTime);