Add shared min and max functions for int

(cherry picked from commit 3ee5031fd7)
This commit is contained in:
Camilla Löwy 2022-03-14 16:01:34 +01:00
parent b43c122dd1
commit 3006c02bc2
5 changed files with 18 additions and 18 deletions

View File

@ -150,6 +150,16 @@ char* _glfw_strdup(const char* source)
return result;
}
int _glfw_min(int a, int b)
{
return a < b ? a : b;
}
int _glfw_max(int a, int b)
{
return a > b ? a : b;
}
float _glfw_fminf(float a, float b)
{
if (a != a)

View File

@ -777,6 +777,8 @@ const char* _glfwGetVulkanResultString(VkResult result);
size_t _glfwEncodeUTF8(char* s, uint32_t codepoint);
char* _glfw_strdup(const char* source);
int _glfw_min(int a, int b);
int _glfw_max(int a, int b);
float _glfw_fminf(float a, float b);
float _glfw_fmaxf(float a, float b);

View File

@ -504,10 +504,8 @@ static void maximizeWindowManually(_GLFWwindow* window)
if (window->maxwidth != GLFW_DONT_CARE && window->maxheight != GLFW_DONT_CARE)
{
if (rect.right - rect.left > window->maxwidth)
rect.right = rect.left + window->maxwidth;
if (rect.bottom - rect.top > window->maxheight)
rect.bottom = rect.top + window->maxheight;
rect.right = _glfw_min(rect.right, rect.left + window->maxwidth);
rect.bottom = _glfw_min(rect.bottom, rect.top + window->maxheight);
}
style = GetWindowLongW(window->win32.handle, GWL_STYLE);
@ -530,8 +528,7 @@ static void maximizeWindowManually(_GLFWwindow* window)
OffsetRect(&rect, 0, GetSystemMetrics(SM_CYCAPTION));
}
if (rect.bottom > mi.rcWork.bottom)
rect.bottom = mi.rcWork.bottom;
rect.bottom = _glfw_min(rect.bottom, mi.rcWork.bottom);
}
SetWindowPos(window->win32.handle, HWND_TOP,

View File

@ -43,11 +43,6 @@
#include <wayland-client.h>
static inline int min(int n1, int n2)
{
return n1 < n2 ? n1 : n2;
}
static _GLFWwindow* findWindowFromDecorationSurface(struct wl_surface* surface,
int* which)
{
@ -784,7 +779,7 @@ static void registryHandleGlobal(void* data,
{
if (strcmp(interface, "wl_compositor") == 0)
{
_glfw.wl.compositorVersion = min(3, version);
_glfw.wl.compositorVersion = _glfw_min(3, version);
_glfw.wl.compositor =
wl_registry_bind(registry, name, &wl_compositor_interface,
_glfw.wl.compositorVersion);
@ -812,7 +807,7 @@ static void registryHandleGlobal(void* data,
{
if (!_glfw.wl.seat)
{
_glfw.wl.seatVersion = min(4, version);
_glfw.wl.seatVersion = _glfw_min(4, version);
_glfw.wl.seat =
wl_registry_bind(registry, name, &wl_seat_interface,
_glfw.wl.seatVersion);

View File

@ -460,11 +460,7 @@ static void checkScaleChange(_GLFWwindow* window)
int maxScale = 1;
for (int i = 0; i < window->wl.monitorsCount; i++)
{
const int scale = window->wl.monitors[i]->wl.scale;
if (maxScale < scale)
maxScale = scale;
}
maxScale = _glfw_max(window->wl.monitors[i]->wl.scale, maxScale);
// Only change the framebuffer size if the scale changed.
if (window->wl.scale != maxScale)