I'm new to the world of Raspberry Pi, so apologies if the answer to these questions seem obvious.
I do a bit of soldering now and then, and I've been given a Raspberry Pi 4 module, and had an extra monitor around, so I decided to make a pseudo microscope with it to help with the soldering, or even just for having a closer look at PCBs. I got a pi camera module with the thin ribbon cable and set up an arm to hold it so it looks down at the table top.
As far as getting it to run, it works. I use:
rpicam-vid -t 0 --width 1920 --height 1080 -f
This provides a live view on the monitor. Even though the fullscreen flag is in the command, it's not quite full screen and you can see a bit of the desktop environment at the top of the screen. That turned out to be fortunate as I can right click the tab that is linked with the camera feed and kill it when I'm done. The next step was I that I wanted to make it so that the camera module would start automatically on startup. I wanted to just have the mouse and not need the keyboard, since I bring the whole microscope setup into a workshop area, so the less I need to bring in, the better. I added a startup script so it would initiate the camera module after startup, but it seems it does this before the desktop environment is loaded, so there is no way to stop the camera module, other than to just unplug the power cable.
How do I go about initiating the camera module automatically but in such a way that I can kill it and safely shut down the Raspberry Pi with the mouse?
My setup is Raspberry Pi 4 Raspberry Pi OS 64-bit based on Debian 12