You are not logged in.

#141 2025-01-28 09:38:20

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,550
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

add a splash at startup - requires the icon to look nice! (splashes there now only show if over 250 images or if multi monitors are present)

The splash looks nice, but appears even with a small number of wallpapers, in which case I'm just waiting for it to go away. Add a minimum number of images before showing the splash? Would counting the files take too long?

EDIT: or else have the splash close itself when the main window is ready?

---
BTW these daily upgrades are great, but if you think a moment, present a moving target to people who want to try it out. It's going to be "let's wait till it settles down" for some people.

Last edited by johnraff (2025-01-29 04:07:43)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#142 2025-01-28 10:05:32

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

fill is it then, both X and W.

Edited https://forums.bunsenlabs.org/viewtopic … 98#p140898 accordingly.


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#143 2025-01-31 08:08:52

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

johnraff wrote:

add a splash at startup - requires the icon to look nice! (splashes there now only show if over 250 images or if multi monitors are present)

The splash looks nice, but appears even with a small number of wallpapers, in which case I'm just waiting for it to go away. Add a minimum number of images before showing the splash? Would counting the files take too long?

EDIT: or else have the splash close itself when the main window is ready?

The EDIT idea is best, using a file monitor. I'll do that.

johnraff wrote:

BTW these daily upgrades are great, but if you think a moment, present a moving target to people who want to try it out. It's going to be "let's wait till it settles down" for some people.

Of course, but this is a devel thread and so far there are only 4 known testers (yourself, myself , @S11 and @ceeslans) smile


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#144 2025-01-31 08:51:56

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,550
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

^Yes, understood, and please carry on pushing out improvements as fast as they occur to you. cool

Just, please don't feel you're being ignored if you don't always get quick feedback.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#145 2025-01-31 10:05:43

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

johnraff wrote:

^Yes, understood, and please carry on pushing out improvements as fast as they occur to you. cool

Yes I have sporadic time constraints as we all often do IRL and other stuff cool

johnraff wrote:

Just, please don't feel you're being ignored if you don't always get quick feedback.

Never at all. I'm not looking for anything but the best this program can be and even the most minor comments, like your EDIT above whipped me into a brainstorm mode. big_smile

GTK has a 'realize' signal that fires off as soon as a window pops on screen. That is the perfect way to to close the 'greeting" It doesn't need much code at all. Just added a file monitor to _greeting, fire off a change to the monitored file when the main_gui is "realize'd" and close the _greeting. It all sounds too easy but it works perfectly. So without further ado the next iter is below.

#!/bin/bash

export V=0.1.3beta
export GTK3DIALOG
export MAINGUI
[[ -z "$GTK3DIALOG" ]] && GTK3DIALOG=gtk3dialog
export BGDIR="${BGDIR:-$HOME/Pictures/wallpapers}"
export PROG=${0##*\/}
export TEMP=/tmp/$PROG
#export TEMP=$HOME/tmp/$PROG # for testing
rm -rf "$TEMP" # incase of a crash because of "Argument list too long"
mkdir -p "$TEMP"
export CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}/$PROG"
mkdir -p "$CONFDIR"
export CONF="$CONFDIR/$PROG.conf"
if [[ ! -f "$CONF" ]];then
	echo "BGDIR=$BGDIR" > "$CONF"
fi
. "$CONF"

wlr-randr >/dev/null 2>&1 && export WAYLAND=yes

case "$1" in
	--restore)
	PROFILE="$2"
	echo $PROFILE
	if [[ -n "$PROFILE" && -r "$CONFDIR/$PROFILE/cmd" ]]; then
		. "$CONFDIR/$PROFILE/cmd" && exit 0
	elif [[ -n "$PROFILE" &&  -x "$CONFDIR/$PROFILE/.fehbg" ]]; then
		exec "$CONFDIR/$PROFILE/.fehbg"
	fi
	if [[ -f "$CONFDIR/cmd" && "$WAYLAND" == 'yes' ]]; then
		. "$CONFDIR/cmd" && exit 0
	elif [[ -x "$HOME/.fehbg" ]]; then
		exec "$HOME/.fehbg"
	else
		exit 1
	fi
	;;
	-d|--delconf)
		rm -f "$CONF"
		exit 0
	;;
	-*v|-*version)
	echo -e "\t$PROG $V\n\t\tGPL-2.0+ licence\n"
	exit 0
	;;
	-*h|-*help)
	echo -e "\t$PROG -h|--help\n\t\tshow this help and exit.\n"
	echo -e "\t$PROG -v|--version\n\t\tprint version and exit.\n"
	echo -e "\t$PROG -d|--delconf\n\t\tdelete $CONF"
	echo -e "\t\tif $PROG doesn't startand exit.\n"
	echo -e "\t$PROG --restore\n\t\trestore backgrounds at session start."
	echo -e "\tAn optional argumant \"\$PROFILE\" is supported.\n"
	echo -e "\ttry \"man $PROG\" for more information."
	exit 0
	;;
esac

# sort out the monitors and positions
if [[ "$WAYLAND" == 'yes' ]]; then
	b=0
	c=1
	MON=''
	pos=''
	while read -r l m n o p q
	do
		case "${l:0:3}" in
			Pos|Mak|Mod|Ser|Phy|Ena|Tra|Sca|Ada)
			if [[ "${l:0:3}" == 'Pos' ]];then
				export pos
				pos=${m%,*};  echo POS=$pos >> "$TEMP/Wmonitor-$((c-1))"
			else
				continue
			fi
			;;
			[a-zA-Z][a-zA-Z][a-zA-Z0-9])MON=$l;;
		esac
		case "$q" in
			current*)res=$l;;
			*)continue;;
		esac
		resX=${res%x*}
		resY=${res#*x}
		echo OUTPUT=$MON >> "$TEMP/Wmonitor-$c"
		echo X=$resX >> "$TEMP/Wmonitor-$c"
		echo Y=$resY >> "$TEMP/Wmonitor-$c"
		c=$((c+1))
		b=$((b+1))
		echo $b > $TEMP/number
	done <<<$(wlr-randr)
	export POPT='edge="top" dist="100"'
	export SOPT='layer="top"'
	export CONFILE="$CONFDIR/Wconf"
else
	k=0
	n=1
	MON=''
	while read -r a b c d z
	do
		echo $a
		[[ "${a}" == 'Monitors:' ]] && continue
		MON=$d
		resX=${c/\/[0-9]*/}
		resY=${c#*x}
		resY=${resY/\/[0-9]*/}
		pos=${c#*+}
		pos=${pos/+/ }
		[[ "${pos%\ *}" == '0' ]] && n=0 # 'xx' position
		pos=${pos%\ *}
		echo  Xmonitor-$n
		echo $MON
		echo $resX
		echo $resY
		echo $pos
		echo OUTPUT=$MON >> "$TEMP/Xmonitor-$n"
		echo X=$resX >> "$TEMP/Xmonitor-$n"
		echo Y=$resY >> "$TEMP/Xmonitor-$n"
		echo POS=$pos >> "$TEMP/Xmonitor-$n"
		n=$((n+1))
		k=$((k+1))
		echo $k > $TEMP/number
	done <<<$(xrandr --listmonitors)
	export POPT='decorated="false"'
	export SOPT=$POPT
	export CONFILE="$CONFDIR/Xconf"
fi

#CSS for splash
[[ -z "$COLOR" ]] && COLOR=666666
echo 'window#splash {
	background: rgba(0,0,0,0.0);
}
#splash {
	background: #5E003E;
	color: #ffffff;
	border-radius: 10px;
	padding: 2px;
}
#sep {
	background: rgba(0,0,0,0.0);
}
#ent {
	background: @theme_selected_bg_color;
}
#noent {
	background: @theme_bg_color;
	color: @theme_fg_color;
	border: none;
}
#cbg {
	background: '#${COLOR}';
}
' > "$TEMP/win.css"

# get the primary output
[[ -z "$TWIDTH" ]] && TWIDTH=9
case $TWIDTH in
	12)THEIGHT=8;;
	11)THEIGHT=9;;
	10)THEIGHT=10;;
	 9)THEIGHT=11;;
	 8)THEIGHT=12;;
esac
e=0
if [[ "$WAYLAND" == 'yes' ]]; then
	for i in $TEMP/Wmonitor*
	do
		# $i is sourced
		. "$i"
		[[ "$POS" == '0' ]] && echo "$OUTPUT = primary" && cp $i $TEMP/ww0
		[[ "$POS" == "$X" ]] && echo "$OUTPUT = secondary" && cp $i $TEMP/ww1
		[[ $POS -gt $X ]] && echo "$OUTPUT = extra" && cp $i $TEMP/ww2$e && e=$((e+1))
	done
	rm $TEMP/Wmonitor* # finished with these
	read -r NUM < "$TEMP/number"
	export NUM
	echo $NUM outputs
	. $TEMP/ww0
	export Wdth=$((X / TWIDTH))
	export MWdth=$((X / 2))
	export MHght=$(((Y * 2 / 3) / 11 * THEIGHT))
	echo "GUI: MWdth=$MWdth x MHght=$MHght"
else
	for f in $TEMP/Xmonitor*
	do
		# $f is sourced
		. "$f"
		[[ "$POS" == '0' ]] && echo "$OUTPUT = primary" && cp $f $TEMP/xx0
		[[ "$POS" == "$X" ]] && echo "$OUTPUT = secondary" && cp $f $TEMP/xx1
		[[ $POS -gt $X ]] && echo "$OUTPUT = extra" && cp $f $TEMP/xx2$e && e=$((e+1))
	done
	rm $TEMP/Xmonitor* # finished with these
	export NUM
	read -r NUM < "$TEMP/number"
	echo $NUM outputs
	. $TEMP/xx0
	export Wdth=$((X / TWIDTH))
	export MWdth=$((X / 2))
	export MHght=$(((Y * 2 / 3) / 11 * THEIGHT))
	echo "GUI: MWdth=$MWdth x MHght=$MHght"
fi

########################    functions     ##############################

# splash window
_splash() {
	[[ -z "$1" ]] && return
	E_VAL=SPLASH
	CR="--geometry=+$((X/2-180))+150"
	case $2 in
		0)[[ "$SPLASH" == 'false' ]] && return
		DIS='
			<button tooltip-text="Do not show again">
				<input file icon="window-close"></input>
				<label>Dismiss</label>
				<action>if grep -q "SPLASH" '$CONF'; then sed -i "s/^SPLASH.*$/SPLASH=false/" '$CONF';else echo SPLASH=false >> '$CONF'; fi</action>
				<action>exit:DISMISS</action>
			</button>'
			E_VAL=Monitors
			;;
		2)E_VAL=Limit;;
		3)ACT='<action>main_gui &</action><action>exit:OK</action>';;
		5)ACT='<action>kill '$PID'</action><action>exit:abort</action>';KILL='<action>kill '$PID'</action>';;
		6)E_VAL=Wait;CR=-c;;
		7)E_VAL=Warning;CR=-c;;
		*)CR=--geometry=+$((X/2-180))+150;ACT='<action>exit:OK</action>';;
	esac
	IVAL=4
	re='^[0-9]'
	[[ $3 =~ $re ]] && IVAL=$3
	if [[ "$WAYLAND" == 'yes' ]]; then
		[[ "$3" == 'b' ]] && POPT='edge="bottom" dist="200"'
	else
		[[ "$3" == 'b' ]] && CR="--geometry=+$((X/2-240))+$((Y-300))"
	fi
	TIMER='<timer interval="'$IVAL'" visible="false">'$KILL'<action>exit:'$E_VAL'</action></timer>'
	echo '<window type-hint="6" icon-name="gtk-info" '$POPT' name="splash" width-request="360">
	<vbox name="splash">
	   <vbox> 
		<hbox name="splash">
		<hbox space-expand="false" space-fill="false">
		  <pixmap name="splash"><width>42</width><input file icon="gtk-info"></input></pixmap>
		  '$TIMER'
	    </hbox>
	    <hbox space-expand="true" space-fill="true">
	      <text name="splash">
			<label>'"$1"'</label>
		  </text>
		</hbox>
		'$RADIO'
		</hbox>
		<hbox name="splash">
			'$DIS'
			<button>
			  <label>OK</label>
			  <input file icon="gtk-ok"></input>
			  '$ACT'
			</button>
		</hbox>
	   </vbox>
	</vbox>
</window>' | $GTK3DIALOG -s "$CR" --styles=$TEMP/win.css
	[[ "$2" == '1' ]] && exit $2
}; export -f _splash

# if < 250 images or on a single monitor there is no welcome splash
# on slow kit a user might want to know if the thing is starting
_greeting() {
	export GREETING='<window type-hint="6" icon-name="xwwall" '$SOPT' name="splash" file-monitor="true" title="'$PROG'" width-request="300">
	<vbox name="splash" space-expand="true" space-fill="true">
	  <hbox space-expand="true" space-fill="true">
	    <pixmap>
	      <input file icon="xwwall"></input><width>64</width>
	    </pixmap>
	  </hbox>
	  <hbox space-expand="true" space-fill="true">
	    <text use-markup="true">
	      <label>"<big><big>Welcome to '$PROG'</big></big>"</label>
	    </text>
	  </hbox>
	</vbox>
	<variable>GREETING</variable>
    <input file>'$TEMP/greeting'</input>
    <action signal="file-changed">exit:GREETING</action>
  </window>'
  $GTK3DIALOG -p GREETING -c --styles=$TEMP/win.css 
}; export -f _greeting

# sort selections
_selections() {
	echo '<hbox>' > $TEMP/ret
	cat $TEMP/selected | while read -r sel
	do
		echo '    <pixmap name="cbg" tooltip-text="'${sel##*\/}'">
		  <width>220</width>
		  <height>120</height>
		  <input file>'$sel'</input>
		</pixmap>' >> $TEMP/ret
	done
	echo '</hbox>' >> $TEMP/ret
}; export -f _selections

# set each background
confirm_gui() {
	_selections
	PIX=$(cat $TEMP/ret)
	export CON='<window icon-name="xwwall" title="Confirm selection">
	<vbox>
    <hbox space-expand="true" space-fill="true">
	    <text><label>Please confirm that the image below is correct.</label></text>
	  </hbox>
	  <hbox space-expand="true" space-fill="true">
		'$PIX'
	  </hbox>
	  <hbox>
	    <button yes>
	      <action signal="button-press-event">echo sleep > '$TEMP/wake'</action>
	      <action signal="button-release-event">exit:Yes</action>
	    </button>
	    <button no>
	      <action>rm -f '$TEMP/increment'</action>
          <action>exit:No</action>
	    </button>
	    <button tooltip-text="If unsatisfied with your choice try again.">
	      <input file icon="refresh"></input>
	      <label>Refresh</label>
          <action>exit:REFRESH</action>
	    </button>
	  </hbox>
	</vbox>
</window>'
	eval "$($GTK3DIALOG -p CON -c --styles=$TEMP/win.css)"
	case $EXIT in
		Yes)_build_command; read -r a b c <<<$(ps -u | grep -m1 'main_gui'); kill -9 $b;;
		REFRESH)rm -f $TEMP/increment $TEMP/selected $TEMP/[XW]set $TEMP/ret;;
		*)rm -f $TEMP/$TEMP/increment $TEMP/selected $TEMP/[XW]set $TEMP/ret; return 1;;
	esac
}; export -f confirm_gui

# build options for output
_output() {
	[[ "$WAYLAND" == 'yes' ]] && fff=ww || fff=xx
	rm -f $TEMP/OP
	for output in $TEMP/${fff}*
	do
		. $output
		export OUTPUT
		export FBG="$1"
		echo "<item>$OUTPUT</item>" >> $TEMP/OP
	done
	[[ -r "$TEMP/increment" ]] || echo -n 1 > "$TEMP/increment"
	INC=$(cat $TEMP/increment)
	case $INC in
		1)DEFAULT=$(sed '1s/item/default/g' < $TEMP/OP | sed -n 1p); echo "$DEFAULT" > $TEMP/default_ent ;;
		2)DEFAULT=$(sed '2s/item/default/g' < $TEMP/OP | sed -n 2p); echo "$DEFAULT" > $TEMP/default_ent ;;
		3)DEFAULT=$(sed '3s/item/default/g' < $TEMP/OP | sed -n 3p); echo "$DEFAULT" > $TEMP/default_ent ;;
		4)DEFAULT=$(sed '4s/item/default/g' < $TEMP/OP | sed -n 4p); echo "$DEFAULT" > $TEMP/default_ent ;;
		5)DEFAULT=$(sed '5s/item/default/g' < $TEMP/OP | sed -n 5p); echo "$DEFAULT" > $TEMP/default_ent ;;
		6)DEFAULT=$(sed '6s/item/default/g' < $TEMP/OP | sed -n 6p); echo "$DEFAULT" > $TEMP/default_ent ;;
	esac
	read -r DEF < $TEMP/default_ent
	. "$CONF"
	sub_gui "$FBG" $INC $DEF
}; export -f _output

# populate buttons for the main GUI
button_gui() {
	local c i j n WALL V buttonsx buttons
	. "$CONF"
	if [[ "$XTRAS" == 'false' || -z "$XTRAS" ]]; then
		echo "$BGDIR"
		c=0
		shopt -s globstar
		for WALL in "$BGDIR"/*{,/**}
		do
			[[ "$(file --brief --mime-type "$WALL" )" = *image* ]] || continue # test mime
			# we take advantage of bash math here
			# for a nicish GUI width *must* be consistent
			i=$((c/4))
			V='  		<button name="cbg" image-position="top" tooltip-text="'"${WALL##*/}"'">
		        <variable>BG'$c'</variable>
		        <input file>'"\"$WALL\""'</input>
				<height>'$Wdth'</height>
				<width>'$Wdth'</width>
				<action signal="button-press-event">_output '"\"$WALL\""' &</action>
				<action signal="button-release-event" type="disable">MAINGUI</action>
		      </button>'
		      buttonsx[i]+="$V"$'\n'
		      c=$((c+1))
		      export TOT=$((c+1))
		      if [[ $c -ge 250 ]];then
				  export TOT=250
				  _splash "Warning: Limit of 250 images" 2 2 &
				  break
			  fi
		done
		shopt -u globstar
		for j in "${!buttonsx[@]}"
		do buttons+="		<hbox>
			${buttonsx[j]}
			</hbox>"$'\n'
		done
		echo "$buttons" > "$TEMP/buttons"
	elif [[ "$XTRAS" == 'true' ]]; then
		echo "${EXTRA_BGDIRS[@]}"
		c=0
		n=0
		while [[ n -lt  "${#EXTRA_BGDIRS[@]}" ]]
		do
			shopt -s globstar
			for WALL in "${EXTRA_BGDIRS[n]}"/*{,/**}
			do
				[[ "$(file --brief --mime-type "$WALL" )" = *image* ]] || continue # test mime
				# we take advantage of bash math here
				# for a nicish GUI width *must* be consistent
				i=$((c/4))
				V='  		<button name="cbg" image-position="top" tooltip-text="'"${WALL##*/}"'">
			        <variable>BG'$c'</variable>
			        <input file>'"\"$WALL\""'</input>
					<height>'$Wdth'</height>
					<width>'$Wdth'</width>
					<action signal="button-press-event">_output '"\"$WALL\""' &</action>
					<action signal="button-release-event" type="disable">MAINGUI</action>
			      </button>'
			      buttonsx[i]+="$V"$'\n'
			      c=$((c+1))
			      export TOT=$((c+1))
			      if [[ $c -ge 250 ]];then
					  export TOT=250
					  _splash "Warning: Limit of 250 images" 2 2 &
					  break
				  fi
			done
			shopt -u globstar
			n=$((n+1))
		done
		for j in "${!buttonsx[@]}"
		do buttons+="		<hbox>
			${buttonsx[j]}
			</hbox>"$'\n'
		done
		echo "$buttons" > "$TEMP/buttons"	
	fi
}

# sub GUI
sub_gui() {
	INC=$2 DEF=$3
	[[ -z "$COLOR" ]] && COLOR=999999
	if [[ "$WAYLAND" == 'yes' ]]; then
		CCOL="-c $COLOR"
		XMODE='<item>tile</item>'
		SS='Wset'
		ACTION='<action signal="button-press-event">echo -e " -o $OUT -m $MODE '$CCOL' -i '\'$1\'' \\" >> '$TEMP/$SS'</action>'
	else
		# feh modes: --bg-scale, --bg-center[ --image-bg=$color], --bg-fill, --bg-max[ --image-bg=$color], --bg-tile
		XCOL=" --image-bg=#${COLOR}"
		[[ $NUM -eq 1 ]] && XMODE='<item>fill</item>'
		SS='Xwset'
		ACTION='<action signal="button-press-event">echo -e " --bg-$MODE '${XCOL}' '\'$1\'' \\" >> '$TEMP/$SS'</action>'
	fi
	if [[ $NUM -eq 1 ]]; then
		DO_ACTION='<action signal="button-press-event">_build_command &</action>'
		ETT='Pressing image will confirm,'
		XTRACTION='<action signal="button-release-event">echo sleep > '$TEMP/wake'</action>
	      <action signal="button-release-event">exit:Yes</action>'
	else
		DO_ACTION='<action signal="button-press-event">if [[ '$INC' -ge '$NUM' ]]; then confirm_gui;fi &</action>'
		ETT='Pressing image will save, you can confirm later,'
	fi
	MTEXT='Choose the Mode.'
    if [[ $INC -eq $NUM && "$WAYLAND" != 'yes' ]]; then # only for X11
    COMBO='<hbox space-expand="false" space-fill="false">
      <entry name="noent" editable="false"><default>Mode:</default><sensitive>false</sensitive></entry>
      <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
      <comboboxtext space-expand="true" space-fill="true">
        <variable>MODE</variable>
        <item>scale</item>
        <item>max</item>
        <item>fill</item>
        <item>center</item>
        <item>tile</item>
      </comboboxtext>
    </hbox>'
    elif [[ "$WAYLAND" == 'yes' ]]; then  
    COMBO='<hbox space-expand="false" space-fill="false">
      <entry name="noent" editable="false"><default>Mode:</default><sensitive>false</sensitive></entry>
      <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
      <comboboxtext space-expand="true" space-fill="true">
        <variable>MODE</variable>
        <item>stretch</item>
        <item>fill</item>
        <item>fit</item>
        <item>center</item>
        <item>tile</item>
      </comboboxtext>
    </hbox>'
    fi
	export SUBGUI='<window icon-name="xwwall" title="Selection">
	<vbox>
    <hbox space-expand="true" space-fill="true">
	  <text><label>'$MTEXT' Press the image to set.</label></text>
	</hbox>
    '$COMBO'
	<hbox space-expand="false" space-fill="false">
      <entry name="noent" editable="false"><default>Output: '$INC'</default><sensitive>false</sensitive></entry>
      <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
      <entry name="ent" editable="false" width-chars="12">
        <variable>OUT</variable>
        '$DEF'
      </entry>
    </hbox>
	  <hbox space-expand="true" space-fill="true">
		<button name="cbg" tooltip-text="'"${1##*/}"$'\n'''$ETT' or Press No to reject and confinue.">
		  <variable>CBG</variable>
	      <input file>'$1'</input>
	  	  <width>320</width>
		  <action signal="button-press-event">echo -n '$((INC+1))' > $TEMP/increment</action>
		  <action signal="button-press-event">echo '$1' >> '$TEMP'/selected</action>
		  '$ACTION'
		  <action>sed -i -e "s% .$%%g" '$TEMP/$SS'</action>
	      <action signal="button-press-event">echo wake > '$TEMP/wake'</action>
		  '$DO_ACTION'
		  '$XTRACTION'
	      <action signal="button-release-event">exit:SUB</action>
		</button>
	  </hbox>
	  <hbox>
	    <button no>
	      <action signal="button-press-event">echo wake > '$TEMP/wake'</action>
	      <action signal="button-release-event">exit:NO</action>
	    </button>
	  </hbox>
	</vbox>
    <variable>SUBGUI</variable>
   </window>'
	eval $($GTK3DIALOG -p SUBGUI -c --styles=$TEMP/win.css)
	case $EXIT in
		Yes)read -r a b c <<<$(ps -u | grep -m1 'main_gui'); kill -9 $b;;
	esac
}; export -f sub_gui

# populate the main GUI
main_gui() {
	echo 'sleep' > "$TEMP/wake"
	[[ -z "$SWIDTH" ]] && SWIDTH=0
	[[ -r "$TEMP/main_gui.xml" ]] && _splash "Please wait ..." 6 2 &
	BUTTONS=$(cat $TEMP/buttons)
	export MAINGUI='<window icon-name="xwwall" file-monitor="true" auto-refresh="true" title="'$PROG' - Background Choice">
  <vbox>
    <hbox space-expand="true" space-fill="true">
      <text use-markup="true" tooltip-text="'$TOT' images"><label>"<b>Select an image for your wallpaper by pressing the image.</b>"</label></text>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox>
      <vbox scrollable="true" height="'$MHght'" width="'$((MWdth+SWIDTH))'">
        '$BUTTONS'
      </vbox>
    </hbox>
    <hbox space-expand="true" space-fill="true">
    <hbox space-expand="false" space-fill="false">
      <button tooltip-text="Preferences">
        <label>Preferences</label>
        <width>16</width>
        <input file icon="preferences-desktop-wallpaper"></input>
        <action>exit:PREFS</action>
      </button>
    </hbox>
	<hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
      <text label="Confirmation is required when finished."></text>
    <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
    <hbox space-expand="false" space-fill="false">
      <button>
        <label>Cancel</label>
        <input file icon="gtk-cancel"></input>
        <action>kill '$PID'</action>
        <action>exit:abort</action>
      </button>
    </hbox>
    </hbox>
  </vbox>
  <variable>MAINGUI</variable>
  <input file>'$TEMP/wake'</input>
  <action signal="realize">echo started > '$TEMP/greeting'</action>
  <action signal="file-changed" type="enable">MAINGUI</action>
</window>'
	[[ -r "$TEMP/main_gui.xml" ]] || printf "%s\n" "$MAINGUI" > $TEMP/main_gui.xml
	eval "$($GTK3DIALOG -f $TEMP/main_gui.xml -c --styles=$TEMP/win.css)"
	
	if [[ "$EXIT" == "PREFS" ]]; then
		_pref
	fi
}; export -f main_gui

# preferences
_pref() {
	. "$CONF"
	if [[ -n "$EXTRA_BGDIRS" ]]; then
		[[ -n "$XTRAS" ]] || XTRAS=true
		DXTRA='	<hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <checkbox>
          <label>enable extra directories.</label>
          <variable>CXTRA</variable>
          <default>'$XTRAS'</default>
        </checkbox>
      </hbox>
    </hbox>'
	fi
	export EXTRA_DIRS='<window icon-name="gtk-preferences" title="Extra Directories" width-request="400">
	  <vbox>
	    <hbox space-expand="true" space-fill="true">
          <text use-markup="true"><label>"<b>Select extra directories.</b>"</label></text>
        </hbox>
        <hseparator space-expand="true" space-fill="true"></hseparator>
        <hbox space-expand="true" space-fill="true">
          <text><label>"Press Save and '$PROG' will restart when you are ready."</label></text>
        </hbox>
        <hseparator name="ent" space-expand="true" space-fill="true"></hseparator>
        <hbox space-expand="true" space-fill="true">
          <text><label>"Choose the directory to search wallpapers."</label></text>
        </hbox>
        <hbox space-expand="true" space-fill="true">
          <hbox space-expand="true" space-fill="true">
           <entry accept="directory" fs-title="'$PROG'">
            <variable>BACKGROUNDS0</variable>
           </entry>
          </hbox>
          <hbox space-expand="false" space-fill="false">
          <button>
            <input file icon="directory-open"></input>
            <variable>FILE_BROWSE_DIRECTORY0</variable>
            <action function="fileselect">BACKGROUNDS0</action>
          </button>
          </hbox>
        </hbox>
        <hseparator space-expand="true" space-fill="true"></hseparator>
        <hbox space-expand="true" space-fill="true">
          <hbox space-expand="true" space-fill="true">
           <entry accept="directory" fs-title="'$PROG'">
            <variable>BACKGROUNDS1</variable>
           </entry>
          </hbox>
          <hbox space-expand="false" space-fill="false">
          <button>
            <input file icon="directory-open"></input>
            <variable>FILE_BROWSE_DIRECTORY1</variable>
            <action function="fileselect">BACKGROUNDS1</action>
          </button>
          </hbox>
        </hbox>
        <hseparator space-expand="true" space-fill="true"></hseparator>
        <hbox space-expand="true" space-fill="true">
          <hbox space-expand="true" space-fill="true">
           <entry accept="directory" fs-title="'$PROG'">
            <variable>BACKGROUNDS2</variable>
          </entry>
          </hbox>
          <hbox space-expand="false" space-fill="false">
          <button>
            <input file icon="directory-open"></input>
            <variable>FILE_BROWSE_DIRECTORY2</variable>
            <action function="fileselect">BACKGROUNDS2</action>
          </button>
          </hbox>
        </hbox>
       </vbox>
	  <variable>EXTRA_DIRS</variable>
	</window>
	'
	
	[[ "$SPLASH" == 'false' ]] && CDEF=false || CDEF=true
	[[ -n "$COLOR" ]] && DEFCOL=#${COLOR} ||  DEFCOL=#666666
	[[ -n "$SWIDTH" ]] && SW=$SWIDTH || SW=0
	[[ -n "$TWIDTH" ]] && TW=$TWIDTH || TW=9
	if [[ $NUM -gt 1 ]]; then
		SPLASHPREF='    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <checkbox>
          <label>enable initial splash screen.</label>
          <variable>SPL</variable>
          <default>'$CDEF'</default>
        </checkbox>
      </hbox>
    </hbox>'
	fi
	export PGUI='<window icon-name="gtk-preferences" title="Preferences" width-request="400">
  <vbox>
    <hbox space-expand="true" space-fill="true">
      <text use-markup="true"><label>"<b>Select your preferences.</b>"</label></text>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <text><label>"Press Save and '$PROG' will restart when you are ready."</label></text>
    </hbox>
    <hseparator name="ent" space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <text><label>"Choose the directory to search wallpapers."</label></text>
    </hbox>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
      <entry accept="directory" fs-title="'$PROG'">
        <default>'$BGDIR'</default>
        <variable>BACKGROUNDS</variable>
      </entry>
      </hbox>
      <hbox space-expand="false" space-fill="false">
      <button>
        <input file icon="directory-open"></input>
        <variable>FILE_BROWSE_DIRECTORY</variable>
        <action function="fileselect">BACKGROUNDS</action>
      </button>
      </hbox>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <text label="Optionally choose extra directories"></text>
      </hbox>
      <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
      <hbox space-expand="true" space-fill="true">
        <button>
          <label>Ok</label>
          <input file icon="gtk-ok"></input>
          <action function="launch">EXTRA_DIRS</action>
        </button>
      </hbox>
    </hbox>
'$DXTRA'
'$SPLASHPREF'
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <hbox space-expand="false" space-fill="false">
        <text label="GUI width adjustment" tooltip-text="Adjust the width of the interface to suit. The thumbnail setting below may also need adjustment."></text>
        </hbox>
        <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
        <hbox space-expand="false" space-fill="false">
        <spinbutton range-min="-300" range-max="300" range-step="2">
          <variable>SW0</variable>
          <default>'$SW'</default>
        </spinbutton>
        </hbox>
      </hbox>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <hbox space-expand="false" space-fill="false">
        <text label="Thumbnail adjustment" tooltip-text="Adjust the width of thumbnail images. May need to adjust above setting to suit. Larger number is smaller width."></text>
        </hbox>
        <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
        <hbox space-expand="false" space-fill="false">
        <spinbutton range-min="8" range-max="12" range-step="1">
          <variable>TW0</variable>
          <default>'$TW'</default>
        </spinbutton>
        </hbox>
      </hbox>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
      <entry editable="false">
        <default>Choose a background color</default>
      </entry>
      </hbox>
      <hbox space-expand="false" space-fill="false">
      <colorbutton>
        <default>'$DEFCOL'</default>
        <variable>CLB0</variable>
      </colorbutton>
      </hbox>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="false" space-fill="false">
      <button>
        <label>Cancel</label>
        <input file icon="gtk-cancel"></input>
        <action>kill '$PID'</action>
        <action>exit:abort</action>
      </button>
      <button>
        <label>Save</label>
        <input file icon="gtk-save"></input>
        <action>exit:SAVE</action>
      </button>
    </hbox>
  </vbox>
</window>'
	eval "$($GTK3DIALOG -p PGUI -c --styles=$TEMP/win.css)"
	if [[ -d "$BACKGROUNDS" ]]; then
		sed -i "s%^BGDIR.*$%BGDIR=\"$BACKGROUNDS\"%" "$CONF"
		rm -f "$TEMP/buttons"
		rm -f "$TEMP/main_gui.xml"
	fi
	if ! [[ -z "$BACKGROUNDS0" && -z "$BACKGROUNDS1" && -z "$BACKGROUNDS2" ]]; then # do nothing if all vars are empty
		if [[ -d "$BACKGROUNDS0" || -d "$BACKGROUNDS1" || -d "$BACKGROUNDS2" ]]; then
			if grep -q 'EXTRA_BGDIRS' "$CONF"; then
				sed -i '/EXTRA_BGDIRS/d' "$CONF"
			fi
			printf "%s" "EXTRA_BGDIRS=( " >>  "$CONF"
			[[ -n "$BACKGROUNDS0" ]] && printf "%s" "\"$BACKGROUNDS0\" " >>  "$CONF"
			[[ -n "$BACKGROUNDS1" ]] && printf "%s" "\"$BACKGROUNDS1\" " >>  "$CONF"
			[[ -n "$BACKGROUNDS2" ]] && printf "%s" "\"$BACKGROUNDS2\" " >>  "$CONF"
			printf "%s\n" ")" >>  "$CONF"
			rm -f "$TEMP/buttons"
			rm -f "$TEMP/main_gui.xml"
			# since user just set these, enable them
			echo "XTRAS=true" >> "$CONF"
		fi
	fi
	if grep -q 'SPLASH' "$CONF"; then
		sed -i "s/^SPLASH.*$/SPLASH=$SPL/" "$CONF"
	else
		echo "SPLASH=$SPL" >> "$CONF"
	fi
	if grep -q 'XTRAS' "$CONF"; then
		[[ -n  "$CXTRA" ]] && \
		sed -i "s/^XTRAS.*$/XTRAS=$CXTRA/" "$CONF"
	else
		[[ -n  "$CXTRA" ]] && \
		echo "XTRAS=$CXTRA" >> "$CONF"
	fi
	if grep -q 'SWIDTH' "$CONF"; then
		sed -i "s/^SWIDTH.*$/SWIDTH=$SW0/" "$CONF"
	else
		echo "SWIDTH=$SW0" >> "$CONF"
	fi
	echo $BACKGROUNDS0 $BACKGROUNDS1 $BACKGROUNDS2
	if grep -q 'TWIDTH' "$CONF"; then
		sed -i "s/^TWIDTH.*$/TWIDTH=$TW0/" "$CONF"
	else
		echo "TWIDTH=$TW0" >> "$CONF"
	fi
	if grep -q 'COLOR' "$CONF"; then
		sed -i "s/^COLOR.*$/COLOR=${CLB0:1:6}/" "$CONF"
	else
		echo "COLOR=${CLB0:1:6}" >> "$CONF"
	fi
	if [[ "$EXIT" == 'SAVE' ]]; then
		exec $0
	fi
}; export -f _pref


_build_command() {
	if [[ "$WAYLAND" == 'yes' ]]; then
		echo 'killall swaybg >/dev/null 2>&1' > $TEMP/cmd
		echo 'swaybg \' >> $TEMP/cmd
		cat $TEMP/Wset >> $TEMP/cmd
		echo '>/dev/null 2>&1 &' >> $TEMP/cmd
		# run it
		. "$TEMP/cmd"
		cat $TEMP/cmd > "$CONFDIR/cmd" # you can put this in your startup file
	else
		# this builds ~/.fehbg with the command below.
		echo 'killall feh >/dev/null 2>&1' > $TEMP/cmd
		echo 'feh \' >> $TEMP/cmd
		cat $TEMP/Xwset >> $TEMP/cmd
		echo '>/dev/null 2>&1 &' >> $TEMP/cmd
		# run it
		. "$TEMP/cmd"
	fi
}; export -f _build_command

_dependencies() {     # adapted from bl-includes
    # Usage: _dependencies command [command...]
    local missing_commands=()
    i=
    for i in "$@"
    do
        hash "$i" 2>/dev/null || missing_commands+=(" $i")
    done

    if [[ ${missing_commands[0]} ]];then
        ERR_MSG="This script requires the following commands: \"${missing_commands[*]}\" .\
Please install the packages containing the missing commands and re-run the script."
        _splash "${ERR_MSG}" 3
        exit
    fi
}

trap_exit() {
	trap "rm -rf $TEMP" EXIT
}; export -f trap_exit


########################      main        ##############################

# required programs
declare -a APPS
if [[ "$WAYLAND" == 'yes' ]]; then
	APPS=( "gtk3dialog" "wlr-randr" "swaybg" )
else
	APPS=( "gtk3dialog" "xrandr" "feh" )
fi
_dependencies  "${APPS[@]}" 

trap_exit
export PID=$$

# test for compatibility
KWNINX=$(pidof kwin_x11)
KWNINW=$(pidof kwin_wayland)
GNOME=$(pidof gnome-session) # covers X11 and wayland
XFCE4=$(pidof xfce4-session) # covers X11 and wayland
if [[ -n "$KWNINX" || "$KWNINW" || "$GNOME" || "$XFCE4" ]]; then # more to add
	_splash "WARNING: Your desktop may be unsupported" 7
fi

if [[ ! -d "$BGDIR" ]]; then
	_splash "Please set a background directory" 3
	_pref
else
	[[ -r "$BGDIR/0Solid_Color.svg" ]] || cat > "$BGDIR/0Solid_Color.svg" <<EOS
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 1366 768">
 <path style="fill:rgba(0,0,0,0.0);" d="m 0,0 1366,0 0,768 -1366,0 z"/>
</svg>	
EOS
fi

touch "$TEMP/greeting"
_greeting &

if [[ "$NUM" != '1' ]]; then
	# this nag can be disabled in prefs
	_splash "You have $NUM monitors connected. Carefully choose an image for each of them." 0 b &
fi

echo ================
button_gui
main_gui

Last edited by micko01 (2025-01-31 23:41:34)


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#146 2025-01-31 14:46:34

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,008

Re: Wallpaper setter for Carbon - X11 and Wayland

I have a couple of thoughts or crazy ideas.

First:
When run for the first time 'xwwall' asks for a directory and thereafter uses that directory.

thoughts or crazy ideas :

1.  could it be possible to have xwwall run using the directory it's started in?
IE:

$ cd /media/5/Wallpapers

and then

xwwall

→ → Then a little YAD script, yxwwall, could be use to start it in various locations.

2. or tell it on the command line: 

xwwall /media/5/Wallpapers/cnb

Don't mind me I'm just rambling

My terminal

 2025·01·31 @ 11:17:56 ~
   $ xwwall
Monitors:
0:
Xmonitor-0
DVI-D-0
1920
1080
0
DVI-D-0 = primary
1 outputs
GUI: MWdth=960 x MHght=715
================
/media/5/Wallpapers
EXIT="Limit"
 
 2025·01·31 @ 11:18:40 ~
   $ 

I do like this little script.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#147 2025-01-31 22:53:54

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

Sector11 wrote:

I have a couple of thoughts or crazy ideas.

First:
When run for the first time 'xwwall' asks for a directory and thereafter uses that directory.

thoughts or crazy ideas :

1.  could it be possible to have xwwall run using the directory it's started in?
IE:

$ cd /media/5/Wallpapers

and then

xwwall

→ → Then a little YAD script, yxwwall, could be use to start it in various locations.

2. or tell it on the command line: 

xwwall /media/5/Wallpapers/cnb

Don't mind me I'm just rambling


(snip)

I do like this little script.

Well I can easily support this idea without much code, but I don't think a CLI switch is warranted because of the extra overhead.

Ideally, you could run it from your chosen directory at initial start (ie remove ~/.config/xwwall/xwwall.conf) and your chosen directory to run in will be saved to the new config, instead of fluffing around with GUI preferences.

I just tried this modification.

~/bin$ diff -Nur xwwall.orig xwwall
--- xwwall.orig	2025-02-01 08:38:36.932609403 +1000
+++ xwwall	2025-02-01 08:27:25.732509816 +1000
@@ -4,7 +4,11 @@
 export GTK3DIALOG
 export MAINGUI
 [[ -z "$GTK3DIALOG" ]] && GTK3DIALOG=gtk3dialog
-export BGDIR="${BGDIR:-$HOME/Pictures/wallpapers}"
+if [[ "$(pwd)" == "$HOME" ]]; then 
+	export BGDIR="${BGDIR:-$HOME/Pictures/wallpapers}"
+else
+	export BGDIR="$(pwd)"
+fi
 export PROG=${0##*\/}
 export TEMP=/tmp/$PROG
 #export TEMP=$HOME/tmp/$PROG # for testing

Then I ran:

~$ cd /usr/share/backgrounds/
~$ xwwall

Here's the result:
3jQ4sJMA_t.png

Never mind the portrait images, they don't render too well in the GUI. Fix on the todo list.

And here's the generated config

BGDIR=/usr/share/backgrounds

So that dir will be used no matter where you start xwwall. If you want to change it just run

xwwall -d && cd /usr/share/backgrounds/xfce && xwwall # (for example)

HTH


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#148 2025-01-31 23:13:44

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,008

Re: Wallpaper setter for Carbon - X11 and Wayland

My idea was in support of multiple directories under /media/5/Wallpapers some of which are:

/media/5/Wallpapers/aircraft
/media/5/Wallpapers/b-n-w
/media/5/Wallpapers/Canada
/media/5/Wallpapers/desert
/media/5/Wallpapers/halloween
/media/5/Wallpapers/Oprical·Illusion
/media/5/Wallpapers/xga


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#149 2025-01-31 23:23:25

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

I think this looks a bit better as far as handling portrait images are concerned. Some users orient their monitors in portrait configuration so that base is now covered.

1c1zrcxE_t.png

I actually just deleted the lines <height>'$Wdth'</height> in button_gui so with that little overhead gone I may be able to bump the image limit back to 300.


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#150 2025-01-31 23:25:30

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

Sector11 wrote:

My idea was in support of multiple directories under /media/5/Wallpapers some of which are:

/media/5/Wallpapers/aircraft
/media/5/Wallpapers/b-n-w
/media/5/Wallpapers/Canada
/media/5/Wallpapers/desert
/media/5/Wallpapers/halloween
/media/5/Wallpapers/Oprical·Illusion
/media/5/Wallpapers/xga


The globbing in the button_gui should search subdirs up to the limit anyway, but if you have upwards of 275 in each then that won't help sad

EDIT - changed 300 to 275

Last edited by micko01 (2025-01-31 23:36:58)


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#151 2025-02-01 01:05:53

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

Here you go @S11

gxwwall wink

#!/bin/bash

############################ user editable #############################
main_dir=/media/5/Wallpapers/
declare -a dirs="( aircraft b-n-w Canada desert halloween Oprical-illusion xga )"
######################### end user editable ############################

# build items for the combobox
ITEMS=''
for dir in ${dirs[@]}; do
 ITEMS="$ITEMS<item>${dir}</item>\n"
done

XITEMS=$(echo -e "$ITEMS")

# gui description
export UI='<window title="Choose a dir" icon-name="gtk-question" width-request="300">
  <vbox>
    <hbox space-expand="true" space-fill="true">
      <text label="Main directory is: '$main_dir'"></text>
    </hbox>
    <hbox space-expand="true" space-fill="true">
      <text label="Make a choice"></text>
    </hbox>
    <hbox space-expand="true" space-fill="true">
      <comboboxtext>
        <variable>DIR</variable>
        '$XITEMS'
      </comboboxtext>
    </hbox>
    <hbox>
      <button ok></button>
    </hbox>
  </vbox>
</window>'

eval $(gtk3dialog -p UI -c)

XDIR=${main_dir}${DIR}
echo $XDIR
# execute xwwall
[[ -d "$DIR" ]] || exit 1 # error
xwwall -d && cd $DIR && xwwall
cd -

Does pretty much what you wanted from a gtk3dialog gui instead of Yad.

5iHAx52N_t.png NNnS2BDd_t.png


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#152 2025-02-01 01:24:27

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

Ok, things have sufficiently diverged from the last version to post another.

  • add greeting splash closing on realize signal from MAINGUI - thanks @johnraff

  • add ability to start from another directory and use that as BGDIR (requires deletion of current config). Thanks @S11

  • trim some redundant code from button_gui; can now use 300 image limit again

  • fix UI for portrait images

  • rename 0Solid_color generated image to Solid_color so it isn't first in the UI

  • if generation of the solid color image is required, make sure the dir is writable

#!/bin/bash

export V=0.1.4beta
export GTK3DIALOG
export MAINGUI
[[ -z "$GTK3DIALOG" ]] && GTK3DIALOG=gtk3dialog
if [[ "$(pwd)" == "$HOME" ]]; then 
	export BGDIR="${BGDIR:-$HOME/Pictures/wallpapers}"
else
	export BGDIR="$(pwd)"
fi
export PROG=${0##*\/}
export TEMP=/tmp/$PROG
#export TEMP=$HOME/tmp/$PROG # for testing
rm -rf "$TEMP" # incase of a crash because of "Argument list too long"
mkdir -p "$TEMP"
export CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}/$PROG"
mkdir -p "$CONFDIR"
export CONF="$CONFDIR/$PROG.conf"
if [[ ! -f "$CONF" ]];then
	echo "BGDIR=$BGDIR" > "$CONF"
fi
. "$CONF"

wlr-randr >/dev/null 2>&1 && export WAYLAND=yes

case "$1" in
	--restore)
	PROFILE="$2"
	echo $PROFILE
	if [[ -n "$PROFILE" && -r "$CONFDIR/$PROFILE/cmd" ]]; then
		. "$CONFDIR/$PROFILE/cmd" && exit 0
	elif [[ -n "$PROFILE" &&  -x "$CONFDIR/$PROFILE/.fehbg" ]]; then
		exec "$CONFDIR/$PROFILE/.fehbg"
	fi
	if [[ -f "$CONFDIR/cmd" && "$WAYLAND" == 'yes' ]]; then
		. "$CONFDIR/cmd" && exit 0
	elif [[ -x "$HOME/.fehbg" ]]; then
		exec "$HOME/.fehbg"
	else
		exit 1
	fi
	;;
	-d|--delconf)
		rm -f "$CONF"
		exit 0
	;;
	-*v|-*version)
	echo -e "\t$PROG $V\n\t\tGPL-2.0+ licence\n"
	exit 0
	;;
	-*h|-*help)
	echo -e "\t$PROG -h|--help\n\t\tshow this help and exit.\n"
	echo -e "\t$PROG -v|--version\n\t\tprint version and exit.\n"
	echo -e "\t$PROG -d|--delconf\n\t\tdelete $CONF"
	echo -e "\t\tif $PROG doesn't startand exit.\n"
	echo -e "\t$PROG --restore\n\t\trestore backgrounds at session start."
	echo -e "\tAn optional argumant \"\$PROFILE\" is supported.\n"
	echo -e "\ttry \"man $PROG\" for more information."
	exit 0
	;;
esac

# sort out the monitors and positions
if [[ "$WAYLAND" == 'yes' ]]; then
	b=0
	c=1
	MON=''
	pos=''
	while read -r l m n o p q
	do
		case "${l:0:3}" in
			Pos|Mak|Mod|Ser|Phy|Ena|Tra|Sca|Ada)
			if [[ "${l:0:3}" == 'Pos' ]];then
				export pos
				pos=${m%,*};  echo POS=$pos >> "$TEMP/Wmonitor-$((c-1))"
			else
				continue
			fi
			;;
			[a-zA-Z][a-zA-Z][a-zA-Z0-9])MON=$l;;
		esac
		case "$q" in
			current*)res=$l;;
			*)continue;;
		esac
		resX=${res%x*}
		resY=${res#*x}
		echo OUTPUT=$MON >> "$TEMP/Wmonitor-$c"
		echo X=$resX >> "$TEMP/Wmonitor-$c"
		echo Y=$resY >> "$TEMP/Wmonitor-$c"
		c=$((c+1))
		b=$((b+1))
		echo $b > $TEMP/number
	done <<<$(wlr-randr)
	export POPT='edge="top" dist="100"'
	export SOPT='layer="top"'
	export CONFILE="$CONFDIR/Wconf"
else
	k=0
	n=1
	MON=''
	while read -r a b c d z
	do
		echo $a
		[[ "${a}" == 'Monitors:' ]] && continue
		MON=$d
		resX=${c/\/[0-9]*/}
		resY=${c#*x}
		resY=${resY/\/[0-9]*/}
		pos=${c#*+}
		pos=${pos/+/ }
		[[ "${pos%\ *}" == '0' ]] && n=0 # 'xx' position
		pos=${pos%\ *}
		echo  Xmonitor-$n
		echo $MON
		echo $resX
		echo $resY
		echo $pos
		echo OUTPUT=$MON >> "$TEMP/Xmonitor-$n"
		echo X=$resX >> "$TEMP/Xmonitor-$n"
		echo Y=$resY >> "$TEMP/Xmonitor-$n"
		echo POS=$pos >> "$TEMP/Xmonitor-$n"
		n=$((n+1))
		k=$((k+1))
		echo $k > $TEMP/number
	done <<<$(xrandr --listmonitors)
	export POPT='decorated="false"'
	export SOPT=$POPT
	export CONFILE="$CONFDIR/Xconf"
fi

#CSS for splash
[[ -z "$COLOR" ]] && COLOR=666666
echo 'window#splash {
	background: rgba(0,0,0,0.0);
}
#splash {
	background: #5E003E;
	color: #ffffff;
	border-radius: 10px;
	padding: 2px;
}
#sep {
	background: rgba(0,0,0,0.0);
}
#ent {
	background: @theme_selected_bg_color;
}
#noent {
	background: @theme_bg_color;
	color: @theme_fg_color;
	border: none;
}
#cbg {
	background: '#${COLOR}';
}
' > "$TEMP/win.css"

# get the primary output
[[ -z "$TWIDTH" ]] && TWIDTH=9
case $TWIDTH in
	12)THEIGHT=8;;
	11)THEIGHT=9;;
	10)THEIGHT=10;;
	 9)THEIGHT=11;;
	 8)THEIGHT=12;;
esac
e=0
if [[ "$WAYLAND" == 'yes' ]]; then
	for i in $TEMP/Wmonitor*
	do
		# $i is sourced
		. "$i"
		[[ "$POS" == '0' ]] && echo "$OUTPUT = primary" && cp $i $TEMP/ww0
		[[ "$POS" == "$X" ]] && echo "$OUTPUT = secondary" && cp $i $TEMP/ww1
		[[ $POS -gt $X ]] && echo "$OUTPUT = extra" && cp $i $TEMP/ww2$e && e=$((e+1))
	done
	rm $TEMP/Wmonitor* # finished with these
	read -r NUM < "$TEMP/number"
	export NUM
	echo $NUM outputs
	. $TEMP/ww0
	export Wdth=$((X / TWIDTH))
	export MWdth=$((X / 2))
	export MHght=$(((Y * 2 / 3) / 11 * THEIGHT))
	echo "GUI: MWdth=$MWdth x MHght=$MHght"
else
	for f in $TEMP/Xmonitor*
	do
		# $f is sourced
		. "$f"
		[[ "$POS" == '0' ]] && echo "$OUTPUT = primary" && cp $f $TEMP/xx0
		[[ "$POS" == "$X" ]] && echo "$OUTPUT = secondary" && cp $f $TEMP/xx1
		[[ $POS -gt $X ]] && echo "$OUTPUT = extra" && cp $f $TEMP/xx2$e && e=$((e+1))
	done
	rm $TEMP/Xmonitor* # finished with these
	export NUM
	read -r NUM < "$TEMP/number"
	echo $NUM outputs
	. $TEMP/xx0
	export Wdth=$((X / TWIDTH))
	export MWdth=$((X / 2))
	export MHght=$(((Y * 2 / 3) / 11 * THEIGHT))
	echo "GUI: MWdth=$MWdth x MHght=$MHght"
fi

########################    functions     ##############################

# splash window
_splash() {
	[[ -z "$1" ]] && return
	E_VAL=SPLASH
	CR="--geometry=+$((X/2-180))+150"
	case $2 in
		0)[[ "$SPLASH" == 'false' ]] && return
		DIS='
			<button tooltip-text="Do not show again">
				<input file icon="window-close"></input>
				<label>Dismiss</label>
				<action>if grep -q "SPLASH" '$CONF'; then sed -i "s/^SPLASH.*$/SPLASH=false/" '$CONF';else echo SPLASH=false >> '$CONF'; fi</action>
				<action>exit:DISMISS</action>
			</button>'
			E_VAL=Monitors
			;;
		2)E_VAL=Limit;;
		3)ACT='<action>main_gui &</action><action>exit:OK</action>';;
		5)ACT='<action>kill '$PID'</action><action>exit:abort</action>';KILL='<action>kill '$PID'</action>';;
		6)E_VAL=Wait;CR=-c;;
		7)E_VAL=Warning;CR=-c;;
		*)CR=--geometry=+$((X/2-180))+150;ACT='<action>exit:OK</action>';;
	esac
	IVAL=4
	re='^[0-9]'
	[[ $3 =~ $re ]] && IVAL=$3
	if [[ "$WAYLAND" == 'yes' ]]; then
		[[ "$3" == 'b' ]] && POPT='edge="bottom" dist="200"'
	else
		[[ "$3" == 'b' ]] && CR="--geometry=+$((X/2-240))+$((Y-300))"
	fi
	TIMER='<timer interval="'$IVAL'" visible="false">'$KILL'<action>exit:'$E_VAL'</action></timer>'
	echo '<window type-hint="6" icon-name="gtk-info" '$POPT' name="splash" width-request="360">
	<vbox name="splash">
	   <vbox> 
		<hbox name="splash">
		<hbox space-expand="false" space-fill="false">
		  <pixmap name="splash"><width>42</width><input file icon="gtk-info"></input></pixmap>
		  '$TIMER'
	    </hbox>
	    <hbox space-expand="true" space-fill="true">
	      <text name="splash">
			<label>'"$1"'</label>
		  </text>
		</hbox>
		'$RADIO'
		</hbox>
		<hbox name="splash">
			'$DIS'
			<button>
			  <label>OK</label>
			  <input file icon="gtk-ok"></input>
			  '$ACT'
			</button>
		</hbox>
	   </vbox>
	</vbox>
</window>' | $GTK3DIALOG -s "$CR" --styles=$TEMP/win.css
	[[ "$2" == '1' ]] && exit $2
}; export -f _splash

# if < 300 images or on a single monitor there is no welcome splash
# on slow kit a user might want to know if the thing is starting
_greeting() {
	export GREETING='<window type-hint="6" icon-name="xwwall" '$SOPT' name="splash" file-monitor="true" title="'$PROG'" width-request="300">
	<vbox name="splash" space-expand="true" space-fill="true">
	  <hbox space-expand="true" space-fill="true">
	    <pixmap>
	      <input file icon="xwwall"></input><width>64</width>
	    </pixmap>
	  </hbox>
	  <hbox space-expand="true" space-fill="true">
	    <text use-markup="true">
	      <label>"<big><big>Welcome to '$PROG'</big></big>"</label>
	    </text>
	  </hbox>
	</vbox>
	<variable>GREETING</variable>
    <input file>'$TEMP/greeting'</input>
    <action signal="file-changed">exit:GREETING</action>
  </window>'
  $GTK3DIALOG -p GREETING -c --styles=$TEMP/win.css 
}; export -f _greeting

# sort selections
_selections() {
	echo '<hbox>' > $TEMP/ret
	cat $TEMP/selected | while read -r sel
	do
		echo '    <pixmap name="cbg" tooltip-text="'${sel##*\/}'">
		  <width>220</width>
		  <height>120</height>
		  <input file>'$sel'</input>
		</pixmap>' >> $TEMP/ret
	done
	echo '</hbox>' >> $TEMP/ret
}; export -f _selections

# set each background
confirm_gui() {
	_selections
	PIX=$(cat $TEMP/ret)
	export CON='<window icon-name="xwwall" title="Confirm selection">
	<vbox>
    <hbox space-expand="true" space-fill="true">
	    <text><label>Please confirm that the image below is correct.</label></text>
	  </hbox>
	  <hbox space-expand="true" space-fill="true">
		'$PIX'
	  </hbox>
	  <hbox>
	    <button yes>
	      <action signal="button-press-event">echo sleep > '$TEMP/wake'</action>
	      <action signal="button-release-event">exit:Yes</action>
	    </button>
	    <button no>
	      <action>rm -f '$TEMP/increment'</action>
          <action>exit:No</action>
	    </button>
	    <button tooltip-text="If unsatisfied with your choice try again.">
	      <input file icon="refresh"></input>
	      <label>Refresh</label>
          <action>exit:REFRESH</action>
	    </button>
	  </hbox>
	</vbox>
</window>'
	eval "$($GTK3DIALOG -p CON -c --styles=$TEMP/win.css)"
	case $EXIT in
		Yes)_build_command; read -r a b c <<<$(ps -u | grep -m1 'main_gui'); kill -9 $b;;
		REFRESH)rm -f $TEMP/increment $TEMP/selected $TEMP/[XW]set $TEMP/ret;;
		*)rm -f $TEMP/$TEMP/increment $TEMP/selected $TEMP/[XW]set $TEMP/ret; return 1;;
	esac
}; export -f confirm_gui

# build options for output
_output() {
	[[ "$WAYLAND" == 'yes' ]] && fff=ww || fff=xx
	rm -f $TEMP/OP
	for output in $TEMP/${fff}*
	do
		. $output
		export OUTPUT
		export FBG="$1"
		echo "<item>$OUTPUT</item>" >> $TEMP/OP
	done
	[[ -r "$TEMP/increment" ]] || echo -n 1 > "$TEMP/increment"
	INC=$(cat $TEMP/increment)
	case $INC in
		1)DEFAULT=$(sed '1s/item/default/g' < $TEMP/OP | sed -n 1p); echo "$DEFAULT" > $TEMP/default_ent ;;
		2)DEFAULT=$(sed '2s/item/default/g' < $TEMP/OP | sed -n 2p); echo "$DEFAULT" > $TEMP/default_ent ;;
		3)DEFAULT=$(sed '3s/item/default/g' < $TEMP/OP | sed -n 3p); echo "$DEFAULT" > $TEMP/default_ent ;;
		4)DEFAULT=$(sed '4s/item/default/g' < $TEMP/OP | sed -n 4p); echo "$DEFAULT" > $TEMP/default_ent ;;
		5)DEFAULT=$(sed '5s/item/default/g' < $TEMP/OP | sed -n 5p); echo "$DEFAULT" > $TEMP/default_ent ;;
		6)DEFAULT=$(sed '6s/item/default/g' < $TEMP/OP | sed -n 6p); echo "$DEFAULT" > $TEMP/default_ent ;;
	esac
	read -r DEF < $TEMP/default_ent
	. "$CONF"
	sub_gui "$FBG" $INC $DEF
}; export -f _output

# populate buttons for the main GUI
button_gui() {
	local c i j n WALL V buttonsx buttons
	. "$CONF"
	if [[ "$XTRAS" == 'false' || -z "$XTRAS" ]]; then
		echo "$BGDIR"
		c=0
		shopt -s globstar
		for WALL in "$BGDIR"/*{,/**}
		do
			[[ "$(file --brief --mime-type "$WALL" )" = *image* ]] || continue # test mime
			# we take advantage of bash math here
			# for a nicish GUI width *must* be consistent
			i=$((c/4))
			V='  		<button name="cbg" image-position="top" tooltip-text="'"${WALL##*/}"'">
		        <input file>'"\"$WALL\""'</input>
				<width>'$Wdth'</width>
				<action signal="button-press-event">_output '"\"$WALL\""' &</action>
				<action signal="button-release-event" type="disable">MAINGUI</action>
		      </button>'
		      buttonsx[i]+="$V"$'\n'
		      c=$((c+1))
		      export TOT=$((c+1))
		      if [[ $c -ge 300 ]];then
				  export TOT=300
				  _splash "Warning: Limit of 300 images" 2 2 &
				  break
			  fi
		done
		shopt -u globstar
		for j in "${!buttonsx[@]}"
		do buttons+="		<hbox>
			${buttonsx[j]}
			</hbox>"$'\n'
		done
		echo "$buttons" > "$TEMP/buttons"
	elif [[ "$XTRAS" == 'true' ]]; then
		echo "${EXTRA_BGDIRS[@]}"
		c=0
		n=0
		while [[ n -lt  "${#EXTRA_BGDIRS[@]}" ]]
		do
			shopt -s globstar
			for WALL in "${EXTRA_BGDIRS[n]}"/*{,/**}
			do
				[[ "$(file --brief --mime-type "$WALL" )" = *image* ]] || continue # test mime
				# we take advantage of bash math here
				# for a nicish GUI width *must* be consistent
				i=$((c/4))
				V='  		<button name="cbg" image-position="top" tooltip-text="'"${WALL##*/}"'">
			        <input file>'"\"$WALL\""'</input>
					<width>'$Wdth'</width>
					<action signal="button-press-event">_output '"\"$WALL\""' &</action>
					<action signal="button-release-event" type="disable">MAINGUI</action>
			      </button>'
			      buttonsx[i]+="$V"$'\n'
			      c=$((c+1))
			      export TOT=$((c+1))
			      if [[ $c -ge 300 ]];then
					  export TOT=300
					  _splash "Warning: Limit of 300 images" 2 2 &
					  break
				  fi
			done
			shopt -u globstar
			n=$((n+1))
		done
		for j in "${!buttonsx[@]}"
		do buttons+="		<hbox>
			${buttonsx[j]}
			</hbox>"$'\n'
		done
		echo "$buttons" > "$TEMP/buttons"	
	fi
}

# sub GUI
sub_gui() {
	INC=$2 DEF=$3
	[[ -z "$COLOR" ]] && COLOR=999999
	if [[ "$WAYLAND" == 'yes' ]]; then
		CCOL="-c $COLOR"
		XMODE='<item>tile</item>'
		SS='Wset'
		ACTION='<action signal="button-press-event">echo -e " -o $OUT -m $MODE '$CCOL' -i '\'$1\'' \\" >> '$TEMP/$SS'</action>'
	else
		# feh modes: --bg-scale, --bg-center[ --image-bg=$color], --bg-fill, --bg-max[ --image-bg=$color], --bg-tile
		XCOL=" --image-bg=#${COLOR}"
		[[ $NUM -eq 1 ]] && XMODE='<item>fill</item>'
		SS='Xwset'
		ACTION='<action signal="button-press-event">echo -e " --bg-$MODE '${XCOL}' '\'$1\'' \\" >> '$TEMP/$SS'</action>'
	fi
	if [[ $NUM -eq 1 ]]; then
		DO_ACTION='<action signal="button-press-event">_build_command &</action>'
		ETT='Pressing image will confirm,'
		XTRACTION='<action signal="button-release-event">echo sleep > '$TEMP/wake'</action>
	      <action signal="button-release-event">exit:Yes</action>'
	else
		DO_ACTION='<action signal="button-press-event">if [[ '$INC' -ge '$NUM' ]]; then confirm_gui;fi &</action>'
		ETT='Pressing image will save, you can confirm later,'
	fi
	MTEXT='Choose the Mode.'
    if [[ $INC -eq $NUM && "$WAYLAND" != 'yes' ]]; then # only for X11
    COMBO='<hbox space-expand="false" space-fill="false">
      <entry name="noent" editable="false"><default>Mode:</default><sensitive>false</sensitive></entry>
      <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
      <comboboxtext space-expand="true" space-fill="true">
        <variable>MODE</variable>
        <item>scale</item>
        <item>max</item>
        <item>fill</item>
        <item>center</item>
        <item>tile</item>
      </comboboxtext>
    </hbox>'
    elif [[ "$WAYLAND" == 'yes' ]]; then  
    COMBO='<hbox space-expand="false" space-fill="false">
      <entry name="noent" editable="false"><default>Mode:</default><sensitive>false</sensitive></entry>
      <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
      <comboboxtext space-expand="true" space-fill="true">
        <variable>MODE</variable>
        <item>stretch</item>
        <item>fill</item>
        <item>fit</item>
        <item>center</item>
        <item>tile</item>
      </comboboxtext>
    </hbox>'
    fi
	export SUBGUI='<window icon-name="xwwall" title="Selection">
	<vbox>
    <hbox space-expand="true" space-fill="true">
	  <text><label>'$MTEXT' Press the image to set.</label></text>
	</hbox>
    '$COMBO'
	<hbox space-expand="false" space-fill="false">
      <entry name="noent" editable="false"><default>Output: '$INC'</default><sensitive>false</sensitive></entry>
      <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
      <entry name="ent" editable="false" width-chars="12">
        <variable>OUT</variable>
        '$DEF'
      </entry>
    </hbox>
	  <hbox space-expand="true" space-fill="true">
		<button name="cbg" tooltip-text="'"${1##*/}"$'\n'''$ETT' or Press No to reject and confinue.">
		  <variable>CBG</variable>
	      <input file>'$1'</input>
	  	  <width>320</width>
		  <action signal="button-press-event">echo -n '$((INC+1))' > $TEMP/increment</action>
		  <action signal="button-press-event">echo '$1' >> '$TEMP'/selected</action>
		  '$ACTION'
		  <action>sed -i -e "s% .$%%g" '$TEMP/$SS'</action>
	      <action signal="button-press-event">echo wake > '$TEMP/wake'</action>
		  '$DO_ACTION'
		  '$XTRACTION'
	      <action signal="button-release-event">exit:SUB</action>
		</button>
	  </hbox>
	  <hbox>
	    <button no>
	      <action signal="button-press-event">echo wake > '$TEMP/wake'</action>
	      <action signal="button-release-event">exit:NO</action>
	    </button>
	  </hbox>
	</vbox>
    <variable>SUBGUI</variable>
   </window>'
	eval $($GTK3DIALOG -p SUBGUI -c --styles=$TEMP/win.css)
	case $EXIT in
		Yes)read -r a b c <<<$(ps -u | grep -m1 'main_gui'); kill -9 $b;;
	esac
}; export -f sub_gui

# populate the main GUI
main_gui() {
	echo 'sleep' > "$TEMP/wake"
	[[ -z "$SWIDTH" ]] && SWIDTH=0
	[[ -r "$TEMP/main_gui.xml" ]] && _splash "Please wait ..." 6 2 &
	BUTTONS=$(cat $TEMP/buttons)
	export MAINGUI='<window icon-name="xwwall" file-monitor="true" auto-refresh="true" title="'$PROG' - Background Choice">
  <vbox>
    <hbox space-expand="true" space-fill="true">
      <text use-markup="true" tooltip-text="'$TOT' images"><label>"<b>Select an image for your wallpaper by pressing the image.</b>"</label></text>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox>
      <vbox scrollable="true" height="'$MHght'" width="'$((MWdth+SWIDTH))'">
        '$BUTTONS'
      </vbox>
    </hbox>
    <hbox space-expand="true" space-fill="true">
    <hbox space-expand="false" space-fill="false">
      <button tooltip-text="Preferences">
        <label>Preferences</label>
        <width>16</width>
        <input file icon="preferences-desktop-wallpaper"></input>
        <action>exit:PREFS</action>
      </button>
    </hbox>
	<hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
      <text label="Confirmation is required when finished."></text>
    <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
    <hbox space-expand="false" space-fill="false">
      <button>
        <label>Cancel</label>
        <input file icon="gtk-cancel"></input>
        <action>kill '$PID'</action>
        <action>exit:abort</action>
      </button>
    </hbox>
    </hbox>
  </vbox>
  <variable>MAINGUI</variable>
  <input file>'$TEMP/wake'</input>
  <action signal="realize">echo started > '$TEMP/greeting'</action>
  <action signal="file-changed" type="enable">MAINGUI</action>
</window>'
	[[ -r "$TEMP/main_gui.xml" ]] || printf "%s\n" "$MAINGUI" > $TEMP/main_gui.xml
	eval "$($GTK3DIALOG -f $TEMP/main_gui.xml -c --styles=$TEMP/win.css)"
	
	if [[ "$EXIT" == "PREFS" ]]; then
		_pref
	fi
}; export -f main_gui

# preferences
_pref() {
	. "$CONF"
	if [[ -n "$EXTRA_BGDIRS" ]]; then
		[[ -n "$XTRAS" ]] || XTRAS=true
		DXTRA='	<hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <checkbox>
          <label>enable extra directories.</label>
          <variable>CXTRA</variable>
          <default>'$XTRAS'</default>
        </checkbox>
      </hbox>
    </hbox>'
	fi
	export EXTRA_DIRS='<window icon-name="gtk-preferences" title="Extra Directories" width-request="400">
	  <vbox>
	    <hbox space-expand="true" space-fill="true">
          <text use-markup="true"><label>"<b>Select extra directories.</b>"</label></text>
        </hbox>
        <hseparator space-expand="true" space-fill="true"></hseparator>
        <hbox space-expand="true" space-fill="true">
          <text><label>"Press Save and '$PROG' will restart when you are ready."</label></text>
        </hbox>
        <hseparator name="ent" space-expand="true" space-fill="true"></hseparator>
        <hbox space-expand="true" space-fill="true">
          <text><label>"Choose the directory to search wallpapers."</label></text>
        </hbox>
        <hbox space-expand="true" space-fill="true">
          <hbox space-expand="true" space-fill="true">
           <entry accept="directory" fs-title="'$PROG'">
            <variable>BACKGROUNDS0</variable>
           </entry>
          </hbox>
          <hbox space-expand="false" space-fill="false">
          <button>
            <input file icon="directory-open"></input>
            <variable>FILE_BROWSE_DIRECTORY0</variable>
            <action function="fileselect">BACKGROUNDS0</action>
          </button>
          </hbox>
        </hbox>
        <hseparator space-expand="true" space-fill="true"></hseparator>
        <hbox space-expand="true" space-fill="true">
          <hbox space-expand="true" space-fill="true">
           <entry accept="directory" fs-title="'$PROG'">
            <variable>BACKGROUNDS1</variable>
           </entry>
          </hbox>
          <hbox space-expand="false" space-fill="false">
          <button>
            <input file icon="directory-open"></input>
            <variable>FILE_BROWSE_DIRECTORY1</variable>
            <action function="fileselect">BACKGROUNDS1</action>
          </button>
          </hbox>
        </hbox>
        <hseparator space-expand="true" space-fill="true"></hseparator>
        <hbox space-expand="true" space-fill="true">
          <hbox space-expand="true" space-fill="true">
           <entry accept="directory" fs-title="'$PROG'">
            <variable>BACKGROUNDS2</variable>
          </entry>
          </hbox>
          <hbox space-expand="false" space-fill="false">
          <button>
            <input file icon="directory-open"></input>
            <variable>FILE_BROWSE_DIRECTORY2</variable>
            <action function="fileselect">BACKGROUNDS2</action>
          </button>
          </hbox>
        </hbox>
       </vbox>
	  <variable>EXTRA_DIRS</variable>
	</window>
	'
	
	[[ "$SPLASH" == 'false' ]] && CDEF=false || CDEF=true
	[[ -n "$COLOR" ]] && DEFCOL=#${COLOR} ||  DEFCOL=#666666
	[[ -n "$SWIDTH" ]] && SW=$SWIDTH || SW=0
	[[ -n "$TWIDTH" ]] && TW=$TWIDTH || TW=9
	if [[ $NUM -gt 1 ]]; then
		SPLASHPREF='    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <checkbox>
          <label>enable initial splash screen.</label>
          <variable>SPL</variable>
          <default>'$CDEF'</default>
        </checkbox>
      </hbox>
    </hbox>'
	fi
	export PGUI='<window icon-name="gtk-preferences" title="Preferences" width-request="400">
  <vbox>
    <hbox space-expand="true" space-fill="true">
      <text use-markup="true"><label>"<b>Select your preferences.</b>"</label></text>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <text><label>"Press Save and '$PROG' will restart when you are ready."</label></text>
    </hbox>
    <hseparator name="ent" space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <text><label>"Choose the directory to search wallpapers."</label></text>
    </hbox>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
      <entry accept="directory" fs-title="'$PROG'">
        <default>'$BGDIR'</default>
        <variable>BACKGROUNDS</variable>
      </entry>
      </hbox>
      <hbox space-expand="false" space-fill="false">
      <button>
        <input file icon="directory-open"></input>
        <variable>FILE_BROWSE_DIRECTORY</variable>
        <action function="fileselect">BACKGROUNDS</action>
      </button>
      </hbox>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <text label="Optionally choose extra directories"></text>
      </hbox>
      <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
      <hbox space-expand="true" space-fill="true">
        <button>
          <label>Ok</label>
          <input file icon="gtk-ok"></input>
          <action function="launch">EXTRA_DIRS</action>
        </button>
      </hbox>
    </hbox>
'$DXTRA'
'$SPLASHPREF'
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <hbox space-expand="false" space-fill="false">
        <text label="GUI width adjustment" tooltip-text="Adjust the width of the interface to suit. The thumbnail setting below may also need adjustment."></text>
        </hbox>
        <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
        <hbox space-expand="false" space-fill="false">
        <spinbutton range-min="-300" range-max="300" range-step="2">
          <variable>SW0</variable>
          <default>'$SW'</default>
        </spinbutton>
        </hbox>
      </hbox>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
        <hbox space-expand="false" space-fill="false">
        <text label="Thumbnail adjustment" tooltip-text="Adjust the width of thumbnail images. May need to adjust above setting to suit. Larger number is smaller width."></text>
        </hbox>
        <hseparator space-expand="true" space-fill="true" name="sep"></hseparator>
        <hbox space-expand="false" space-fill="false">
        <spinbutton range-min="8" range-max="12" range-step="1">
          <variable>TW0</variable>
          <default>'$TW'</default>
        </spinbutton>
        </hbox>
      </hbox>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="true" space-fill="true">
      <hbox space-expand="true" space-fill="true">
      <entry editable="false">
        <default>Choose a background color</default>
      </entry>
      </hbox>
      <hbox space-expand="false" space-fill="false">
      <colorbutton>
        <default>'$DEFCOL'</default>
        <variable>CLB0</variable>
      </colorbutton>
      </hbox>
    </hbox>
    <hseparator space-expand="true" space-fill="true"></hseparator>
    <hbox space-expand="false" space-fill="false">
      <button>
        <label>Cancel</label>
        <input file icon="gtk-cancel"></input>
        <action>kill '$PID'</action>
        <action>exit:abort</action>
      </button>
      <button>
        <label>Save</label>
        <input file icon="gtk-save"></input>
        <action>exit:SAVE</action>
      </button>
    </hbox>
  </vbox>
</window>'
	eval "$($GTK3DIALOG -p PGUI -c --styles=$TEMP/win.css)"
	if [[ -d "$BACKGROUNDS" ]]; then
		sed -i "s%^BGDIR.*$%BGDIR=\"$BACKGROUNDS\"%" "$CONF"
		rm -f "$TEMP/buttons"
		rm -f "$TEMP/main_gui.xml"
	fi
	if ! [[ -z "$BACKGROUNDS0" && -z "$BACKGROUNDS1" && -z "$BACKGROUNDS2" ]]; then # do nothing if all vars are empty
		if [[ -d "$BACKGROUNDS0" || -d "$BACKGROUNDS1" || -d "$BACKGROUNDS2" ]]; then
			if grep -q 'EXTRA_BGDIRS' "$CONF"; then
				sed -i '/EXTRA_BGDIRS/d' "$CONF"
			fi
			printf "%s" "EXTRA_BGDIRS=( " >>  "$CONF"
			[[ -n "$BACKGROUNDS0" ]] && printf "%s" "\"$BACKGROUNDS0\" " >>  "$CONF"
			[[ -n "$BACKGROUNDS1" ]] && printf "%s" "\"$BACKGROUNDS1\" " >>  "$CONF"
			[[ -n "$BACKGROUNDS2" ]] && printf "%s" "\"$BACKGROUNDS2\" " >>  "$CONF"
			printf "%s\n" ")" >>  "$CONF"
			rm -f "$TEMP/buttons"
			rm -f "$TEMP/main_gui.xml"
			# since user just set these, enable them
			echo "XTRAS=true" >> "$CONF"
		fi
	fi
	if grep -q 'SPLASH' "$CONF"; then
		sed -i "s/^SPLASH.*$/SPLASH=$SPL/" "$CONF"
	else
		echo "SPLASH=$SPL" >> "$CONF"
	fi
	if grep -q 'XTRAS' "$CONF"; then
		[[ -n  "$CXTRA" ]] && \
		sed -i "s/^XTRAS.*$/XTRAS=$CXTRA/" "$CONF"
	else
		[[ -n  "$CXTRA" ]] && \
		echo "XTRAS=$CXTRA" >> "$CONF"
	fi
	if grep -q 'SWIDTH' "$CONF"; then
		sed -i "s/^SWIDTH.*$/SWIDTH=$SW0/" "$CONF"
	else
		echo "SWIDTH=$SW0" >> "$CONF"
	fi
	echo $BACKGROUNDS0 $BACKGROUNDS1 $BACKGROUNDS2
	if grep -q 'TWIDTH' "$CONF"; then
		sed -i "s/^TWIDTH.*$/TWIDTH=$TW0/" "$CONF"
	else
		echo "TWIDTH=$TW0" >> "$CONF"
	fi
	if grep -q 'COLOR' "$CONF"; then
		sed -i "s/^COLOR.*$/COLOR=${CLB0:1:6}/" "$CONF"
	else
		echo "COLOR=${CLB0:1:6}" >> "$CONF"
	fi
	if [[ "$EXIT" == 'SAVE' ]]; then
		exec $0
	fi
}; export -f _pref


_build_command() {
	if [[ "$WAYLAND" == 'yes' ]]; then
		echo 'killall swaybg >/dev/null 2>&1' > $TEMP/cmd
		echo 'swaybg \' >> $TEMP/cmd
		cat $TEMP/Wset >> $TEMP/cmd
		echo '>/dev/null 2>&1 &' >> $TEMP/cmd
		# run it
		. "$TEMP/cmd"
		cat $TEMP/cmd > "$CONFDIR/cmd" # you can put this in your startup file
	else
		# this builds ~/.fehbg with the command below.
		echo 'killall feh >/dev/null 2>&1' > $TEMP/cmd
		echo 'feh \' >> $TEMP/cmd
		cat $TEMP/Xwset >> $TEMP/cmd
		echo '>/dev/null 2>&1 &' >> $TEMP/cmd
		# run it
		. "$TEMP/cmd"
	fi
}; export -f _build_command

_dependencies() {     # adapted from bl-includes
    # Usage: _dependencies command [command...]
    local missing_commands=()
    i=
    for i in "$@"
    do
        hash "$i" 2>/dev/null || missing_commands+=(" $i")
    done

    if [[ ${missing_commands[0]} ]];then
        ERR_MSG="This script requires the following commands: \"${missing_commands[*]}\" .\
Please install the packages containing the missing commands and re-run the script."
        _splash "${ERR_MSG}" 3
        exit
    fi
}

trap_exit() {
	trap "rm -rf $TEMP" EXIT
}; export -f trap_exit


########################      main        ##############################

# required programs
declare -a APPS
if [[ "$WAYLAND" == 'yes' ]]; then
	APPS=( "gtk3dialog" "wlr-randr" "swaybg" )
else
	APPS=( "gtk3dialog" "xrandr" "feh" )
fi
_dependencies  "${APPS[@]}" 

trap_exit
export PID=$$

# test for compatibility
KWNINX=$(pidof kwin_x11)
KWNINW=$(pidof kwin_wayland)
GNOME=$(pidof gnome-session) # covers X11 and wayland
XFCE4=$(pidof xfce4-session) # covers X11 and wayland
if [[ -n "$KWNINX" || "$KWNINW" || "$GNOME" || "$XFCE4" ]]; then # more to add
	_splash "WARNING: Your desktop may be unsupported" 7
fi

if [[ ! -d "$BGDIR" ]]; then
	_splash "Please set a background directory" 3
	_pref
else
	if  [[ -w "$(pwd)" ]]; then
		[[ -r "$BGDIR/Solid_Color.svg" ]] || cat > "$BGDIR/Solid_Color.svg" <<EOS
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 1366 768">
 <path style="fill:rgba(0,0,0,0.0);" d="m 0,0 1366,0 0,768 -1366,0 z"/>
</svg>	
EOS
	fi
fi

touch "$TEMP/greeting"
_greeting &

if [[ "$NUM" != '1' ]]; then
	# this nag can be disabled in prefs
	_splash "You have $NUM monitors connected. Carefully choose an image for each of them." 0 b &
fi

echo ================
button_gui
main_gui

#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#153 2025-02-01 12:08:07

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,008

Re: Wallpaper setter for Carbon - X11 and Wayland

micko01 wrote:

Here you go @S11

gxwwall wink

#!/bin/bash

############################ user editable #############################
main_dir=/media/5/Wallpapers/
declare -a dirs="( aircraft b-n-w Canada desert halloween Oprical-illusion xga )"
######################### end user editable ############################

# build items for the combobox
ITEMS=''
for dir in ${dirs[@]}; do
 ITEMS="$ITEMS<item>${dir}</item>\n"
done

XITEMS=$(echo -e "$ITEMS")

# gui description
export UI='<window title="Choose a dir" icon-name="gtk-question" width-request="300">
  <vbox>
    <hbox space-expand="true" space-fill="true">
      <text label="Main directory is: '$main_dir'"></text>
    </hbox>
    <hbox space-expand="true" space-fill="true">
      <text label="Make a choice"></text>
    </hbox>
    <hbox space-expand="true" space-fill="true">
      <comboboxtext>
        <variable>DIR</variable>
        '$XITEMS'
      </comboboxtext>
    </hbox>
    <hbox>
      <button ok></button>
    </hbox>
  </vbox>
</window>'

eval $(gtk3dialog -p UI -c)

XDIR=${main_dir}${DIR}
echo $XDIR
# execute xwwall
[[ -d "$DIR" ]] || exit 1 # error
xwwall -d && cd $DIR && xwwall
cd -

Does pretty much what you wanted from a gtk3dialog gui instead of Yad.

https://thumbs2.imgbox.com/16/ab/5iHAx52N_t.png https://thumbs2.imgbox.com/ab/57/NNnS2BDd_t.png

OH I gotta try that  Thank you!


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#154 2025-02-22 08:42:30

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

New version uploaded.

  • version bumped to 0.2.0

  • fixed the 'ps' string so gui dies on confirm

Check your updates for boron and carbon smile


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#155 2025-02-23 03:12:24

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

micko01 wrote:

New version uploaded.

  • version bumped to 0.2.0

  • fixed the 'ps' string so gui dies on confirm

Check your updates for boron and carbon smile

Sorry another version bump. Should be in apt by now.

  • ver 0.2.1

  • fixes some lazy typos in the help


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#156 2025-02-25 10:38:20

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

micko01 wrote:
micko01 wrote:

New version uploaded.

  • version bumped to 0.2.0

  • fixed the 'ps' string so gui dies on confirm


Check your updates for boron and carbon smile

Sorry another version bump. Should be in apt by now.

  • ver 0.2.1

  • fixes some lazy typos in the help

Apologies again roll

  • bump version

  • fix ps string for single monitors too

Get it from apt with an update.

Last edited by micko01 (2025-02-25 10:39:14)


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#157 2025-02-26 16:20:12

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,008

Re: Wallpaper setter for Carbon - X11 and Wayland

YUP!
2025·02·26 @ 13:18:49 ~

   $ ser xwwall
p   xwwall                          - Wallpaper setter for X11 and Wayland     
 
 2025·02·26 @ 13:18:59 ~
   $ 

Thank you.


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#158 2025-03-16 12:17:42

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

There's another update but nothing has changed.

What? (I hear).

Well I decided to separate out the debian/ files for 2 reasons.

1. reprepro needs new source if I change something simple in debian/. Like I had to add the file dependency in case that doesn't exist.
2. Because of 1. this eases maintenance and the version only needs a bump now when there is an actual bugfix.

The debian files are in a separate branch now. https://github.com/01micko/xwwall/tree/debian


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

#159 2025-03-16 12:39:10

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,550
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

^I think you need to update the version if anything changes anywhere in the package, including inside debian/. Otherwise you get the situation of two different .deb files having the same version number. Not cool. Bad Things can happen.

EDIT Of course that only applies to packages that have already been uploaded for users to upgrade to. As long as the .deb hasn't been anywhere except your machine then it doesn't matter.

Agreed, having to rebuild the whole package and re-add it to reprepro for some trivial change is quite a pain. I have to do that quite often, but do try to save up changes and push out a bunch together so the version bump brings something for users.

Last edited by johnraff (2025-06-01 05:55:38)


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#160 2025-04-17 06:44:31

micko01
void main()
From: Queensland, Australia
Registered: 2024-04-07
Posts: 492
Website

Re: Wallpaper setter for Carbon - X11 and Wayland

Anyway, my HP lappy died, nothing from poweron sad . Nothing through external monitor sad .

So I bought a recycled Dell with a touch screen smile . Arrived Tuesday. I installed Boron on it and it mostly works OOTB. I think the touch screen needs either a newer kernel or some Xorg config but that is of little importance. Wayland handles it much better as it does work OOTB with labwc (using my friends Vanilla Dpup, a puppy spin based on Trixie, wayland only).  Also tried a live build of Slackware-curent (which ships labwc) and works fine there too.

Anyway, Boron it is for now and since it has 1 HDMI port and USB-C I can hook up to 3 external monitors, but for now only have 2 at hand. So I tested out xwwall and the results are as expected.

Here's pretty much what my desktop looks like ATM.

2025-04-17-153721_5760x1080_scrot-thumb.png

I do really need to test with 4 at some point because there are corner cases I haven't covered yet, like setting up monitors in a 2 x 2 config instead of 4 in a row.


#!/bin/sh
echo '#include <stdio.h>\nvoid main() { printf("Hi, bunsenlabs\\n"); return; }' > bunsen.c
gcc bunsen.c -o bunsen
./bunsen

Offline

Board footer

Powered by FluxBB