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" 9COLOR_YELLOW="\e[0;33m" 10 11XRDB_FILE=$1 12shift 13 14OUTPUT_PNG=$1 15shift 16 17XVFB=$(which Xvfb 2> /dev/null) 18XDOTOOL=$(which xdotool 2> /dev/null) 19XRDB=$(which xrdb 2> /dev/null) 20ROFI=$(which rofi 2> /dev/null) 21 22function check_tool() 23{ 24 if [ -z "${1}" ] 25 then 26 echo -e "${COLOR_RED}Failed to find:${RESET} $2" 27 exit 1 28 fi 29} 30 31XPID= 32function create_fake_x ( ) 33{ 34 export DISPLAY=":$1" 35 echo "Starting fake X: ${DISPLAY}" 36 ${XVFB} ${DISPLAY} -screen 0 800x600x24 & 37 XPID=$! 38 sleep 1 39} 40 41function destroy_fake_x ( ) 42{ 43 if [ -n "${XPID}" ] 44 then 45 echo "Stopping fake X: ${XPID}" 46 kill ${XPID} 47 wait ${XPID} 48 fi 49} 50 51function generate() 52{ 53 echo "Normal" 54 echo "Alternative" 55 echo "Urgent" 56 echo "Urgent alternative" 57 echo "Active" 58 echo "Active alternative" 59 echo "Normal selected" 60} 61 62# Check required tools 63check_tool "${XVFB}" "Xvfb (X on virtual framebuffer)" 64check_tool "${XDOTOOL}" "commandline X11 automation tool" 65check_tool "${XRDB}" "X server resource database utility" 66check_tool "${ROFI}" "Rofi, the tool we are screenshotting" 67 68# Create random display number 69VDISPLAY=${RANDOM} 70let "VDISPLAY %= 20" 71VDISPLAY=$((VDISPLAY+100)) 72 73echo "Xvfb: ${XVFB}" 74echo "Xresources: ${XRDB_FILE}" 75echo "Xvfb Display: ${VDISPLAY}" 76 77ROFI_OPTIONS="-selected-row 6 -u 2,3 -a 4,5 -location 0 -width 100 -lines 7 -columns 1" 78 79export DISPLAY=${VDISPLAY} 80 81if [ -n "${OUTPUT_PNG}" ] 82then 83 export ROFI_PNG_OUTPUT="${OUTPUT_PNG}" 84fi 85 86# Create fake X11 87create_fake_x ${VDISPLAY} 88 89# Load Xresources if specified. 90if [ -n "${XRDB_FILE}" ] 91then 92 echo -e "${COLOR_YELLOW}Loading Xresources:${RESET} ${XRDB_FILE}" 93 ${XRDB} -retain -load ${XRDB_FILE} 94fi 95 96(generate | ${ROFI} -config "${XRDB_FILE}" -dmenu ${ROFI_OPTIONS} > /dev/null )& 97sleep 1 98${XDOTOOL} key Alt+S 99${XDOTOOL} key Return 100sleep 2 101destroy_fake_x 102