Smooth scrolling with greatest trackball MX Ergo

With no doubt, MX Ergo is one of the greatest trackball in the market right now.

Before it, I used Logitech M570 Wireless trackball mouse then I hear about MX Ergo. I’ve been waiting for this device for well over a decade – a Bluetooth version of Logitech’s fabled TrackMan Marble Wheel. And this is, indeed, a really nice trackball for use with new laptops that don’t have USB-A ports, such as the MacBook/MacBook Pro.

Logitech MX Ergo Wireless Trackball Mouse
Logitech MX Ergo Wireless Trackball Mouse

The trackball functionality is exactly as you’d expect if you used the M570, with a few extra features – tiltable scrollwheel, the ‘precision’ button to allow fine control, and the ability to switch between two devices. The AA battery has been replaced by li-poly and recharges via micro-USB.
A unique adjustable hinge allows you to choose the best angle between 0°and 20° for a more natural hand position and greater comfort.

MX Ergo is working on Linux/Windows flawlessly

This mous is working well on Windows of course.

I’m using it with Arch Linux daily, and everything works pretty much as expected. I’m using the Unifying Receiver on a Dell mornitor that connected with my Mac Book and Bluetooth on a Arch Linux laptop with Wayland. Everything works on the laptop, and everything but horizontal scrolling  isn’t working on the Mac Book (I solved it below). I’m not sure if the difference is MacOS versus Arch Linux or Unifying Receiver versus Bluetooth.

MX Ergo horiontal scrolling problem on Mac Book

But, switching to MX Ergo, especially from Macbook’s trackpad or Magic Mouse, and people around you will soon hear you complain about the stupid scrolling of the trackball.

Apparently it’s not too bad, but unliked M570, MX Ergo lack of smooth scrolling, horizontal scrolling will affects your workflow a lot. For example, if you need to work with design tools like Figma or Sketch regularly.

I’ve had that problem too, until when I discovered an awesome script from u/Jitowix on Reddit.

So, there are two options:

  1. Use a non-free application called Smooze to get the problem solved.
  2. Or be a geek and spend sometimes setting up some script to solve the problem.

I choose option 2, it’s not too hard by the way, follow these two steps and you’ll have smooth scrolling on your trackball by holding Right Mouse button while scroll your ball.

  1. Install Hammerspoon via Homebrew:
    brew cask install hammerspoon
    
  2. Open ~/.hammerspoon/init.lua and type in this script:
-- https://github.com/tekezo/Karabiner/issues/814
-- HANDLE SCROLLING WITH MOUSE BUTTON PRESSED
local scrollMouseButton = 2
local deferred = false

overrideOtherMouseDown =
  hs.eventtap.new(
  {hs.eventtap.event.types.rightMouseDown},
  function(e)
    deferred = true
    return true
  end
)

overrideOtherMouseUp =
  hs.eventtap.new(
  {hs.eventtap.event.types.rightMouseUp},
  function(e)
    if (deferred) then
      overrideOtherMouseDown:stop()
      overrideOtherMouseUp:stop()
      hs.eventtap.rightClick(e:location(), pressedMouseButton)
      overrideOtherMouseDown:start()
      overrideOtherMouseUp:start()
      return true
    end
    return false
  end
)

local oldmousepos = {}
local scrollmult = 2 -- negative multiplier makes mouse work like traditional scrollwheel, for macOS, use positive number.

dragOtherToScroll =
  hs.eventtap.new(
  {hs.eventtap.event.types.rightMouseDragged},
  function(e)
    deferred = false
    oldmousepos = hs.mouse.getAbsolutePosition()
    local dx = e:getProperty(hs.eventtap.event.properties["mouseEventDeltaX"])
    local dy = e:getProperty(hs.eventtap.event.properties["mouseEventDeltaY"])
    local scroll = hs.eventtap.event.newScrollEvent({dx * scrollmult, dy * scrollmult}, {}, "pixel")
    -- put the mouse back
    hs.mouse.setAbsolutePosition(oldmousepos)
    return true, {scroll}
  end
)

overrideOtherMouseDown:start()
overrideOtherMouseUp:start()
dragOtherToScroll:start()

Then start Hammerspoon, or reload config if you’re already started it.