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

2
  • What window manager do you use? Doing something on focus change is a job for the WM, but not all of them offer this functionality. Commented Jan 22, 2016 at 22:30
  • @Gilles I'm running Gnome 3.
    – oblitum
    Commented Jan 22, 2016 at 23:03

2 Answers 2

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.

3
  • You need to fix your test, -eq is for comparing integers. I've provided an answer based on yours.
    – oblitum
    Commented Jan 21, 2016 at 9:23
  • 1
    Running on a tight loop is not a good idea. Commented Jan 22, 2016 at 22:29
  • @Gilles, I do that keep in mind. But also I had warned OP by adding comment that this code will be in forever loop.
    – SHW
    Commented Jan 27, 2016 at 8:06
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
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .