I am trying to convert firefox-ctrl-q-workaround to also handle Ctrl-Shift-C. This is because I keep using Ctrl-Shift-C in Firefox by mistake and popping open Developer Tools all the time is getting tedious. Firefox, incredibly annoyingly, does not have any way of configuring shortcuts.
The setup looks broadly like this:
First, bind the key in i3 to a script:
# i3 config
bindsym --release Control+Shift+c exec --no-startup-id ~/ctrl_c_map.sh
And the script itself looks like:
# This is the active window
W="$(xdotool getactivewindow)"
# Get window class
WM_CLASS="$(xprop -id "$W" | awk -F '"' '/WM_CLASS/{print $4}')"
# Succeed if the WM_CLASS is firefox
is_firefox() {
[ "$WM_CLASS" == "firefox" ] || [ "$WM_CLASS" == "Firefox Developer Edition" ]
}
send_key() {
keytosend=$1
xdotool key --clearmodifiers --window "$W" "$keytosend"
}
if is_firefox; then
# remap to copy (Ctrl+C)
send_key ctrl+c
else
# re-send original C-S-c as it was actually useful
send_key ctrl+shift+c
fi
This works in Firefox - the Ctrl-Shift-C event is caught and remapped to a Ctrl-C, and any selected text is copied. Horray!
However, in any other program (specifically in a terminal where Ctrl-Shift-C is genuinely useful), there's a problem. When the ctrl+shift+c
key is sent using xdotool
, i3 catches it again and fires the script again, landing us in an infinite loop that you can only escape by mashing Ctrl/Shift. Moreover, the target window never gets its Ctrl-Shift-C key: it's endlessly circulating between i3 and bash, but never actually arriving.
How can you send the same bound key from within an i3 bindsym
-triggered script without a infinite loop?
Perhaps you could restrict the match on Control+Shift+c
by using criteria which matches just firefox, something like
bindsym Control+Shift+c [class="Firefox"] exec xdotool key --clearmodifiers ctrl+c