Add listener for fractional scale events

This commit is contained in:
Kovid Goyal
2024-03-21 13:02:12 +05:30
parent 5d0c25f5ea
commit 6979f1c5eb
2 changed files with 20 additions and 0 deletions

2
glfw/wl_platform.h vendored
View File

@@ -163,6 +163,7 @@ typedef struct _GLFWwindowWayland
struct xdg_toplevel* toplevel;
struct zxdg_toplevel_decoration_v1* decoration;
} xdg;
struct wp_fractional_scale_v1 *wp_fractional_scale_v1;
_GLFWcursor* currentCursor;
double cursorPosX, cursorPosY, allCursorPosX, allCursorPosY;
@@ -173,6 +174,7 @@ typedef struct _GLFWwindowWayland
// We need to track the monitors the window spans on to calculate the
// optimal scaling factor.
int integer_scale;
uint32_t fractional_scale;
bool initial_scale_notified;
_GLFWmonitor** monitors;
int monitorsCount;

18
glfw/wl_window.c vendored
View File

@@ -458,6 +458,17 @@ static const struct wl_surface_listener surfaceListener = {
surfaceHandleLeave
};
static void
fractional_scale_preferred_scale(void *data, struct wp_fractional_scale_v1 *wp_fractional_scale_v1 UNUSED, uint32_t scale) {
_GLFWwindow *window = data;
if (scale == window->wl.fractional_scale) return;
debug("Fractional scale requested: %u/120 = %.2f\n", scale, scale / 120.);
}
static const struct wp_fractional_scale_v1_listener fractional_scale_listener = {
.preferred_scale = &fractional_scale_preferred_scale,
};
static bool createSurface(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig)
{
@@ -484,6 +495,10 @@ static bool createSurface(_GLFWwindow* window,
if (xscale <= 0.0001 || xscale != xscale || xscale >= 24) xscale = 1.0;
if (xscale > 1) scale = (int)xscale;
}
if (_glfw.wl.wp_fractional_scale_manager_v1 && _glfw.wl.wp_viewporter) {
window->wl.wp_fractional_scale_v1 = wp_fractional_scale_manager_v1_get_fractional_scale(_glfw.wl.wp_fractional_scale_manager_v1, window->wl.surface);
wp_fractional_scale_v1_add_listener(window->wl.wp_fractional_scale_v1, &fractional_scale_listener, window);
}
debug("Creating window at size: %dx%d and scale %d\n", wndconfig->width, wndconfig->height, scale);
window->wl.native = wl_egl_window_create(window->wl.surface, wndconfig->width * scale, wndconfig->height * scale);
@@ -1000,6 +1015,9 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
_glfw.wl.keyRepeatInfo.keyboardFocusId = 0;
}
if (window->wl.wp_fractional_scale_v1)
wp_fractional_scale_v1_destroy(window->wl.wp_fractional_scale_v1);
if (window->context.destroy)
window->context.destroy(window);