Automate GNOME Configuration with dconf

When I install a fresh Linux distro on a workstation I typically keep the default settings. This is almost always Fedora, and has been for about 10 years. This is either a case of Fedora having great defaults for my workflow, or my workflow has changed to fit Fedora’s defaults. Either cause doesn’t change the outcome.

On installing Fedora 31 on a new laptop I found left click didn’t work on the touchpad. A quick search showed this was a feature of GNOME 2.8 for touchpads to use a gesture as a secondary click rather than the touchpad. This can be changed to allow the use of the left and right area of the touchpad through:

  • install gnome-tweaks
  • open gnome-tweaks
  • click ‘Keyboard & Mouse’ on the left menu
  • scroll down to ‘Mouse Click Emulation’
  • click to select ‘Area’

I already keep a list of packages to install every time I reinstall my workstation, so might as well automate this workflow too. Granted, workstations aren’t reinstalled that often, but Infrastructure as Code is a great thing even beyond server infrastructure

dconf

Dconf is a key value configuration system used by GNOME. Its loosely structured, but keys should be grouped together logically.

Find what needs to be changed

The dconf command has a handful of commands for interacting with key value mappings. The ones we’re interested in here (straight from the usage) are:

  • read Read the value of a key
  • list List the contents of a dir
  • write Change the value of a key
  • watch Watch a path for changes

To know what changes are being done by gnome-tweaks, we can run dconf in a terminal and simply see what it’s doing:

$ dconf watch /

Next we open up gnome-tweaks and make our change with the terminal still open. If you click around you’ll add more output to the dconf command and it might not match the below ouput, but this gives us:

$ dconf watch /
/org/gnome/desktop/peripherals/touchpad/click-method
'areas'

Set the change

Now we know what needs to be changed. Now when we’re setting up our desktop, we can automatically add this key by adding this value as the user via dconf:

$ dconf write "/org/gnome/desktop/peripherals/touchpad/click-method" "'areas'"

Ansible

I mentioned that I already automate package installation on a new desktop, that is just one part of an ansible role. Ansible has a dconf module, so this is even an easy change in an Ansible task.

- name: enable areas click method for right click on touchpad
dconf:
key: "/org/gnome/desktop/peripherals/touchpad/click-method"
state: present
value: "'areas'"
become: "yes"
become_user: "{{ ansible_env.USERNAME }}"

A couple notes on this task. The playbook is using become to run the entire playbook as root via sudo from my user on my workstation. Dconf settings are per user, so the setting needs to be modified as the user. using become: yes and become_user: "{{ ansible_env.USERNAME}}" runs the command as our workstation user that kicked off the playbook via a local connection, not root.

Comments are closed.