Fix build for FreeBSD and quash all warnings.

Remove usage of deprecated GTK mutex and thread functions, use "double complex" where appropriate, add declarations to header files where missing, add return values to non-void functions without one.