Configure application-specific gestures with Fusuma v2!
Tags: linux, ubuntu, ruby
Published: 2021-06-12 07:10:49

---
title: Configure application-specific gestures with Fusuma v2!
published: true
description: 
tags: linux, ubuntu, ruby
// cover_image: https://opengraph.githubassets.com/71c8ffb2ad3f28643d1511dbc431d5bb79497a24e785c6918583432b4068bf6c/iberianpig/fusuma-plugin-appmatcher
---

Starting from this article, I will explain how to configure the new features available in Fusuma v2.
If you haven't updated to Fusuma v2, please refer to the previous article.
{% post https://dev.to/iberianpig/fusuma-multi-touch-gesture-for-linux-updated-to-v2-11i0 %}

So far, Fusuma has only allowed you to set one type of action for a gesture globally.
However, by using the context of Fusuma v2, you will be able to switch Config dynamically.

In this article, we will install `fusuma-plugin-appmatcher` and configure application-specific settings on Fusuma's config.yml.


{% github iberianpig/fusuma-plugin-appmatcher %}

## Install fusuma-plugin-appmatcher

Run the following command in a terminal

```
$ sudo gem install fusuma-plugin-appmatcher
```

## How to configure fusuma-plugin-appmather

### Get the application name to use in the configuration.

To get application name (WM_CLASS) to specify in config.yml, use `$ fusuma-appmatcher -l`.
Without `-l` option, only foreground application names are retrieved.

```sh
$ fusuma-appmatcher -l
discord
Slack
Gnome-terminal
Google-chrome
```

### Set `context: WM_CLASS` in config.yml.

To add to the existing config.yml. 

1. add `---` to the bottom of `~/.config/fusuma/config.yml` to separate `context`.
2. add `context: { application: Google-chrome }`.
3. add `swipe: ...  ...` and describe the gestures as usual.


In the following example, 4-finger gesture is the default setting, and 3-finger swipe gesture is assigned with different behaviors for Google Chrome and Gnome Terminal.

{% gist https://gist.github.com/iberianpig/4a8682ddcd4020d299462d0cfaddf8d9 %}

This example uses [fusuma-plugin-wmctrl](https://github.com/iberianpig/fusuma-plugin-wmctrl) , [fusuma-plugin-sendkey](https://github.com/iberianpig/fusuma-plugin-sendkey) and [fusuma-plugin-keypress](https://github.com/iberianpig/fusuma-plugin-keypress) .

When I try swiping up three fingers on Google Chrome and Gnome Terminal respectively, both tabs open.
I was able to assign different keys to them: `LEFTCTRL+T` for Google Chrome and `LEFTSHIFT+LEFTCTRL+T` for Gnome Terminal.

## Concept of Context in Fusuma v2

Actually, Fusuma runs as an event-driven application.

When a user touches the trackpad, some touch events will be sent to Fusuma. Fusuma will calculate the events and if they exceed the threshold, it will pass them to the executor plugin as swipe events and execute the action associated with the event content from config.yml.

Fusuma will search the config.yml for actions that match the event, but when a context event is issued, Fusuma will search the config for actions that match that context.

* Fusuma v2 can accept YAML documents containing `---`.
* You can create a context by separating the config.yml with three `---` hyphens.
* The first document delimited by `---` is treated as the default configuration.
* By the way, `---` is a standard YAML syntax that allows multiple documents to be described in one file.


Under `context:` is the event-name of the context and its value.

```yaml
context:
  event-name: value

swipe:
  3:
    left:
      sendkey: 'LEFTALT+RIGHT'
```


Currently, context events can only be fired by the fusuma-plugin-appmatcher plugin.

In the future, we plan to support context events from tail or external commands by generalizing the events.
For example, a user can define a config that is valid only when a specific device is connected.