Use double for wayland float calculation

This commit is contained in:
Kovid Goyal
2024-04-19 22:20:02 +05:30
parent 5055c0d98d
commit 8d1b0e54af
5 changed files with 27 additions and 27 deletions

View File

@@ -89,7 +89,7 @@ create_shadow_mask(size_t width, size_t height, size_t margin, size_t kernel_siz
static size_t
create_shadow_tile(_GLFWwindow *window) {
const size_t margin = (size_t)roundf(decs.metrics.width * decs.for_window_state.fscale);
const size_t margin = (size_t)round(decs.metrics.width * decs.for_window_state.fscale);
if (st.data && st.for_decoration_size == margin) return margin;
st.for_decoration_size = margin;
free(st.data);
@@ -115,10 +115,10 @@ swap_buffers(_GLFWWaylandBufferPair *pair) {
}
static size_t
init_buffer_pair(_GLFWWaylandBufferPair *pair, size_t width, size_t height, float scale) {
init_buffer_pair(_GLFWWaylandBufferPair *pair, size_t width, size_t height, double scale) {
memset(pair, 0, sizeof(_GLFWWaylandBufferPair));
pair->width = (int)roundf(width * scale);
pair->height = (int)roundf(height * scale);
pair->width = (int)round(width * scale);
pair->height = (int)round(height * scale);
pair->viewport_width = width; pair->viewport_height = height;
pair->stride = 4 * pair->width;
pair->size_in_bytes = pair->stride * pair->height;
@@ -213,7 +213,7 @@ render_minimize(uint8_t *out, unsigned width, unsigned height) {
memset(out, 0, width * height);
unsigned thickness = height / 12;
unsigned baseline = height - thickness * 2;
unsigned side_margin = (int)roundf(thickness * 3.8f);
unsigned side_margin = scale(thickness, 3.8f);
if (!thickness || width <= side_margin || height < baseline + 2 * thickness) return;
render_hline(out, width, thickness, baseline, side_margin, width - side_margin);
}
@@ -468,7 +468,7 @@ render_shadows(_GLFWwindow *window) {
static bool
create_shm_buffers(_GLFWwindow* window) {
const float scale = _glfwWaylandWindowScale(window);
const double scale = _glfwWaylandWindowScale(window);
decs.mapping.size = 0;
#define bp(which, width, height) decs.mapping.size += init_buffer_pair(&decs.which.buffer, width, height, scale);

2
glfw/wl_init.c vendored
View File

@@ -222,7 +222,7 @@ pointer_handle_frame(void *data UNUSED, struct wl_pointer *pointer UNUSED) {
memset(&info, 0, sizeof(info));
if (x != 0.0f || y != 0.0f) {
float scale = _glfwWaylandWindowScale(window);
float scale = (float)_glfwWaylandWindowScale(window);
y *= scale; x *= scale;
_glfwInputScroll(window, x, y, highres, _glfw.wl.xkb.states.modifiers);
}

4
glfw/wl_platform.h vendored
View File

@@ -233,7 +233,7 @@ typedef struct _GLFWwindowWayland
struct {
int width, height;
bool focused, needs_shadow;
float fscale;
double fscale;
WaylandWindowState toplevel_states;
} for_window_state;
@@ -423,7 +423,7 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version);
void _glfwWaylandAfterBufferSwap(_GLFWwindow *window);
void _glfwSetupWaylandDataDevice(void);
void _glfwSetupWaylandPrimarySelectionDevice(void);
float _glfwWaylandWindowScale(_GLFWwindow*);
double _glfwWaylandWindowScale(_GLFWwindow*);
int _glfwWaylandIntegerWindowScale(_GLFWwindow*);
void animateCursorImage(id_type timer_id, void *data);
struct wl_cursor* _glfwLoadCursor(GLFWCursorShape, struct wl_cursor_theme*);

View File

@@ -169,8 +169,8 @@ _glfwPlatformUpdateIMEState(_GLFWwindow *w, const GLFWIMEUpdateEvent *ev) {
commit();
break;
case GLFW_IME_UPDATE_CURSOR_POSITION: {
const float scale = _glfwWaylandWindowScale(w);
#define s(x) (int)roundf((x) / scale)
const double scale = _glfwWaylandWindowScale(w);
#define s(x) (int)round((x) / scale)
const int left = s(ev->cursor.left), top = s(ev->cursor.top), width = s(ev->cursor.width), height = s(ev->cursor.height);
#undef s
if (left != last_cursor_left || top != last_cursor_top || width != last_cursor_width || height != last_cursor_height) {

32
glfw/wl_window.c vendored
View File

@@ -349,19 +349,19 @@ _glfwWaylandIntegerWindowScale(_GLFWwindow *window) {
return ans;
}
float
double
_glfwWaylandWindowScale(_GLFWwindow *window) {
float ans = _glfwWaylandIntegerWindowScale(window);
if (window->wl.fractional_scale) ans = window->wl.fractional_scale / 120.f;
double ans = _glfwWaylandIntegerWindowScale(window);
if (window->wl.fractional_scale) ans = window->wl.fractional_scale / 120.;
return ans;
}
static void
resizeFramebuffer(_GLFWwindow* window) {
float scale = _glfwWaylandWindowScale(window);
int scaled_width = (int)roundf(window->wl.width * scale);
int scaled_height = (int)roundf(window->wl.height * scale);
debug("Resizing framebuffer to: %dx%d window size: %dx%d at scale: %.2f\n",
double scale = _glfwWaylandWindowScale(window);
int scaled_width = (int)round(window->wl.width * scale);
int scaled_height = (int)round(window->wl.height * scale);
debug("Resizing framebuffer to: %dx%d window size: %dx%d at scale: %.3f\n",
scaled_width, scaled_height, window->wl.width, window->wl.height, scale);
wl_egl_window_resize(window->wl.native, scaled_width, scaled_height, 0, 0);
update_regions(window);
@@ -395,9 +395,9 @@ clipboard_mime(void) {
static void
apply_scale_changes(_GLFWwindow *window, bool resize_framebuffer, bool update_csd) {
float scale = _glfwWaylandWindowScale(window);
double scale = _glfwWaylandWindowScale(window);
if (resize_framebuffer) resizeFramebuffer(window);
_glfwInputWindowContentScale(window, scale, scale);
_glfwInputWindowContentScale(window, (float)scale, (float)scale);
if (update_csd) csd_set_visible(window, true); // resize the csd iff the window currently has CSD
int buffer_scale = window->wl.fractional_scale ? 1 : (int)scale;
wl_surface_set_buffer_scale(window->wl.surface, buffer_scale);
@@ -415,7 +415,7 @@ dispatchChangesAfterConfigure(_GLFWwindow *window, int32_t width, int32_t height
}
if (scale_changed) {
debug("Scale changed to %.2f in dispatchChangesAfterConfigure\n", _glfwWaylandWindowScale(window));
debug("Scale changed to %.3f in dispatchChangesAfterConfigure\n", _glfwWaylandWindowScale(window));
apply_scale_changes(window, !size_changed, false);
}
@@ -468,7 +468,7 @@ static void surfaceHandleEnter(void *data,
window->wl.monitors[window->wl.monitorsCount++] = monitor;
if (checkScaleChange(window)) {
debug("Scale changed to %.2f in surfaceHandleEnter\n", _glfwWaylandWindowScale(window));
debug("Scale changed to %.3f in surfaceHandleEnter\n", _glfwWaylandWindowScale(window));
apply_scale_changes(window, true, true);
}
}
@@ -492,7 +492,7 @@ static void surfaceHandleLeave(void *data,
window->wl.monitors[--window->wl.monitorsCount] = NULL;
if (checkScaleChange(window)) {
debug("Scale changed to %.2f in surfaceHandleLeave\n", _glfwWaylandWindowScale(window));
debug("Scale changed to %.3f in surfaceHandleLeave\n", _glfwWaylandWindowScale(window));
apply_scale_changes(window, true, true);
}
}
@@ -1494,11 +1494,11 @@ void _glfwPlatformGetFramebufferSize(_GLFWwindow* window,
int* width, int* height)
{
_glfwPlatformGetWindowSize(window, width, height);
float fscale = _glfwWaylandWindowScale(window);
double fscale = _glfwWaylandWindowScale(window);
if (width)
*width = (int)roundf(*width * fscale);
*width = (int)round(*width * fscale);
if (height)
*height = (int)roundf(*height * fscale);
*height = (int)round(*height * fscale);
}
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
@@ -1521,7 +1521,7 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
void _glfwPlatformGetWindowContentScale(_GLFWwindow* window,
float* xscale, float* yscale)
{
float fscale = _glfwWaylandWindowScale(window);
float fscale = (float)_glfwWaylandWindowScale(window);
if (xscale)
*xscale = fscale;
if (yscale)