2

I'd like to execute xinput disable bcm5974 when Gnome Terminal (and maybe some other application) gets focused, and xinput enable bcm5974 when it loses focus.

This is because libinput and my macbook's touchpad are not friends, libinput's palm rejection barely works, it's really driving me nuts when editing code in Vim and it scrolls by accident, or when typing a command at the terminal.

libinput 1.1.4-1
xf86-input-libinput 0.16.0-1
ArchLinux

oblitum
  • 965

2 Answers2

1

This following command will give you the name of focused application

xdotool getwindowfocus getwindowname

Using this, You can write a wrapper-script to achieve your goal.

e.g.

while [ true ]
do
  FocusApp=`xdotool getwindowfocus getwindowname`
  if [ "xTerminal" -eq "x$FocusApp" ]; then
          xinput disable bcm5974
  else
          xinput enable bcm5974
  fi
done

Above code will run forever checking for focused application. If get the expected result then execute the if condition otherwise execute else condition.

You can fine tune this script to suit your bill.

SHW
  • 14,786
  • 14
  • 66
  • 101
1

Used xprop to get the class of my window and xdotool like bellow:

xdotool search --onlyvisible --classname gnome-terminal-server behave %@ focus exec xinput disable bcm5974 &

xdotool search --classname gnome-terminal-server behave %@ blur exec xinput enable bcm5974 &

The previous is unstable so the following script based on @SHW's answer is better:

#!/bin/sh

[ "$(pgrep -x $(basename $0))" != "$$" ] && exit 1

while [ true ]
do
    window=`xdotool getwindowfocus getwindowname`
    is_enabled=`xinput --list-props bcm5974 | awk '/Device Enabled/{print $NF}'`
    if [ "$window" = "Terminal" -o "$window" = "Guake!" ]; then
        if [ "$is_enabled" = "1" ]; then
            xinput disable bcm5974
        fi
    else
        if [ "$is_enabled" = "0" ]; then
            xinput enable bcm5974
        fi
    fi
    sleep 1
done
oblitum
  • 965