c语言 - XLIB 窗口管理器中的终端未接收屏幕键盘上"OnBoard"的按键



考虑以下在线找到的最小窗口管理器。它可以编译并运行良好。

#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
Display *display;
Window window;
XEvent event;
int s;
/* open connection with the server */
display = XOpenDisplay(NULL);
if (display == NULL)
{
fprintf(stderr, "Cannot open displayn");
exit(1);
}
s = DefaultScreen(display);
/* create window */
window = XCreateSimpleWindow(display, RootWindow(display, s), 10, 10, 200, 200, 1,
BlackPixel(display, s), WhitePixel(display, s));
/* select kind of events we are interested in */
XSelectInput(display, window, KeyPressMask | KeyReleaseMask );
/* map (show) the window */
XMapWindow(display, window);
/* event loop */
while (1)
{
XNextEvent(display, &event);
/* keyboard events */
if (event.type == KeyPress)
{
printf( "KeyPress: %xn", event.xkey.keycode );
/* exit on ESC key press */
if ( event.xkey.keycode == 0x09 )
break;
}
else if (event.type == KeyRelease)
{
printf( "KeyRelease: %xn", event.xkey.keycode );
}
}
/* close connection to server */
XCloseDisplay(display);
return 0;
}

在这个窗口管理器中,我可以加载一个终端(如 xterm(和带有 ubuntu 的屏幕键盘程序(服务器添加,安装了 xinit(。板载屏幕键盘不会在此最小窗口管理器中向其他窗口发送键输入(板载加载在屏幕底部区域(。

请注意,DWM 极简主义窗口管理器按预期工作(板载输入将发送到所有其他窗口(。 我无法在 DWM 源中找到考虑这种事情的地方。

我的问题是:如何使这个迷你窗口管理器允许板载屏幕键盘将输入发送到其他窗口?

找到了解决方案。 我应该在终端上使用XSetInputFocus,然后输入正确。

//e.window is the program window for the program that should get the input.
XSetInputFocus(mDisplay, e.window, RevertToPointerRoot, CurrentTime);

最新更新