Package: sensible-utils
Version: 0.0.10
Severity: wishlist
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

There is currently no sensible way to execute an X11 terminal emulator
in XEmbed mode.

Programs like claws-email, sylpheed, and recently introduced astroid,
supports spawning an editor by use of the XEmbed protocol.

Several X11 emulators support XEmbed, but unfortunately they use
different options to enable that mode.

Attached is a shell script that a) resolves which X11 terminal emulator
is currently called by x-terminal-emulator, b) resolves the option name
used by that particular emulator to enable XEmbed mode, and c) eecutes
x-terminal-emulator in XEmbed mode.

Please include this script as part of sensible-utils.

 - Jonas

P.S.

Specifically for email clients spawning an editor embedded would be yet
another script sensible-xembed-editor, which first resolves if an X11
editor is preferred and available - but let's address this more general
tool first.

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEn+Ppw2aRpp/1PMaELHwxRsGgASEFAlngu1kACgkQLHwxRsGg
ASEQcA//VIrI5AVfviTsVw0oBHeypvl08AjBOOSigUS3HgRNN1gw2iBn8uxEGuIC
R3TqdQeZd990VJIu3z4Yh13kcnZVbo1fD3FXMQiPUB853hS5wSH79KGFV0ztpMX6
k8jny4B/RsvjsN5jHGKIQfty/2pfB9gs+lHtAcUCxndVC3fJVBg3GKi4u7BorRme
2QWTnKyPi+IM3+VkGFsTlHgGGQKlvy184GvNmCKALsENLRnLoYTvJSAwBXe6C7ZD
0WBxb3Qht6lbJXWOE2iM7Thh+fPTE6bAXeDCBUOT9mu9Dl9xxixWdgdRHPki0j5B
RQ45ZGvVPmU6QvKgOEADy7vCApv6DQuMC01S7u0eJRXNqQHmEmCv80Or1ZifuZZm
TawObcTcLf+gpP+aCS66fJyc3rqHGVCcrlfbW0qABcgHo7a/sqyWm7Nsbce32t5X
G4Tx6MneqobUWY+4lt5USjYXPr+E6uy0V9xEN4G81iXBKusjpiPS89tNUh6lOc3g
wBJbQltTs/fvdtZaWj7ijMDB5ZAZMAApxOnWcay4vZhWJhpOUdy9sxCG45kHKB5+
uHvjaNpzJfJ0Ajd8R9RoKWeMNdmbjBqQW0ouDGXUsbMq1R+uEjIOJX3aEzWq3Ojy
JEyzD7rgKBSvtWtGwkGTeVintOv8KbMKvo0CQcC/NhEgvHQfFlw=
=zFe3
-----END PGP SIGNATURE-----
#!/bin/sh
# Copyright © 2017 Jonas Smedegaard <[email protected]>
# Description: execute x-terminal-emulator in XEmbed mode
#
# This program is free software;
# you can redistribute it and/or modify it
# under the terms of the GNU General Public License
# as published by the Free Software Foundation;
# either version 3, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
# TODO
#  * Support more X11 terminal emulators

set -eu

PRG=$(basename "$0")

showhelp() {
        cat <<EOF
Usage: $PRG --window ID [-- terminal-emulator-opts-and-args...]
Execute x-terminal-emulator in XEmbed mode

  --window      XEmbed window ID
  -h, --help    This help text
  --debug       Enable debugging output

Examples:
  $PRG --id 12345
  $PRG --id 12345 -- -e \$EDITOR foo.txt

Debugging is also enabled when environment variable DEBUG in non-empty.
EOF
}

exit1() {
        response="${1:+Error: }${1:-Internal error!}"
        echo >&2 "$response"
        exit 1
}

# set defaults
DEBUG=${DEBUG:-}
WINDOW=''

# parse cmdline options
TEMP=$(getopt -s sh -o h -l help,debug,window: -n "$PRG" -- "$@") \
        || exit1 "Internal getopt error."
eval set -- "$TEMP"
while true ; do
        case "$1" in
                -h|--help) showhelp; exit;;
                --debug) DEBUG=true; shift;;
                --window) WINDOW="$2"; shift 2;;
                --) shift; break;;
                *) exit1 "Internal error resolving options.";;
        esac
done

[ -n "$WINDOW" ] || exit1 "XEmbed window ID is missing"

# resolve basename of default X11 terminal emulator
_emulator_symlink=$(which x-terminal-emulator)
_emulator_path=$(realpath "$_emulator_symlink")
emulator=$(basename "$_emulator_path")

# resolve name of option to enable XEmbed mode of X11 terminal emulator
case "$emulator" in
        rxvt-unicode|urxvt|urxvtcd) embed_option="-embed";;
        stterm|st) embed_option="-w";;
        xterm) embed_option="-into";;
        *) exit1 "Unsupported X11 terminal emulator: $emulator";;
esac

[ -z "$DEBUG" ] || echo >&2 Debug: x-terminal-emulator "$embed_option" 
"$WINDOW" "$@"

exec x-terminal-emulator "$embed_option" "$WINDOW" "$@"

Reply via email to