服务:虚拟机鼠标和宿主机鼠标同时移动显示

问题

KVM 里运行 Win10 时,虚拟机内的鼠标光标与宿主机光标同时显示、同时移动(窗口化状态下);窗口最大化后正常,只显示一个光标。

现象与实测证据

项实测值
窗口化两个光标同时显示、同时移动
最大化只剩一个(guest 光标),恢复正常
QEMU 侧指针设备(info mice)Mouse #2: QEMU PS/2 Mouse + * Mouse #3: QEMU HID Tablet (absolute)(★ = 当前生效的是绝对模式的 tablet)
客户端侧(SPICE_DEBUG=1)spice-widget.c:2670 mouse mode 2 (client)(已是客户端鼠标模式)+ cursor 通道连通 + set_cursor: flags 1, size 0(guest 报"隐藏光标")
guest 侧spice-agent 服务 Running ✓、vdagent 进程在 ✓、QXL 驱动在 ✓
域定义<input type='tablet' bus='usb'/> 在 ✓(PS/2 鼠标是 libvirt 隐含添加的,XML 里没有)

检索到的官方依据

  • SPICE 官方手册(spice-space.org spice-user-manual.html → Mouse modes)原文两种模式:
    · Server mouse:"When a user clicks inside the Spice client window, the client mouse is captured and set invisible."
    · Client mouse:"Not captured and is used as the effective pointing device. To enable client mouse, the VDI host application must register an absolute pointing device (e.g. USB tablet in QEMU)."
  • 完全同症状的问答(superuser #1160043《Two mouse cursors when using virt-manager》,2.2 万浏览)最高票解法:给域加 <input type='tablet' bus='usb'/>(accepted)/安装 SPICE Windows Guest Tools;相关 issue 另明确"别删 tablet"。

⇒ 本机把上述三条标准解全部满足了,所以不是配置缺失。

结论(当前状态,2026-10-15)

光标重叠未彻底解决;但本轮排查后鼠标性能明显改善,移动非常灵敏,用户表示满意,就此收口。

机理:在 client 鼠标模式下,宿主机光标本身就是「有效指针」(官方原话 "not captured and is used as the effective pointing device"),同时 guest 端也会绘制自己的光标 ⇒ 窗口化时形成一对;而最大化/全屏时客户端捕获指针、隐藏本地光标 ⇒ 只剩一个。属于 spice-gtk 在「client 模式 + 未捕获」下的固有表现。

可选项(本次未采用)

  • 退回 server 鼠标模式:去掉 <input type='tablet' bus='usb'/> ⇒ 之后点击窗口就只留一个光标;代价与官方建议相反(指针在高负载/高延迟下会发涩、可能丢同步)。
  • 使用最大化 / 全屏(当前最优解,用户已采用)。

排查过程中已排除的

  • 缺 tablet ✗(在,且是当前生效设备)
  • 缺 SPICE 客机工具 ✗(spice-agent / vdagent 均在)
  • PS/2 鼠标是多余指针设备:确实存在(libvirt 隐含设备,XML 里删不掉;Windows 视其为启动关键设备,Disable-PnpDevice 报"不支持"、pnputil /disable-device 报"无法禁用关键系统设备")——但它不是本症状的主因(client 模式已生效)。

复现 / 取证命令

# QEMU 侧:当前生效的指针设备与模式
virsh -c qemu:///system qemu-monitor-command win10-old --hmp "info mice"

# 客户端侧:光标模式与 cursor 通道(需图形会话环境变量)
SPICE_DEBUG=1 G_MESSAGES_DEBUG=all virt-viewer -c qemu:///system win10-old 2>&1 | grep -iE "mouse mode|cursor"

边界

  • 本篇记录的是"光标重叠"这一症状的取证与结论;性能改善属本轮附带效果。
  • 未采用的 server 模式方案若日后需要实施,注意它会与官方推荐(tablet)相反,且需完整停+起域才生效(设备不支持热插)。