Skip to content

Commit

Permalink
igl | shell | Correctly handle desktop fullscreen mode on Windows
Browse files Browse the repository at this point in the history
Summary: Correctly handle desktop fullscreen mode on Windows.

Reviewed By: mmaurer

Differential Revision: D62981405

fbshipit-source-id: 9b0f2c10d938237c6250735bbae026f0c8b35467
  • Loading branch information
corporateshark authored and facebook-github-bot committed Sep 19, 2024
1 parent 8f305c6 commit ce8b7f1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 10 deletions.
28 changes: 25 additions & 3 deletions shell/windows/opengl/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,38 @@ GLFWwindow* initGLWindow(const shell::RenderSessionConfig& config) {
glfwWindowHint(GLFW_DOUBLEBUFFER, true);
glfwWindowHint(GLFW_RESIZABLE, true);
glfwWindowHint(GLFW_SRGB_CAPABLE, true);
glfwWindowHint(GLFW_MAXIMIZED, config.screenMode != shell::ScreenMode::Windowed);

int posX = 0;
int posY = 0;
int width = config.width;
int height = config.height;

if (config.screenMode == shell::ScreenMode::FullscreenNoTaskbar) {
// render full screen without overlapping the task bar
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);

glfwGetMonitorWorkarea(monitor, &posX, &posY, &width, &height);
} else if (config.screenMode == shell::ScreenMode::Fullscreen) {
glfwWindowHint(GLFW_MAXIMIZED, true);
}

GLFWwindow* windowHandle =
glfwCreateWindow(config.width, config.height, config.displayName.c_str(), NULL, NULL);
glfwCreateWindow(width, height, config.displayName.c_str(), nullptr, nullptr);
if (!windowHandle) {
IGLLog(IGLLogError, "initGLWindow> we couldn't create the window");
glfwTerminate();
return nullptr;
}

if (config.screenMode == shell::ScreenMode::FullscreenNoTaskbar) {
glfwSetWindowPos(windowHandle, posX, posY);
}

glfwGetFramebufferSize(windowHandle, &width, &height);
shellParams_.viewportSize.x = width;
shellParams_.viewportSize.y = height;

int result = glfwGetWindowAttrib(windowHandle, GLFW_CLIENT_API);

glfwMakeContextCurrent(windowHandle);
Expand Down Expand Up @@ -285,7 +307,7 @@ int main(int argc, char* argv[]) {
.colorFramebufferFormat = TextureFormat::RGBA_SRGB,
.width = 1024,
.height = 768,
.screenMode = shell::ScreenMode::Windowed,
.screenMode = shell::ScreenMode::FullscreenNoTaskbar,
},
};

Expand Down
28 changes: 25 additions & 3 deletions shell/windows/opengles/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,37 @@ GLFWwindow* initGLESWindow(const shell::RenderSessionConfig& config) {
glfwWindowHint(GLFW_DOUBLEBUFFER, true);
glfwWindowHint(GLFW_RESIZABLE, true);
glfwWindowHint(GLFW_SRGB_CAPABLE, true);
glfwWindowHint(GLFW_MAXIMIZED, config.screenMode != shell::ScreenMode::Windowed);

int posX = 0;
int posY = 0;
int width = config.width;
int height = config.height;

if (config.screenMode == shell::ScreenMode::FullscreenNoTaskbar) {
// render full screen without overlapping the task bar
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);

glfwGetMonitorWorkarea(monitor, &posX, &posY, &width, &height);
} else if (config.screenMode == shell::ScreenMode::Fullscreen) {
glfwWindowHint(GLFW_MAXIMIZED, true);
}

GLFWwindow* windowHandle =
glfwCreateWindow(config.width, config.height, config.displayName.c_str(), NULL, NULL);
glfwCreateWindow(width, height, config.displayName.c_str(), nullptr, nullptr);
if (!windowHandle) {
glfwTerminate();
return nullptr;
}

if (config.screenMode == shell::ScreenMode::FullscreenNoTaskbar) {
glfwSetWindowPos(windowHandle, posX, posY);
}

glfwGetFramebufferSize(windowHandle, &width, &height);
shellParams_.viewportSize.x = width;
shellParams_.viewportSize.y = height;

int result = glfwGetWindowAttrib(windowHandle, GLFW_CLIENT_API);

glfwMakeContextCurrent(windowHandle);
Expand Down Expand Up @@ -192,7 +214,7 @@ int main(int argc, char* argv[]) {
.colorFramebufferFormat = TextureFormat::RGBA_UNorm8,
.width = 1024,
.height = 768,
.screenMode = shell::ScreenMode::Windowed,
.screenMode = shell::ScreenMode::FullscreenNoTaskbar,
},
};

Expand Down
25 changes: 21 additions & 4 deletions shell/windows/vulkan/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,33 @@ GLFWwindow* initWindow(const shell::RenderSessionConfig& config) {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE);
glfwWindowHint(GLFW_MAXIMIZED, config.screenMode != shell::ScreenMode::Windowed);

int posX = 0;
int posY = 0;
int width = config.width;
int height = config.height;

if (config.screenMode == shell::ScreenMode::FullscreenNoTaskbar) {
// render full screen without overlapping the task bar
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);

glfwGetMonitorWorkarea(monitor, &posX, &posY, &width, &height);
} else if (config.screenMode == shell::ScreenMode::Fullscreen) {
glfwWindowHint(GLFW_MAXIMIZED, true);
}

GLFWwindow* windowHandle =
glfwCreateWindow(config.width, config.height, config.displayName.c_str(), nullptr, nullptr);
glfwCreateWindow(width, height, config.displayName.c_str(), nullptr, nullptr);
if (!windowHandle) {
glfwTerminate();
return nullptr;
}

int width, height;
if (config.screenMode == shell::ScreenMode::FullscreenNoTaskbar) {
glfwSetWindowPos(windowHandle, posX, posY);
}

glfwGetFramebufferSize(windowHandle, &width, &height);
shellParams_.viewportSize.x = width;
shellParams_.viewportSize.y = height;
Expand Down Expand Up @@ -207,7 +224,7 @@ int main(int argc, char* argv[]) {
.colorFramebufferFormat = TextureFormat::BGRA_UNorm8,
.width = 1024,
.height = 768,
.screenMode = shell::ScreenMode::Windowed,
.screenMode = shell::ScreenMode::FullscreenNoTaskbar,
},
};

Expand Down

0 comments on commit ce8b7f1

Please sign in to comment.