Disable key when program is running
Solution 1:
Simple Solution
Create two shortcuts, one for disabling the Super key, and one for restoring it at will.
Go to System Settings -> Keyboard -> Shortcuts -> Custom , and click + button. Name the new shortcut "Disable Dash". The command is
gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ show-launcher 'Disabled'
To create shortcut for re-enabling the script, repeat the above steps, but the command should be
gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ show-launcher '<Super>'
A Scripting Solution
The script bellow will disable the Super key when program that the user has specified has focus. Note that the user still is able to click the dash icon with the mouse to invoke the Dash. The program name must be single-quoted and exactly the same as appears in Unity Launcher. Multiple windows can be specified in the same format separated by space
For instance, to disable Super key every time firefox window has focus, the script must be called as
disable_super_key.sh 'Firefox Web Browser'
To disable both firefox
and gnome-terminal
do
disable_super_key.sh 'Firefox Web Browser' 'Terminal'
How to get the script
Users can either copy the source here or alternatively obtain it from github following the instructions bellow:
sudo apt-get install git
cd /opt ; sudo git clone https://github.com/SergKolo/sergrep.git
sudo chmod -R +x sergrep
The script will be located in /opt/sergrep/disable_super_key.sh
To make the script start automatically on every login, refer to How do I start applications automatically on login? . Provide /opt/sergrep/disable_super_key.sh
(full path) as the command
Script Source
#!/usr/bin/env bash
#
###########################################################
# Author: Serg Kolo , contact: [email protected]
# Date: April 12 , 2016
# Purpose: Disable super key that brings up Unity Dash
# per specific application
#
# Written for: https://askubuntu.com/q/754884/295286
# Tested on: Ubuntu 14.04 LTS
###########################################################
# Copyright: Serg Kolo , 2016
#
# Permission to use, copy, modify, and distribute this software is hereby granted
# without fee, provided that the copyright notice above and this permission statement
# appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
ARGV0="$0"
ARGC=$#
enable_dash_key()
{
gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ show-launcher '<Super>'
}
disable_dash_key()
{
gsettings set org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ show-launcher 'Disabled'
}
get_active_app()
{
qdbus org.ayatana.bamf \
/org/ayatana/bamf/matcher \
org.ayatana.bamf.matcher.ActiveApplication
}
get_active_app_name()
{
qdbus org.ayatana.bamf \
$(get_active_app) \
org.ayatana.bamf.view.Name
}
check_active_app()
{
active_name=$(get_active_app_name)
local is_found
for win in "${windows_list[@]}"
do
if [ "$active_name" = "$win" ] ; then
is_found=true
break
else
is_found=false
fi
done
if $is_found ; then
disable_dash_key
else
enable_dash_key
fi
}
print_usage()
{
cat << EOF
Copyright Serg Kolo , 2016
Usage: disable_super_key.sh 'App Name 1' [ 'App Name 2' 'App Name 3' ... ]
The script disables the Super key for the specified set of applications
under Ubuntu's Unity environment. The list of windows must be space
separated, each app name single quoted and exactly as it appears on the
launcher (or as it appears in the .desktop file of that app), so spelling
and spacing matter.
Note that the script only disables the Super key as shortcut for Dash.
The user still will be able to invoke Dash by manually clicking on the
Ubuntu icon in the launcher
EOF
}
main()
{
if [ $ARGC -eq 0 ]; then
print_usage
exit
fi
local windows_list
windows_list=( "$@" )
dbus-monitor --profile "type='signal',member='FocusedWindowChanged'" |\
while read line
do
case "$line" in
*FocusedWindowChanged*) check_active_app ;;
esac
done
}
main "$@"