Linux系统隐藏鼠标指针
注:不同显示管理器环境(LightDM/GDM3)方法不同,可用命令查看:cat /etc/X11/default-display-manager
方法一: LightDM 隐藏鼠标指针
效果:永久隐藏鼠标指针,点击移动时也不会显示鼠标指针
- 编辑 lightdm.conf 配置文件(如果文件不存在,则从步骤 3 开始操作)
# 备份源文件(可选):sudo cp /etc/lightdm/lightdm.conf /etc/lightdm/lightdm.conf.baksudo vim /etc/lightdm/lightdm.conf
- 在配置文件末尾处添加以下一行内容,并保存退出
xserver-command=X -bs -core -nocursor# 隐藏鼠标:echo 'xserver-command=X -bs -core -nocursor' | sudo tee -a /etc/lightdm/lightdm.conf# 显示鼠标:sudo sed -i '/^xserver-command=X -bs -core -nocursor$/d' /etc/lightdm/lightdm.conf
- 如果 /etc/lightdm/lightdm.conf 目录下文件不存在,则手动创建并添加以下两行内容
[Seat:*]
xserver-command=X -bs -core -nocursor# 隐藏鼠标:echo -e '[Seat:*]\nxserver-command=X -bs -core -nocursor' | sudo tee -a /etc/lightdm/lightdm.conf# 显示鼠标:sudo sed -i '/^\[Seat:\*\]$/,/^xserver-command=X -bs -core -nocursor$/d' /etc/lightdm/lightdm.conf
- 重启 lightdm 服务生效
sudo systemctl restart lightdm
方法二:GDM3 隐藏鼠标指针
效果:永久隐藏鼠标指针,点击移动时也不会显示鼠标指针
- 编辑 Xorg 配置文件,如果不存在则手动创建(或尝试编辑/usr/bin/X)
# 备份源文件(可选):sudo cp /usr/bin/Xorg /usr/bin/Xorg.baksudo vim /usr/bin/Xorg
- 在如下对应位置加入参数 -nocursor (倒数第二行)
#!/bin/sh
#
# Execute Xorg.wrap if it exists otherwise execute Xorg directly.
# This allows distros to put the suid wrapper in a separate package.basedir=/usr/lib/xorg
if [ -x "$basedir"/Xorg.wrap ]; thenexec "$basedir"/Xorg.wrap "$@"
elseexec "$basedir"/Xorg "$@" -nocursor
fi# 添加参数:sudo sed -i 's|Xorg "$@"|Xorg "$@" -nocursor|' /usr/bin/Xorg# 删除参数:sudo sed -i 's| -nocursor||' /usr/bin/Xorg
- 重启 gdm 服务生效
sudo systemctl restart gdm
方法三:使用 unclutter 自动隐藏鼠标指针
效果:非活动状态下自动隐藏鼠标指针,点击或移动使用时会短暂显示
- 安装 unclutter 工具
sudo apt updatesudo apt install unclutter -y
- 执行以下命令隐藏鼠标指针(临时)
unclutter -idle 0.1 -root# -idle 0.1 表示 0.1 秒无操作后隐藏指针# -root 表示作用于根窗口
- 设置开机启动,编辑 ~/.xprofile 文件(没有就创建),添加以下内容
unclutter -idle 0 &# echo "unclutter -idle 0 &" > ~/.xprofile