🕵️‍♂️ Engage in discussions ANONYMOUSLY. NO REGISTRATION is required. 💬

✅ Registered accounts earn up to $25 per thread via PayPal and BTC. 🤑 Read more in News and Announcments! Unlock the ability to chat, share, send private messages and earn money per post in our community. Just register an account. It's Free!

SignUp Now!
  • 🕵️‍♂️ Engage in discussions ANONYMOUSLY. NO REGISTRATION is required. 💬 ✅ Registered accounts earn up to $25 per thread via PayPal and BTC. 🤑 Read more... Unlock the ability to chat, share, send private messages and earn money per post in our community. Just register an account. It's Free!

How to configure middle-mouse scrolling on Linux to replicate the autoscrolling behavior found on Windows?

New member
Joined
Aug 20, 2023
Messages
3
Credits
30
Issue: I'm seeking systemwide middle-mouse scrolling in Linux similar to Windows.

Attempted Solution: Enabled middle-mouse scrolling with "xinput set-prop 7 "libinput Scroll Method Enabled" 0, 0, 1."

Current Functionality:
  • Clicking does nothing, follows default DE action.
  • Holding the button mimics the scroll wheel, lacking 'automatic scrolling.'

Desired Functionality:
  • Enable 'locked scrolling' upon click, allowing effortless scrolling.
  • Display a symbol indicating the starting position on click or hold.
  • Implement 'automatic scrolling' when the middle mouse button is held.

Consideration: Acknowledging potential challenges in achieving full autoscrolling functionality systemwide.

I know there are more advanced users on the forums here. Please help!
 
New member
Joined
Aug 20, 2023
Messages
9
Credits
63
This is what I use on my main machine. You can put it in settings -> autostart to make it fire up on system launch

Bash:
#!/bin/bash
# Autoscroll (Hold Only)

# Configuration
middle_mouse_button=2
mouse_scroll_up=4
mouse_scroll_down=5
mouse_scroll_left=6
mouse_scroll_right=7
enable_vertical_scroll=1
enable_horizontal_scroll=1

# Caution: Below are the script dynamics
echo -n | xsel -n -i

# Dynamically obtain the mouse ID
mouse_id=$(xinput --list | grep -i -m 1 'mouse' | grep -o 'id=[0-9]\+' | grep -o '[0-9]\+')
toggle=0

while [ $toggle -eq 0 ]; do
    sleep 0.02
    middle_mouse_state=$(xinput --query-state $mouse_id | grep 'button\[2' | cut -d \= -f2)
    toggle=$(xinput --query-state $mouse_id | grep 'button\[2' | grep -c up)
    eval $(xdotool getmouselocation --shell)
    current_y=$Y

    # Scroll down
    while [ $current_y -gt $start_y ] && [ $toggle -eq 0 ]; do
        eval $(xdotool getmouselocation --shell)
        current_y=$Y
        speed=$(expr $current_y / 100 - $start_y / 100)
        xdotool click --repeat $speed --delay 1 $mouse_scroll_down
        toggle=$(xinput --query-state $mouse_id | grep 'button\[2' | grep -c up)
        sleep 0.02
    done

    # Scroll up
    while [ $current_y -lt $start_y ] && [ $toggle -eq 0 ]; do
        eval $(xdotool getmouselocation --shell)
        current_y=$Y
        speed=$(expr $current_y / 100 - $start_y / 100 | sed 's:-::')
        xdotool click --repeat $speed --delay 1 $mouse_scroll_up
        toggle=$(xinput --query-state $mouse_id | grep 'button\[2' | grep -c up)
        sleep 0.02
    done

done
 
New member
Joined
Aug 20, 2023
Messages
3
Credits
30
Holy sh*t! Thanks for the share. This works so good but looks so complex that I don't think I can modify it at all.

Edit: I also found out that the left-right (horizontal scroll is not there)
 
Moderator
Joined
Aug 18, 2023
Messages
19
Credits
216
I have two scripts that do exactly that. One of them is using Python and replicates Windows scrolling and the other automatically finds your mouse with simple Bash. There's no need to write "xinput list". It automatically searches for any matching item inside the list with "mouse" in it.

Simple bash, works on scroll hover. Save it as mid_mouse_autoscroll.sh in directory of your choice and invoke it in ~/.config/autostart/ with a mid_mouse_autoscroll.desktop file.

Bash:
#!/bin/bash

# Initialize arrays to store information
NOT_MOUSE_IDS=()
MOUSE_IDS=()

# Get all device IDs
ALL_IDS=($(xinput list --id-only))

if [ ${#ALL_IDS[@]} -gt 0 ]; then
    for DEVICE_ID in "${ALL_IDS[@]}"; do
        # Check if the device is a mouse by querying its properties
        IS_MOUSE=$(xinput list --name-only $DEVICE_ID | grep -i "mouse")

        if [ -n "$IS_MOUSE" ]; then
            MOUSE_IDS+=("$DEVICE_ID")

            # Set mouse properties for scrolling
            xinput set-prop $DEVICE_ID "libinput Scroll Method Enabled" 0, 0, 1 2>/dev/null
            xinput set-prop $DEVICE_ID "libinput Button Scrolling Button" 2 2>/dev/null

            echo -e "\e[32mFound mouse device with ID: $DEVICE_ID [$IS_MOUSE]\e[0m"
            echo -e "\e[32mMouse properties set for scrolling.\e[0m"
        else
            NOT_MOUSE_IDS+=("$DEVICE_ID")
        fi
    done

    # Display devices that are not mice
    echo -e "Devices checked that are not mice: ${NOT_MOUSE_IDS[@]}"

    # Display count of mice found
    MOUSE_COUNT=${#MOUSE_IDS[@]}
    if [ "$MOUSE_COUNT" -eq 0 ]; then
        echo -e "\e[33mNo devices that are mice are found.\e[0m"
        echo "Please enter the IDs of mouse devices manually (e.g., 1 3 5) or press Enter to skip:"
        read -r MANUAL_MOUSE_IDS
        MOUSE_IDS=($MANUAL_MOUSE_IDS)
    fi

    if [ ${#MOUSE_IDS[@]} -gt 0 ]; then
        echo -e "\e[32m$MOUSE_COUNT mouse device(s) found.\e[0m"
    else
        echo "No mouse devices specified manually. Exiting."
        exit 0
    fi
else
    echo "No devices found."
fi

# Continue with the script for the manually specified mouse devices
for DEVICE_ID in "${MOUSE_IDS[@]}"; do
    # Set mouse properties for scrolling
    xinput set-prop $DEVICE_ID "libinput Scroll Method Enabled" 0, 0, 1 2>/dev/null
    xinput set-prop $DEVICE_ID "libinput Button Scrolling Button" 2 2>/dev/null

    echo -e "\e[32mMouse properties set for scrolling on device with ID: $DEVICE_ID\e[0m"
done


mid_mouse_autoscroll.desktop content

Code:
[Desktop Entry]
Exec=/home/bjordanov/scripts/sys-modifications/mid_hold_autoscroll.sh
Icon=dialog-scripts
Name=mid_hold_autoscroll.sh
Path=
Type=Application
X-KDE-AutostartScript=true
 
New member
Joined
Aug 20, 2023
Messages
3
Credits
30
This is a beautiful solution but not quite what I was looking for but the horizontal autoscroll works so that's a bonus. Can you share the one solution you made with Python, please?
 
Top