Primary selection

Primary selection 协议

此协议提供了与 X 服务器的 primary selection 设备匹配的能力。此 primary selection 是常用剪贴板选择的快捷方式,只需选中文本即可在其他地方复制。执行此操作的事实标准方式是鼠标中键,但不仅限于此。

希望支持 primary selection 的客户端应创建一个 primary selection 源,并在文本选择更改时通过 wp_primary_selection_device.set_selection 将其设置为选择。为了尽量减少指针驱动文本选择中的调用,应在操作完成后仅执行一次。类似地,当文本取消选择时应设置 NULL 源。

wp_primary_selection_offer 对象首先通过 wp_primary_selection_device.data_offer 事件公布。在此事件之后,primary data offer 将立即发出 wp_primary_selection_offer.offer 事件以告知所提供的 mime 类型。

当 primary selection 更改时,具有键盘焦点的客户端将接收 wp_primary_selection_device.selection 事件。只有具有键盘焦点的客户端才会收到带有非 NULL wp_primary_selection_offer 的此类事件。在键盘焦点更改期间,先前具有焦点的客户端将接收带有 NULL wp_primary_selection_offer 的 wp_primary_selection_device 事件。

为了请求 primary selection 数据,客户端必须传递与触发操作的按下事件相关的最近序列号。如果合成器认为该序列号有效且最近,wp_primary_selection_source.send 事件将在另一端发生以开始传输。拥有 primary selection 的客户端应写入请求的数据,并立即关闭文件描述符。

如果 primary selection 所有者客户端在传输期间消失,读取数据的客户端将接收 wp_primary_selection_device.selection 事件,并附带关闭的文件描述符以表示终止。

X primary selection 模拟

primary selection 设备管理器是一个单例全局对象,提供对 primary selection 的访问。它允许创建 wp_primary_selection_source 对象,以及检索每个 seat 的 wp_primary_selection_device 对象。

create_source(id: new_id<zwp_primary_selection_source_v1>)
参数
类型
描述
idnew_id<zwp_primary_selection_source_v1>
创建新的 primary selection 源

创建新的 primary selection 源。

get_device(id: new_id<zwp_primary_selection_device_v1>, seat: object<wl_seat>)
参数
类型
描述
idnew_id<zwp_primary_selection_device_v1>
seatobject<wl_seat>
创建新的 primary selection 设备

为给定 seat 创建新的数据设备。

destroy()
销毁 primary selection 设备管理器

销毁 primary selection 设备管理器。



set_selection(source: object<zwp_primary_selection_source_v1>, serial: uint)
参数
类型
描述
sourceobject<zwp_primary_selection_source_v1>允许为空
serialuint
serial of the event that triggered this request
设置 primary selection

替换当前选择。primary selection 的先前所有者将接收 wp_primary_selection_source.cancelled 事件。

要取消选择,将源设置为 NULL。

destroy()
销毁 primary selection 设备

销毁 primary selection 设备。

参数
类型
描述
offernew_id<zwp_primary_selection_offer_v1>
介绍新的 wp_primary_selection_offer

介绍可用于接收当前 primary selection 的新 wp_primary_selection_offer 对象。紧随此事件之后,新的 wp_primary_selection_offer 对象将发送 wp_primary_selection_offer.offer 事件以描述所提供的 mime 类型。

参数
类型
描述
idobject<zwp_primary_selection_offer_v1>允许为空
通告新的 primary selection

wp_primary_selection_device.selection 事件用于通知客户端新的 primary selection。此事件在介绍此对象的 wp_primary_selection.data_offer 之后以及 offer 通过 wp_primary_selection_offer.offer 宣布其 mime 类型之后发送。

data_offer 在收到新的 offer 或 NULL 之前或客户端失去键盘焦点之前有效。客户端必须在此事件上销毁先前的 selection data_offer(如有)。


提供传输 primary selection 内容

wp_primary_selection_offer 表示将 primary selection 剪贴板内容传输到客户端的 offer。与 wl_data_offer 类似,该 offer 还描述了数据可以转换为的 mime 类型,并提供了将数据直接传输到客户端的机制。

receive(mime_type: string, fd: fd)
参数
类型
描述
mime_typestring
fdfd
请求传输数据

要传输 primary selection 剪贴板的内容,客户端发出此请求并指示它想要接收的 mime 类型。传输通过传递的文件描述符(通常使用 pipe 系统调用创建)进行。源客户端以请求的 mime 类型表示写入数据,然后关闭文件描述符。

接收客户端从管道的读取端读取直到 EOF 并关闭其端,此时传输完成。

destroy()
销毁 primary selection offer

销毁 primary selection offer。

offer(mime_type: string)
参数
类型
描述
mime_typestring
通告提供的 mime 类型

在通过 wp_primary_selection_device.data_offer 宣布 wp_primary_selection_offer 后立即发送。每个提供的 mime 类型发送一个事件。


提供替换 primary selection 的内容

wp_primary_selection_offer 的源端,它提供了描述所提供的数据并响应传输 primary selection 剪贴板请求内容的方式。

offer(mime_type: string)
参数
类型
描述
mime_typestring
添加提供的 mime 类型

此请求将 mime 类型添加到向目标通告的 mime 类型集合中。可以多次调用以提供多种类型。

destroy()
销毁 primary selection 源

销毁 primary selection 源。

send(mime_type: string, fd: fd)
参数
类型
描述
mime_typestring
fdfd
发送 primary selection 内容

从客户端请求当前 primary selection 内容。通过传递的文件描述符发送指定的 mime 类型,然后关闭它。

cancelled()
请求 primary selection 内容被取消

此 primary selection 源不再有效。客户端应清理并销毁此 primary selection 源。


合成器支持

Cage
Cage
0.2.0
COSMIC
COSMIC
1.0.0~beta.8
GameScope
GameScope
3.15.14
Hyprland
Hyprland
0.52.1
Jay
1.12.0
KWin
KWin
6.6
Labwc
Labwc
0.9.2
Louvre
Louvre
2.14.1
Mir
Mir
2.26
Muffin
Muffin
6.6.0
Mutter
Mutter
49.2
niri
niri
25.11
phoc
phoc
0.52
river
river
0.3.13
Sway
Sway
1.11
Treeland
Treeland
0.8.0
Wayfire
Wayfire
0.9.0
Weston
Weston
14.0.2
zwp_primary_selection_device_manager_v1
1
1
x
1
1
1
1
x
1
1
1
1
1
1
1
1
1
x

Copyright © 2015, 2016 Red Hat

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Footer

© 2026 Wayland Explorer

本网站与 Wayland 官方项目无任何关联。网站所有内容均根据 Wayland 协议 XML 文件自动生成。

本网站使用的 Visual Studio Code - Codicons 遵循 CC BY 4.0 许可。