Jon Combe logo

Binding mouse buttons on Linux

September 2024A few days ago

I had the idea recently to bind the two unused buttons on the side of my mouse so that clicking them moved my desktop workspaces up and down. I already do this using keyboard shortcuts of course, using Ctrl+Super+Up and Ctrl+Super+Down in my case, but I thought it might be handy to have this on the mouse too.

That should be easy to do, right? Well it is when you know how.

I fiddled around with xbindkeys for an age but couldn't get it to do what I wanted. In the end, I found easystroke which, despite a challenging UI, did the job nicely.

The instructions below are tested on a standard Pop!_OS install, but note that I couldn't get this to work when using the Wayland windowing system. I don't know why.

Here's how I did it:

Installation

First, install it using sudo apt install easystroke or whatever your equivalent function is.

Tell easystroke which mouse buttons you want to use

Open up the software and then:

  • click on the Preferences tab
  • expand the Additional buttons thingy
  • click the Add button
  • move your mouse over the grey box that appears and click the appropriate button on your mouse
  • repeat the process for any other buttons you want easystroke to recognise.

Define the actions you want to happen

  • go back to the Actions tab
  • click the Add Action button
  • rename it from "Gesture 1" to something more descriptive
  • change the type from Command to Key. You may get a warning here about Easystoke wanting to "inhibit shortcuts". If so, click Allow.
  • click where it says Key combination... and type the keyboard shortcut combination you want to be triggered
  • with the action you've just added still highlighted, click the Record Stroke button, then press the mouse button you want to trigger the action
  • repeat the process for any other actions you want to add.

This process isn't the most intuitive, so here's a screenshot showing the end outcome I wanted:

Binding mouse buttons on Linux

At this point, you should be able to use your mouse buttons to trigger the actions you've just defined.

Tidying up

Easystroke shows a little indicator on screen of the action you've just performed. If, like me, you find this a little annoying, you can disable it by deselecting the Show popups checkbox on the Preferences tab.

Finally, you probably want these actions available automatically each time you boot up your machine. To do that, go to the Preferences tab again, and enable the Autostart easystroke checkbox.

Et voilà!