From cc004b35467a453c436a938462597686a6a2a983 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 17 Dec 2018 21:04:22 +0000 Subject: [PATCH] Fix compatibility with macOS's dark mode. --- .../Sdl2PlatformWindow.cs | 25 +++++++++++++++++++ packaging/osx/buildpackage.sh | 2 +- thirdparty/fetch-thirdparty-deps-osx.sh | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs index 7bc8ad45db..f85ed81578 100644 --- a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs +++ b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs @@ -113,6 +113,31 @@ namespace OpenRA.Platforms.Default window = SDL.SDL_CreateWindow("OpenRA", SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, windowSize.Width, windowSize.Height, windowFlags); + // Work around an issue in macOS's GL backend where the window remains permanently black + // (if dark mode is enabled) unless we drain the event queue before initializing GL + if (Platform.CurrentPlatform == PlatformType.OSX) + { + SDL.SDL_Event e; + while (SDL.SDL_PollEvent(out e) != 0) + { + // We can safely ignore all mouse/keyboard events and window size changes + // (these will be caught in the window setup below), but do need to process focus + if (e.type == SDL.SDL_EventType.SDL_WINDOWEVENT) + { + switch (e.window.windowEvent) + { + case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST: + Game.HasInputFocus = false; + break; + + case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED: + Game.HasInputFocus = true; + break; + } + } + } + } + surfaceSize = windowSize; windowScale = 1; diff --git a/packaging/osx/buildpackage.sh b/packaging/osx/buildpackage.sh index 90dc9afb0f..da613f2b10 100755 --- a/packaging/osx/buildpackage.sh +++ b/packaging/osx/buildpackage.sh @@ -9,7 +9,7 @@ if [[ "$OSTYPE" != "darwin"* ]]; then command -v genisoimage >/dev/null 2>&1 || { echo >&2 "macOS packaging requires genisoimage."; exit 1; } fi -LAUNCHER_TAG="osx-launcher-20171118" +LAUNCHER_TAG="osx-launcher-20181118" if [ $# -ne "2" ]; then echo "Usage: $(basename "$0") tag outputdir" diff --git a/thirdparty/fetch-thirdparty-deps-osx.sh b/thirdparty/fetch-thirdparty-deps-osx.sh index 9c5f9e7eac..b5e8dce27e 100755 --- a/thirdparty/fetch-thirdparty-deps-osx.sh +++ b/thirdparty/fetch-thirdparty-deps-osx.sh @@ -1,6 +1,6 @@ #!/bin/bash -LAUNCHER_TAG="osx-launcher-20171118" +LAUNCHER_TAG="osx-launcher-20181118" download_dir="${0%/*}/download/osx" mkdir -p "$download_dir"