平板电脑
本文汇总了在平板电脑上运行 Arch Linux 的相关信息。文中包含了如何让此类设备正常使用触摸键盘、触控笔、触控笔旋转以及屏幕旋转的说明。
触控笔
- 如需手动配置触控笔设备(虽不推荐),请参考 Linux Wacom 项目 Wiki。
- 如果安装 xf86-input-wacom 后键盘在 X 环境下无法正常工作,请注释掉
/usr/share/X11/xorg.conf.d/70-wacom.conf中所有不必要的条目,并将生成的文件放入/etc/xorg.conf.d/70-wacom.conf。
On-screen keyboards
参见 应用程序列表/实用工具#屏幕键盘。
在 GNOME 中使用
根据您的设备情况,默认的 GNOME 屏幕键盘会在您点击文本输入框时自动弹出。如果您的设备“平板模式”检测功能无法正常工作(参考 mutter 问题),您可以尝试自定义“GNOME 设置 > 辅助功能”。
“启用屏幕键盘”将使其在文本输入框获得焦点时始终显示。
“始终显示辅助功能菜单”允许您根据需要手动启用或禁用该功能。
旋转
屏幕旋转
以下小节展示了通用解决方案,桌面环境或 Wayland 合成器可能提供了相关配置选项,有时通过图形界面即可实现。
TTY
fbcon=rotate:1
Wayland
使用以下 内核参数,详细信息请参考 内核模式设置#强制模式
video=DSI-1:panel_orientation=right_side_up
Xorg
最简单的方法是使用 xrandr(1) § orientation
$ xrandr --orientation left
在某些驱动上,这会破坏 DPI,导致字体无法阅读。xrandr -o 选项已较为陈旧。使用 xrandr(1) § rotate 可以解决该问题,但需要先指定 --output 选项
$ xrandr --output eDP --rotate left
触摸屏与触控笔旋转
使用 xinput
您可以使用 xinput 来旋转触控笔,方式与旋转触摸屏相同。
将触控笔输入设置为纵向模式
$ xinput set-prop name_of_stylus_or_touch_screen --type=float "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
恢复为横向模式
$ xinput set-prop name_of_stylus_or_touch_screen --type=float "Coordinate Transformation Matrix" 0 0 0 0 0 0 0 0 0
如果您的触控笔仅被列为键盘设备
$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=14 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ ELAN0732:00 04F3:272A Pen id=11 [slave keyboard (3)]
用笔触摸屏幕
$ xinput list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=14 [slave pointer (2)]
⎜ ↳ ELAN0732:00 04F3:272A Pen Pen (0) id=17 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ ELAN0732:00 04F3:272A Pen id=11 [slave keyboard (3)]
使用新列出的指针设备,上述命令应能按预期旋转触控笔。
使用 xsetwacom
如果尚未操作,参考 绘图板,旋转触摸屏输入的另一种方法是按前述建议 安装 xf86-input-wacom Xorg 驱动。安装后,有多种命令可用于操作和管理触摸屏输入。
将触控笔输入设置为纵向模式
$ xsetwacom set stylus Rotate cw
恢复为横向模式
$ xsetwacom set stylus Rotate none
如果找不到“stylus”设备,请使用
$ xsetwacom list devices
获取设备列表。
例如:
xsetwacom set "Wacom Co.,Ltd. Pen and multitouch sensor Pen stylus" Rotate cw
来源: https://xournal.sourceforge.net/manual.html
如果仍然无法改变旋转方向,可以尝试使用 xinput。
自动旋转
在 Xorg 中使用
一个简单的 Xorg 自动旋转脚本实现方式如下(使用 xorg-xinput、xorg-xrandr 以及 iio-sensor-proxy 中的 monitor-sensor)
~/bin/2in1screen
#!/bin/bash
DEVICE="ILTP7807:00 222A:FFF1"
DISPLAYNAME="DSI-1"
monitor-sensor | while read -r line; do
case "$line" in
*normal*)
xrandr --output $DISPLAYNAME --rotate normal
xinput set-prop "$DEVICE" "Coordinate Transformation Matrix" 1 0 0 0 1 0 0 0 1
;;
*left-up*)
xrandr --output $DISPLAYNAME --rotate left
xinput set-prop "$DEVICE" "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
;;
*right-up*)
xrandr --output $DISPLAYNAME --rotate right
xinput set-prop "$DEVICE" "Coordinate Transformation Matrix" 0 1 0 -1 0 1 0 0 1
;;
*bottom-up*)
xrandr --output $DISPLAYNAME --rotate inverted
xinput set-prop "$DEVICE" "Coordinate Transformation Matrix" -1 0 1 0 -1 1 0 0 1
;;
esac
done
确保将其标记为 可执行文件。
使用相同原理的替代方案有 rotate.py 或 2in1screen.c。
两者都需要根据您的实际设备名称和/或路径进行调整。
您可以将其放在 .xinitrc 的 exec 行之前
.xinitrc
#!/bin/sh # xrandr --dpi 180 xrdb -merge ~/.Xresources ~/bin/2in1screen & exec wm_name
注意 GitHub 上还有许多其他旋转脚本,包括
- https://github.com/freundTech/surface-tools/tree/master/autorotate
- https://github.com/andrewrembrandt/surface-autorotate2
在 GNOME 中使用
参见 iio-sensor-proxy。安装 iio-sensor-proxy 软件包。
如果您希望启用旋转,但遇到 GNOME 自动调整亮度方式不当的问题,可以使用这些命令禁用它。
对于当前用户,也可以通过电源管理 GUI 完成
$ dbus-launch gsettings set org.gnome.settings-daemon.plugins.power ambient-enabled false
对于 GDM(无法通过 GUI 设置),请以 gdm 用户身份运行
[gdm]$ dbus-launch gsettings set org.gnome.settings-daemon.plugins.power ambient-enabled false
在默认的 Wayland 模式下,GNOME 的屏幕旋转在某些无法报告屏幕翻转内核事件 (SW_TABLET_MODE) 的笔记本电脑上会损坏,导致 GNOME 无法开启某些平板功能:GitLab 上有相关讨论。安装 gnome-shell-extension-screen-autorotateAUR 扩展,以在检测到触摸屏时强制假定为平板模式。
或者使用 X11 模式,您可以在登录界面选择。
使用 KDE 模块
- 从 Plasma 5.25+ 开始,Plasma Wayland 会话不再需要 kded-rotation-gitAUR。
- kded_rotation 处于早期开发阶段,且实现方式比较暴力,请谨慎使用。
安装 iio-sensor-proxy 和 kded-rotation-gitAUR,然后重启 Plasma 会话。屏幕旋转应该即可正常工作。
对于触摸屏自动旋转,请编辑 /usr/bin/orientation-helper 脚本,将硬编码的输入设备名称更改为您自己的设备名称(从 xinput list 的输出中选择)。
使用 rot8
安装 rot8-gitAUR,在 Wayland 下执行 rot8,或在 X11 下执行 rot8 --touchscreen TOUCHSCREEN。它可以通过使用 exec rot8 与 i3 或 sway 很好地集成。
若仅在启用平板模式时才启动 rot8,您可以使用 acpid,并修改 /etc/acpi/handler.sh 中的处理程序,在触发平板模式事件时执行 rot8(您可以调用 acpi_listen 并通过翻转显示器来获取正确的事件)。
/etc/acpi/handler.sh
...
video/tabletmode)
case "$3" in
0000008A)
#echo 'tablet mode'
case "$4" in
00000001)
DISPLAY=:0 rot8 --touchscreen TOUCHSCREEN &
logger 'tablet mode enabled'
;;
00000000)
killall rot8
DISPLAY=:0 xrandr --output eDP-1 --rotate normal
rmmod wacom
modprobe wacom
logger 'tablet mode disabled'
;;
*)
logger "ACPI action undefined: $4"
;;
esac
;;
*)
logger "ACPI action undefined: $3"
esac
;;
...
rot8 将自动检测方向并旋转现代 Linux 桌面屏幕和输入设备。有关其他配置,请参考 [2]。
在 Sway 中使用
一个简单的 Sway 自动旋转脚本实现方式如下(使用 iio-sensor-proxy 中的 monitor-sensor)
#!/bin/bash
monitor-sensor | mawk -W interactive '/Accelerometer orientation changed:/ { print $NF; fflush();}' | while read -r line
do
case "$line" in
normal) swaymsg output eDP-1 transform 0 ;;
bottom-up) swaymsg output eDP-1 transform 180 ;;
right-up) swaymsg output eDP-1 transform 90 ;;
left-up) swaymsg output eDP-1 transform 270 ;;
esac
done
确保将其标记为 可执行文件。
在 Hyprland 中使用
一个简单的 Hyprland 自动旋转脚本实现方式如下(使用 iio-sensor-proxy 中的 monitor-sensor)
~/.config/hypr/scripts/auto-rotate.sh
#!/bin/bash
TOUCHSCREEN="nvtk0603:00-0603:f001"
pkill -f "monitor-sensor" 2>/dev/null
monitor-sensor | while read -r line; do
case "$line" in
*"orientation changed: normal"*)
# Laptop mode (landscape)
hyprctl keyword monitor "eDP-1,preferred,auto,2,transform,3"
hyprctl keyword "device[$TOUCHSCREEN]:transform" 3
;;
*"orientation changed: left-up"*)
# Tablet portrait (rotated left)
hyprctl keyword monitor "eDP-1,preferred,auto,2,transform,0"
hyprctl keyword "device[$TOUCHSCREEN]:transform" 0
;;
*"orientation changed: right-up"*)
# Tablet portrait (rotated right)
hyprctl keyword monitor "eDP-1,preferred,auto,2,transform,2"
hyprctl keyword "device[$TOUCHSCREEN]:transform" 2
;;
*"orientation changed: bottom-up"*)
# Laptop mode flipped
hyprctl keyword monitor "eDP-1,preferred,auto,2,transform,1"
hyprctl keyword "device[$TOUCHSCREEN]:transform" 1
;;
esac
done
确保将其标记为 可执行文件,并作为 exec-once 添加到 hyprland.conf 或 execs.conf 中。
在 Labwc 中使用
一个简单的 Labwc 自动旋转脚本实现方式如下(使用 wlr-randr、sed 以及 iio-sensor-proxy 中的 monitor-sensor)
~/bin/2in1screen
#!/bin/bash
DISPLAYNAME="eDP-1"
monitor-sensor | while read -r line; do
case "$line" in
*normal*)
wlr-randr --output eDP-1 --transform normal
sed -i '/<calibrationMatrix>/c\ <calibrationMatrix>1 0 0 0 1 0</calibrationMatrix>' $HOME/.config/labwc/rc.xml
labwc -r
;;
*left-up*)
wlr-randr --output eDP-1 --transform 90
sed -i '/<calibrationMatrix>/c\ <calibrationMatrix>0 -1 1 1 0 0</calibrationMatrix>' $HOME/.config/labwc/rc.xml
labwc -r
;;
*right-up*)
wlr-randr --output eDP-1 --transform 270
sed -i '/<calibrationMatrix>/c\ <calibrationMatrix>0 1 0 -1 0 1</calibrationMatrix>' $HOME/.config/labwc/rc.xml
labwc -r
;;
*bottom-up*)
wlr-randr --output eDP-1 --transform 180
sed -i '/<calibrationMatrix>/c\ <calibrationMatrix>-1 0 1 0 -1 1</calibrationMatrix>' $HOME/.config/labwc/rc.xml
labwc -r
;;
esac
done
确保将其标记为 可执行文件。
请注意,默认的校准矩阵应在 ~/.config/labwc/rc.xml 中创建,因为该脚本假设其存在。
~/.config/labwc/rc.xml
<labwc_config>
<libinput>
<device>
<calibrationMatrix>1 0 0 0 1 0</calibrationMatrix>
</device>
</libinput>
</labwc_config>
平板模式
您可以使用 linuxflip-gitAUR 或 detect-tablet-mode-gitAUR 来配置笔记本和平板模式(例如启用/禁用键盘/触摸板/轨迹点、启动/关闭屏幕键盘等)。
如果没有检测到传感器,可以使用 tablet-modeAUR 手动触发。
桌面环境 / 窗口管理器
i3
在屏幕空间受限的平板上,使用像 i3 这样的平铺窗口管理器非常有意义。起初这可能显得不够直观,但请想一想:Android、iOS 和 Windows 10 的平板模式其实都使用了平铺窗口管理器。因此,i3 是运行 Arch 的平板电脑的绝佳选择。问题在于 i3 是为键盘操作设计的,没有鼠标的情况下,内置的触控支持几乎没有。大部分情况下,用户需要自行构建,通过触控手势(参见 #技巧与提示)或在状态栏/面板中添加触控按钮控件。使用 polybar 状态栏的用户可以尝试 i3touchmenu。
Xfce
Xfce 在平板上运行良好。但是,当 xfce-screensaver 锁定时,默认情况下无法显示屏幕键盘。可以通过转到 设置 > 屏幕保护程序 > 锁定屏幕 并启用 屏幕键盘 选项来启用它。您还需要添加显示您所选键盘所需的命令。例如,使用 onboard 输入此命令: onboard -e
技巧与提示
Easystroke
Easystroke 是一款手势识别应用程序,可以通过各种输入设备(包括触控笔、鼠标和触摸)识别手势。手势可用于启动程序、输入文本、模拟按钮和按键以及滚动。Easystroke 可在 AUR 中获取: easystroke-gitAUR。
Easystroke 目前已不再维护,作者推荐使用 mouse-actions 代替: mouse-actions-cli-binAUR 和 mouse-actions-gui-binAUR。
检查触控笔电量
参见: 笔记本电脑#电池状态
在笔尖位置启动 CellWriter
Easystroke 的一个实用功能是将其配置为在鼠标指针的正下方启动 CellWriter。
#!/bin/bash
# Original author: mr_deimos (ubuntuforums.org). February 14, 2010
# Many bugs fixed and improvements made by Ben Wong. October 20, 2010
# This script toggles the cellwriter letter recognizer window.
# If a cellwriter window is visible, it will be hidden.
# If cellwriter is not already running, this will create a new process.
# If coordinates are specified, the window pops up at those coordinates.
# If coordinates are not specified, the window is toggled, but not moved.
# Implementation Note: this script is trickier than it should be
# because cellwriter does two stupid things. First, it has no
# --get-state option, so we can't tell if it is hidden or not. Second,
# both the notification area applet and the actual program window have
# the same window name in X, which means we can't simply use xwininfo
# to find out if it is showing or not.
#
# (Of course, we wouldn't have to be doing this crazy script at all,
# if cellwriter had a --toggle-window option to toggle showing the
# keyboard, but that's another rant...)
#
# To work around the problem, we'll assume that if the window we got
# information about from xwininfo is smaller than 100 pixels wide, it
# must be an icon in the notification area. This may be the wrong
# assumption, but, oh well...
if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then
verbose=echo
shift
else
verbose=:
fi
if [[ "$1" && -z "$2" || "$1" == "-h" || "$1" == "--help" ]] ; then
cat >&2 <<EOF
$(basename $0): Toggle showing the cellwriter window, optionally moving it."
Usage: $(basename $0) [x y]"
Where x and y are the desired position of the cellwriter window."
If x and y are omitted, the window is not moved."
EOF
exit 1
fi
if [[ "$1" && "$2" ]]; then
x=$[$1-20] # Offset slightly so cursor will be in window
y=$[$2-30]
[ $x -lt 0 ] && x=0 # Minimum value is zero
[ $y -lt 0 ] && y=0
fi
if ! xwininfo -root >/dev/null; then
echo "$(basename $0): Error: Could not connect to your X server." >&2
exit 1
fi
# Try to obtain CellWriter's window id.
# We can't use "xwininfo -name" b/c that might find the notification icon.
OLDIFS="$IFS"
IFS=$'\n'
for line in $(xwininfo -root -tree | grep CellWriter); do
line=0x${line#*0x} # Just to get rid of white space before 0x.
$verbose -en "Checking: $line\t"
if [[ $line =~ (0x[A-Fa-f0-9]+).*\)\ *([0-9]+)x([0-9]+) ]]; then
id=${BASH_REMATCH[1]}
width=${BASH_REMATCH[2]}
height=${BASH_REMATCH[3]}
if [[ $width -gt 100 ]]; then
$verbose "looks good."
CW_WIN_ID=$id
break;
else
$verbose "too small, ignoring."
fi
else
echo "BUG: The xwininfo regular expression in $0 is broken." >&2
fi
done
IFS="$OLDIFS"
#Check if Cellwriter's window is visible
if [ "$CW_WIN_ID" ] ; then
CW_MAP_STATE=`xwininfo -id "$CW_WIN_ID"|grep "Map State"|cut -f 2 -d :`
else
$verbose "Can't find cellwriter window, checking for a running process..."
if ! pgrep -x cellwriter >& /dev/null; then
$verbose "No cellwriter process running, starting a new one."
if [[ "$x" && "$y" ]]; then
cellwriter --show-window --window-x=$x --window-y=$y &
else
cellwriter --show-window &
fi
exit 0
else
$verbose "Found a process, so the window has not been created yet."
$verbose "Pretending the window is UnMapped."
CW_MAP_STATE=IsUnMapped
fi
fi
$verbose "Map state: $CW_MAP_STATE"
case "$CW_MAP_STATE" in
*IsViewable*) # Window is currently visible.
$verbose "hiding window"
cellwriter --hide-window &
;;
*IsUnMapped*) # Window is currently hidden or non-existent.
if [[ "$x" && "$y" && "$CW_WIN_ID" ]]; then
$verbose "moving window to $x $y"
xdotool windowmove $CW_WIN_ID $x $y
fi
$verbose "showing window"
cellwriter --show-window & # In bg in case cw is not already running
;;
*) # This will never happen...
echo "BUG: cellwriter is neither viewable nor unmapped" >&2
echo "BUG: ...which means this script, $0, is buggy." >&2
exit 1
;;
esac
exit 0
将脚本保存为 cellwriter.sh 并放入 /usr/local/bin/ 或 $HOME/bin,并使其成为 可执行文件。
然后在 Easystroke 中创建一个绑定到以下命令的手势
cellwriter.sh $EASYSTROKE_X1 $EASYSTROKE_Y1
启动它(使用您创建的手势)时,它会直接在您的触控笔下方打开。
字母手势
您还可以使用 Easystroke 为整个字母表创建手势,从而大部分取代 CellWriter。为了避免为大写字母创建单独的手势,您可以使用以下 脚本 来激活 Shift 键。
#!/bin/bash if [ -f /tmp/shift ] then xte "keydown Shift_L" "key $1" "keyup Shift_L" rm -f /tmp/shift else xte "key $1" fi
将脚本保存为 keypress.sh 并放入 /usr/local/bin/ 或 $HOME/bin,并使其成为 可执行文件。
然后在 Easystroke 中创建一个绑定到以下命令的手势
touch /tmp/shift
这将激活 Shift 键。要激活字母键,将您的手势绑定到以下命令
keypress.sh $LETTER
将 $LETTER 替换为您要输入的相应字母。
因此,当您想要输入大写字母时,使用 Shift 键的手势,紧接着使用字母的手势。如果您想要小写字母,只需直接使用该字母的手势即可。
Xournal & Xournal++
Xournal
Xournal 是一款用于记笔记、绘画以及通过触控笔维护日志的应用程序。Xournal 旨在提供卓越的图形质量(子像素分辨率)和整体功能。
您还可以通过补丁扩展 xournalAUR 的功能,以启用文档自动保存和插入图片等功能。参见 SourceForge 获取所有可用补丁的链接。要应用补丁,参见 打补丁软件包。
Xournal++
Xournal++ (xournalpp) 是目前正在开发的 Xournal 后继版本。如果您想要更新的 Xournal 版本,可以尝试它。它目前非常稳定,几乎没有导致崩溃的错误。
GDM
您还可以在 GDM 中使用 CellWriter。首先以 root 身份用文本编辑器打开 /etc/gdm/Init/Default。然后在文件末尾附近,添加加粗所示的行
fi cellwriter --keyboard-only & exit 0
您可以添加 --window-x 和 --window-y 来相应地调整 CellWriter 的位置。例如
cellwriter --keyboard-only --window-x=512 --window-y=768 &
要在用户会话中启动完整的 CellWriter 实例,您可能需要终止在 GDM 上下文中以“仅键盘”开关启动的实例。将类似 killall cellwriter 的命令添加到您新建的文件 /etc/gdm/PostLogin/Default 中。
LightDM
配置 LightDM 以使用 Onboard 进行触摸屏登录和解锁,可能是提供屏幕键盘登录的最简单(且稳定)的方案(使用默认的 GTK 欢迎界面时)。
确保安装了 onboard 和 lightdm-gtk-greeter-settings,并运行 lightdm-gtk-greeter-settings 来配置 onboard 的启动。
指定 onboard -t Droid -l Phone 可以配置 Droid 主题并设置 Phone 布局。
Touchegg
Touchegg 是一款多点触控手势识别器。它可以识别最多五根手指的手势(点击、拖动、缩放、旋转...)。
故障排除
Wacom 驱动
这些命令对于排查故障非常有用
wacdump -f tpc /dev/ttyS0 xidump -l xidump -u stylus
如果 xidump 显示您的平板电脑最大分辨率与屏幕分辨率相同,则说明 wacom 驱动已将您的 wacom 坐标重新缩放到 X 服务器的分辨率。要解决此问题,请尝试使用以下参数重新编译 linuxwacom 驱动
./configure --disable-quirk-tablet-rescale
屏幕旋转支持
某些视频驱动程序不支持旋转。要检查您的驱动程序是否支持旋转,请检查 xrandr 输出中的方向列表
normal left inverted right