如何阻止/解决 Java 应用程序窃取 Linux 窗口管理器焦点的问题

发布于 2024-09-02 00:08:43 字数 1067 浏览 2 评论 0原文

我们希望用 Java 快速制作小部件原型。我们将它们覆盖在用专有的第三方图形包编写的显示器顶部。我们发现 Java GUI 窃取了窗口管理器的键盘焦点。

窗口管理器是fvwm,我尝试对其进行配置,以便将Java应用程序设置为不获得焦点,此外,如果它确实获得焦点,则将其移走并将其交给其他GUI。

如果我用 Java 应用程序运行它,它就不起作用(每当鼠标位于 Java GUI 上时,它就会获得键盘焦点)-如果我交换一些标准 X GUI 小部件(XEyes)来代替 Java GUI,它就会像魅力一样工作。这为 Java 不尊重 ICCCM 的说法(由 fvwm 的人坚持)提供了一定的可信度。

我想知道其他人是否解决了这个问题,如果解决了,又是如何解决的。到目前为止,我有几个选择来尝试解决这个问题:

1)调整Java设置,希望如果我关闭焦点,它可能会将焦点控制权交还给窗口管理器(到目前为止,我已经尝试过“setFocusable( false)" 在父 JFrame 上。这不起作用。线程 "http://java.sun.com/javase/6/webnotes/trouble/TSG-Desktop/html/awt.html#gdaao" 指示我应该改为“Window. setFocusableWindowState(false)" 相关的 GUI 尚未在 Window 中重做,但我也不完全相信 Java 将放弃焦点

2) 使用 JNI 在 Java 程序中进行低级 X 调用。我认为这可能会起作用,但是,我从来没有玩过低级别的 X。我不确定我应该使用什么调用(XtSetKeyboardFocus() 应该是危险的调用...)或者我如何识别我正在操作的 GUI(在这方面,fvwm 很好,因为它们有一个 GUI,允许您单击另一个 GUI 并找出它的“名称”和“类”)

3)使用“更强大”的窗口管理器。一些不使用 ICCCM 的窗口管理器可能能够更好地处理 Java。当然,经理人太多了,我不知道该关注什么。同样,许多人似乎缺乏指定应用程序的重点(大多数人似乎只关心广泛的政策)。

We want to quickly prototype widgets in Java. We overlay them on top of a display written in a proprietary 3rd party graphics package. We find that the Java GUI steals keyboard focus away from the window manager.

The window manager is fvwm, I've tried configuring it so the Java app is setup not to get focus, and furthermore if it ever does get focus to take it away and give it to the other GUI.

If I run this with the Java app it doesn't work (whenever the mouse is over the Java GUI it has keyboard focus)- if I swap some standard X GUI widget (XEyes) in place of the Java GUI it works like a charm. This lends some creedence to the claim (maintained by the people at fvwm) that Java is not respecting the ICCCM.

I'm wondering if other people have solved this problem and if so how. So far I have a few choices for how to try and fix this:

1) twiddle Java settings, hoping that if I turn off focus there maybe it will hand back focus control to the window manager (so far I've tried "setFocusable(false)" on the parent JFrame. This didn't work. A thread "http://java.sun.com/javase/6/webnotes/trouble/TSG-Desktop/html/awt.html#gdaao" indicated I should instead do "Window.setFocusableWindowState(false)" The GUI in question hasn't been redone in a Window yet but I'm also not completely convinced that Java will relenquish the focus

2) make low level X calls in the Java program using JNI. I think this would probably work, but, I've never played much with low level X. I'm unsure what calls I should be using (XtSetKeyboardFocus() is supposed to be dangerous to call...) or how I can identify the GUI's I'm operating on (in this respect fvwm was nice since they had a GUI that allowed you to click on another GUI and find out its "name" and "class")

3) use a "stronger" window manager. Some window managers that don't use ICCCM might be able to deal with Java better. Of course, there are a plethora of managers, and I'm not sure what to concentrate on. Likewise many seem to be short on specifying focus by app (most seem only to care about broad policies).

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

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

发布评论

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

评论(1

梓梦 2024-09-09 00:08:43

最后,原型在 JWindow 而不是 JFrame 中被重新设计,当 JWindow 调用 setFocusableWindowState(false) 时,Java 确实交回了焦点...问题解决了。

Finally the prototype was reworked in a JWindow rather than a JFrame, and when that JWindow had setFocusableWindowState(false) called on it Java did hand back focus... problem solved.

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