Reverted where the main runloop check is located.
Added a couple of fixes for hook_disable being called where it cannot stop.
I am still not comfortable with the thread safety in the library.  Testing is needed for hook_disable from the callback.  It is still not clear if that should be possible particularly on X11.
Added pthread_cond_timedwait if nanosleep is unavailable.
Merge origin/master

Conflicts:
	src/darwin/hook_thread.c
	src/x11/hook_thread.c