2015-12-10 16:55:00 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
##
|
|
|
|
# Script used to create a screenshot of rofi.
|
|
|
|
# License: See rofi
|
|
|
|
##
|
|
|
|
RESET="\e[0m"
|
|
|
|
COLOR_RED="\e[0;31m"
|
|
|
|
COLOR_YELLOW="\e[0;33m"
|
|
|
|
|
|
|
|
XRDB_FILE=$1
|
|
|
|
shift
|
|
|
|
|
2015-12-10 19:57:43 +00:00
|
|
|
OUTPUT_PNG=$1
|
|
|
|
shift
|
|
|
|
|
2021-08-14 11:03:16 +00:00
|
|
|
XVFB=$(which Xvfb 2>/dev/null)
|
|
|
|
XDOTOOL=$(which xdotool 2>/dev/null)
|
|
|
|
XRDB=$(which xrdb 2>/dev/null)
|
|
|
|
ROFI=$(which rofi 2>/dev/null)
|
2015-12-10 16:55:00 +00:00
|
|
|
|
2021-08-14 11:03:16 +00:00
|
|
|
check_tool()
|
2015-12-10 16:55:00 +00:00
|
|
|
{
|
|
|
|
if [ -z "${1}" ]
|
|
|
|
then
|
|
|
|
echo -e "${COLOR_RED}Failed to find:${RESET} $2"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
XPID=
|
2021-08-14 11:03:16 +00:00
|
|
|
create_fake_x()
|
2015-12-10 16:55:00 +00:00
|
|
|
{
|
|
|
|
export DISPLAY=":$1"
|
|
|
|
echo "Starting fake X: ${DISPLAY}"
|
2021-08-14 11:03:16 +00:00
|
|
|
${XVFB} "${DISPLAY}" -screen 0 800x600x24 &
|
2015-12-10 16:55:00 +00:00
|
|
|
XPID=$!
|
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
|
2021-08-14 11:03:16 +00:00
|
|
|
destroy_fake_x()
|
2015-12-10 16:55:00 +00:00
|
|
|
{
|
|
|
|
if [ -n "${XPID}" ]
|
|
|
|
then
|
|
|
|
echo "Stopping fake X: ${XPID}"
|
2021-08-14 11:03:16 +00:00
|
|
|
kill "${XPID}"
|
|
|
|
wait "${XPID}"
|
2015-12-10 16:55:00 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-08-14 11:03:16 +00:00
|
|
|
generate()
|
2015-12-10 16:55:00 +00:00
|
|
|
{
|
|
|
|
echo "Normal"
|
|
|
|
echo "Alternative"
|
|
|
|
echo "Urgent"
|
|
|
|
echo "Urgent alternative"
|
|
|
|
echo "Active"
|
|
|
|
echo "Active alternative"
|
|
|
|
echo "Normal selected"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check required tools
|
|
|
|
check_tool "${XVFB}" "Xvfb (X on virtual framebuffer)"
|
|
|
|
check_tool "${XDOTOOL}" "commandline X11 automation tool"
|
|
|
|
check_tool "${XRDB}" "X server resource database utility"
|
|
|
|
check_tool "${ROFI}" "Rofi, the tool we are screenshotting"
|
|
|
|
|
|
|
|
# Create random display number
|
|
|
|
VDISPLAY=${RANDOM}
|
|
|
|
let "VDISPLAY %= 20"
|
|
|
|
VDISPLAY=$((VDISPLAY+100))
|
|
|
|
|
|
|
|
echo "Xvfb: ${XVFB}"
|
|
|
|
echo "Xresources: ${XRDB_FILE}"
|
|
|
|
echo "Xvfb Display: ${VDISPLAY}"
|
|
|
|
|
2015-12-10 17:04:53 +00:00
|
|
|
ROFI_OPTIONS="-selected-row 6 -u 2,3 -a 4,5 -location 0 -width 100 -lines 7 -columns 1"
|
2015-12-10 16:55:00 +00:00
|
|
|
|
|
|
|
export DISPLAY=${VDISPLAY}
|
|
|
|
|
2015-12-10 19:57:43 +00:00
|
|
|
if [ -n "${OUTPUT_PNG}" ]
|
|
|
|
then
|
|
|
|
export ROFI_PNG_OUTPUT="${OUTPUT_PNG}"
|
|
|
|
fi
|
|
|
|
|
2015-12-10 16:55:00 +00:00
|
|
|
# Create fake X11
|
2021-08-14 11:03:16 +00:00
|
|
|
create_fake_x "${VDISPLAY}"
|
2015-12-10 16:55:00 +00:00
|
|
|
|
|
|
|
# Load Xresources if specified.
|
|
|
|
if [ -n "${XRDB_FILE}" ]
|
|
|
|
then
|
|
|
|
echo -e "${COLOR_YELLOW}Loading Xresources:${RESET} ${XRDB_FILE}"
|
2021-08-14 11:03:16 +00:00
|
|
|
${XRDB} -retain -load "${XRDB_FILE}"
|
2015-12-10 16:55:00 +00:00
|
|
|
fi
|
|
|
|
|
2016-11-12 18:34:10 +00:00
|
|
|
(generate | ${ROFI} -config "${XRDB_FILE}" -dmenu ${ROFI_OPTIONS} > /dev/null )&
|
2015-12-10 16:55:00 +00:00
|
|
|
sleep 1
|
|
|
|
${XDOTOOL} key Alt+S
|
|
|
|
${XDOTOOL} key Return
|
|
|
|
sleep 2
|
|
|
|
destroy_fake_x
|