在 X (*nix) 上实现剪贴板功能而不访问事件循环?
如果你有一个窗口但无法访问事件循环,并且只能对 X 进行函数调用,是否可以实现文本的复制粘贴。我已经在 Windows 和 OSX 上实现了剪贴板,只需要 API 函数调用。在 *nix 上用 X 也可能有同样的情况吗?有人告诉我您绝对需要访问 X 事件循环。有没有一种方法可以仅通过 api 调用来实现基本的字符串剪贴板功能?
Is it possible to implement copy-paste of text if you have a window but no access to the event loop, and can only make function calls to X. I've implemented clipboard on Windows and OSX with nothing but API function calls. Is the same possible on *nix with X? I was told you absolutely need access to the X event loop. Is there a way to implement basic string clipboard functionality with only api calls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的回答是“不”。
下面是长答案...
Windows 和 X 剪贴板(不知道 OSX)之间的主要区别是:
因此,为了在 X 客户端中实现 COPY,您必须首先拥有剪贴板,然后监听并回复获取剪贴板内容消息。要实现 PASTE,您必须发送获取剪贴板内容消息并等待回复。这两个操作都需要您扰乱事件循环。
这就是为什么在 X 中,在终止源应用程序后复制的数据不可用。除非您使用某种剪贴板服务器,即侦听事件剪贴板所有者即将死亡并保存数据副本以供将来粘贴的应用程序。
公平地说,Windows 剪贴板也可以在直接传输模式下工作,但据我所知很少使用,并且仅适用于非常大的数据。
Short answer is "no".
Long answer following...
The main difference between Windows and X clipboard (don't know about OSX) is that:
So, in order to implement COPY in an X client, you have to own the clipboard first, and then listen and reply to the get clipboard contents messages. And to implement PASTE you have to send the get clipboard contents message and wait for the reply. Both of these operations require you to mess with the event loop.
That's why in X the copied data is not available after you kill the source application. Unless you use some kind of clipboard server, that is, an application that listens to the event owner of clipboard is dying and saves a copy of the data for future pastes.
To be fair, Windows clipboard can work also in the direct transfer mode, but it is rarely used, AFAIK, and only for very big pieces of data.