Multi-monitor bug with 4K display

I am testing multi-monitor support for my GLFW application and I have come across a bug. The code I am using works 100% fine with 2 monitors, if one monitor is 1920x1080 and the second is 1920x1200, but if the second monitor is a 4K monitor then a lot weird stuff starts happening.

If I choose a window size of 1536x864 on the second monitor, a 3840x2160 window is created, with the entire area black and the1536x864 area of content in the bottom left corner!

If I choose a window size of 2560x1440 on the second monitor, this time the window is created with the correct size, but the mouse co-ordinates are wrong - they are offset 50 pixels downwards.

This is the code I am using:

int numMonitors;
GLFWmonitor** monitors = glfwGetMonitors(&numMonitors);

int xPos;
int yPos;
int widthWorkArea;
int heightWorkArea;
glfwGetMonitorWorkarea(monitors[m_ixMonitorCurr], &xPos, &yPos, &widthWorkArea, &heightWorkArea);

	if (m_posWindow.m_x < xPos || m_posWindow.m_x >= xPos+widthWorkArea) m_posWindow.m_x = xPos;
	if (m_posWindow.m_y < yPos || m_posWindow.m_y >= yPos+heightWorkArea) m_posWindow.m_y = yPos;

		glfwWindowHint(GLFW_DECORATED, GL_FALSE);
			g_pWindow = glfwCreateWindow(pMonitorSettings->GetScreenWidth(),
				pMonitorSettings->GetScreenHeight(), "Merc Tactics", NULL, NULL);
			glfwSetWindowPos(g_pWindow, m_posWindow.m_x,
				m_posWindow.m_y);

Hi @lefty

What version of GLFW and what are the details of the system you are using (OS + Window system if using Linux)?

it’s GLFW 3.3.9 and the OS is Windows 10.

Funnily enough the same code works perfectly on Linux

I would first try GLFW 3.4 or the latest from Github.

If you still have issues I would then investigate whether this might be related to Window Content Scale: GLFW: Window guide

There are a number of multi-monitor related issues on Github For Windows, but I can’t find any exactly related to yours nor can I replicate this (but I also don’t have a 4k monitor to test with).

Thanks for the answer. I will try 3.4