1#!/usr/bin/env bash 2 3## 4# Script used to create a screenshot of rofi. 5# License: See rofi 6## 7RESET="\e[0m" 8COLOR_RED="\e[0;31m" 9 10THEME_FILE=$1 11shift 12 13OUTPUT_PNG=$1 14shift 15 16XVFB=$(which Xvfb 2> /dev/null) 17XDOTOOL=$(which xdotool 2> /dev/null) 18ROFI=$(which rofi 2> /dev/null) 19SCROT=$(which scrot 2> /dev/null) 20FEH=$(which feh 2> /dev/null) 21COMPTON=$(which compton 2> /dev/null) 22 23function check_tool() 24{ 25 if [ -z "${1}" ] 26 then 27 echo -e "${COLOR_RED}Failed to find:${RESET} $2" 28 exit 1 29 fi 30} 31 32XPID= 33function create_fake_x ( ) 34{ 35 export DISPLAY=":$1" 36 echo "Starting fake X: ${DISPLAY}" 37 ${XVFB} ${DISPLAY} -screen 0 1024x600x24& 38 XPID=$! 39 sleep 1 40} 41 42function destroy_fake_x ( ) 43{ 44 if [ -n "${XPID}" ] 45 then 46 echo "Stopping fake X: ${XPID}" 47 kill ${XPID} 48 wait ${XPID} 49 fi 50} 51 52function generate() 53{ 54 echo "Normal" 55 echo "Alternative" 56 echo "Urgent" 57 echo "Urgent alternative" 58 echo "Active" 59 echo "Active alternative" 60 echo "Normal selected" 61} 62 63# Check required tools 64check_tool "${XVFB}" "Xvfb (X on virtual framebuffer)" 65check_tool "${XDOTOOL}" "commandline X11 automation tool" 66check_tool "${ROFI}" "Rofi, the tool we are screenshotting" 67check_tool "${FEH}" "FEH, to set example background" 68check_tool "${SCROT}" "Tool to take screenshot" 69check_tool "${COMPTON}" "COMPTON, tool to do transparency" 70 71# Create random display number 72VDISPLAY=${RANDOM} 73let "VDISPLAY %= 20" 74VDISPLAY=$((VDISPLAY+100)) 75 76echo "Xvfb: ${XVFB}" 77echo "Xvfb Display: ${VDISPLAY}" 78 79ROFI_OPTIONS="-selected-row 6 -u 2,3 -a 4,5 -location 0 -width 100 -lines 7 -columns 1" 80 81export DISPLAY=${VDISPLAY} 82 83# Create fake X11 84create_fake_x ${VDISPLAY} 85sleep 1 86fluxbox & 87sleep 1; 88compton -b 89feh --bg-center background.jpg 90(generate | ${ROFI} -no-config -theme "${THEME_FILE}" -dmenu ${ROFI_OPTIONS} > /dev/null )& 91sleep 1 92#${XDOTOOL} key Alt+S 93scrot ${OUTPUT_PNG} 94${XDOTOOL} key Return 95sleep 2 96destroy_fake_x 97