how to get view_mode from within hook_field_formatter_view I've created a custom field formatter which works correctly. My problem is that I want to differentiate its output depending on whether it's being used in a default or teaser view mode.

The hook_field_formatter_view doesn't seem to provide this.

One way I can solve this is by providing a setting on that formatter (hook_field_formatter_settings_form) with possible values default and teaser. I'd then have to go to the teaser view mode of all content types and configure this setting on all uses of that formatter. I'd then be able to get the setting using $display['settings']. This would work but it's a bad solution since it would be replicating data that is already there and it also requires administrative work.

Is there a cleaner solution to this?
Imho a formatter shouldn't be dependent on the view mode. It's the site builder's choice which formatter to use in which view mode, and through that decide how things look. It sounds to me like you'd be better off either having two formatters, or having one formatter which can be configured.

My understanding of the Drupal way here is that you provide the general purpose tools (just like a module typically provides permissions, but not a new role - leaving it to the site builder to aggregate perms into roles appropriate for their particular needs). Every time I create a new view mode I want to have complete power to make it do exactly what I want.