当某个程序打开时,如何禁用 Cinnamon 中的 Alt-Tab 应用程序切换?

当某个程序打开时,如何禁用 Cinnamon 中的 Alt-Tab 应用程序切换?

我使用 emacs 并在某些模式下将填充命令设置为Alt- ,Tab并且作为习惯的产物,我想保持这种状态。

有没有一种简单的方法可以在 emacs 打开时通过Alt-禁用应用程序切换?Tab

答案1

我有一个解决方案。您需要做的就是启动此观察程序脚本:

#!/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 ~ /emacs/) 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

脚本无限循环检查窗口类emacs并禁用/启用Alt+TabShift+ Alt+Tab


如果出现任何问题,您可以将条目重置为默认设置:

gsettings reset org.gnome.desktop.wm.keybindings switch-applications
gsettings reset org.gnome.desktop.wm.keybindings switch-applications-backward

就我而言:

% gsettings reset org.gnome.desktop.wm.keybindings switch-applications  
% gsettings get org.gnome.desktop.wm.keybindings switch-applications   
['<Super>Tab', '<Alt>Tab']

% gsettings reset org.gnome.desktop.wm.keybindings switch-applications-backward
% gsettings get org.gnome.desktop.wm.keybindings switch-applications-backward  
['<Shift><Super>Tab', '<Shift><Alt>Tab']

致谢

@Serg和他的回答如何在终端中禁用输入语言切换
@JacobVlijm感谢他的评论

答案2

我想到了一个丑陋的黑客方式......

键盘设置应存储在:~/.config/dconf/user 因此,如果您有两个文件,一个Alt+Tab是系统范围启用的,另一个Alt+Tab是全局禁用的,那么理论上您可以交换它们。

简单的脚本将会:

  1. 备份Alt+Tab Enabled
  2. 复制Disabled Alt+TabEnabled Alt+Tab
  3. 运行 Emacs
  4. Emacs 关闭后,将文件复制回原处

该脚本将用于打开/运行 Emacs

我不知道它是否会起作用,为了安全起见,我会先在 VB 中尝试它,但现在不幸的是我没有时间尝试......

相关内容