[client] wayland: get scale from wp-fractional-scale-v1 if possible

This commit is contained in:
Quantum
2026-06-03 20:27:45 -04:00
committed by Geoffrey McRae
parent e406b0fee8
commit 938a2a6c22
3 changed files with 41 additions and 9 deletions

View File

@@ -46,6 +46,9 @@ static void registryGlobalHandler(void * data, struct wl_registry * registry,
else if (!strcmp(interface, wp_viewporter_interface.name))
wlWm.viewporter = wl_registry_bind(wlWm.registry, name,
&wp_viewporter_interface, 1);
else if (!strcmp(interface, wp_fractional_scale_manager_v1_interface.name))
wlWm.fractionalScaleManager = wl_registry_bind(wlWm.registry, name,
&wp_fractional_scale_manager_v1_interface, 1);
else if (!strcmp(interface, zwp_relative_pointer_manager_v1_interface.name))
wlWm.relativePointerManager = wl_registry_bind(wlWm.registry, name,
&zwp_relative_pointer_manager_v1_interface, 1);

View File

@@ -47,6 +47,7 @@
#include "wayland-idle-inhibit-unstable-v1-client-protocol.h"
#include "wayland-xdg-output-unstable-v1-client-protocol.h"
#include "wayland-xdg-activation-v1-client-protocol.h"
#include "wayland-fractional-scale-v1-client-protocol.h"
#include "scale.h"
@@ -175,6 +176,8 @@ struct WaylandDSState
struct wp_viewporter * viewporter;
struct wp_viewport * viewport;
struct wp_fractional_scale_manager_v1 * fractionalScaleManager;
struct wp_fractional_scale_v1 * fractionalScaleInterface;
struct zxdg_output_manager_v1 * xdgOutputManager;
struct wl_list outputs; // WaylandOutput::link
struct wl_list surfaceOutputs; // SurfaceOutput::link

View File

@@ -31,8 +31,21 @@
// Surface-handling listeners.
static void setScale(struct WaylandScale newScale)
{
wlWm.scale = newScale;
wlWm.fractionalScale = waylandScaleIsFractional(newScale);
wlWm.needsResize = true;
waylandCursorScaleChange();
app_invalidateWindow(true);
waylandStopWaitFrame();
}
void waylandWindowUpdateScale(void)
{
if (wlWm.fractionalScaleInterface)
return;
struct WaylandScale maxScale = waylandScaleFromInt(0);
struct SurfaceOutput * node;
@@ -44,14 +57,7 @@ void waylandWindowUpdateScale(void)
}
if (waylandScaleValid(maxScale))
{
wlWm.scale = maxScale;
wlWm.fractionalScale = waylandScaleIsFractional(maxScale);
wlWm.needsResize = true;
waylandCursorScaleChange();
app_invalidateWindow(true);
waylandStopWaitFrame();
}
setScale(maxScale);
}
static void wlSurfaceEnterHandler(void * data, struct wl_surface * surface, struct wl_output * output)
@@ -85,6 +91,16 @@ static const struct wl_surface_listener wlSurfaceListener = {
.leave = wlSurfaceLeaveHandler,
};
static void fractionalScalePreferredScale(void * data,
struct wp_fractional_scale_v1 * fractionalScale, uint32_t scale)
{
setScale(waylandScaleFromRatio(scale, 120));
}
static const struct wp_fractional_scale_v1_listener fractionalScaleListener = {
.preferred_scale = fractionalScalePreferredScale,
};
bool waylandWindowInit(const char * title, const char * appId, bool fullscreen, bool maximize, bool borderless, bool resizable)
{
wlWm.scale = waylandScaleFromInt(1);
@@ -110,7 +126,15 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
return false;
}
wl_surface_add_listener(wlWm.surface, &wlSurfaceListener, NULL);
if (wlWm.fractionalScaleManager)
{
wlWm.fractionalScaleInterface = wp_fractional_scale_manager_v1_get_fractional_scale(
wlWm.fractionalScaleManager, wlWm.surface);
wp_fractional_scale_v1_add_listener(wlWm.fractionalScaleInterface,
&fractionalScaleListener, NULL);
}
else
wl_surface_add_listener(wlWm.surface, &wlSurfaceListener, NULL);
if (!wlWm.desktop->shellInit(wlWm.display, wlWm.surface,
title, appId, fullscreen, maximize, borderless, resizable))
@@ -122,6 +146,8 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
void waylandWindowFree(void)
{
if (wlWm.fractionalScaleInterface)
wp_fractional_scale_v1_destroy(wlWm.fractionalScaleInterface);
wl_surface_destroy(wlWm.surface);
lgFreeEvent(wlWm.frameEvent);
}