I use my desk for both working from home with my company MacBook & gaming/development using my desktop PC.
Both computers are plugged into both monitors, and I use a UGREEN USB 3.0 Switch to swap my peripherals between the two computers as needed.
In order to get the monitors to come along for the ride with the peripherals, I made use of a display protocol, DDC/CI, which allows you to control monitor settings via software.
I used a program ControlMyMonitor on Windows and Lunar on MacOS to send these input commands. This took a little bit of trial and error to get working, as the commands are different for each monitor. Some monitors don’t support this at all, notably LG monitors - which is why I got rid of mine 😓 and bought a Dell instead.
MacOS
I use a free tool, Stecker that detects when devices are connected/disconnected and can be configured to run a script or Apple Shortcut.
Stecker detects when my keyboard is disconnected by my USB switch and runs this Apple shortcut which triggers Lunar to change the monitor input.
Windows
I looked into tools similar to Stecker for Windows but didn’t have much luck - there’s a few option like using AutoHotKey but from what I could tell they relied on rapidly polling if devices were still connected, rather than being triggered by an operating system event.
It seemed a little inefficient to be checking if my keyboard was connected multiple times a second, so instead I opted for a simple batch script that I run manually when I switch computers.
ControlMyMonitor.exe /SetValue "Primary" 60 16
ControlMyMonitor.exe /SetValue "Secondary" 60 15
I keep a shortcut to this script on my desktop and run it just before I hit the USB switch to change my peripherals. It’s not as seamless as the MacOS solution, but it works well enough for me.
One last problem
If I try to switch to a computer with turned off displays, e.g. power saving has kicked in, the monitor will keep searching for a input and get stuck on one computer, or a no signal screen. I’ve mostly fixed this by setting longer times before displays are turned off, and remembering to jiggle the mouse or mash some keys before the monitor input switching gives up.