zzrough / gs-extensions-drop-down-terminal

Drop Down Terminal extension for the Gnome Shell
https://extensions.gnome.org/extension/442/drop-down-terminal/
GNU General Public License v3.0
416 stars 91 forks source link

Keyboard shortcut should activate the terminal if unfocused but visible #241

Open thiagoa opened 4 years ago

thiagoa commented 4 years ago

Due to the principle of least surprise (in my opinion), if the terminal is unfocused but visible the default keyboard shortcut should simply activate it. To make it work like that in the meantime, I've unset the default keyboard shortcut and associated a custom keyboard shortcut through Gnome using the following bash script:

#!/bin/bash

is_open=$(wmctrl -l -x | grep 'Drop Down Terminal.DropDownTerminalWindow')
wm_id=$(xdotool getactivewindow)
wm_class=$(xprop -id "$wm_id" | grep WM_CLASS)
is_focused=$(echo $wm_class | grep DropDownTerminal)

function send_command {
  dbus-send --type=method_call \
            --dest=org.zzrough.GsExtensions.DropDownTerminal \
            /org/zzrough/GsExtensions/DropDownTerminal \
            org.zzrough.GsExtensions.DropDownTerminal.$1
}

if [[ ! -z "$is_open" ]] && [[ -z "$is_focused" ]]; then
  send_command Focus
else
  send_command Toggle
fi