# not a script as I am not showing that I used web browser to get pem for https://github.com/Smithay/smithay.git
# updated ca-certs....I do show some fixes tho below
# cargo fix1 https://github.com/rust-lang/cargo/issues/13457#issuecomment-2063947062

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe "
P=niri
V=v26.04
V1=26.04
SRC=$P-$V1
SRC2=$SRC/target/release
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc clang rust gdk-pixbuf2-dev graphene-dev gtk4-dev libadwaita-dev libdisplay-info-dev libinput-dev seatd-dev  "    
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

URL1=https://raw.githubusercontent.com/void-linux/void-packages/refs/heads/master/srcpkgs/niri/patches
URL2=https://github.com/niri-wm/niri/archive/refs/tags
cd /tmp
/usr/local/bin/wget -nc --no-check-certificate \
$URL1/remove-session.patch \
$URL2/v26.04.tar.gz 
tar xvf v*gz
cd $SRC
patch -p1 -i ../remove-session.patch

# fix cargo ssl error for https://index.crates.io/config.json 
##############################################################  Note I build by root so change pathway if you use non-root
[ -d /root/.cargo ] || mkdir -p /root/.cargo
echo 'cargo-net.git-fetch-with-cli = true
registries.crates-io.protocol = "git" ' > /root/.cargo/config.toml

# fix cargo ssl error for https://github.com/Smithay/smithay.git
#################################################################
# A add the crt to /usr/local/share/ca-certificates and follow instructions
# B /etc/ssl pathway as per home bin
[ -d /etc/ssl/certs ] || mkdir -p /etc/ssl/certs
[ -f /etc/ca-certificates.conf ] || cp -p /usr/local/share/ca-certificates/files/ca-certificates.conf /etc
update-ca-certificates
ln -s /usr/local/etc/ssl/certs/ca-certificates.crt /etc/ssl/cacert.pem
ln -s /usr/local/etc/ssl/certs/ca-certificates.crt /etc/ssl/ca-bundle.crt

cargo build --release # takes 4m 2 s
cd /tmp

# doc
######
mkdir -p $P-doc/usr/local/share/doc/$P/wiki
cp $SRC/docs/wiki/* $P-doc/usr/local/share/doc/$P/wiki
cp $SRC/resources/default-config.kdl $P-doc/usr/local/share/doc/$P/

# main
######
mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v 3' > $P/usr/local/share/doc/$P/LICENSE

mkdir -p $P/usr/local/bin $P/usr/local/share/wayland-sessions
cp $SRC2/niri $P/usr/local/bin
strip --strip-unneeded $P/usr/local/bin/$P


cp $SRC/resources/*.desktop $P/usr/local/share/wayland-sessions
sed 's|bin|local/bin|' -i $P/usr/local/share/wayland-sessions/$P.desktop # patch did not use usr loc pathway

# the config is currently at resources/default-config.kdl but we need home config called ~/.config/niri/config.kdl
###########################################################
mkdir -p $P/usr/local/share/$P/files
cp $SRC/resources/default-config.kdl $P/usr/local/share/$P/files/config.kdl
CFG=$P/usr/local/share/$P/files/config.kdl

# DELETE section  
################
sed '632d'     -i $CFG # ending }
sed '625,627d' -i $CFG # quit section
# from here To show list frees up Mod+letter OR SUPER+letter
# make letter h j k l  ....L then used for lock for swaylock....i&u used elsewhere already
sed '474,475D' -i $CFG 
sed '470d'     -i $CFG 
sed '465,466d' -i $CFG 
sed '461,462d' -i $CFG 
sed '457d'     -i $CFG 
sed '453d'     -i $CFG 
sed '446,449d' -i $CFG 
sed '437,440d' -i $CFG 
sed '430,431d' -i $CFG 
sed '423,424d' -i $CFG 
sed '416,419d' -i $CFG 
sed '407,410d' -i $CFG 
sed '360,367d' -i $CFG # show list of kbs

# EDIT layout section
#####################
sed 's|waybar|sfwbar|'g -i $CFG
sed 's|commonly used|great IMHO|' -i $CFG

# ADD kb combos section
#######################
echo '
// Line 25 ENABLES numlock  to disable preface it with // turning it into a comment and not an action
// lines 369-72 detail how to run multiple commands using spawn-sh
// a number of letters freed up to use with Mod or SUPER 

// Mod + /, which is usually the same as Mod-?, shows a list of important hotkeys.
// when you search for duplicates Mod can mean SUPER so do multiples for those please
Mod+Slash { show-hotkey-overlay; }

// binds for executing your fav TCEs...change to suit...check with $ niri validate
SUPER+Return { spawn "lxterminal"; }
SUPER+Slash  { show-hotkey-overlay; } // shows a list of important hotkeys.
Ctrl+Alt+Delete { quit; } // alternative to super+e below

SUPER+A      { spawn "apps";       }
SUPER+C      { spawn "cpanel";     }
SUPER+D      { spawn "fuzzel";     } // SUPER+F already defined as toggle fullscreen
ALT+E        { spawn "exittc";     }
SUPER+E      { quit;               } // The quit action will show a confirmation dialog to avoid accidental exits.
ALT+F        { spawn "firefox";    } 
SUPER+L      { spawn "swaylock";   } // no need to run swaylock -fl
ALT+M        { spawn "mnttool";    }
SUPER+P      { spawn "pcmanfm";    }
SUPER+S      { spawn "sfwbar";     } // optional TCE if not loaded does not bork niri
SUPER+T      { spawn "l3afpad";    }

} ' >> $CFG
###############  end of key bindings back to other stuff

echo '#!/bin/sh
tce-load -i niri  
seatd-launch niri ' >  $P/usr/local/share/$P/files/start-niri
chmod 755 $P/usr/local/share/$P/files/start-niri

# tce.install
############# 
mkdir -p  $P/usr/local/tce.installed
echo '#!/bin/sh
USER=`cat /etc/sysconfig/tcuser`
DIR1=/home/$USER/.local/bin && FILE1=$DIR1/start-niri && SRC1=/usr/local/share/niri/files/start-niri
[ -d $DIR1 ] || mkdir -p $DIR1 && chown $USER:staff $DIR1
[ -f $FILE1 ] || cp $SRC1 $DIR1/ && chmod 755 $FILE1 && chown $USER:staff $FILE1    

DIR2=/home/$USER/.config/niri && FILE2=$DIR2/config.kdl && SRC2=/usr/local/share/niri/files/config.kdl
[ -d $DIR2 ] || mkdir -p $DIR2 && chown $USER:staff $DIR2
[ -f $FILE2 ] || cp $SRC2 $DIR2/ && chmod 644 $FILE2 && chown -R $USER:staff $FILE2   ' > $P/usr/local/tce.installed/$P 
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed


# TCZ them
#######
LIST="$P $P-doc "
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:          niri-doc.tcz 
Description:    wiki of text files
                video demo https://tinyurl.com/niri-demo
Version:        26.04
Author:         Ivan Molodetskikh & contributors
Original-site:  https://github.com/niri-wm/niri
Copying-policy: GPL v3 
Size:           132K		
Extension_by:   aus9 
Tags:           wayland  
Comments:       As I have reduced config which was 633 lines
                I have put and renamed the orginal config as
                /usr/local/share/doc/niri/default-config.kdl

Change-log:     2026/09/25 v 26.04 on 17x
Current:        2026/09/25 '  > $P-doc.tcz.info

echo 'Title:          niri.tcz 
Description:    scrollable-tiling wayland compositor
Version:        26.04
Author:         Ivan Molodetskikh & contributors
Original-site:  https://github.com/niri-wm/niri
Copying-policy: GPL v3  
Size:           12M		
Extension_by:   aus9 
Tags:           wayland  
Comments:       Windows are arranged in columns on an infinite strip going to the right. 
                Opening a new window never causes existing windows to resize. Workspaces are 
                dynamic and arranged vertically. For multi monitor users- Every monitor has 
                its own separate window strip. Windows can never "overflow" onto an adjacent monitor.

                On first start a popup of mainly logo + letter key bindings appears. Lots more in the config.
                The letter is in uppercase but you input in lowercase. The main ones to watch out are:
                (logo + E) = exit to prompt while (Alt + E) opens exittc for shutdown and reboot ONLY
                "Mod" is a special modifier equal to Super when running on a TTY, and is Alt when running as 
                a winit window. If sfwbar loaded, it too will autostart  

                On first start I recommend you launch your file manager or text editor and edit
                ~/.config/config.kdl # you can load niri inside X but most errors will resolve when on tty 
                (wayland) to edit your config or start-niri command. Feel free to alter your dep file or your 
                start-niri bin file. If your kb changes result in duplicates or bad syntax, you will get a report. 
                niri will not start if bad config. Inside niri run $ niri validate to see errors. Suggest make one 
                change and validate please!
                
                You can have 2 or more different kb shortcuts to do the same action, but I have removed a number of those,
                to free up more free letters for your combinations. Most of my changes are at the BOTTOM of the config. 
                Original Config had over 600 lines, so $ niri validate is a must command. Note the word "spawn" 
                in key bindings make no sense for a one off command like swaylock but pressing kb combo will repeat command
                so repeating (eg) launch terminal is what gives you a scrollable work space. (logo + ->) will scroll to the right 
                etc....You can always have one opened app for each workspace!

                Optional TCES ignoring your preferred text editor/file mgr,media player
                swaylock --but kb combo works without needing  $ swaylock -fl
                sfwaybar - a configurable panel at top of monitor....better than waybar IMHO 
                fuzzel - a fuzzy search of desktop files and launcher
                rofi or wofi -- executables search and launcher 
               
                # xwayland not supported instead use (if needed)
                TCE=xwayland-satellite                
      
Change-log:     2026/09/25 v 26.04 on 17x
Current:        2026/09/25  '  > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED'
# libpangocairo-1.0.so.0]libpango-1.0.so.0] pango
# libgobject-2.0.so.0]libglib-2.0.so.0] glib2 pango
# libcairo.so.2] cairo  pango
# libpipewire-0.3.so.0] pipewire
# libdisplay-info.so.1] libdisplay-info
# libgbm.so.1] libEGL
# libseat.so.1] seatd
# libudev.so.0] udev-lib
# libinput.so.10] libinput
# libpixman-1.so.0] pixman
# libxkbcommon.so.0] libxkbcommon

echo 'libdisplay-info.tcz
libinput.tcz 
libEGL.tcz
lxterminal.tcz
pipewire.tcz 
seatd.tcz  ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

