X11剪贴板如何处理多种数据格式? [英] How does X11 clipboard handle multiple data formats?

查看:155
本文介绍了X11剪贴板如何处理多种数据格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这也可能发生在您身上-有时,当您将某些网页中的文本复制到您喜欢的Webmail客户端中的RTF电子邮件草稿中时,您会不喜欢粘贴的具有不同的字体/大小/粗细..它会以某种方式记住样式(通常是图片,当选中时)。

It probably happened to you as well - sometimes when you copy a text from some web page into your rich-text e-mail draft in your favorite webmail client, you dislike the fact that the pasted piece has a different font/size/weight.. it somehow remembers the style (often images, when selected). How is it than that if you paste the same into your favorite text editor like Vim, there's no HTML, just the plain text?

似乎剪贴板保存了各种格式的选定数据。一个人如何访问这些格式中的任何一种数据(以编程方式或使用某种实用程序)? X11剪贴板如何工作?

It seems that clipboard maintains the selected data in various formats. How can one access data in any one of those formats (programmatically or with some utility)? How does the X11 clipboard work?

推荐答案

您从中复制的应用程序会宣传其可以提供的格式(主要由MIME类型标识)。您粘贴到的应用程序必须选择其首选格式,然后从源应用程序请求该格式。

The app you copy from advertises formats (mostly identified by MIME types) it can provide. The app you paste into has to pick its preferred format and request that one from the source app.

您可能看不到所有样式信息转移的原因是这些应用程序没有

The reason you may not see all style info transferred is that the apps don't both support a common format that includes the style info.

您还可以看到问题,因为应用程序可能会尝试粘贴HTML,但实际上并不能处理所有HTML。或者这些应用程序可能有错误,或者可能无法就特定的MIME类型真正意味着什么。

You can also see issues because an app may for example try to paste HTML, but not really be able to handle all HTML. Or the apps may be buggy, or may not agree on what a particular MIME type really means.

当然,几乎所有应用程序都可以复制和粘贴纯文本,但是除此之外,一触即发。如果您看不到有意义的内容,则可以针对其中一个应用程序提交错误。

Almost all apps can both copy and paste plain text, of course, but beyond that it's touch and go. If you don't get what seems to make sense, you could file a bug vs. one of the apps.

您可能会注意到,如果退出该应用程序,您会重新复制时,您将无法再粘贴。 (除非您正在运行剪贴板管理器之类的东西。)这是因为在目标应用程序要求粘贴格式之前,实际上没有数据离开源应用程序。
有剪贴板管理器可在您复制和存储数据时立即要求数据,因此您可以在源应用程序退出后粘贴,但是它们有缺点(如果数据很大,或者提供10个数据格式等)。

You may notice that if you exit the app you're copying from, you can no longer paste. (Unless you're running a "clipboard manager" or something.) This is because no data actually leaves the source app until the destination app asks for a format to paste. There are "clipboard managers" that ask for data immediately anytime you copy and store that data, so you can paste after the source app exits, but they have downsides (what if the data is huge, or is offered in 10 formats, etc.)

以下python代码将显示当前复制数据的可用格式(如果已安装pygtk)。此应用程序显示ctrl + c复制的数据,而不是单击中键的复活节彩蛋。 (请参见 http://freedesktop.org/wiki/Specifications/ClipboardsWiki

The following python code will show available formats for the currently-copied data, if you have pygtk installed. This app shows the ctrl+c copied data, not the middle-click easter egg. (See http://freedesktop.org/wiki/Specifications/ClipboardsWiki)

#!/usr/bin/python

import gtk;
clipboard = gtk.clipboard_get()
print("Current clipboard offers formats: " + str(clipboard.wait_for_targets()))

这篇关于X11剪贴板如何处理多种数据格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆