When requested monitor number doesn't exist, then gdk_display_get_monitor() returns NULL - there shouldn't be any operations tried on NULL objects. In the current implementation the caller doesn't know whether the call actually succeeds.
Therefore add a safety check and report back via return code. This also has the nice side effect that it makes looping easier.
Signed-off-by: Enrico Weigelt, metux IT consult firstname.lastname@example.org