如何像 Ghostscript 一样将 X11 键盘事件路由到标准输入?

发布于 2024-11-17 06:28:09 字数 265 浏览 4 评论 0原文

我正在尝试编写 Ghostscript 的克隆,但我不知道它们是如何制作的,因此您可以在图形窗口中键入内容,并且击键显示在终端窗口中,就像您一开始就在那里键入它们一样。因此,收到 KeyRelease 事件后,我可以以某种方式将字符填充到标准输入中,以便用正常的文件读取代码来读取吗?或者我是否必须在标准输入前面创建自己的内部缓冲区,以便我可以将新字符写入其中?或者是否有一些简单的方法可以将键盘事件从我的应用程序窗口映射到 Xterm?

我愿意做这份工作,但我什至不知道我在这里寻找什么。帮助?!!

I'm trying to write a clone of ghostscript and I can't figure out how they make it so you can type into the graphics window, and the keystrokes show up in the terminal window as though you'd typed them there to begin with. So having received the KeyRelease Event, can I stuff the char into stdin somehow, to be read with normal filereading code? Or do I have to make my own internal buffer in front of stdin so I can hack new chars into it? Or is ther some simple way to map keyboard events from my application window to Xterm?

I'm willing to do the work, but I don't even know what I'm looking for here. Help?!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

大海や 2024-11-24 06:28:09

我不认为 gs 会这样做(至少在 Linux 上)。

我尝试从 SSH 会话运行到我的 Linux 机器,并将焦点切换到弹出渲染图像(老虎)的 X11 窗口,并且我按下的键没有转到远程主机上的应用程序。

strace(的末尾)显示 GS 正在等待 stdin - 使用 fd=0 进行读取

read(3, "  } if\n  psuserparams readonly p"..., 4096) = 3258
brk(0x1124000)                          = 0x1124000
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x7f8ccaee5000, 4096)            = 0
poll([{fd=4, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=4, revents=POLLOUT}])
writev(4, [{"+\2\1\0", 4}, {NULL, 0}, {"", 0}], 3) = 4
poll([{fd=4, events=POLLIN}], 1, -1)    = 1 ([{fd=4, revents=POLLIN}])
read(4, "\1\1'\0\0\0\0\0\1\0\200\0\0\0\0\0\1\0\0\0\264\2\0\0008\0A\2\4\0\0\0", 4096) = 32
read(4, 0xc9bd54, 4096)                 = -1 EAGAIN (Resource temporarily unavailable)
fstat(1, {st_mode=S_IFREG|0644, st_size=143204, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8ccaee5000
write(1, "GS>", 3GS>)                      = 3
read(0,  ...unfinished ...

我必须将焦点切换回 ssh 窗口,以便按键 (Ctrl-C) 生效。当焦点是图像 X11 窗口时,我尝试过“退出”以及 ctrl-C。

I don't think gs does this (at least on linux).

I tried it running from to my linux box from a SSH session and switched focus to the X11 windows that pops up with the rendered image (tiger) and the keys I pressed there did NOT go to the application on the remote host.

The (end of the) strace shows GS waiting for stdin -- the read with fd=0

read(3, "  } if\n  psuserparams readonly p"..., 4096) = 3258
brk(0x1124000)                          = 0x1124000
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x7f8ccaee5000, 4096)            = 0
poll([{fd=4, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=4, revents=POLLOUT}])
writev(4, [{"+\2\1\0", 4}, {NULL, 0}, {"", 0}], 3) = 4
poll([{fd=4, events=POLLIN}], 1, -1)    = 1 ([{fd=4, revents=POLLIN}])
read(4, "\1\1'\0\0\0\0\0\1\0\200\0\0\0\0\0\1\0\0\0\264\2\0\0008\0A\2\4\0\0\0", 4096) = 32
read(4, 0xc9bd54, 4096)                 = -1 EAGAIN (Resource temporarily unavailable)
fstat(1, {st_mode=S_IFREG|0644, st_size=143204, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8ccaee5000
write(1, "GS>", 3GS>)                      = 3
read(0,  ...unfinished ...

I had to switch focus back to the ssh window in order for the key press (Ctrl-C) to take effect. I had tried "quit" as well as ctrl-C when the focus was the image X11 window.

別甾虛僞 2024-11-24 06:28:09

我不知道答案,但我知道找到答案的方法。在 strace 下运行 Ghostscript 并观察它在做什么。这通常比尝试阅读源代码更容易,信息也更丰富。

I don't know the answer, but I know the way to find it. Run ghostscript under strace and watch what it's doing. This is usually a lot easier and more informative than trying to read source.

生来就爱笑 2024-11-24 06:28:09

尤里卡!

在文件中 gdevxini.c

435             wm_hints.flags = InputHint;
436             wm_hints.input = False;
437             XSetWMHints(xdev->dpy, xdev->win, &wm_hints);       /* avoid input focus */

编辑:现在我知道它是什么样子了,我能够找到一些文档:

输入成员用于向窗口管理器传达应用程序使用的输入焦点模型...从不期望任何键盘输入的应用程序...应将此成员设置为False
--X Window 系统:C 库和协议参考,第 282 页

Eureka!

in the file gdevxini.c

435             wm_hints.flags = InputHint;
436             wm_hints.input = False;
437             XSetWMHints(xdev->dpy, xdev->win, &wm_hints);       /* avoid input focus */

Edit: Now that I know what it looks like, I was able to find some documentation:

The input member is used to communicate to the window manager the input focus model used by the application.... Applications that never expect any keyboard input ... should set this member to False.
--X Window System: C Library and Protocol Reference, p.282

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文