使用 Java 通过 ID 在 X11 窗口上绘画
我的目标是使用 Java 库在 X11 窗口上绘图。问题是我想在一个已经存在的窗口上执行此操作,并且我知道它的窗口 ID。我已经使用 C 和 Rust 完成了此操作,但现在想使用 Java。
我可以在 AWT 中找到它创建窗口并获取窗口 ID 的位置: https://github.com/openjdk/client/blob/master/src/java.desktop/unix/classes/sun/awt/X11/XBaseWindow.java#L380
我相信“注入”这里的 ID 将对实现目标大有帮助。
我应该如何改变这种行为?我尝试过制作 类来扩展相关的 AWT 类,但遇到了我的代码不在正确的包中的问题。 [1]
我尝试过反射,但被 XFramePeer 对象卡住,无法访问其超类的任何字段/方法。 [2]
是的,我知道这可能是一个愚蠢的差事。
代码示例: 1:在 Java 中 - https://github.com/robbieh/AWTForeignXWindow 2:在 Clojure 中 - https://gist.github.com/robbieh/c4662690abff19fc1cca12decd9b486e
My goal is to use Java libraries to paint on an X11 window. The problem is I want to do this on a window that already exists and that I know the window ID of it. I've done this with C and Rust, but would like to use Java now.
I can find in AWT where it creates a window and gets a window ID:
https://github.com/openjdk/client/blob/master/src/java.desktop/unix/classes/sun/awt/X11/XBaseWindow.java#L380
I believe that "injecting" the ID here would go a long way to accomplishing the goal.
How should I go about changing this behavior? I've tried making
classes to extend the relevant AWT classes, but run into problems with my code not being in the right package. [1]
I've tried reflection, but get stuck with the XFramePeer object and can't access any fields/methods of it's superclass. [2]
Yes, I understand this may be a fool's errand.
Code samples:
1: In Java - https://github.com/robbieh/AWTForeignXWindow
2: In Clojure - https://gist.github.com/robbieh/c4662690abff19fc1cca12decd9b486e
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两年后我有了答案,使用 JNA 但绕过 AWT 窗口。这是一个在 Clojure 中演示的存储库,以防其他人稍后查看这里。
https://github.com/robbieh/clj-xscreensaver-basic-demo
After two years I have an answer, using JNA but bypassing AWT windows. Here's a repo demonstrating it in Clojure in case anyone else comes looking here later.
https://github.com/robbieh/clj-xscreensaver-basic-demo