说在前面:下述两个方案默认仅在X11环境下有效,Wayland环境无法使用。Ubuntu 21.04以前默认使用X11,所以两种方案都可以使用,Ubuntu 21.04开始默认使用Wayland,请注意。
方案2可以兼容Wayland使用,但是我没有尝试过,如需要请参考项目说明
方案1:touchegg(推荐)
开源项目地址:https://github.com/JoseExposito/touchegg
1.1 安装
- 方式1: 添加ppa仓库安装
sudo add-apt-repository ppa:touchegg/stable
sudo apt update
sudo apt install touchegg
- 方式2: 下载deb安装包安装
安装包下载地址:https://github.com/JoseExposito/touchegg/releases
wget https://github.com/JoseExposito/touchegg/releases/download/2.0.11/touchegg_2.0.11_amd64.deb
sudo dpkg -i touchegg_2.0.11_amd64.deb
安装完成后使用touchegg
命令启动应用,重启电脑后touchegg会自动启动。
1.2 修改配置
1. 使用可视化界面Touché配置(推荐)
下载Touché安装包进行安装,安装包下载地址:https://github.com/JoseExposito/touche/releases
wget https://github.com/JoseExposito/touche/releases/download/1.0.6/touche_1.0.6_amd64.deb
sudo dpkg -i touche_1.0.6_amd64.deb
这里截一份我的三指和四指配置:
- 三指上滑:最大化/恢复窗口
- 三指下滑:最小化窗口
- 三指左滑:左分屏
- 三指右滑:右分屏
- 四指上下滑:Gnome系统默认切换工作窗口
- 四指左滑:后退操作
- 四指右滑:前进操作
- 双指操作:页面缩放比例调整
2. 使用文件配置
创建默认配置文件
$ mkdir -p ~/.config/touchegg && cp -n /usr/share/touchegg/touchegg.conf ~/.config/touchegg/touchegg.conf
下面是我的配置文件内容,和上述GUI配置是一样的
<touchégg>
<settings>
<!--
Delay, in milliseconds, since the gesture starts before the animation is displayed.
Default: 150ms if this property is not set.
Example: Use the MAXIMIZE_RESTORE_WINDOW action. You will notice that no animation is
displayed if you complete the action quick enough. This property configures that time.
-->
<property name="animation_delay">150</property>
<!--
Percentage of the animation to be completed to apply the action.
Default: 20% if this property is not set.
Example: Use the MAXIMIZE_RESTORE_WINDOW action. You will notice that, even if the
animation is displayed, the action is not executed if you did not moved your fingers far
enough. This property configures the percentage of the animation that must be reached to
execute the action.
-->
<property name="action_execute_threshold">20</property>
<!--
Global animation colors can be configured to match your system colors using HEX notation:
<color>909090</color>
<borderColor>FFFFFF</borderColor>
You can also use auto:
<property name="color">auto</property>
<property name="borderColor">auto</property>
Notice that you can override an specific animation color.
-->
<property name="color">auto</property>
<property name="borderColor">auto</property>
</settings>
<!--
Configuration for every application.
-->
<application name="All">
<gesture type="SWIPE" fingers="3" direction="UP">
<action type="MAXIMIZE_RESTORE_WINDOW">
<animate>true</animate>
</action>
</gesture>
<gesture type="SWIPE" fingers="3" direction="DOWN">
<action type="MINIMIZE_WINDOW">
<animate>true</animate>
</action>
</gesture>
<gesture type="SWIPE" fingers="3" direction="LEFT">
<action type="TILE_WINDOW">
<direction>left</direction>
<animate>true</animate>
</action>
</gesture>
<gesture type="SWIPE" fingers="3" direction="RIGHT">
<action type="TILE_WINDOW">
<direction>right</direction>
<animate>true</animate>
</action>
</gesture>
<gesture type="PINCH" fingers="3" direction="IN">
<action type="CLOSE_WINDOW">
<animate>true</animate>
<color>F84A53</color>
<borderColor>F84A53</borderColor>
</action>
</gesture>
<gesture type="SWIPE" fingers="4" direction="UP">
<action type="CHANGE_DESKTOP">
<direction>auto</direction>
<animate>true</animate>
<animationPosition>auto</animationPosition>
</action>
</gesture>
<gesture type="SWIPE" fingers="4" direction="DOWN">
<action type="CHANGE_DESKTOP">
<direction>auto</direction>
<animate>true</animate>
<animationPosition>auto</animationPosition>
</action>
</gesture>
<gesture type="SWIPE" fingers="4" direction="LEFT">
<action type="SEND_KEYS">
<repeat>false</repeat>
<modifiers>Alt_L</modifiers>
<keys>Left</keys>
<on>begin</on>
</action>
</gesture>
<gesture type="SWIPE" fingers="4" direction="RIGHT">
<action type="SEND_KEYS">
<repeat>false</repeat>
<modifiers>Alt_L</modifiers>
<keys>Right</keys>
<on>begin</on>
</action>
</gesture>
<gesture type="PINCH" fingers="4" direction="OUT">
<action type="SHOW_DESKTOP">
<animate>true</animate>
</action>
</gesture>
<gesture type="PINCH" fingers="4" direction="IN">
<action type="SEND_KEYS">
<repeat>false</repeat>
<modifiers>Super_L</modifiers>
<keys>A</keys>
<on>begin</on>
</action>
</gesture>
<gesture type="PINCH" fingers="2" direction="IN">
<action type="SEND_KEYS">
<repeat>true</repeat>
<modifiers>Control_L</modifiers>
<keys>KP_Subtract</keys>
<decreaseKeys>KP_Add</decreaseKeys>
</action>
</gesture>
<gesture type="PINCH" fingers="2" direction="OUT">
<action type="SEND_KEYS">
<repeat>true</repeat>
<modifiers>Control_L</modifiers>
<keys>KP_Add</keys>
<decreaseKeys>KP_Subtract</decreaseKeys>
</action>
</gesture>
</application>
<!--
Configuration for specific applications.
-->
<application name="Google-chrome,Chromium-browser,Firefox">
<gesture type="PINCH" fingers="2" direction="IN">
<action type="SEND_KEYS">
<repeat>true</repeat>
<modifiers>Control_L</modifiers>
<keys>KP_Subtract</keys>
<decreaseKeys>KP_Add</decreaseKeys>
</action>
</gesture>
<gesture type="PINCH" fingers="2" direction="OUT">
<action type="SEND_KEYS">
<repeat>true</repeat>
<modifiers>Control_L</modifiers>
<keys>KP_Add</keys>
<decreaseKeys>KP_Subtract</decreaseKeys>
</action>
</gesture>
</application>
</touchégg>
具体配置信息的含义可以参考项目README.md
文档
方案2 :fusuma
开源项目地址:https://github.com/iberianpig/fusuma
我一开始用的是fusuma,后来发现touchegg更好用,因此推荐使用touchegg。你可以都试试,然后选择自己觉得好用的。
这个项目的README.md
文档中也有详细的安装说明,这里就不赘述了。下面说几点安装中的建议:
- 安装过程第3步,用gem安装fusuma时,先把gem的源改为国内的会快点
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
- 下面是我之前使用的配置文件
~/.config/fusuma/config.yml
,可供参考
swipe:
3:
left:
command: 'xdotool key alt+Left'
right:
command: 'xdotool key alt+Right'
up:
command: 'xdotool key ctrl+alt+Down'
threshold: 1.5
down:
command: 'xdotool key ctrl+alt+Up'
threshold: 1.5
4:
left:
command: 'xdotool key super+Left'
right:
command: 'xdotool key super+Right'
up:
command: 'xdotool key super+Up'
down:
command: 'xdotool key super+s'
pinch:
2:
in:
command: 'xdotool key ctrl+equal'
threshold: 0.1
out:
command: 'xdotool key ctrl+minus'
threshold: 0.1
threshold:
swipe: 1
pinch: 1
interval:
swipe: 1
pinch: 1