Leading isospin-breaking corrections to pion, kaon, and charmed-meson masses with twisted-mass fermions