Do not call explicit lockf(lOCK_UN) to not unlock the file buffers are flushed. This is simpler than adding flush() call.
Gui daemon isn't aware of multihead parameters, also gui protocol doesn't support such information - currently by design it is configured via Qubes RPC service. At GUI startup send monitor layout to the VM.