Huy's Notes
Smooth scrolling with MX Ergo

Smooth scrolling with MX Ergo

#hardware

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

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 the lack of smooth scrolling, horizontal scrolling will affect 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.

On MacOS

So, there are two options: 1) Use a non-free application called Smooze to get the problem solved. Or 2) 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.

On Windows

Based on the answer from ChrisN on StackOverflow.

First, install X-Mouse Button Control from http://www.highrez.co.uk/downloads/XMouseButtonControl.htm.

Then, open the application, select the modification for Right mouse button, set it to "Change movement to scroll". That's it.

On Linux

Linux seemed to have built-in solution for this, but first, you need to figure out your device name:

xinput --list

For me, the device is Logitech MX Ergo and it's a pointer device. So, I set these atttributes to enable hold right mouse button for scrolling:

# Hold right mouse button to scroll
xinput --set-prop 'pointer:Logitech MX Ergo' 'libinput Scroll Method Enabled' 0, 0, 1
xinput --set-prop 'pointer:Logitech MX Ergo' 'libinput Button Scrolling Button' 3
xinput --set-prop 'pointer:Logitech MX Ergo' 'libinput Middle Emulation Enabled' 1

Referred in


If you think this note resonated, be it positive or negative, please feel free to send me an email and we can talk.