Only grab keyboard when we have focus
There was an issue with the new grabs that were introduced in commit
2289342de7222e4ff2483eae95bb9898830e6097. On macOS when running
vncviewer in fullscreen on one monitor, we saw that we sometimes got
resize and fullscreen events when switching the focus away from
vncviewer. With the changes in the commit mentioned above this meant
that we immediately grabbed the keyboard again, thus never releasing it.
Fixes #1332.
(cherry picked from commit
72e94ca93d3ada8fb7f518fa65644d2bc172bd4b)