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

  • 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. – Gilles 'SO- stop being evil' Jan 22 '16 at 22:30
  • @Gilles I'm running Gnome 3. – pepper_chico Jan 22 '16 at 23:03
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.

  • You need to fix your test, -eq is for comparing integers. I've provided an answer based on yours. – pepper_chico Jan 21 '16 at 9:23
  • Running on a tight loop is not a good idea. – Gilles 'SO- stop being evil' Jan 22 '16 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 Jan 27 '16 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.