#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   exit 1
fi

export CFLAGS="-mtune=generic -Os -pipe"  
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions "

P=woodland
V=2.0.5
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc librsvg-dev libinput-dev wlroots-dev pkgconf-dev stb-dev xwayland xkbcommon-woodland "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
rm -rf *.svg # assume none but to be safe
/usr/local/bin/wget -nc --no-check-certificate \
https://github.com/DiogenesN/woodland/archive/refs/tags/v2.0.5.tar.gz \
https://www.dropbox.com/scl/fi/gs6w1c855atpxowcogzf1/files1.tar.gz?rlkey=y4qat6kcgv1kwlod8dojghasl&st=mcrquetq&dl=0
tar xvf files1.tar.gz
tar xvf v*gz
cd $SRC
cp include/xdg-shell-protocol.h                       /usr/local/include
cp include/pointer-constraints-unstable-v1-protocol.h /usr/local/include
cp include/wlr_foreign_toplevel_management_v1.h       /usr/local/include
chmod 755 ./configure
sed 's|-march=native||'                 -i Makefile.in
sed 's|usr/include|usr/local/include| ' -i Makefile.in
sed 's|usr/lib|usr/local/lib| '         -i Makefile.in
./configure # defaults to usr/local
# gcc found......make found......pkgconf found.....libstb-dev found....libdrm-dev found.
# librsvg2-dev found.....libinput-dev found....libcairo2-dev found....libdbus-1-dev found.
# libwayland-dev found.libpixman-1-dev found..libxkbcommon-dev found..libwlroots-0.18-dev found...All done!
make -j6  # seconds
make install DESTDIR=/tmp/$P
cd /tmp

# main
######
mkdir -p $P/usr/local/share/doc/$P $P/usr/local/share/wayland-sessions $P/usr/local/share/$P/files $P/usr/local/tce.installed
echo 'GPL v 2' > $P/usr/local/share/doc/$P/COPYING

echo '[Desktop Entry]
Name=Woodland
Comment=A stacking Wayland compositor
Exec=woodland
Type=Application ' > $P/usr/local/share/wayland-sessions/$P.desktop

echo '#!/bin/sh
tce-load -i woodland  
seatd-launch dbus-run-session woodland ' > $P/usr/local/share/$P/files/wood
chmod 755 $P/usr/local/share/$P/files/wood

mv *.svg $P/usr/local/share/$P/files/
mv woodland.ini $P/usr/local/share/$P/files/
chown root:root -R $P/usr/local/share/$P/files/ # as I packed them as local user then uploaded etc

# tce.install
#############  
echo '#!/bin/sh
# on first run, the ini file would have been created but lack TC functions
# in forcing a TC-centric ini, I was missing icons until forced them too
# window_sizes.db is created upon exitting woodland

USER=`cat /etc/sysconfig/tcuser`
DIR1=/home/$USER/.local/bin && FILE1=$DIR1/wood && SRC1=/usr/local/share/woodland/files/wood
[ -d $DIR1 ] || mkdir -p $DIR1
if [ ! -f $FILE1 ] ; then
   cp $SRC1 $DIR1 && chmod 755 $FILE1 && chown -R $USER:staff $FILE1
fi    
DIR2=/home/$USER/.config/woodland && DIR3=/home/$USER/.config/woodland/icons && SRC2=/usr/local/share/woodland/files
[ -d $DIR2 ] || mkdir -p $DIR2
[ -d $DIR3 ] || mkdir -p $DIR3
LISTICONS="brightness.svg dio-volume-high.svg dio-volume-low.svg dio-volume-mid.svg dio-volume-off.svg network.svg network-off.svg noicon.svg notes.svg"
for Z in $LISTICONS
do
if [ ! -f $DIR3/$Z ] ; then
   cp $SRC2/$Z $DIR3 && chmod 644 $DIR3/$Z
fi 
done 
LISTFILES="woodland.ini"
for Z in $LISTFILES
do
if [ ! -f $DIR2/$Z ] ; then
   cp $SRC2/$Z $DIR2 && chmod 644 $DIR2/$Z
fi
done
chown -R $USER:staff $DIR2 # do the lot in one hit   ' > $P/usr/local/tce.installed/$P 
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed
strip --strip-unneeded $P/usr/local/bin/$P

# TCZ them
#######
LIST="$P "
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal 

echo 'Title:          woodland.tcz
Description:    wlroots stacking compositor
Version:        2.0.5
Author:         Nicolas Dio
Original-site:  https://github.com/DiogenesN/woodland
Copying-policy: GPL v 2
Size:           120K
Extension_by:   aus9 @linuxquestions.org
Tags:           wayland compositor wlroots
Comments:       Entire desktop can be zoomed by holding down Super key and rotate mouse wheel 
                up or down or rotate wheel top LH corner.
                HOVER your mouse pointer bottom RH corner to bring up widget panel 
                Some panel items need extra packages or setups YMMV
                Clicking network widget may freeze for ~ 10s for scanning wifi 
                but I only tested the time/calender widget as I am on a tower. 

                "within 10mm" means clicking at 45 degree angle to corner. That is, 
                pretend there is a line from LH bottom corner to RH top corner. You are clicking
                on that line at the top or bottom....now read on. You can change ini setting            
                
                Clicking "within 10mm" of top RH corner brings up window list for all opened apps 
                including minimised apps. Restore minimised Apps via this list. 
                Rotate opened apps by Alt+Tab and reverse rotate by Ctl+Alt+Tab.
                WARNING stacking windows might hide another window needing your input.
                This happened to me in copying over an existing file using pcmanfm, there were
                2 dialog boxes...one was hidden until I rotated the stack.

                Clicking "within 10mm" bottom LH corner brings up menu list
                -- acts as alternative to wbar. Each item is clickable text.
                                
                If your app has no maximise button you can drag the window borders to max.
                All gtk3 max buttons to work. Max. button in firefox acts like F11
                ...press F11 to get back to normal.
                                
                TCEs NOT SUPPORTED - exittc sfwbar slurp swaylock waybar wlr-randr xwayland 
                apps GUI can play up. If clicking browse a few times fails, then 
                Super+Esc -> wood and retry please. Apps works better fully maximised

                TCE positives
                * lxterminal has been defined as your terminal and can be changed
                ---- remember to edit your ini & dep file if you prefer another terminal
                ---- apps GUI works on wayland with lxterminal
                * brightnessctl for brightness and read brightness and panel sections
                  https://github.com/DiogenesN/woodland/blob/main/README.md
                * grim for screenshots
                * wlrctl for window placement (not tested)
                * wofi for search and launch executables
                Note that both grim and wofi have menu and kb shortcuts but not made dependency                

                You need to exit woodland and restart if you modify the ini for the following:
                welcome_screen d_power_path background tap_to_click window placement zoom_speed
                So EDITS of kb shortcuts and menus are refreshed without doing anything special.
                Hard coded kb shortcuts are:  Super+Esc to prompt
                Super+x closes the current window. Alt+Tab already discussed.
                
                On first use...I recommend you stay in current desktop and run $ tce-load -i woodland
                It creates ~/.local/bin/wood and files under ~/.config/woodland includes ini file
                To start desktop Exit to prompt & run $ wood 
                When you exit woodland via the methods in this info or ini file, a new file is created
                under your ~.config/woodland for sizes.....you can safely ignore this.
                You either force sizes via the ini file or click max. button or drag the window edges
                You decide what to change in your ini file, but I recommend that you at least try out
                lxterminal which is a forced dependency as I assume you are not a wayland addict. LOL

                For wayland addicts
                If you like woodland to be your default desktop, replace startx in /home/<name>/.profile
                with /home/<name>/.local/bin/wood....change <name> to local login name 
                I suggest you leave current desktop in boot list so you can get back to it by
                Super+Esc then run startx
                                       
Change-log:     2025/12/03 v 2.0.5 on 16x
Current:        2025/12/03 '  > $P.tcz.info

# xkbcommon-woodland  is not a run dep but a keyboard config dependency....without it kb combos fail
# seatd is loaded by wlroots 
readelf -d $P/usr/local/bin/* | grep 'NEEDED'
#libdbus-1.so.3] dbus ..lxterminal BUT NOT ALL TERMINALS THAT RUN ON WAYLAND
#librsvg-2.so.2] librsvg
#libgio-2.0.so.0]libgobject-2.0.so.0]libglib-2.0.so.0] glib2 librsvg
#libgdk_pixbuf-2.0.so.0] gdk-pibuf2 librsvg
#libcairo.so.2] cairo librsvg
#libwlroots-0.18.so] wlroots
#libinput.so.10] libinput
#libpixman-1.so.0] pixman librsvg
#libxkbcommon.so.0] libxkbcommon lxterminal (also havoc foot tilda sakura gnome-terminal)
#libwayland-server.so.0] wayland wlroots
# submitqc will delete dbus and libxkbcommon but I leave in as members may change terminal
# lxterminal is defined in ini....x*woodland is needed by ini for kb shortcuts


echo 'dbus.tcz
librsvg.tcz
wlroots.tcz
libinput.tcz
xkbcommon-woodland.tcz 
lxterminal.tcz' > $P.tcz.dep

# I want all run dependencies but submitqc will remove 2 that lxterminal loads...but members may change away from it

