Move app caching into InputHookManager

This avoids a problem I noticed in gh-6496, where a subclassed handler
would have its application registered by the parent class under the
wrong name.
Merge pull request #6505 from takluyver/inputhook-api-tweak

Move app caching into InputHookManager