0

I know that I'm able to disable (and even change) the Alt+Tab window switching shortcut through Ubuntu's settings menu. However, what I'd like to do is keep it for all but a certain application.

Is there a way to conditionally disable Alt+Tab when that application is open? Or some way I can rig a script together to do approximately this?


EDIT: The specific application I want Alt-Tabbing disabled for is godot. The following script (from this post) fails to work on my machine:

#!/bin/bash

keySwitchApplication="switch-applications"
keySwitchApplicationBackward="switch-applications-backward"

backupSwitchApplications="$(gsettings get org.gnome.desktop.wm.keybindings "$keySwitchApplication")"
disableSwitchApplications="$(gsettings get org.gnome.desktop.wm.keybindings "$keySwitchApplication" | sed "s/\,*\s*'<Alt>Tab'//")"

backupSwitchApplicationsBackward="$(gsettings get org.gnome.desktop.wm.keybindings "$keySwitchApplicationBackward")"
disableSwitchApplicationsBackward="$(gsettings get org.gnome.desktop.wm.keybindings "$keySwitchApplicationBackward" | sed "s/\,*\s*'<Shift><Alt>Tab'//")"

disabled="0"

while true; do
  isActive=$(wmctrl -lx | awk -v search=$(printf 0x0%x $(xdotool getactivewindow)) -v wm_class="$wm_class" '{ if($1 ~ search && $3 ~ /godot/) print $3 }')

  if [[ "$isActive" != "" ]]; then
    # echo "active"
    if [[ "$disabled" == "0" ]]; then
      # echo "disable shortcut"
      gsettings set org.gnome.desktop.wm.keybindings "$keySwitchApplication" "$disableSwitchApplications"
      gsettings set org.gnome.desktop.wm.keybindings "$keySwitchApplicationBackward" "$disableSwitchApplicationsBackward"
      disabled="1";
    fi
  else
    # echo "not active"
    if [[ "$disabled" == "1" ]]; then
      # echo "enable shortcut"
      gsettings set org.gnome.desktop.wm.keybindings "$keySwitchApplication" "$backupSwitchApplications"
      gsettings set org.gnome.desktop.wm.keybindings "$keySwitchApplicationBackward" "$backupSwitchApplicationsBackward"
      disabled="0"
    fi;
  fi;
  sleep 1
done

In fact just simply calling

gsettings set org.gnome.desktop.wm.keybindings switch-applications-backward "['']"

gsettings set org.gnome.desktop.wm.keybindings switch-applications "['']"

fails to disable Alt-Tabbing in Ubuntu 19.04.

  • Do you mean that Alt+Tab should be totally disabled when that application is running (or its window is in focus) or do you just want that application (or its windows) not to appear in the task switcher? – DK Bose Sep 10 '19 at 01:05
  • @DKBose: The former – user1770201 Sep 10 '19 at 01:06
  • If https://askubuntu.com/questions/638538/how-can-i-disable-alt-tab-application-switching-in-cinnamon-when-a-certain-progr?rq=1 meets your requirements, you can close the current question as a duplicate of the linked question. – DK Bose Sep 10 '19 at 03:55
  • @DKBose: That post is topical but for some reason the solution provided doesn't work on my machine. See my edited response above. – user1770201 Sep 12 '19 at 23:41

0 Answers0