#!/bin/sh
#] 
#] *********************
#] $ bash "$d_bin"'image: combine image streams via shutter screen capture.sh' 
# www.BillHowell.ca  04Aug2024 initial 
# view in text editor, using constant-width font (eg courier), tabWidth = 3


#24************************24




#24************************24
# List of operators, generated with :
# $ grep  "^#]"  "$d_bin"'image: combine image streams via shutter screen capture.sh' |  sed "s/^#\]/  /" 

#




#08********08
# Setup 

source  "$d_bin""standard header.sh"
source  "$d_bin""fileops.sh"

# webSearch "Linux and how do I capture a screen area with a bash command?"
# see "$d_SysMaint"'images/0_image notes.txt'


#08********08
# code 

#  shutter_it()  - 
# 04Aug2024 must generalise in future, now tied to nullSchool.net work

	shutter_it()
{
	d_work="$d_web"'My sports & clubs/natural- Suspicious/images/'
	d_imgSeq1="$d_work"'240804 July N hemisphere/'
	d_imgSeq2="$d_work"'240804 July S hemisphere/'
	d_imgSeqR="$d_work"'240804 July N and S hemispheres/'

	p_imgLst1="$d_temp"'0_imageSequence list1.txt'
	p_imgLst2="$d_temp"'0_imageSequence list2.txt'
	p_winIDlst="$d_temp"'shutter_it winLst.txt'

	find  "$d_imgSeq1"  -type f  -name  "*.png"  |  sort -u  >"$p_imgLst1"
	find  "$d_imgSeq2"  -type f  -name  "*.png"  |  sort -u  >"$p_imgLst2"

	# images must already have been [open, position]ed!!!  complicated by same fnames
	# get image window IDs
	wmctrl -l  |  grep  -i  '240701.png'  |   sed  's|\(^[0-9abcdefx]*\).*|\1|'  >"$p_winIDlst"
	exec 7<"$p_winIDlst"
	read -u 7 winIDimage1
	read -u 7 winIDimage2
		echo "winIDimage[1, 2]= $winIDimage1  $winIDimage2"

	# make sure windows are top on screen!!
	xdotool  windowactivate "$winIDimage1"
	xdotool  windowactivate "$winIDimage2"

#	Multiple file reads (roster database-like) :
	exec 8<"$p_imgLst2"
	while read -u 9 p_image1; do
		read -u 8 p_image2

		# check that fnames are consistent, if so shutter screen capture
		fname1=$( pth_get_fnam "$p_image1" )
		fname2=$( pth_get_fnam "$p_image2" )
		if  [ "$fname1" == "$fname2" ]; then 
			echo "fname1 = $fname1"
			# capture combined image 
			#shutter  --select=[3,475,1150,520]  --output="$d_imgSeqR$fname1"
			shutter  --select=3,475,1150,520  --exit_after_capture  --output="$d_imgSeqR$fname1"

			# using ImageMagik :
			#import -window root -resize 400x300 -delay 200 screenshot.png

			# advance each window to next image in sequence
			xdotool  windowactivate "$winIDimage1"; sleep 1s; xdotool  key  0xff53; sleep 1s  
			xdotool  windowactivate "$winIDimage2"; sleep 1s; xdotool  key  0xff53; sleep 1s  
		else
			echo 'fname1 != fname2: '
			echo "   fname1 = $fname1"
			echo "   fname2 = $fname2"
			echo ''
		fi

	done 9< "$p_imgLst1" 
}  

# test
#	13:04$ xdotool  --window  0x05e00007  key  right  
#	(symbol) No such key name 'right'. Ignoring it.
#	(symbol) No such key name 'right'. Ignoring it.
#	~
#	13:13$ xdotool  --window  0x05e00007  key  right
#	xdotool: unrecognized option '--window'
#	Usage: xdotool <cmd> <args>
#	~
#	13:14$ xdotool  key  right  0x05e00007  
#	(symbol) No such key name 'right'. Ignoring it.
#	(symbol) No such key name 'right'. Ignoring it.
#	~
#	13:24$ xdotool  windowactivate 0x05e00007;  xdotool  key  0xff53 
#	~
#	>> yes, WORKED!!






#08********08
# Procedures -  To run :

# 1.	first, open all image windows that will be screen captured 
#		xviewer is my standard app
#		must get window ID : $ wmctrl -l  | grep  -i  '.png'  

#
# 2.	tighten images in each window, example 04Aug2024
#		10:39$ xdotool getmouselocation
#		x:3 y:483 screen:0 window:98566151
#		~
#		10:42$ xdotool getmouselocation
#		x:1137 y:993 screen:0 window:98566380
#		~
#		$ shutter  --select=[3,475,1150,520]  --output="$d_web"'My sports & clubs/
#							natural- Suspicious/images/240804 July N and S hemispheres/240701.png'
#		>> oops - forgot to re-size window
#		>>> retry : OK WORKS!!
#		I don't want the resulting image to pop up at the end
#				$ shutter  --select=[3,475,1150,520]  --exit_after_capture  -
#					-output="$d_web"'My sports & clubs/natural- Suspicious/images/
#										240804 July N and S hemispheres/240701.png'
#		>> PERFECT!  also avoids garbage messages and program "hangs suspended"
#





#08********08
# run - select one of options

	shutter_it





# $ bash  "$d_bin"'image: combine image streams via shutter screen capture.sh'  

# enddoc
