I have my work laptop and my personal PC connected to my PC monitor. I'm thinking up an automation to detect when I'm working, i.e.there's motion on my desk and the monitor is displaying HDMI 1 for my work machine and not HDMI 2 for my personal machine. Without this distinction my rule will treat working and playing Elden Ring identically.
I used to use a KVM to switch sources. It could have made this work because there's an LED on each channel, i could have rigged a nodemcu to report which led was on, but that KVM has been giving me issues so I'm back to square one on that idea.
Additional challenges that may thwart your ideas: 1) my work laptop is issued by a law firm with incredible security, i cannot install anything or change any configuration on that machine. However my PC is all mine so if there's a script that could send an http request to makerapi when the computer is NOT displaying to a monitor, i could install it there and that would mostly work because their are only the two binary options, assuming i don't shut down the PC. 2) my work laptop remains active even when I'm not working. It does not sleep, shut down, lock or log off when I'm switched to the other source.