--- layout: post title: Linux下使用高漫M5数位板的方法 subtitle: 基于Ubuntu 22.04及Archlinux衍生版 date: 2022-10-21 author: Duter2016 header-img: img/post-bg-debug.png catalog: true music-id: music-idfull: tags: - 数位板 - Linux --- > 本文基于Linuxmint 21 (基于Ubuntu 22.04)、Archlinux测试通过 高漫M5数位板官方驱动是支持Win/Mac/Android的, 然而没有提供Linux驱动。 ## 一、Linuxmint 21 (基于Ubuntu 22.04)安装驱动方法 但是已有高手发现Huion(绘王)和Gaomon(高漫)数位板某些型号是相互对应的,驱动也能通用。这就好办了! 先在软件管理器安装两个软件,或命令安装: ``` sudo apt-get install Xserver-xorg-input-wacom sudo apt-get install Kde-config-tablet ``` ### 1、检查数位板设备 目前的Linux内核大部分都能识别出高漫数位板了。 (1)首先查看设备id,终端运行: `lsusb` 显示: `Bus 002 Device 013: ID 256c:0064 GAOMON Gaomon Tablet` 设备id是256c:0064。也就是 ``` idVendor 256c idProduct 0064 ``` (2)终端运行命令: ``` sudo usbhid-dump -es -m 256c:0064 | tee frame_wheel_srolling.txt ``` 查看设备是否能正常上报,发现能正常上报数据,说明设备本身没有问题。 ### 2、安装驱动 DIGImend项目旨在改进Linux对通用图形输入板的支持,是用于Linux内核的图形输入板驱动程序的集合。今天我们的主角就是它 * 项目主页:[http://digimend.github.io/](http://digimend.github.io/) * 项目地址:[https://github.com/DIGImend/digimend-kernel-drivers](https://github.com/DIGImend/digimend-kernel-drivers) 访问这个项目网址: [DIGImend/digimend-kernel-drivers](https://github.com/DIGImend/digimend-kernel-drivers) ,下载最新的zip文件,并解压。 按照网站的提示,做如下操作: (1)安装内核头文件: ``` sudo apt-get install -y "linux-headers-$(uname -r)" ``` (2)安装DKMS (Dynamic Kernel Module Support): ``` sudo apt-get install -y dkms ``` (3)进入刚刚的解压文件目录,运行终端: ``` sudo make dkms_install ``` 以上为自动安装,网站还提供了手动安装的步骤,此处从略。 (4)卸载原先的设备: ``` sudo modprobe -r hid-kye hid-uclogic hid-polostar hid-viewsonic ``` (5)在`/etc/X11/xorg.conf.d`目录下添加文件`50-digimend.conf`, 内容如下: ``` Section "InputClass" Identifier "Tablet" MatchUSBID "256c:0064" MatchDevicePath "/dev/input/event*" Driver "wacom" EndSection ``` 上面就完成了驱动适配。 现在项目主页已经有打包的deb包了,也可以直接安装deb包,然后 `cd /usr/share/X11/xorg.conf.d/` 然后修改`50-digimend.conf` 文件 在`husion tablets with wacom driver` 下面增加一个(高漫m5是`256c:0064`)然后就可以了。 拔下数位板USB连线,重启或注销一下系统就可以正常使用数位板了。 ### 3、将M5由竖屏映射更改为横屏映射 以上安装完驱动后,你在Xournal++中使用数位板时,你会发现数位板中书写文字,文字是扁的,比较难看,原因是M5在Linux上的默认映射是竖屏的,而笔记本屏幕是横屏的,写上的字自然是扁的! 只需要把高漫M5数位板由竖屏映射更改为横屏映射即可! 如下修改方法参考了如下wiki内容: * [【xsetwacom】](https://github.com/linuxwacom/xf86-input-wacom/wiki/xsetwacom) * [【Rotation】](https://github.com/linuxwacom/xf86-input-wacom/wiki/Rotation) (1)首先,查找终端中使用的“设备名称”: ``` xinput list ``` 会输出含有如下信息的内容: ``` ⎜ ↳ GAOMON Gaomon Tablet stylus id=15 [slave pointer (2)] ⎜ ↳ GAOMON Gaomon Tablet eraser id=16 [slave pointer (2)] ``` (2)数位板驱动程序支持90度角的旋转。旋转可以在运行时应用(例如通过 xsetwacom)。对于 Rotate 参数,只需选择您喜欢旋转的一个输入工具方向。这四个有效的设置是: * "none": 数位板不在软件中旋转,而是使用其默认方向。 * "half": 数位板旋转180度(上下颠倒)。 * "cw": 数位板顺时针旋转90度。 * "ccw": 数位板逆时针旋转90度。 **请注意**,旋转是一个数位板范围的选择。如果你旋转一个输入工具,与同一个数位板相关的所有其他工具都要旋转到相同的方向。 因此,我们在终端运行如下命令,即可把M5旋转为横向: ``` xsetwacom set "GAOMON Gaomon Tablet stylus" rotate ccw xsetwacom set "GAOMON Gaomon Tablet eraser" rotate ccw ``` 虽然 xsetwacom 设置命令一旦输入终端就会应用,但是它们不会在重新启动后持续,及重启后,数位板又再次变为竖屏映射。为此,您可以使用这些命令创建一个可执行脚本,并将其添加到启动应用程序中。 (3)创建横屏映射脚本 如果我们每次重启系统后,都要输入命令来改变映射方向,记命令有点麻烦,我们直接建立一个sh脚本就能简化过程了! 建立一个sh文件`Tablet_PC_Rotation.sh`,脚本内容如下: ``` #!/bin/sh # 将高漫 M5 数位板由竖屏改为横屏映射 CCW # '''none''': the tablet is not rotated in software and uses its natural rotation. # '''half''': the tablet is rotated by 180 degrees (upside-down) # '''cw''': the tablet is rotated 90 degrees clockwise # '''ccw''': the tablet is rotated 90 degrees counter-clockwise # 更改为横屏start xsetwacom set "GAOMON Gaomon Tablet stylus" rotate ccw xsetwacom set "GAOMON Gaomon Tablet eraser" rotate ccw # 更改为横屏end # 更改为竖屏start # xsetwacom set "GAOMON Gaomon Tablet stylus" rotate none # xsetwacom set "GAOMON Gaomon Tablet eraser" rotate none # 更改为竖屏end #任意键 get_char() { SAVEDSTTY=`stty -g` stty -echo stty cbreak dd if=/dev/tty bs=1 count=1 2> /dev/null stty -raw stty echo stty $SAVEDSTTY } #任意键 #任意键退出 开始 echo "已将高漫 M5 数位板由竖屏映射改为横屏映射!" echo "" echo "【若想将高漫 M5 数位板恢复为竖屏映射,仅需热插拔一次数位板即可!】" echo "" echo "每热插拔一次数位板,改为横屏映射需执行一次本脚本!" echo "" # echo "组合键 CTRL+C 终止运行脚本命令! ..." echo "按任意键退出对话框..." char=`get_char` #任意键退出 结束 ``` 然后,建立一个执行以上脚本的.desktop启动快捷方式,命名为`GaomonM5Rotation.desktop`,内容如下: ``` #!/usr/bin/env xdg-open [Desktop Entry] Encoding=UTF-8 Name=GaomonM5Rotation Name[zh_CN]=高漫M5横屏 Exec=sh /home/用户名/opt/Gaomon/Tablet_PC_Rotation.sh Type=Application Terminal=true Comment[zh_CN]=将高漫M5由竖屏改为横屏 Icon=/home/用户名/opt/icons/Gaomon.png Name[zh_CN]=GaomonM5Rotation.desktop Categories=Office; ``` 图标`Gaomon.png`,自己下载一个图片文件吧。 然后把以上三个文件`Tablet_PC_Rotation.sh`、`GaomonM5Rotation.desktop`、`Gaomon.png`都放到`/home/用户名/opt/Gaomon/`目录下,然后,将`GaomonM5Rotation.desktop`加入开始菜单就可以了。 **注意:** * 若想将高漫 M5 数位板恢复为竖屏映射,仅需热插拔一次数位板即可! * 每热插拔一次数位板,改为横屏映射需执行一次本脚本! ## 二、Archlinux系统(wayland桌面)驱动安装方法 AUR仓库中的`0.6.5.1`版本目前还不支持Gaomon M5,但是[OpenTabletDriver](https://github.com/OpenTabletDriver/OpenTabletDriver)主仓库的分支[gonX/OpenTabletDriver](https://github.com/gonX/OpenTabletDriver/tree/yoink-gaomon-m5-support)已经支持Gaomon M5。我们只需要重新编辑一下aur中opentabletdriver的PKGBUILD文件,安装分支[gonX/OpenTabletDriver](https://github.com/gonX/OpenTabletDriver/tree/yoink-gaomon-m5-support)即可。 用如下链接下载分支包:[https://github.com/gonX/OpenTabletDriver/archive/refs/heads/yoink-gaomon-m5-support.tar.gz](https://github.com/gonX/OpenTabletDriver/archive/refs/heads/yoink-gaomon-m5-support.tar.gz) 将下载的`OpenTabletDriver-yoink-gaomon-m5-support.tar.gz`重命名为`OpenTabletDriver-0.8.1.tar.gz`备用。 如下操作: ``` cd /tmp yay -G opentabletdriver cd opentabletdriver ``` 开始编辑PKGBUILD: ``` subl PKGBUILD ``` 将PKGBUILD修改为如下: ``` # Maintainer: Sebastian 'gonX' Jensen # Contributor: LavaDesu pkgname=opentabletdriver _pkgname=OpenTabletDriver pkgver=0.8.1 pkgrel=1 pkgdesc="A cross-platform open source tablet driver" arch=('x86_64') url="https://opentabletdriver.net" # license FIXME tracked upstream: # https://github.com/OpenTabletDriver/OpenTabletDriver/issues/3571 license=('LGPL3') # FIXME: use SPDX format depends=('dotnet-runtime-8.0' 'gtk3' 'libevdev') optdepends=('libxrandr: x11 display querying support' 'libx11') makedepends=('dotnet-sdk>=8.0' 'jq' 'git') conflicts=( 'digimend-kernel-drivers-dkms-git' 'digimend-drivers-git-dkms' 'digimend-kernel-drivers-dkms' 'digimend-kernel-drivers' ) install="notes.install" # unified binary dotnet releases break when stripped # see https://github.com/dotnet/runtime/issues/54947 # # disabling debug is necessary for the time being # see https://gitlab.archlinux.org/archlinux/packaging/packages/pacman/-/issues/19 options=('!strip') source=("$_pkgname-$pkgver.tar.gz::https://github.com/gonX/OpenTabletDriver/archive/refs/heads/yoink-gaomon-m5-support.tar.gz" "notes.install" ) sha256sums=('4375014218368dbdc1360d4e8e661e3e47c41b071e2e9f38ceca0463e3ac7ab8' '33e50caf00ab290463acaa09b024bcd8bcf6a39911db2fc506e88495171bf3e3') _srcdir="OpenTabletDriver-$pkgver" build() { export DOTNET_CLI_TELEMETRY_OPTOUT=1 export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true cd "$srcdir/$_srcdir" if check_option "strip" y; then EXTRA_OPTIONS="/p:DebugType=None /p:DebugSymbols=false" fi export OTD_CONFIGURATIONS="${PWD}/OpenTabletDriver.Configurations/Configurations" ./eng/linux/package.sh --package Generic -c Release -- $EXTRA_OPTIONS } package() { cd "$srcdir/$_srcdir" cp -r ./dist/files/* "${pkgdir}/" # moving LICENSE to the suggested Arch folder is also tracked upstream: # https://github.com/OpenTabletDriver/OpenTabletDriver/issues/3572 mkdir -p "$pkgdir"/usr/share/licenses/$pkgname mv "$pkgdir"/usr/share/doc/opentabletdriver/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE rmdir -p --ignore-fail-on-non-empty "$pkgdir"/usr/share/doc/opentabletdriver } ``` 将下载的`OpenTabletDriver-0.8.1.tar.gz`复制到`/tmp/opentabletdriver`目录下。 最后编译安装: ``` makepkg -si ``` 编译安装过程中如果提示找不到目录:`/tmp/opentabletdriver-0.8.1/src/OpenTabletDriver-0.8.1`,只需在`/tmp/opentabletdriver-0.8.1/src/`下将目录名`OpenTabletDriver-yoink-gaomon-m5-support`重命名为目录`/tmp/opentabletdriver-0.8.1/src/OpenTabletDriver-0.8.1`即可。然后,再次执行一遍`makepkg -si`编译即可。 然后,终端执行 ``` # 安装mkinitcpio sudo pacman -S mkinitcpio # Regenerate initramfs sudo mkinitcpio -P # Unload kernel modules sudo rmmod wacom hid_uclogic ``` 如果安装后,在开始菜单启动OpenTabletDriver无响应。那就在终端执行`otd-gui`,如果提示如下: ``` You must install or update .NET to run this application. App: /usr/lib/opentabletdriver/OpenTabletDriver.UX.Gtk Architecture: x64 Framework: 'Microsoft.NETCore.App', version '7.0.0' (x64) .NET location: /usr/share/dotnet The following frameworks were found: 6.0.36 at [/usr/share/dotnet/shared/Microsoft.NETCore.App] 8.0.19 at [/usr/share/dotnet/shared/Microsoft.NETCore.App] 9.0.8 at [/usr/share/dotnet/shared/Microsoft.NETCore.App] Learn more: https://aka.ms/dotnet/app-launch-failed To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0&arch=x64&rid=arch-x64&os=endeavouros ``` 说明缺少依赖`dotnet-runtime-7.0-bin`,在终端安装即可: ``` yay -S dotnet-runtime-7.0-bin ``` 编译安装过程中,NuGet 的全局包缓存目录`~/.nuget/packages/`,存储所有通过 NuGet 安装的 .NET 包,包含项目依赖的第三方库、工具包的缓存版本,占用空间会接近3个G,这个目录的缓存文件可以安全删除,NuGet 会在需要时自动重新下载所需包。使用官方命令清理所有 NuGet 缓存(包括全局包、临时文件等): ``` dotnet nuget locals all --clear ``` PS. 相关系统服务命令为 ``` systemctl --user enable --now opentabletdriver.service systemctl --user restart opentabletdriver.service ``` ## 参考 * [Linux下使用高漫(Gaomon)1060 Pro数位板](https://fspark.me/archives/Linux-Gaomon-1060Pro-Graphics-Tablet.html#fn-2) * [入手高漫 1060pro linux驱动适配 与设置](https://www.bilibili.com/read/cv14090353) * [Linux下安装高漫数位板的驱动](https://zhuanlan.zhihu.com/p/89877402) * [wiki/xsetwacom](https://github.com/linuxwacom/xf86-input-wacom/wiki/xsetwacom)