Admiral_Jezza

XMouseAutoScroll

Oct 18th, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.32 KB | Software | 0 0
  1. #!/bin/bash
  2.  
  3. # The window names we are looking for
  4. TARGET_WINDOWS=("Europa Universalis IV" "World of Warships")
  5.  
  6. # The xinput device name
  7. DEVICE_NAME="SINOWEALTH ADXM0620"
  8.  
  9. # Previous window state
  10. PREV_STATE=""
  11.  
  12. while true; do
  13.     # Get the name of the currently focused window
  14.     CURRENT_WINDOW=$(xdotool getwindowfocus getwindowname)
  15.  
  16.     # Flag to check if any target window is focused
  17.     WINDOW_MATCH=false
  18.  
  19.     # Loop through all target windows
  20.     for TARGET_WINDOW in "${TARGET_WINDOWS[@]}"; do
  21.         if [[ "$CURRENT_WINDOW" == *"$TARGET_WINDOW"* ]]; then
  22.             WINDOW_MATCH=true
  23.             if [[ "$PREV_STATE" != "focused" ]]; then
  24.                 # If previously unfocused, now focused on one of the target windows
  25.                 xinput --set-prop "$DEVICE_NAME" 'libinput Scroll Method Enabled' 0, 0, 0
  26.                 PREV_STATE="focused"
  27.             fi
  28.         fi
  29.     done
  30.  
  31.     # If no target windows are focused
  32.     if [[ "$WINDOW_MATCH" == false ]]; then
  33.         if [[ "$PREV_STATE" != "unfocused" ]]; then
  34.             # If previously focused, now unfocused
  35.             xinput --set-prop "$DEVICE_NAME" 'libinput Scroll Method Enabled' 0, 0, 1
  36.             PREV_STATE="unfocused"
  37.         fi
  38.     fi
  39.  
  40.     # Sleep for a short while before checking again (adjust as needed)
  41.     sleep 1
  42. done
Tags: Linux BASH SH
Advertisement
Add Comment
Please, Sign In to add comment