Last active
September 22, 2016 09:44
-
-
Save marek-saji/90c34e47689cbef235fe76251706c7d0 to your computer and use it in GitHub Desktop.
Create a virtual screen and allow connecting to it via VNC
This file contains hidden or 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/sh | |
# | |
# Create a virtual screen and allow connecting to it via VNC | |
# | |
# Based on: | |
# - https://bbs.archlinux.org/viewtopic.php?id=191555 | |
# - https://bitbucket.org/denilsonsa/small_scripts/src/default/screenlayout/create-virtual-modelines.sh?fileviewer=file-view-default | |
# | |
# GistID: 90c34e47689cbef235fe76251706c7d0 | |
set -e | |
### | |
# Configure virtual screen with defined modeline | |
# | |
# $*: Modeline definition, passed to gtf(1) | |
add_modeline () | |
{ | |
local primaryoutput virtualoutput | |
local modeline name | |
primaryoutput="$( | |
xrandr | grep ' connected primary' | cut -d' ' -f1 | head -n1 | |
)" | |
if [ -z "${primaryoutput}" ] | |
then | |
echo "ERROR: Failed to determine primary output" | |
exit 1 | |
fi | |
virtualoutput="$( | |
xrandr | grep 'VIRTUAL' | cut -d' ' -f1 | head -n1 | |
)" | |
if [ -z "${virtualoutput}" ] | |
then | |
echo "ERROR: Failed to determine virtual output" | |
exit 1 | |
fi | |
modeline="$( | |
gtf "$@" | sed -n 's/.*Modeline "\([^" ]\+\)" \(.*\)/\1 \2/p' | |
)" | |
if [ -z "${modeline}" ] | |
then | |
echo "ERROR: Failed to calculate modeline: $*" | |
exit 1 | |
fi | |
name="$( | |
echo "${modeline}" | sed 's/\([^ ]\+\) .*/\1/' | |
)" | |
if [ -z "${name}" ] | |
then | |
echo "ERROR: Failed to get name from modeline: ${modeline}" | |
exit 1 | |
fi | |
xrandr \ | |
--output "${virtualoutput}" --off \ | |
--output "${primaryoutput}" --auto | |
xrandr --delmode "${virtualoutput}" "${name}" || : | |
xrandr --rmmode "${name}" || : | |
# shellcheck disable=SC2086 | |
xrandr --newmode ${modeline} | |
xrandr --addmode "${virtualoutput}" "${name}" | |
xrandr \ | |
--output "${virtualoutput}" \ | |
--mode "${name}" \ | |
--right-of "${primaryoutput}" | |
} | |
# iPad Air 2 is 2048×1536 | |
add_modeline 1024 768 60 | |
x11vnc -clip xinerama1 -forever -noxdamage -repeat | |
# TODO Clean up on Ctrl-C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment