Optical and magnetic control of exciton valley pseudospin in layered two-dimensional semiconductors