mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Wayland: Be more specific about scales
We are about to introduce another scaling method (fractional-scale-v1), so it will become more important to be specific about what scales are used where and what their units are. This removes 'content scale' from window and monitor structs. A monitor (output) now has just a 'scale', which becomes a 'buffer scale' when applied to a window. A window now has a list of 'output scales' to select its buffer scale from. Content scales are calculated from the respective monitor or window when queried, even if the calculation right now is to just return the same value as before.
This commit is contained in:
parent
e25c1cc74f
commit
4c283e4a3c
@ -112,16 +112,16 @@ static void outputHandleScale(void* userData,
|
|||||||
{
|
{
|
||||||
struct _GLFWmonitor* monitor = userData;
|
struct _GLFWmonitor* monitor = userData;
|
||||||
|
|
||||||
monitor->wl.contentScale = factor;
|
monitor->wl.scale = factor;
|
||||||
|
|
||||||
for (_GLFWwindow* window = _glfw.windowListHead; window; window = window->next)
|
for (_GLFWwindow* window = _glfw.windowListHead; window; window = window->next)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < window->wl.scaleCount; i++)
|
for (int i = 0; i < window->wl.outputScaleCount; i++)
|
||||||
{
|
{
|
||||||
if (window->wl.scales[i].output == monitor->wl.output)
|
if (window->wl.outputScales[i].output == monitor->wl.output)
|
||||||
{
|
{
|
||||||
window->wl.scales[i].factor = monitor->wl.contentScale;
|
window->wl.outputScales[i].factor = monitor->wl.scale;
|
||||||
_glfwUpdateContentScaleWayland(window);
|
_glfwUpdateBufferScaleFromOutputsWayland(window);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version)
|
|||||||
|
|
||||||
// The actual name of this output will be set in the geometry handler
|
// The actual name of this output will be set in the geometry handler
|
||||||
_GLFWmonitor* monitor = _glfwAllocMonitor("", 0, 0);
|
_GLFWmonitor* monitor = _glfwAllocMonitor("", 0, 0);
|
||||||
monitor->wl.contentScale = 1;
|
monitor->wl.scale = 1;
|
||||||
monitor->wl.output = output;
|
monitor->wl.output = output;
|
||||||
monitor->wl.name = name;
|
monitor->wl.name = name;
|
||||||
|
|
||||||
@ -207,9 +207,9 @@ void _glfwGetMonitorContentScaleWayland(_GLFWmonitor* monitor,
|
|||||||
float* xscale, float* yscale)
|
float* xscale, float* yscale)
|
||||||
{
|
{
|
||||||
if (xscale)
|
if (xscale)
|
||||||
*xscale = (float) monitor->wl.contentScale;
|
*xscale = (float) monitor->wl.scale;
|
||||||
if (yscale)
|
if (yscale)
|
||||||
*yscale = (float) monitor->wl.contentScale;
|
*yscale = (float) monitor->wl.scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwGetMonitorWorkareaWayland(_GLFWmonitor* monitor,
|
void _glfwGetMonitorWorkareaWayland(_GLFWmonitor* monitor,
|
||||||
|
@ -389,10 +389,10 @@ typedef struct _GLFWwindowWayland
|
|||||||
|
|
||||||
// We need to track the monitors the window spans on to calculate the
|
// We need to track the monitors the window spans on to calculate the
|
||||||
// optimal scaling factor.
|
// optimal scaling factor.
|
||||||
int contentScale;
|
int bufferScale;
|
||||||
_GLFWscaleWayland* scales;
|
_GLFWscaleWayland* outputScales;
|
||||||
int scaleCount;
|
int outputScaleCount;
|
||||||
int scaleSize;
|
int outputScaleSize;
|
||||||
|
|
||||||
struct zwp_relative_pointer_v1* relativePointer;
|
struct zwp_relative_pointer_v1* relativePointer;
|
||||||
struct zwp_locked_pointer_v1* lockedPointer;
|
struct zwp_locked_pointer_v1* lockedPointer;
|
||||||
@ -586,7 +586,7 @@ typedef struct _GLFWmonitorWayland
|
|||||||
|
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int contentScale;
|
int scale;
|
||||||
} _GLFWmonitorWayland;
|
} _GLFWmonitorWayland;
|
||||||
|
|
||||||
// Wayland-specific per-cursor data
|
// Wayland-specific per-cursor data
|
||||||
@ -677,7 +677,7 @@ GLFWbool _glfwGetGammaRampWayland(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
|
|||||||
void _glfwSetGammaRampWayland(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
|
void _glfwSetGammaRampWayland(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
|
||||||
|
|
||||||
void _glfwAddOutputWayland(uint32_t name, uint32_t version);
|
void _glfwAddOutputWayland(uint32_t name, uint32_t version);
|
||||||
void _glfwUpdateContentScaleWayland(_GLFWwindow* window);
|
void _glfwUpdateBufferScaleFromOutputsWayland(_GLFWwindow* window);
|
||||||
|
|
||||||
void _glfwAddSeatListenerWayland(struct wl_seat* seat);
|
void _glfwAddSeatListenerWayland(struct wl_seat* seat);
|
||||||
void _glfwAddDataDeviceListenerWayland(struct wl_data_device* device);
|
void _glfwAddDataDeviceListenerWayland(struct wl_data_device* device);
|
||||||
|
@ -312,7 +312,7 @@ static void setContentAreaOpaque(_GLFWwindow* window)
|
|||||||
|
|
||||||
static void resizeFramebuffer(_GLFWwindow* window)
|
static void resizeFramebuffer(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
int scale = window->wl.contentScale;
|
int scale = window->wl.bufferScale;
|
||||||
int scaledWidth = window->wl.width * scale;
|
int scaledWidth = window->wl.width * scale;
|
||||||
int scaledHeight = window->wl.height * scale;
|
int scaledHeight = window->wl.height * scale;
|
||||||
|
|
||||||
@ -357,7 +357,7 @@ static void resizeWindow(_GLFWwindow* window)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwUpdateContentScaleWayland(_GLFWwindow* window)
|
void _glfwUpdateBufferScaleFromOutputsWayland(_GLFWwindow* window)
|
||||||
{
|
{
|
||||||
if (wl_compositor_get_version(_glfw.wl.compositor) <
|
if (wl_compositor_get_version(_glfw.wl.compositor) <
|
||||||
WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION)
|
WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION)
|
||||||
@ -368,13 +368,13 @@ void _glfwUpdateContentScaleWayland(_GLFWwindow* window)
|
|||||||
// Get the scale factor from the highest scale monitor.
|
// Get the scale factor from the highest scale monitor.
|
||||||
int maxScale = 1;
|
int maxScale = 1;
|
||||||
|
|
||||||
for (int i = 0; i < window->wl.scaleCount; i++)
|
for (int i = 0; i < window->wl.outputScaleCount; i++)
|
||||||
maxScale = _glfw_max(window->wl.scales[i].factor, maxScale);
|
maxScale = _glfw_max(window->wl.outputScales[i].factor, maxScale);
|
||||||
|
|
||||||
// Only change the framebuffer size if the scale changed.
|
// Only change the framebuffer size if the scale changed.
|
||||||
if (window->wl.contentScale != maxScale)
|
if (window->wl.bufferScale != maxScale)
|
||||||
{
|
{
|
||||||
window->wl.contentScale = maxScale;
|
window->wl.bufferScale = maxScale;
|
||||||
wl_surface_set_buffer_scale(window->wl.surface, maxScale);
|
wl_surface_set_buffer_scale(window->wl.surface, maxScale);
|
||||||
_glfwInputWindowContentScale(window, maxScale, maxScale);
|
_glfwInputWindowContentScale(window, maxScale, maxScale);
|
||||||
resizeFramebuffer(window);
|
resizeFramebuffer(window);
|
||||||
@ -396,19 +396,19 @@ static void surfaceHandleEnter(void* userData,
|
|||||||
if (!window || !monitor)
|
if (!window || !monitor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (window->wl.scaleCount + 1 > window->wl.scaleSize)
|
if (window->wl.outputScaleCount + 1 > window->wl.outputScaleSize)
|
||||||
{
|
{
|
||||||
window->wl.scaleSize++;
|
window->wl.outputScaleSize++;
|
||||||
window->wl.scales =
|
window->wl.outputScales =
|
||||||
_glfw_realloc(window->wl.scales,
|
_glfw_realloc(window->wl.outputScales,
|
||||||
window->wl.scaleSize * sizeof(_GLFWscaleWayland));
|
window->wl.outputScaleSize * sizeof(_GLFWscaleWayland));
|
||||||
}
|
}
|
||||||
|
|
||||||
window->wl.scaleCount++;
|
window->wl.outputScaleCount++;
|
||||||
window->wl.scales[window->wl.scaleCount - 1].factor = monitor->wl.contentScale;
|
window->wl.outputScales[window->wl.outputScaleCount - 1] =
|
||||||
window->wl.scales[window->wl.scaleCount - 1].output = output;
|
(_GLFWscaleWayland) { output, monitor->wl.scale };
|
||||||
|
|
||||||
_glfwUpdateContentScaleWayland(window);
|
_glfwUpdateBufferScaleFromOutputsWayland(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void surfaceHandleLeave(void* userData,
|
static void surfaceHandleLeave(void* userData,
|
||||||
@ -420,17 +420,18 @@ static void surfaceHandleLeave(void* userData,
|
|||||||
|
|
||||||
_GLFWwindow* window = userData;
|
_GLFWwindow* window = userData;
|
||||||
|
|
||||||
for (int i = 0; i < window->wl.scaleCount; i++)
|
for (int i = 0; i < window->wl.outputScaleCount; i++)
|
||||||
{
|
{
|
||||||
if (window->wl.scales[i].output == output)
|
if (window->wl.outputScales[i].output == output)
|
||||||
{
|
{
|
||||||
window->wl.scales[i] = window->wl.scales[window->wl.scaleCount - 1];
|
window->wl.outputScales[i] =
|
||||||
window->wl.scaleCount--;
|
window->wl.outputScales[window->wl.outputScaleCount - 1];
|
||||||
|
window->wl.outputScaleCount--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwUpdateContentScaleWayland(window);
|
_glfwUpdateBufferScaleFromOutputsWayland(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wl_surface_listener surfaceListener =
|
static const struct wl_surface_listener surfaceListener =
|
||||||
@ -970,7 +971,7 @@ static GLFWbool createNativeSurface(_GLFWwindow* window,
|
|||||||
|
|
||||||
window->wl.width = wndconfig->width;
|
window->wl.width = wndconfig->width;
|
||||||
window->wl.height = wndconfig->height;
|
window->wl.height = wndconfig->height;
|
||||||
window->wl.contentScale = 1;
|
window->wl.bufferScale = 1;
|
||||||
window->wl.title = _glfw_strdup(wndconfig->title);
|
window->wl.title = _glfw_strdup(wndconfig->title);
|
||||||
window->wl.appId = _glfw_strdup(wndconfig->wl.appId);
|
window->wl.appId = _glfw_strdup(wndconfig->wl.appId);
|
||||||
|
|
||||||
@ -997,7 +998,7 @@ static void setCursorImage(_GLFWwindow* window,
|
|||||||
buffer = cursorWayland->buffer;
|
buffer = cursorWayland->buffer;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (window->wl.contentScale > 1 && cursorWayland->cursorHiDPI)
|
if (window->wl.bufferScale > 1 && cursorWayland->cursorHiDPI)
|
||||||
{
|
{
|
||||||
wlCursor = cursorWayland->cursorHiDPI;
|
wlCursor = cursorWayland->cursorHiDPI;
|
||||||
scale = 2;
|
scale = 2;
|
||||||
@ -1398,7 +1399,7 @@ static void pointerHandleMotion(void* userData,
|
|||||||
struct wl_cursor_theme* theme = _glfw.wl.cursorTheme;
|
struct wl_cursor_theme* theme = _glfw.wl.cursorTheme;
|
||||||
int scale = 1;
|
int scale = 1;
|
||||||
|
|
||||||
if (window->wl.contentScale > 1 && _glfw.wl.cursorThemeHiDPI)
|
if (window->wl.bufferScale > 1 && _glfw.wl.cursorThemeHiDPI)
|
||||||
{
|
{
|
||||||
// We only support up to scale=2 for now, since libwayland-cursor
|
// We only support up to scale=2 for now, since libwayland-cursor
|
||||||
// requires us to load a different theme for each size.
|
// requires us to load a different theme for each size.
|
||||||
@ -2120,7 +2121,7 @@ void _glfwDestroyWindowWayland(_GLFWwindow* window)
|
|||||||
|
|
||||||
_glfw_free(window->wl.title);
|
_glfw_free(window->wl.title);
|
||||||
_glfw_free(window->wl.appId);
|
_glfw_free(window->wl.appId);
|
||||||
_glfw_free(window->wl.scales);
|
_glfw_free(window->wl.outputScales);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title)
|
void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title)
|
||||||
@ -2279,9 +2280,9 @@ void _glfwGetFramebufferSizeWayland(_GLFWwindow* window, int* width, int* height
|
|||||||
{
|
{
|
||||||
_glfwGetWindowSizeWayland(window, width, height);
|
_glfwGetWindowSizeWayland(window, width, height);
|
||||||
if (width)
|
if (width)
|
||||||
*width *= window->wl.contentScale;
|
*width *= window->wl.bufferScale;
|
||||||
if (height)
|
if (height)
|
||||||
*height *= window->wl.contentScale;
|
*height *= window->wl.bufferScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwGetWindowFrameSizeWayland(_GLFWwindow* window,
|
void _glfwGetWindowFrameSizeWayland(_GLFWwindow* window,
|
||||||
@ -2305,9 +2306,9 @@ void _glfwGetWindowContentScaleWayland(_GLFWwindow* window,
|
|||||||
float* xscale, float* yscale)
|
float* xscale, float* yscale)
|
||||||
{
|
{
|
||||||
if (xscale)
|
if (xscale)
|
||||||
*xscale = (float) window->wl.contentScale;
|
*xscale = (float) window->wl.bufferScale;
|
||||||
if (yscale)
|
if (yscale)
|
||||||
*yscale = (float) window->wl.contentScale;
|
*yscale = (float) window->wl.bufferScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwIconifyWindowWayland(_GLFWwindow* window)
|
void _glfwIconifyWindowWayland(_GLFWwindow* window)
|
||||||
|
Loading…
Reference in New Issue
Block a user