Files
LookingGlass/client/displayservers/Wayland/scale.h
Quantum c8edf1eaf3
Some checks failed
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Has been cancelled
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Has been cancelled
build / module (push) Has been cancelled
build / host-linux (push) Has been cancelled
build / host-windows-cross (push) Has been cancelled
build / host-windows-native (push) Has been cancelled
build / idd (push) Has been cancelled
build / obs (clang) (push) Has been cancelled
build / obs (gcc) (push) Has been cancelled
build / docs (push) Has been cancelled
[client] wayland: use round half away from zero behaviour
In fractional-scale-v1, the scaling is defined as follows:

> For toplevel surfaces, the size is rounded halfway away from zero.

Previously, it is undefined. This commit makes waylandScaleMulInt follow
the round half away from zero behaviour.
2026-06-06 02:32:23 +10:00

81 lines
2.2 KiB
C

/**
* Looking Glass
* Copyright © 2017-2026 The Looking Glass Authors
* https://looking-glass.io
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdint.h>
struct WaylandScale
{
int32_t num;
int32_t den;
};
static inline struct WaylandScale waylandScaleFromInt(int32_t scale)
{
return (struct WaylandScale) { scale, 1 };
}
static inline struct WaylandScale waylandScaleFromRatio(int32_t num, int32_t den)
{
return (struct WaylandScale) { num, den };
}
static inline bool waylandScaleValid(struct WaylandScale scale)
{
return scale.num > 0 && scale.den > 0;
}
static inline bool waylandScaleEqual(struct WaylandScale a, struct WaylandScale b)
{
return (int64_t)a.num * b.den == (int64_t)b.num * a.den;
}
static inline int waylandScaleCmp(struct WaylandScale a, struct WaylandScale b)
{
int64_t lhs = (int64_t)a.num * b.den;
int64_t rhs = (int64_t)b.num * a.den;
return (lhs > rhs) - (lhs < rhs);
}
static inline bool waylandScaleIsFractional(struct WaylandScale scale)
{
return waylandScaleValid(scale) && scale.num % scale.den != 0;
}
static inline int waylandScaleFloor(struct WaylandScale scale)
{
return scale.num / scale.den;
}
static inline int waylandScaleCeil(struct WaylandScale scale)
{
return (scale.num + scale.den - 1) / scale.den;
}
static inline int waylandScaleMulInt(struct WaylandScale scale, int value)
{
return (int)(((int64_t)value * scale.num + scale.den / 2) / scale.den);
}
static inline double waylandScaleToDouble(struct WaylandScale scale)
{
return (double)scale.num / (double)scale.den;
}