Namely I'm trying to watch a movie and screen goes black after 30 minutes (yes I know how to configure this, just an example).
This isn’t correct, actually. There is the Do Not Disturb mode in OS X that disables any non-essential notifications and alerts. It can be toggled manually for one day, or according to user-set daily start and end times.
Of course, even though the API exists, apps use it differently and somewhat inconsistently: for example, Apple’s native FaceTime will not distract you in DND mode, but Skype will if someone calls you.
Point being, there is an example of such API that tells any app that asks whether is now a good time to interrupt the user. (Not to argue that actually inferring what you do and avoiding distracting and stealing focus in the middle of typing, as in your example, would take it to another level.)
No Windows, I don't want to update Java (yet again) when I'm playing a fullscreened video game.
Notifications could be deferred while the user is actively typing. When the user goes idle, deferred notifications can be displayed. This becomes more important as more "push" features are crammed into browsers and apps.