From 266acb80cfe2a53af1f57dcdaba25a528d7922bb Mon Sep 17 00:00:00 2001 From: probonopd Date: Wed, 9 Aug 2017 15:33:01 +0200 Subject: [PATCH] Update worker.sh --- code/worker.sh | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/code/worker.sh b/code/worker.sh index 7062e353..bf7c4105 100644 --- a/code/worker.sh +++ b/code/worker.sh @@ -111,22 +111,26 @@ if [ "$TERMINAL" == "false" ] ; then # Get a list of open windows xwininfo -tree -root echo "===" - xwininfo -tree -root | grep 0x | grep '": ("' + xwininfo -tree -root | grep 0x | grep '": ("' | sed -e 's/^[[:space:]]*//' - # xpra screenshot database/$INPUTBASENAME/screenshot # does not produce a screenshot; FIXME - - # results in grey screenshot - # screenshot is empty and has not been saved (maybe there are no windows or they are not currently shown) - # import -window root database/$INPUTBASENAME/screenshot.jpg # ImageMagick - - # results in grey screenshot, too - sudo apt-get -y install scrot - scrot -b 'screenshot_$wx$h.jpg' # -u gives "X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)" - mv screenshot_* database/$INPUTBASENAME/ + # Count the windows on screen + NUMBER_OF_WINDOWS=$(wc -l $(xwininfo -tree -root | grep 0x | grep '": ("' | sed -e 's/^[[:space:]]*//')) + echo "NUMBER_OF_WINDOWS: $NUMBER_OF_WINDOWS" + if [ NUMBER_OF_WINDOWS -lt 1 ] ; then + echo "ERROR: Could not find a single window on screen :-(" + fi + + # Works with Xvfb but cannot select window by ID + # sudo apt-get -y install scrot + # scrot -b 'screenshot_$wx$h.jpg' # -u gives "X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)" + # mv screenshot_* database/$INPUTBASENAME/ # Works with Xvfb - # sudo apt-get -y install x11-apps netpbm - # xwd -root -silent -display :99.0 | xwdtopnm | pnmtojpeg > database/$INPUTBASENAME/screenshot.jpg && cat database/$INPUTBASENAME/screenshot.jpg + sudo apt-get -y install x11-apps netpbm xdotool + xwd -id $(xdotool getactivewindow) -silent -display :0 | xwdtopnm | pnmtojpeg > database/$INPUTBASENAME/screenshot.jpg && echo "Snap!" + + # We could simulate X11 keyboard/mouse input with xdotool here if needed + else echo "TODO: Make a screenshot of a terminal application" fi