To share one monitor, keyboard and mouse between two devices, mac mini and a macbook try:

brew cask install barrier

Then to avoid changing the input source by using the buttons in the monitor try https://github.com/kfix/ddcctl:

cd /tmp
git clone https://github.com/kfix/ddcctl.git
cd ddcctl
make && make install

In my case to switch from the mac mini (HDMI) to the laptop via (DP) I use:

ddcctl -d 1 -i 15

From the laptop (USB-C -> DP) to HDMI, switch back to the mac mini:

ddcctl -d 1 -i 17