"lock" mouse to current window/game?

i am trying to play games with a trackball in mame2010 on ubuntu 18.10 with retropie, but aparently the “cursor” can move off screen making the games unplayable and there really isnt much help to gather on the retropie forum.

can someone please help me find a way to lock the mouse to the screen/window/game?

is there a mame or retroarch option for this?