summaryrefslogtreecommitdiffstats
path: root/script
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2015-12-10 17:55:00 +0100
committerDave Davenport <qball@gmpclient.org>2015-12-10 17:55:00 +0100
commitad77b9857a8df9cd20fc3101c7590b7322d62961 (patch)
tree9a70b31b2216d14edc1caa3ee560c2ddf35c7e92 /script
parent61738f881f4f236dc93f5202b8b74923a35c6ae1 (diff)
Add script that can create screenshot for Xresources 'theme' for webpage.
Diffstat (limited to 'script')
-rwxr-xr-xscript/rofi-create-screenshot.sh97
1 files changed, 97 insertions, 0 deletions
diff --git a/script/rofi-create-screenshot.sh b/script/rofi-create-screenshot.sh
new file mode 100755
index 00000000..0e6042bf
--- /dev/null
+++ b/script/rofi-create-screenshot.sh
@@ -0,0 +1,97 @@
+#!/usr/bin/env bash
+
+##
+# Script used to create a screenshot of rofi.
+# License: See rofi
+##
+RESET="\e[0m"
+BOLD="\e[1m"
+COLOR_BLACK="\e[0;30m"
+COLOR_RED="\e[0;31m"
+COLOR_GREEN="\e[0;32m"
+COLOR_YELLOW="\e[0;33m"
+COLOR_BLUE="\e[0;34m"
+
+XRDB_FILE=$1
+shift
+
+XVFB=$(which Xvfb 2> /dev/null)
+XDOTOOL=$(which xdotool 2> /dev/null)
+XRDB=$(which xrdb 2> /dev/null)
+ROFI=$(which rofi 2> /dev/null)
+
+function check_tool()
+{
+ if [ -z "${1}" ]
+ then
+ echo -e "${COLOR_RED}Failed to find:${RESET} $2"
+ exit 1
+ fi
+}
+
+XPID=
+function create_fake_x ( )
+{
+ export DISPLAY=":$1"
+ echo "Starting fake X: ${DISPLAY}"
+ ${XVFB} ${DISPLAY} -screen 0 1024x768x24 &
+ XPID=$!
+ sleep 1
+}
+
+function destroy_fake_x ( )
+{
+ if [ -n "${XPID}" ]
+ then
+ echo "Stopping fake X: ${XPID}"
+ kill ${XPID}
+ wait ${XPID}
+ fi
+}
+
+function generate()
+{
+ 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}"
+
+ROFI_OPTIONS="-selected-row 6 -u 2,3 -a 4,5"
+
+export DISPLAY=${VDISPLAY}
+
+# Create fake X11
+create_fake_x ${VDISPLAY}
+
+# Load Xresources if specified.
+if [ -n "${XRDB_FILE}" ]
+then
+ echo -e "${COLOR_YELLOW}Loading Xresources:${RESET} ${XRDB_FILE}"
+ ${XRDB} -retain -load ${XRDB_FILE}
+fi
+
+(generate | ${ROFI} -dmenu ${ROFI_OPTIONS} > /dev/null )&
+sleep 1
+${XDOTOOL} key Alt+S
+${XDOTOOL} key Return
+sleep 2
+destroy_fake_x