Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

controlling mouse sensitivity primarily for 640x480 Dosbos-X windows

When you want to run an old Windows 9x-era software title in dosbox-x, and it the program has a very small maximum resolution, you might want to lower the resolution of the virtual desktop, and then maximize the window of the emulator.

And if you want to do this, your effective mouse sensitivity goes through the roof. You can try lowering it in the virtual environment, but that has limited effect.

So, you can adjust it in your X11 environment. I don't use a desktop environment, and xfce4-settings-manager can view but not make changes to settings (I guess it needs an xfce4 daemon running for that somewhere). So I modify the xinput properties directly. First of all, here's the script.

files/2024/listings/mouse-sensitivity.sh (Source)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
# File: mouse-sensitivity.sh
# Location: /usr/local/bin
# Author: bgstack15
# Startdate: 2024-02-14-4 14:04
# SPDX-License-Identifier: GPL-3.0-only
# Title: Simple control for mouse sensitivity
# Purpose: provide easy options to slow down my mouse
# History:
# Usage: ./mouse-sensitivity.sh slow
# Reference:
#    https://unix.stackexchange.com/questions/90572/how-can-i-set-mouse-sensitivity-not-just-mouse-acceleration
#    https://shallowsky.com/blog/linux/setting-mouse-speed.html
#    experimentation for my mouse
# Improve:
# Dependencies:
#    x11, notify-send | zenity
# Documentation:

# Functions
warn() {
   #zenity --icon-name mouse --warning --text "${1}"
   notify-send --icon mouse --expire-time=2000 "Mouse sensitivity" "${1}"
}

# Load config
test -f "${XDG_CONFIG_HOME:-~/.config}/mouse-sensitivity.conf" && . "${XDG_CONFIG_HOME:-~/.config}/mouse-sensitivity.conf"
test -z "${DEVICE_NAME}" && DEVICE_NAME="Logitech Wireless Receiver Mouse"
# Load environment/runtime settings
if test -z "${SPEED}" ;
then
   if test -n "${1}" ;
   then
      SPEED="${1}"
   else
      warn "Need SPEED or \$1 of number between -1.0 and 1.0, or slow, normal, fast."
      exit 1
   fi
fi

# determine xinput id
xid="$( xinput list | sed -n -r -e "/${DEVICE_NAME}/{s/.*id=([0-9]+).*/\1/;p;}" )"

# Validate SPEED
if echo "${SPEED}" | grep -qE '^[0-9\.\-]+$' ;
then
   # a decimal number, so running with just that number
   :
elif echo "${SPEED}" | grep -qE '^(slow|normal|fast)' ;
then
   case "${SPEED}" in
      slow) SPEED=-1 ;;
      normal) SPEED=0 ;;
      fast) SPEED=1 ;;
   esac
else
   warn "Need speed of number between -1.0 and 1.0, or slow, normal, fast."
   exit 1
fi

# Run command
printf '%s\n' "Setting device ${xid} speed ${SPEED}" 1>&2
xinput set-prop "${xid}" "libinput Accel Speed" "${SPEED}"

You can configure it with a file ~/.config/mouse-sensitivity.conf for the exact device name to look for. I hardcoded the property to modify, but I actually have no idea if that is different for different mice. I'll probably improve this over time.

So now the mouse doesn't zip around quite as ridiculously as before in the tiny, zoomed-in retro environment, so it's easier to click on things!

Comments