You are not logged in.

#61 2024-12-19 07:08:14

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

Re: Wallpaper setter for Carbon - X11 and Wayland

^This all looks very promising. Fixed window for _splash and free for main sounds just right.
I'll get those patches in and report back.

First I want to backport picom though. Just for a change of pace.
EDIT well that didn't take long.
picom 11.2-0.1 from Sid built with no problems and fixed the round corners with xrender backend - on both xwwall and geany. cool

So we can just wait till it arrives in Trixie.

(Still can't use glx backend on qemu though. It's running fine on my real machine.)

Last edited by johnraff (2024-12-19 07:46:01)


...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

#62 2024-12-19 09:43:27

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

Re: Wallpaper setter for Carbon - X11 and Wayland

johnraff wrote:

3) Choose image, instead of pressing image in popup, mistakenly press "Confirm" in main dialogue - app freezes. I don't know how this should be fixed.

Now completely fixed because the main window is gone when the popup appears. smile

---
To display user's local wallpapers BGDIR needs adjusting:

export BGDIR="${BGDIR:-$HOME/Pictures/wallpapers}"

We've established that the symlink from $HOME/Pictures/wallpapers/bunsen to /usr/share/images/bunsen/wallpapers is being followed OK?

---

micko01 wrote:

I always find efficient shell is better than python (probably more opining really!)

Bash can be slow sometimes, depending on what you're trying to do (efficient shell, right), but I've generally found python to be slower, yes. And if you can trim the shell code down to what will run on dash, for example, it's a good bit faster. (The BL places menu for example - when it was written the speed difference was really noticable. With modern hardware, not so much.)

---

micko01 wrote:

...a configurable background color if you choose 'center'...
Only 1 color is supported, seems a bit complicated to add custom colors for each image but is possible. If I do I may as well support just a solid color for BG as well.

Even if you don't support individual backgrounds for each image, it might be worth being able to set a plain colour BG.

---
The confirm boxes might usefully display the selected image name.

---
The preferences dialogue box seems to be offering an image, when I would expect it to be allowing the user to choose the directory to search (recursively) for wallpapers.

---
And, workflow. Till just now I was wondering if it was necessary to get the user to confirm their choice of wallpaper no less than three times. How about going straight from the first popup where the mode and output are chosen - then no more questions asked? Just now I clicked the main dialogue when I should have clicked "confirm" and got warned that there were no more displays to configure, so I sort of see what that last confirmation might be doing, but still think it feels like overkill.

But OTOH, consider this kind of user: applies a wallpaper, decides the one they want is the next one, so wants to go back to the main image choice window to try that. Or maybe wants to try a different Mode. These people would prefer not to have to start the app up from scratch each time, but keep the main window until they press "Close".

But the final call on these things is yours.


...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

#63 2024-12-19 11:28:40

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

Re: Wallpaper setter for Carbon - X11 and Wayland

johnraff wrote:
johnraff wrote:

3) Choose image, instead of pressing image in popup, mistakenly press "Confirm" in main dialogue - app freezes. I don't know how this should be fixed.

Now completely fixed because the main window is gone when the popup appears. smile

---
To display user's local wallpapers BGDIR needs adjusting:

export BGDIR="${BGDIR:-$HOME/Pictures/wallpapers}"

We've established that the symlink from $HOME/Pictures/wallpapers/bunsen to /usr/share/images/bunsen/wallpapers is being followed OK?

---

Good and Yes smile


johnraff wrote:
micko01 wrote:

I always find efficient shell is better than python (probably more opining really!)

Bash can be slow sometimes, depending on what you're trying to do (efficient shell, right), but I've generally found python to be slower, yes. And if you can trim the shell code down to what will run on dash, for example, it's a good bit faster. (The BL places menu for example - when it was written the speed difference was really noticable. With modern hardware, not so much.)

#!/usr/bin/busybox ash offers a good compromise but still lose bash globbing and some other bash features. dash is a bit limited for such a complex script and externals can slow things a lot

---

johnraff wrote:
micko01 wrote:

...a configurable background color if you choose 'center'...
Only 1 color is supported, seems a bit complicated to add custom colors for each image but is possible. If I do I may as well support just a solid color for BG as well.

Even if you don't support individual backgrounds for each image, it might be worth being able to set a plain colour BG.

Could probably add a colorbutton to the main gui.


johnraff wrote:

---
The confirm boxes might usefully display the selected image name.

Agreed, and shall implement, probably as tool-tips.


johnraff wrote:

---
The preferences dialogue box seems to be offering an image, when I would expect it to be allowing the user to choose the directory to search (recursively) for wallpapers.

I need to mangle the string before the GUI, not after. Shall implement soon, and was aware of that shortfall.

johnraff wrote:

---
And, workflow. Till just now I was wondering if it was necessary to get the user to confirm their choice of wallpaper no less than three times. How about going straight from the first popup where the mode and output are chosen - then no more questions asked? Just now I clicked the main dialogue when I should have clicked "confirm" and got warned that there were no more displays to configure, so I sort of see what that last confirmation might be doing, but still think it feels like overkill.

But OTOH, consider this kind of user: applies a wallpaper, decides the one they want is the next one, so wants to go back to the main image choice window to try that. Or maybe wants to try a different Mode. These people would prefer not to have to start the app up from scratch each time, but keep the main window until they press "Close".

But the final call on these things is yours.

On my local version, the confirm splash pops when monitor count is reached, not after. The actual confirm GUI can be re-entrant if a user makes a mistake or isn't happy.

So far, I think it's going pretty well, but probably more real world feedback is needed, especially the X11 side with multiple monitors (more than 2).

Perhaps I should build gtk3dialog for bookworm so that ordinary Boron users can join in on the testing.The more testers and feedback, the better the app will be. smile


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

Offline

#64 2024-12-20 02:00:58

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

Re: Wallpaper setter for Carbon - X11 and Wayland

micko01 wrote:

So far, I think it's going pretty well

Very much so. I think it's already an improvement on both Nitrogen and Azote. cool

but probably more real world feedback is needed, especially the X11 side with multiple monitors (more than 2).

Perhaps I should build gtk3dialog for bookworm so that ordinary Boron users can join in on the testing.The more testers and feedback, the better the app will be. smile

Sounds like a good idea. We can ship it in BL's backports repo.


...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

#65 2024-12-20 02:18:11

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

Re: Wallpaper setter for Carbon - X11 and Wayland

common wallpaper for Xorg and Wayland

I've just run into this, but if you set a wallpaper on Xorg and then boot into Wayland, 'xwwall --restore' will not restore it. Likewise in the other direction. The two backgound settings are independent. It's obvious because the Xorg wallpaper is set in ~/.fehbg and Wayland in ~/.config/xwwall/cmd

Carrying the same wallpaper over between the two sessions would mean some code rewriting, and I don't know if you'd feel like doing it or not.

For example, instead of ~/.config/xwwall/cmd, create eg ~/.config/xwwall/background storing the display mode and image path, and then create the feh or swaybg command on the fly depending on the current session.

There might be some complications I haven't thought of...

EDIT Maybe another - possibly better - way would be to generate both swaybg and feh commands at the time the image is chosen - when a few milliseconds extra don't matter - apply the appropriate one for the session, but store both as two separate files. Then when restoring, choose the appropriate file. (I guess .fehbg can be ignored in this scenario.)
EDIT2 No, it looks too difficult to generate the command if not running in that kind of session. sad

Last edited by johnraff (2024-12-20 05:15:59)


...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

#66 2024-12-20 13:26:36

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

Re: Wallpaper setter for Carbon - X11 and Wayland

Make it available and I'll test it here on SoxDog (BearDog = LilyDog)
Debian 12.8 = pure X


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#67 2024-12-21 00:12:58

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

Re: Wallpaper setter for Carbon - X11 and Wayland

johnraff wrote:

common wallpaper for Xorg and Wayland

Let's shelve this for now. It looks like too much work for whatever benefit.
Some users might actually prefer to have different wallpapers for Xorg and Wayland. smile

micko01 wrote:

Perhaps I should build gtk3dialog for bookworm so that ordinary Boron users can join in on the testing.

This, I think. Get feedback from other users like Sector11.


...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

#68 2024-12-21 23:19:53

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

Re: Wallpaper setter for Carbon - X11 and Wayland

New version, well ver num is the same but there's quite some differences from the last iteration.

Additions:

  • bugfix the directory chooser in Preferences. Now shows just the directory, Regarding this I've opted for only 1 directory. 2 is possible but one may encounter errors. See next point.

  • cap the image limit at 100. This could go higher, haven't actually tested the limit but I do know if '$TEMP/buttons' grows too big we get Argument list too long error and it crashes the program without warning. A _splash is popped notifying the user of the 100 limit and the program carries on. I *think* the limit is based on bytes, so it isn't so easy to calculate. Maybe I can count the bytes in '$TEMP/buttons' and cut off at some conservative level. The limit is around 2MB, on my 64 bit x86 system but this may (IDK) vary across arches and endianess. It's calculated by

    getconf ARG_MAX

    I'll look into this soon.

  • Because of the above bug, do a force rm of TEMP when the prog is re-entrant. I was finding that 'TEMP/buttons' was being appended to after Preferences. That's how I discovered the bug!

  • Added a tooltip showing the image name to the Confirm GUI.

  • Remove Confirm button from MAIN gui

  • Add a label 'Preferences' to that button in MAIN gui - balances the GUI a bit

  • Add a few more checks and pop appropriate warnings or fatal errors.

Here it is:

#!/bin/bash

export V=0.1.0
export GTK3DIALOG
[[ -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"

case "$1" in
	--restore)
	if [[ -f "$CONFDIR/cmd" && -n "$WAYLAND_DISPLAY" ]]; then
		. "$CONFDIR/cmd" && exit 0
	elif [[ -x "$HOME/.fehbg" ]]; then
		exec "$HOME/.fehbg"
	else
		exit 1
	fi
	;;
	-*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 --restore\n\t\trestore backgrounds at session start.\n"
	echo -e "\ttry \"man $PROG\" for more information."
	exit 0
	;;
esac

# sort out the monitors and positions
if [[ -n "$WAYLAND_DISPLAY" ]]; 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
echo 'window#splash {
	background: rgba(0,0,0,0.0);
}
#splash {
	background: #5E003E;
	color: #ffffff;
	border-radius: 10px;
	padding: 2px;
}
' > "$TEMP/win.css"



# get the primary output
e=0
if [[ -n "$WAYLAND_DISPLAY" ]]; 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 W=$((X / 9))
	export H=$((Y / 10))
	export MW=$((X / 2))
	export MH=$((Y * 2 / 3))
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 $i $TEMP/xx2$e && e=$((e+1))
	done
	rm $TEMP/Xmonitor* # finished with these
	export NUM
	read NUM < $TEMP/number
	echo $NUM outputs
	. $TEMP/xx0
	export W=$((X / 9))
	export H=$((Y / 10))
	export MW=$((X / 2))
	export MH=$((Y * 2 / 3))
fi

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

# splash window
_splash() {
	[[ -z "$1" ]] && return
	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>'
			;;
		2);;
		3)ACT='<action>main_gui &</action><action>exit:OK</action>';;
		4)ACT='<action>confirm_gui &</action><action>exit:OK</action>';;
		5)ACT='<action>kill '$PID'</action><action>exit:abort</action>';KILL='<action>kill '$PID'</action>';;
		*)ACT='<action>exit:OK</action>';;
	esac
	IVAL=4
	re='^[0-9]'
	[[ $3 =~ $re ]] && IVAL=$3
	[[ $2 -eq 4 ]] && IVAL=4
	echo '<window '$POPT' name="splash" width-request="360">
	<vbox name="splash">
		<hbox name="splash">
		<hbox space-expand="false" space-fill="false">
		  <pixmap name="splash"><width>42</width><input file icon="gtk-info"></input></pixmap>
		  <timer interval="'$IVAL'" visible="false">'$KILL'<action>exit:BYE</action></timer>
	    </hbox>
	    <hbox space-expand="true" space-fill="true">
	      <text name="splash">
			<label>'"$1"'</label>
		  </text>
		</hbox>
		</hbox>
		<hbox name="splash">
			'$DIS'
			<button>
			  <label>OK</label>
			  <input file icon="gtk-ok"></input>
			  '$ACT'
			</button>
		</hbox>
	</vbox>
</window>' | $GTK3DIALOG -s --styles=$TEMP/win.css
	[[ "$2" == '1' ]] && exit $2
}; export -f _splash

# sort selections
_selections() {
	echo '<hbox>' > $TEMP/ret
	cat $TEMP/selected | while read -r sel
	do
		echo '    <pixmap tooltip-text="'${sel##*\/}'">
		  <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="background" 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></button>
	    <button no></button>
	  </hbox>
	</vbox>
</window>'
	eval "$($GTK3DIALOG -p CON -c --styles=$TEMP/win.css)"
	case $EXIT in
		Yes)_build_command;;
		*)return 1;;
	esac
}; export -f confirm_gui

# populate the main GUI
button_gui() {
	c=0
	shopt -s globstar
	for WALL in "$BGDIR"/*{,/**}
	do
		file -b --mime-type "$WALL" | grep -q 'image' || continue # test mime
		# we take advantage of bash math here
		# for a nicish GUI width *must* be consistent
		i=$((c/4))
		echo '  <button image-position="top" tooltip-text="'"${WALL##*/}"'">
	        <variable>BG'$c'</variable>
	        <input file>'"\"$WALL\""'</input>
			<height>'$W'</height>
			<width>'$W'</width>
			<action>_output '"\"$WALL\""' &</action>
			<action>exit:BG'$c'</action>
	      </button>' >> $TEMP/buttonsx$i
	      c=$((c+1))
	      if [[ $c -ge 100 ]];then
			  _splash "Warning: Limit of 100 images" 2 2 &
			  break
		  fi
	done
	shopt -u globstar
	for j in $(ls "$TEMP" | grep 'buttonsx[0-9]*')
	do echo "		<hbox>
		$(cat "$TEMP/$j")
		</hbox>" >> $TEMP/buttons
	done
}

# sub GUI
sub_gui() {
	[[ -z "$COLOR" ]] && COLOR=999999
	if [[ -n "$WAYLAND_DISPLAY" ]]; then
		CCOL="-c $COLOR"
		SS='Wset'
		ACTION='<action>echo -e " -o $OUT -m $MODE '$CCOL' \\ \n\t -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}"
		SS='Xwset'
		ACTION='<action>if [[ "$MODE" == "stretch" || "$MODE" == "fit" ]];then MODE=fill;fi; echo -e " --bg-$MODE '${XCOL}' \\ \n\t'\'$1\'' \\" >> '$TEMP/$SS'</action>'
	fi
	[[ -r "$TEMP/increment" ]] || echo -n 1 > $TEMP/increment
	INC=$(cat $TEMP/increment)
	# set default for entry
	case $INC in
		1)DEFAULT=$(sed '1s/item/default/g' < $TEMP/OP | sed -n 1p) ;;
		2)DEFAULT=$(sed '2s/item/default/g' < $TEMP/OP | sed -n 2p) ;;
		3)DEFAULT=$(sed '3s/item/default/g' < $TEMP/OP | sed -n 3p) ;;
		4)DEFAULT=$(sed '4s/item/default/g' < $TEMP/OP | sed -n 4p) ;;
		5)DEFAULT=$(sed '5s/item/default/g' < $TEMP/OP | sed -n 5p) ;;
		6)DEFAULT=$(sed '6s/item/default/g' < $TEMP/OP | sed -n 6p) ;;
	esac
	if [[ $INC -gt $NUM ]]; then
		_splash "You are at your monitor limit. Confirm?" 4
	else
	export SUBGUI='<window icon-name="background" title="Selection">
	<vbox>
    <hbox space-expand="true" space-fill="true">
	    <text><label>Choose Mode and press the image</label></text>
	  </hbox>
    <hbox space-expand="true" space-fill="false">
      <text use-markup="true"><label>"<big>Mode:</big>"</label></text>
      <comboboxtext>
        <variable>MODE</variable>
        <item>stretch</item>
        <item>center</item>
        <item>tile</item>
        <item>fit</item>
      </comboboxtext>
    </hbox>
	 <hbox space-expand="true" space-fill="false">
      <text use-markup="true"><label>"<big>Output:</big>"</label></text>
      <entry>
        <variable>OUT</variable>
        '$DEFAULT'
      </entry>
    </hbox>
	  <hbox space-expand="true" space-fill="true">
		<button tooltip-text="Press image to confirm or No to reject and confinue.">
		  <variable>CBG</variable>
	      <input file>'$1'</input>
	  	  <width>320</width>
		  <action>echo -n '$((INC+1))' > $TEMP/increment</action> 
		  <action>if grep -q $OUT '$TEMP'/'$SS' >/dev/null 2>&1; then _splash "Only 1 wall per monitor. Maybe you have reached the monitor limit?." 3;fi;</action>
		  <action>echo '$1' >> '$TEMP'/selected</action>
		  '$ACTION'
		  <action>sed -i "s% $%%g" '$TEMP/$SS'</action>
		  <action>if [[ '$INC' -ge '$NUM' ]]; then _splash "Confirm your selection?" 4;fi &</action>
		  <action>if [[ '$INC' -lt '$NUM' ]]; then main_gui;fi &</action>
	      <action>exit:CBG</action>
		</button>
	  </hbox>
	  <hbox>
	    <text label="Output: '$INC'"></text>
	    <button>
	      <label>No</label>
	      <input file icon="gtk-no"></input>
	      <action>main_gui &</action>
	      <action>exit:NO</action>
	    </button>
	  </hbox>
	</vbox>
   </window>'
	$GTK3DIALOG -p SUBGUI -c --styles=$TEMP/win.css
	fi
}; export -f sub_gui
	
# populate the main GUI
main_gui() {
	[[ -r "$TEMP/main_gui.xml" ]] && _splash "Please wait ..." 2 2 &
	BUTTONS=$(cat $TEMP/buttons)
	export MAINGUI='<window icon-name="background" title="Background Choice" width-request="'$MW'">
  <vbox>
    <hbox space-expand="true" space-fill="true">
      <text use-markup="true"><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="'$MH'">
        '$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"></hseparator>
      <text label="Press Confirm when you are ready."></text>
    <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>
    </hbox>
    </hbox>
  </vbox>
</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
	[[ "$SPLASH" == 'false' ]] && CDEF=false || CDEF=true
	[[ -n "$COLOR" ]] && DEFCOL=#${COLOR} ||  DEFCOL=#cccccc
	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>
    <hbox space-expand="true" space-fill="true">  
      <text><label>"Just choose any image file in your chosen directory."</label></text>
    </hbox>
    <hbox space-expand="true" space-fill="true">  
      <hbox space-expand="true" space-fill="true">  
      <entry accept="directory">
        <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">  
        <checkbox>
          <label>enable initial splash screen.</label>
          <variable>SPL</variable>
          <default>'$CDEF'</default>
        </checkbox>
      </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"
		button_gui
	fi
	if grep -q 'SPLASH' $CONF; then
		sed -i "s/^SPLASH.*$/SPLASH=$SPL/" $CONF
	else
		echo "SPLASH=$SPL" >> $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 options for output
_output() {
	[[ -n "$WAYLAND_DISPLAY" ]] && 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
	. $CONF
	sub_gui "$FBG"
}; export -f _output

_build_command() {
	if [[ -n "$WAYLAND_DISPLAY" ]]; 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

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


########################      main        ##############################
trap_exit
export PID=$$

if [[ -n "$WAYLAND_DISPLAY" ]]; then
	case "$XDG_CURRENT_DESKTOP" in
		wlroots|labwc|sway*|river|niri|hyprland)echo "$XDG_CURRENT_DESKTOP";; # this can be expanded later
		*)_splash "Unfortunately your desktop $XDG_CURRENT_DESKTOP is unsupported" 5;;
	esac
fi

if [[ ! -d "$BGDIR" ]]; then
	_splash "Please set a background directory" 3
	_pref
fi

if [[ "$NUM" != '1' ]]; then
	_splash "You have $NUM monitors connected. Carefully choose an image for each of them." 0 &
fi
echo ================
button_gui
main_gui

BTW, I have successfully built gtk3dialog in a Boron VM and posted a git repo branch, with debian/ dir thanks to @johnraff:
https://github.com/01micko/gtk3dialog/tree/boron

I can't really host it at my repo as IDK how to add 'boron' to reprepro. I could if I know that. So far yet to find out.


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

Offline

#69 2024-12-22 02:16:13

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

Re: Wallpaper setter for Carbon - X11 and Wayland

micko01 wrote:

I can't really host it at my repo as IDK how to add 'boron' to reprepro.

Try adding a new stanza to <reprepro_base>/conf/distributions.
Here's what I've got for the boron backports:

Origin: bunsenlabs
Label: bunsenlabs
Codename: bookworm-backports
Suite: bookworm-backports
Architectures: i386 amd64 source
Components: main
Description: BunsenLabs bookworm backports repository
SignWith: <BL Release key>
NotAutomatic: yes
ButAutomaticUpgrades: yes
Contents: allcomponents

Compare with what you've got for carbon and adjust accordingly.
(We use "bookworm-backports" so users installing BL backports can simultaneously pull in deps from Debian backports with apt install <package> -t bookworm-backports, but you needn't do that.)

If you've got an "incoming" directory you might need to add the distribution to the "Allow:" line in <reprepro_base>/conf/incoming.


...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

#70 2024-12-22 05:52:11

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

Re: Wallpaper setter for Carbon - X11 and Wayland

johnraff wrote:
micko01 wrote:

I can't really host it at my repo as IDK how to add 'boron' to reprepro.

Try adding a new stanza to <reprepro_base>/conf/distributions.
Here's what I've got for the boron backports:

Origin: bunsenlabs
Label: bunsenlabs
Codename: bookworm-backports
Suite: bookworm-backports
Architectures: i386 amd64 source
Components: main
Description: BunsenLabs bookworm backports repository
SignWith: <BL Release key>
NotAutomatic: yes
ButAutomaticUpgrades: yes
Contents: allcomponents

Compare with what you've got for carbon and adjust accordingly.
(We use "bookworm-backports" so users installing BL backports can simultaneously pull in deps from Debian backports with apt install <package> -t bookworm-backports, but you needn't do that.)

If you've got an "incoming" directory you might need to add the distribution to the "Allow:" line in <reprepro_base>/conf/incoming.

Works big_smile

sqg7kqDt.png

More to come, maybe a new thread for boron users to enable my repo. ATM, only gtk3dialog there, but this prog could end up there soon. And maybe a couple more useful ones.

Oh, need to rewrite that bottom line in the GUI!


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

Offline

#71 2024-12-22 06:04:00

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

Re: Wallpaper setter for Carbon - X11 and Wayland

@Sector11. You can join the fun now. See https://forums.bunsenlabs.org/viewtopic.php?id=9273


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

Offline

#72 2024-12-22 09:52:20

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

Re: Wallpaper setter for Carbon - X11 and Wayland

Looking good!

micko01 wrote:

bugfix the directory chooser in Preferences.

Preferences text could be changed to something like "Choose the directory to search wallpapers"
But it does the job.

cap the image limit at 100.
A _splash is popped notifying the user of the 100 limit and the program carries on.

I've got a lot of wallpapers and see that popup. No problem.

I can't figure out what the preference to "enable initial splash screen" is doing.

Added a tooltip showing the image name to the Confirm GUI.

I'd like to see that tooltip on the Selection GUI stage TBH.
POC, line #337:

<button tooltip-text="'"${1##*/}"$'\n''Press image to confirm or No to reject and confinue.">

(This is assuming that $1 always carries a single filepath.)

Perhaps more annoying is that a "confirm your selection" popup only has an OK button, and times out, closing the whole app. Press OK in time, to get yet another "confirm" popup. Let's get more user feedback, but personally I'd be fine if the wallpaper was set when the Selection image is clicked. Though perhaps there are complications with multiple monitors that those extra steps are needed for?

One other small thing,  the app window comes up slightly too narrow, with a horizontal scroll bar, both on my Carbon VM (X or Wayland):
vzZ0t0tl.png

and also my Boron machine:
OnLGHOql.png

The window can be dragged a bit bigger (with some juddering though) but @micko01 your screenshots always look perfect. (This has been happening since the very first version.)


...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

#73 2024-12-22 13:23:30

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

Re: Wallpaper setter for Carbon - X11 and Wayland

micko01 wrote:

@Sector11. You can join the fun now. See https://forums.bunsenlabs.org/viewtopic.php?id=9273

No good for me.

 2024·12·22 @ 10:19:21 ~
   $ get azote
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 azote : Depends: libgtk-3-0t64 but it is not installable
E: Unable to correct problems, you have held broken packages.
 
 2024·12·22 @ 10:20:03 ~
   $ 

Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#74 2024-12-22 19:51:57

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

Re: Wallpaper setter for Carbon - X11 and Wayland

Sector11 wrote:
micko01 wrote:

@Sector11. You can join the fun now. See https://forums.bunsenlabs.org/viewtopic.php?id=9273

No good for me.

 2024·12·22 @ 10:19:21 ~
   $ get azote
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 azote : Depends: libgtk-3-0t64 but it is not installable
E: Unable to correct problems, you have held broken packages.
 
 2024·12·22 @ 10:20:03 ~
   $ 

Sounds like you enabled carbon-trixie repo. Delete it from your apt sources and try again following the 'or if on boron' instruction. I clarified a little by adding a 'for carbon trixie' heading to the page.

azote is not in my 'boron' repo. Only 1 package is, gtk3dialog and that's the one we want for xwwall.


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

Offline

#75 2024-12-23 08:45:46

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

Re: Wallpaper setter for Carbon - X11 and Wayland

This will be the last until next week.

  • fixed preferences screen so checkbox is not shown in single monitor setup

  • if dual mons on X the splash for dual monitors shows at top-left, all other splashes are centered. On wayland shows bottom, others center top

  • when done, go directly to confirm_gui - no need for a nag there.

  • Up image limit to 250. 300 works for me but 350 fails with 'Argument list too long'

  • widened the hbox for the button_gui, hopefully no horizontal scrolbar shows up and images pack in a bit better

  • maybe others that I fail to recall in the limited time I have right now!

Here goes:

#!/bin/bash

export V=0.1.0
export GTK3DIALOG
[[ -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"

case "$1" in
	--restore)
	if [[ -f "$CONFDIR/cmd" && -n "$WAYLAND_DISPLAY" ]]; then
		. "$CONFDIR/cmd" && exit 0
	elif [[ -x "$HOME/.fehbg" ]]; then
		exec "$HOME/.fehbg"
	else
		exit 1
	fi
	;;
	-*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 --restore\n\t\trestore backgrounds at session start.\n"
	echo -e "\ttry \"man $PROG\" for more information."
	exit 0
	;;
esac

# sort out the monitors and positions
if [[ -n "$WAYLAND_DISPLAY" ]]; 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
echo 'window#splash {
	background: rgba(0,0,0,0.0);
}
#splash {
	background: #5E003E;
	color: #ffffff;
	border-radius: 10px;
	padding: 2px;
}
' > "$TEMP/win.css"



# get the primary output
e=0
if [[ -n "$WAYLAND_DISPLAY" ]]; 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 W=$((X / 9))
	export H=$((Y / 10))
	export MW=$((X / 2))
	export MH=$((Y * 2 / 3))
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 $i $TEMP/xx2$e && e=$((e+1))
	done
	rm $TEMP/Xmonitor* # finished with these
	export NUM
	read NUM < $TEMP/number
	echo $NUM outputs
	. $TEMP/xx0
	export W=$((X / 9))
	export H=$((Y / 10))
	export MW=$((X / 2))
	export MH=$((Y * 2 / 3))
fi

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

# splash window
_splash() {
	[[ -z "$1" ]] && return
	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>'
			;;
		2)CR=-c;;
		3)CR=-c;ACT='<action>main_gui &</action><action>exit:OK</action>';;
		5)CR=-c;ACT='<action>kill '$PID'</action><action>exit:abort</action>';KILL='<action>kill '$PID'</action>';;
		*)CR=-c;ACT='<action>exit:OK</action>';;
	esac
	IVAL=4
	re='^[0-9]'
	[[ $3 =~ $re ]] && IVAL=$3
	if [[ -n "$WAYLAND_DISPLAY" ]]; then
		[[ "$3" == 'b' ]] && POPT='edge="bottom" dist="200"'
	else
		[[ "$3" == 'b' ]] && CR="--geometry=+0+0" && echo $CR
	fi
	TIMER='<timer interval="'$IVAL'" visible="false">'$KILL'<action>exit:BYE</action></timer>'
	echo '<window '$POPT' name="splash" width-request="360">
	<vbox name="splash">
		<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>
		</hbox>
		<hbox name="splash">
			'$DIS'
			<button>
			  <label>OK</label>
			  <input file icon="gtk-ok"></input>
			  '$ACT'
			</button>
		</hbox>
	</vbox>
</window>' | $GTK3DIALOG -s "$CR" --styles=$TEMP/win.css
	[[ "$2" == '1' ]] && exit $2
}; export -f _splash

# sort selections
_selections() {
	echo '<hbox>' > $TEMP/ret
	cat $TEMP/selected | while read -r sel
	do
		echo '    <pixmap tooltip-text="'${sel##*\/}'">
		  <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="background" 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></button>
	    <button no></button>
	  </hbox>
	</vbox>
</window>'
	eval "$($GTK3DIALOG -p CON -c --styles=$TEMP/win.css)"
	case $EXIT in
		Yes)_build_command;;
		*)return 1;;
	esac
}; export -f confirm_gui

# populate the main GUI
button_gui() {
	rm -f ~/zbuttons 
	c=0
	shopt -s globstar
	for WALL in "$BGDIR"/*{,/**}
	do
		file -b --mime-type "$WALL" | grep -q 'image' || continue # test mime
		# we take advantage of bash math here
		# for a nicish GUI width *must* be consistent
		i=$((c/4))
		V='  		<button image-position="top" tooltip-text="'"${WALL##*/}"'">
	        <variable>BG'$c'</variable>
	        <input file>'"\"$WALL\""'</input>
			<height>'$W'</height>
			<width>'$W'</width>
			<action>_output '"\"$WALL\""' &</action>
			<action>exit:BG'$c'</action>
	      </button>' 
	      echo "$V" >> $TEMP/buttonsx$i
	      c=$((c+1))
	      if [[ $((i*4)) -eq $c ]]; then
	          echo "<hbox>" >> ~/zbuttons
	          echo "$V" >> ~/zbuttons
	      else
	          echo "$V" >> ~/zbuttons
	      fi
	      if [[ $c -ge 250 ]];then
			  _splash "Warning: Limit of 250 images" 2 2 &
			  break
		  fi
	done
	shopt -u globstar
	for j in $(ls "$TEMP" | grep 'buttonsx[0-9]*')
	do echo "		<hbox>
		$(cat "$TEMP/$j")
		</hbox>" >> $TEMP/buttons
	done
}

# sub GUI
sub_gui() {
	[[ -z "$COLOR" ]] && COLOR=999999
	if [[ -n "$WAYLAND_DISPLAY" ]]; then
		CCOL="-c $COLOR"
		SS='Wset'
		ACTION='<action>echo -e " -o $OUT -m $MODE '$CCOL' \\ \n\t -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}"
		SS='Xwset'
		ACTION='<action>if [[ "$MODE" == "stretch" || "$MODE" == "fit" ]];then MODE=fill;fi; echo -e " --bg-$MODE '${XCOL}' \\ \n\t'\'$1\'' \\" >> '$TEMP/$SS'</action>'
	fi
	[[ -r "$TEMP/increment" ]] || echo -n 1 > $TEMP/increment
	INC=$(cat $TEMP/increment)
	# set default for entry
	case $INC in
		1)DEFAULT=$(sed '1s/item/default/g' < $TEMP/OP | sed -n 1p) ;;
		2)DEFAULT=$(sed '2s/item/default/g' < $TEMP/OP | sed -n 2p) ;;
		3)DEFAULT=$(sed '3s/item/default/g' < $TEMP/OP | sed -n 3p) ;;
		4)DEFAULT=$(sed '4s/item/default/g' < $TEMP/OP | sed -n 4p) ;;
		5)DEFAULT=$(sed '5s/item/default/g' < $TEMP/OP | sed -n 5p) ;;
		6)DEFAULT=$(sed '6s/item/default/g' < $TEMP/OP | sed -n 6p) ;;
	esac
	if [[ $INC -gt $NUM ]]; then
		_splash "You are at your monitor limit. Confirm?" 4
	else
	export SUBGUI='<window icon-name="background" title="Selection">
	<vbox>
    <hbox space-expand="true" space-fill="true">
	    <text><label>Choose Mode and press the image</label></text>
	  </hbox>
    <hbox space-expand="true" space-fill="false">
      <text use-markup="true"><label>"<big>Mode:</big>"</label></text>
      <comboboxtext>
        <variable>MODE</variable>
        <item>stretch</item>
        <item>center</item>
        <item>tile</item>
        <item>fit</item>
      </comboboxtext>
    </hbox>
	 <hbox space-expand="true" space-fill="false">
      <text use-markup="true"><label>"<big>Output:</big>"</label></text>
      <entry>
        <variable>OUT</variable>
        '$DEFAULT'
      </entry>
    </hbox>
	  <hbox space-expand="true" space-fill="true">
		<button tooltip-text="'"${1##*/}"$'\n''Press image to confirm or No to reject and confinue.">
		  <variable>CBG</variable>
	      <input file>'$1'</input>
	  	  <width>320</width>
		  <action>echo -n '$((INC+1))' > $TEMP/increment</action> 
		  <action>if grep -q $OUT '$TEMP'/'$SS' >/dev/null 2>&1; then _splash "Only 1 wall per monitor. Maybe you have reached the monitor limit?." 3;fi;</action>
		  <action>echo '$1' >> '$TEMP'/selected</action>
		  '$ACTION'
		  <action>sed -i "s% $%%g" '$TEMP/$SS'</action>
		  <action>if [[ '$INC' -ge '$NUM' ]]; then confirm_gui;fi &</action>
		  <action>if [[ '$INC' -lt '$NUM' ]]; then main_gui;fi &</action>
	      <action>exit:CBG</action>
		</button>
	  </hbox>
	  <hbox>
	    <text label="Output: '$INC'"></text>
	    <button>
	      <label>No</label>
	      <input file icon="gtk-no"></input>
	      <action>main_gui &</action>
	      <action>exit:NO</action>
	    </button>
	  </hbox>
	</vbox>
   </window>'
	$GTK3DIALOG -p SUBGUI -c --styles=$TEMP/win.css
	fi
}; export -f sub_gui
	
# populate the main GUI
main_gui() {
	[[ -r "$TEMP/main_gui.xml" ]] && _splash "Please wait ..." 2 2 &
	BUTTONS=$(cat $TEMP/buttons)
	export MAINGUI='<window icon-name="background" title="Background Choice">
  <vbox>
    <hbox space-expand="true" space-fill="true">
      <text use-markup="true"><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="'$MH'" width="'$MW'">
        '$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"></hseparator>
      <text label="Confirmation is required when finished."></text>
    <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>
    </hbox>
    </hbox>
  </vbox>
</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
	[[ "$SPLASH" == 'false' ]] && CDEF=false || CDEF=true
	[[ -n "$COLOR" ]] && DEFCOL=#${COLOR} ||  DEFCOL=#cccccc
	if [[ $NUM > 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>
    <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">
        <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>
'$SPLASHPREF'
    <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"
		button_gui
	fi
	if grep -q 'SPLASH' $CONF; then
		sed -i "s/^SPLASH.*$/SPLASH=$SPL/" $CONF
	else
		echo "SPLASH=$SPL" >> $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 options for output
_output() {
	[[ -n "$WAYLAND_DISPLAY" ]] && 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
	. $CONF
	sub_gui "$FBG"
}; export -f _output

_build_command() {
	if [[ -n "$WAYLAND_DISPLAY" ]]; 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

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


########################      main        ##############################
trap_exit
export PID=$$

if [[ -n "$WAYLAND_DISPLAY" ]]; then
	case "$XDG_CURRENT_DESKTOP" in
		wlroots|labwc|sway*|river|niri|hyprland)echo "$XDG_CURRENT_DESKTOP";; # this can be expanded later
		*)_splash "Unfortunately your desktop $XDG_CURRENT_DESKTOP is unsupported" 5;;
	esac
fi

if [[ ! -d "$BGDIR" ]]; then
	_splash "Please set a background directory" 3
	_pref
fi

if [[ "$NUM" != '1' ]]; then
	_splash "You have $NUM monitors connected. Carefully choose an image for each of them." 0 b &
fi
echo ================
button_gui
main_gui

Merry Xmas!


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

Offline

#76 2024-12-23 12:56:26

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

Re: Wallpaper setter for Carbon - X11 and Wayland

micko01 wrote:

Sounds like you enabled carbon-trixie repo. Delete it from your apt sources and try again following the 'or if on boron' instruction. I clarified a little by adding a 'for carbon trixie' heading to the page.

azote is not in my 'boron' repo. Only 1 package is, gtk3dialog and that's the one we want for xwwall.

See, when it's S11-proof, anyone can do it.

DONE!

micko01 wrote:

This will be the last until next week.

{snip}

Merry Xmas!

NICE!

[Warning: Limit of 250 images]
And no sub-folders

ME:

/media/5/Wallpapers
→ 53 folders
→ 397 files

BUT works like a charm.
I Like it!
See it here

Merry Christmas


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#77 2024-12-28 05:52:19

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

Re: Wallpaper setter for Carbon - X11 and Wayland

^Good job @S11, nice screenshot. Thanks for testing.

---

Next.

Just tested on my boron VM, no surprises.

  • reworked the splash placement in X

  • In X, splash screens are now on the top layer - <window type-hint="6" ...>

  • removed some redundant code - possibly more to go

  • added a 'refresh' button to confirm_gui (with tooltip) so that the main_gui pops to try again

  • added a tooltip in the main_gui opening sentence with the image count

Seems to flow a bit more now - less clunk tongue

#!/bin/bash

export V=0.1.0
export GTK3DIALOG
[[ -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"

case "$1" in
	--restore)
	if [[ -f "$CONFDIR/cmd" && -n "$WAYLAND_DISPLAY" ]]; then
		. "$CONFDIR/cmd" && exit 0
	elif [[ -x "$HOME/.fehbg" ]]; then
		exec "$HOME/.fehbg"
	else
		exit 1
	fi
	;;
	-*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 --restore\n\t\trestore backgrounds at session start.\n"
	echo -e "\ttry \"man $PROG\" for more information."
	exit 0
	;;
esac

# sort out the monitors and positions
if [[ -n "$WAYLAND_DISPLAY" ]]; 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
echo 'window#splash {
	background: rgba(0,0,0,0.0);
}
#splash {
	background: #5E003E;
	color: #ffffff;
	border-radius: 10px;
	padding: 2px;
}
' > "$TEMP/win.css"



# get the primary output
e=0
if [[ -n "$WAYLAND_DISPLAY" ]]; 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 W=$((X / 9))
	export H=$((Y / 10))
	export MW=$((X / 2))
	export MH=$((Y * 2 / 3))
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 $i $TEMP/xx2$e && e=$((e+1))
	done
	rm $TEMP/Xmonitor* # finished with these
	export NUM
	read NUM < $TEMP/number
	echo $NUM outputs
	. $TEMP/xx0
	export W=$((X / 9))
	export H=$((Y / 10))
	export MW=$((X / 2))
	export MH=$((Y * 2 / 3))
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;;
		*)CR=-c;ACT='<action>exit:OK</action>';;
	esac
	IVAL=4
	re='^[0-9]'
	[[ $3 =~ $re ]] && IVAL=$3
	if [[ -n "$WAYLAND_DISPLAY" ]]; 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">
		<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>
		</hbox>
		<hbox name="splash">
			'$DIS'
			<button>
			  <label>OK</label>
			  <input file icon="gtk-ok"></input>
			  '$ACT'
			</button>
		</hbox>
	</vbox>
</window>' | $GTK3DIALOG -s "$CR" --styles=$TEMP/win.css
	[[ "$2" == '1' ]] && exit $2
}; export -f _splash

# sort selections
_selections() {
	echo '<hbox>' > $TEMP/ret
	cat $TEMP/selected | while read -r sel
	do
		echo '    <pixmap tooltip-text="'${sel##*\/}'">
		  <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="background" 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></button>
	    <button no></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;;
		REFRESH)rm -f $TEMP/increment $TEMP/selected $TEMP/[XW]set rm -f $TEMP/ret
		        main_gui &;;
		*)return 1;;
	esac
}; export -f confirm_gui

# populate the main GUI
button_gui() {
	c=0
	shopt -s globstar
	for WALL in "$BGDIR"/*{,/**}
	do
		file -b --mime-type "$WALL" | grep -q 'image' || continue # test mime
		# we take advantage of bash math here
		# for a nicish GUI width *must* be consistent
		i=$((c/4))
		V='  		<button image-position="top" tooltip-text="'"${WALL##*/}"'">
	        <variable>BG'$c'</variable>
	        <input file>'"\"$WALL\""'</input>
			<height>'$W'</height>
			<width>'$W'</width>
			<action>_output '"\"$WALL\""' &</action>
			<action>exit:BG'$c'</action>
	      </button>' 
	      echo "$V" >> $TEMP/buttonsx$i
	      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 $(ls "$TEMP" | grep 'buttonsx[0-9]*')
	do echo "		<hbox>
		$(cat "$TEMP/$j")
		</hbox>" >> $TEMP/buttons
	done
}

# sub GUI
sub_gui() {
	[[ -z "$COLOR" ]] && COLOR=999999
	if [[ -n "$WAYLAND_DISPLAY" ]]; then
		CCOL="-c $COLOR"
		SS='Wset'
		ACTION='<action>echo -e " -o $OUT -m $MODE '$CCOL' \\ \n\t -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}"
		SS='Xwset'
		ACTION='<action>if [[ "$MODE" == "stretch" || "$MODE" == "fit" ]];then MODE=fill;fi; echo -e " --bg-$MODE '${XCOL}' \\ \n\t'\'$1\'' \\" >> '$TEMP/$SS'</action>'
	fi
	[[ -r "$TEMP/increment" ]] || echo -n 1 > $TEMP/increment
	INC=$(cat $TEMP/increment)
	# set default for entry
	case $INC in
		1)DEFAULT=$(sed '1s/item/default/g' < $TEMP/OP | sed -n 1p) ;;
		2)DEFAULT=$(sed '2s/item/default/g' < $TEMP/OP | sed -n 2p) ;;
		3)DEFAULT=$(sed '3s/item/default/g' < $TEMP/OP | sed -n 3p) ;;
		4)DEFAULT=$(sed '4s/item/default/g' < $TEMP/OP | sed -n 4p) ;;
		5)DEFAULT=$(sed '5s/item/default/g' < $TEMP/OP | sed -n 5p) ;;
		6)DEFAULT=$(sed '6s/item/default/g' < $TEMP/OP | sed -n 6p) ;;
	esac
	if [[ $INC -gt $NUM ]]; then
		_splash "You are at your monitor limit. Confirm?" 4
	else
	export SUBGUI='<window icon-name="background" title="Selection">
	<vbox>
    <hbox space-expand="true" space-fill="true">
	    <text><label>Choose Mode and press the image</label></text>
	  </hbox>
    <hbox space-expand="true" space-fill="false">
      <text use-markup="true"><label>"<big>Mode:</big>"</label></text>
      <comboboxtext>
        <variable>MODE</variable>
        <item>stretch</item>
        <item>center</item>
        <item>tile</item>
        <item>fit</item>
      </comboboxtext>
    </hbox>
	 <hbox space-expand="true" space-fill="false">
      <text use-markup="true"><label>"<big>Output:</big>"</label></text>
      <entry>
        <variable>OUT</variable>
        '$DEFAULT'
      </entry>
    </hbox>
	  <hbox space-expand="true" space-fill="true">
		<button tooltip-text="'"${1##*/}"$'\n''Press image to confirm or No to reject and confinue.">
		  <variable>CBG</variable>
	      <input file>'$1'</input>
	  	  <width>320</width>
		  <action>echo -n '$((INC+1))' > $TEMP/increment</action> 
		  <action>if grep -q $OUT '$TEMP'/'$SS' >/dev/null 2>&1; then _splash "Only 1 wall per monitor. Maybe you have reached the monitor limit?." 3;fi;</action>
		  <action>echo '$1' >> '$TEMP'/selected</action>
		  '$ACTION'
		  <action>sed -i "s% $%%g" '$TEMP/$SS'</action>
		  <action>if [[ '$INC' -ge '$NUM' ]]; then confirm_gui;fi &</action>
		  <action>if [[ '$INC' -lt '$NUM' ]]; then main_gui;fi &</action>
	      <action>exit:CBG</action>
		</button>
	  </hbox>
	  <hbox>
	    <text label="Output: '$INC'"></text>
	    <button>
	      <label>No</label>
	      <input file icon="gtk-no"></input>
	      <action>main_gui &</action>
	      <action>exit:NO</action>
	    </button>
	  </hbox>
	</vbox>
   </window>'
	$GTK3DIALOG -p SUBGUI -c --styles=$TEMP/win.css
	fi
}; export -f sub_gui
	
# populate the main GUI
main_gui() {
	[[ -r "$TEMP/main_gui.xml" ]] && _splash "Please wait ..." 6 2 &
	BUTTONS=$(cat $TEMP/buttons)
	export MAINGUI='<window icon-name="background" title="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="'$MH'" width="'$MW'">
        '$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"></hseparator>
      <text label="Confirmation is required when finished."></text>
    <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>
    </hbox>
    </hbox>
  </vbox>
</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
	[[ "$SPLASH" == 'false' ]] && CDEF=false || CDEF=true
	[[ -n "$COLOR" ]] && DEFCOL=#${COLOR} ||  DEFCOL=#cccccc
	if [[ $NUM > 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>
    <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">
        <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>
'$SPLASHPREF'
    <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 grep -q 'SPLASH' $CONF; then
		sed -i "s/^SPLASH.*$/SPLASH=$SPL/" $CONF
	else
		echo "SPLASH=$SPL" >> $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 options for output
_output() {
	[[ -n "$WAYLAND_DISPLAY" ]] && 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
	. $CONF
	sub_gui "$FBG"
}; export -f _output

_build_command() {
	if [[ -n "$WAYLAND_DISPLAY" ]]; 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

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


########################      main        ##############################
trap_exit
export PID=$$

if [[ -n "$WAYLAND_DISPLAY" ]]; then
	case "$XDG_CURRENT_DESKTOP" in
		wlroots|labwc|sway*|river|niri|hyprland)echo "$XDG_CURRENT_DESKTOP";; # this can be expanded later
		*)_splash "Unfortunately your desktop $XDG_CURRENT_DESKTOP is unsupported" 5;;
	esac
fi

if [[ ! -d "$BGDIR" ]]; then
	_splash "Please set a background directory" 3
	_pref
fi

if [[ "$NUM" != '1' ]]; then
	_splash "You have $NUM monitors connected. Carefully choose an image for each of them." 0 b &
fi
echo ================
button_gui
main_gui

Might be near time for this to go up to github, but I'll have to make a nice icon, manpage, .desktop and debian/ stuffs.

Hope everyone had a good Chrissy (Typical Aussie, abreviate everything)


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

Offline

#78 2024-12-28 08:01:41

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

Re: Wallpaper setter for Carbon - X11 and Wayland

^All working nicely cool

...except for that irritating not-quite-wide-enough window:
Just in case it was a desktop size thing I resized my VM to the display's full 1440x900 before taking this screenshot:
fxI5ftgl.png
On real metal Boron with the same size display the issue is gone. vyJoYBP.gif
If nobody else is seeing this, let's leave it, at least for now.

@micko anything I could try tweaking in the script to see if it affects this?

Last edited by johnraff (2024-12-28 08:13:30)


...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

#79 2024-12-28 09:35:33

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

Re: Wallpaper setter for Carbon - X11 and Wayland

johnraff wrote:

^All working nicely cool

..[snip]

@micko anything I could try tweaking in the script to see if it affects this?

@ line 395 (main_gui)

<vbox scrollable="true" height="'$MH'" width="'$MW'">

Maybe try adding a few pixels.

<vbox scrollable="true" height="'$MH'" width="'$((MW+20))'">

20 is rather arbitrary, increase or decrease as required and if it turns out to be an issue on bare metal we can add that as a config option.

At least your images seem to line up a bit nicer now. I didn't really notice the horizontal scrollbar on my boron VM but it is there. +20 fixes it for me but my VM is 1280x800 so a little wider. Try 50 or something for your situation.

G1KXyGH.png


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

Offline

#80 2024-12-28 16:09:55

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

Re: Wallpaper setter for Carbon - X11 and Wayland

micko01 wrote:

^Good job @S11, nice screenshot. Thanks for testing.

You're welcome.
New script running just fine.

But with my forgetter, since I'm still using nitrogen for now, I forgot the name:
SO:

 2024·12·28 @ 12:40:11 ~/bin
   $ ftxt GTK3DIALOG
xwall
4:export GTK3DIALOG
5:[[ -z "$GTK3DIALOG" ]] && GTK3DIALOG=gtk3dialog
217:</window>' | $GTK3DIALOG -s "$CR" --styles=$TEMP/win.css
252:	eval "$($GTK3DIALOG -p CON -c --styles=$TEMP/win.css)"
374:	$GTK3DIALOG -p SUBGUI -c --styles=$TEMP/win.css
417:	eval "$($GTK3DIALOG -f $TEMP/main_gui.xml -c --styles=$TEMP/win.css)"
498:	eval "$($GTK3DIALOG -p PGUI -c --styles=$TEMP/win.css)"
 
 2024·12·28 @ 12:40:21 ~/bin
   $ 

Oh yea xwall ----

I made a change for me at least on line 388:

	export MAINGUI='<window icon-name="background" title="xwall's Background Choice">

Seeing the name will help my rememberer!

OOPS!  Did not like the " ' " so:

	export MAINGUI='<window icon-name="background" title="xwall | Background Choice">

Check it out here

And also Lines 1 and 2

#!/bin/bash
# ~/bin/xwall

@John - I do not have the problem you are having.
EDIT:  OH I see - a VM ..... mine is running live on a 1920x1080 monitor.

Last edited by Sector11 (2024-12-28 16:11:55)


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

Board footer

Powered by FluxBB