Created
November 2, 2018 13:50
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# ARG_HELP([Configure a mobile device as an external screen:]) | |
# ARG_POSITIONAL_SINGLE([width],[Width of the external screen]) | |
# ARG_POSITIONAL_SINGLE([height],[Height of the external screen]) | |
# ARG_POSITIONAL_SINGLE([position],[Position of the external screen: top, right, bottom, or left],[position - right]) | |
# ARGBASH_GO() | |
# needed because of Argbash --> m4_ignore([ | |
### START OF CODE GENERATED BY Argbash v2.6.1 one line above ### | |
# Argbash is a bash code generator used to get arguments parsing right. | |
# Argbash is FREE SOFTWARE, see https://argbash.io for more info | |
# Generated online by https://argbash.io/generate | |
die() | |
{ | |
local _ret=$2 | |
test -n "$_ret" || _ret=1 | |
test "$_PRINT_HELP" = yes && print_help >&2 | |
echo "$1" >&2 | |
exit ${_ret} | |
} | |
begins_with_short_option() | |
{ | |
local first_option all_short_options | |
all_short_options='h' | |
first_option="${1:0:1}" | |
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0 | |
} | |
# THE DEFAULTS INITIALIZATION - POSITIONALS | |
_positionals=() | |
_arg_position="position - right" | |
# THE DEFAULTS INITIALIZATION - OPTIONALS | |
print_help () | |
{ | |
printf '%s\n' "Configure a mobile device as an external screen:" | |
printf 'Usage: %s [-h|--help] <width> <height> [<position>]\n' "$0" | |
printf '\t%s\n' "<width>: Width of the external screen" | |
printf '\t%s\n' "<height>: Height of the external screen" | |
printf '\t%s\n' "<position>: Position of the external screen: top, right, bottom, or left (default: 'position - right')" | |
printf '\t%s\n' "-h,--help: Prints help" | |
} | |
parse_commandline () | |
{ | |
while test $# -gt 0 | |
do | |
_key="$1" | |
case "$_key" in | |
-h|--help) | |
print_help | |
exit 0 | |
;; | |
-h*) | |
print_help | |
exit 0 | |
;; | |
*) | |
_positionals+=("$1") | |
;; | |
esac | |
shift | |
done | |
} | |
handle_passed_args_count () | |
{ | |
_required_args_string="'width' and 'height'" | |
test ${#_positionals[@]} -ge 2 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require between 2 and 3 (namely: $_required_args_string), but got only ${#_positionals[@]}." 1 | |
test ${#_positionals[@]} -le 3 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect between 2 and 3 (namely: $_required_args_string), but got ${#_positionals[@]} (the last one was: '${_positionals[*]: -1}')." 1 | |
} | |
assign_positional_args () | |
{ | |
_positional_names=('_arg_width' '_arg_height' '_arg_position' ) | |
for (( ii = 0; ii < ${#_positionals[@]}; ii++)) | |
do | |
eval "${_positional_names[ii]}=\${_positionals[ii]}" || die "Error during argument parsing, possibly an Argbash bug." 1 | |
done | |
} | |
parse_commandline "$@" | |
handle_passed_args_count | |
assign_positional_args | |
# OTHER STUFF GENERATED BY Argbash | |
### END OF CODE GENERATED BY Argbash (sortof) ### ]) | |
# [ <-- needed because of Argbash | |
mn="$1" | |
mw=1080 | |
mh=1920 | |
# Device | |
ds=2 # Scale | |
dw=`echo "1440 / ${ds}" | bc` | |
dh=`echo "2960 / ${ds}" | bc` | |
th=`echo "${dh}" | bc` | |
tw=`echo "$mw + $dw" | bc` | |
ms="${mw}x${mh}" # Main screen | |
ds="${dw}x${dh}" # Device screen | |
ts="${tw}x${mh}" # Total screen | |
offset=`echo "$mw + 1" | bc` | |
xrandr --fb $ts --output $mn --panning "${ts}+0+0/${ts}+0+0" | |
sleep 3 | |
echo "${ms} + ${ds} = ${ts}" | |
xrandr --fb $ts --output $mn --panning "${ms}+0+0/${ts}+0+0" | |
x11vnc -clip "${ms}+${offset}+0" -nocursorshape -nocursorpos | |
# ] <-- needed because of Argbash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment