You might want to test DISPLAY_DEVICE_ATTACHED_TO_DESKTOP and/or DISPLAY_DEVICE_ACTIVE on the DISPLAY_DEVICE of the monitor, not the graphics device as you're currently doing (i.e. with monitorDevice)
DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
DISPLAY_DEVICE_ACTIVE
DISPLAY_DEVICE
monitorDevice