Gtk:将焦点发送到顶级窗口而不丢失第一个顶级窗口
情况如下:
1)我有两个顶级窗口,A 和 B
2)A 在 B 前面
如何将键盘焦点发送到窗口 B,同时保持窗口 A 在 B 前面?
Here is the situation:
1) I have two toplevel windows, A and B
2) A is in front of B
How can I send to keyboard focus to the window B while keeping the window A in front of B ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您控制两个窗口,并且这是在像 Linux 这样的 X11 系统上。如果没有,那就更具挑战性。我在一个应用程序中完成了类似的事情,这里有一些回忆。
您可能已经发现不能只使用 gtk_widget_grab_focus() 来做到这一点。这只适用于当窗口本身具有焦点时确定窗口中的哪个小部件具有焦点。
X11 根据窗口层次结构、来自窗口管理器的信息等来确定哪个窗口获取键盘事件。但是,您可以通过 GDK 进行修改以获得您想要的结果。
您必须了解 GDK 事件传播,并且可能阅读一些 GDK 源代码。但我相信,一般来说,您需要做的是:
如果窗口属于不同的应用程序,您可以查看 gdk_event_send_client_message(),但我从未使用过它。
I'm assuming you control both windows, and this is on an X11 system like Linux. If not, it's much more challenging. I've done things like this within a single app, and here are some recollections.
You've probably figured out you can't just use gtk_widget_grab_focus() to do it. That only works for determining which widget within a window has focus when the window itself has focus.
It's X11 that determines which window gets a keyboard event, based on the window hierarchy, info from the window manager, etc. However, you can monkey around with that via GDK to get the result you want.
You'll have to learn about GDK event propagation, and probably read some of the GDK sources. But I believe that, generally, what you'll need to do is this:
If the windows belong to different apps, you can look at gdk_event_send_client_message(), but I've never used it.
如果您不介意它不是直接的,您可以将键盘事件从顶层窗口发送到其后面的窗口。当然,这是假设两个窗口都是由您创建的,而不是编写一个程序来悬停在后台并读取单独程序上使用的键盘输入。
If you don't mind that it's not direct, you could send the keyboard events from the top level window to the one behind it. Of course that assumes that both windows are created by you rather than writing a program to hover in the background and read keyboard input being used on a separate program.
gtk_window_set_keep_above
< /a>(a)
后跟gtk_window_present
(b)
?gtk_window_set_keep_above
(a)
followed bygtk_window_present
(b)
?