Restore Wayland compatibility.

It was broken by e15ec56bf0237 because it wasn't deemed important. However chances are people will eventually start using Dolphin on that configuration, so we shouldn't frivolously drop compatibility without good reason.

This patch reintroduces the removed code portions with slightly cleaner coding style. Other than that, unittests won't build with USE_EGL because our Wayland support code wasn't deemed important enough when PR #716 was merged. Ideally we'd fix this, but for now I'd just like to restore application compatibility.