mirror of
https://github.com/glfw/glfw.git
synced 2024-11-14 06:23:50 +00:00
Make monitor and joystick names static strings
Related to #478.
(cherry picked from commit da236ba807
)
This commit is contained in:
parent
020ce99170
commit
e756ae1d85
@ -63,7 +63,7 @@ static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen)
|
|||||||
&it) != 0)
|
&it) != 0)
|
||||||
{
|
{
|
||||||
// This may happen if a desktop Mac is running headless
|
// This may happen if a desktop Mac is running headless
|
||||||
return NULL;
|
return _glfw_strdup("Display");
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((service = IOIteratorNext(it)) != 0)
|
while ((service = IOIteratorNext(it)) != 0)
|
||||||
@ -101,7 +101,7 @@ static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen)
|
|||||||
{
|
{
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
"Cocoa: Failed to find service port for display");
|
"Cocoa: Failed to find service port for display");
|
||||||
return NULL;
|
return _glfw_strdup("Display");
|
||||||
}
|
}
|
||||||
|
|
||||||
CFDictionaryRef names =
|
CFDictionaryRef names =
|
||||||
@ -114,7 +114,7 @@ static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen)
|
|||||||
{
|
{
|
||||||
// This may happen if a desktop Mac is running headless
|
// This may happen if a desktop Mac is running headless
|
||||||
CFRelease(info);
|
CFRelease(info);
|
||||||
return NULL;
|
return _glfw_strdup("Display");
|
||||||
}
|
}
|
||||||
|
|
||||||
const CFIndex size =
|
const CFIndex size =
|
||||||
@ -356,7 +356,7 @@ void _glfwPollMonitorsNS(void)
|
|||||||
const CGSize size = CGDisplayScreenSize(displays[i]);
|
const CGSize size = CGDisplayScreenSize(displays[i]);
|
||||||
char* name = getMonitorName(displays[i], screen);
|
char* name = getMonitorName(displays[i], screen);
|
||||||
if (!name)
|
if (!name)
|
||||||
name = _glfw_strdup("Unknown");
|
continue;
|
||||||
|
|
||||||
_GLFWmonitor* monitor = _glfwAllocMonitor(name, size.width, size.height);
|
_GLFWmonitor* monitor = _glfwAllocMonitor(name, size.width, size.height);
|
||||||
monitor->ns.displayID = displays[i];
|
monitor->ns.displayID = displays[i];
|
||||||
|
@ -430,7 +430,6 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
|
|||||||
|
|
||||||
js = _glfw.joysticks + jid;
|
js = _glfw.joysticks + jid;
|
||||||
js->present = GLFW_TRUE;
|
js->present = GLFW_TRUE;
|
||||||
js->name = _glfw_strdup(name);
|
|
||||||
js->axes = calloc(axisCount, sizeof(float));
|
js->axes = calloc(axisCount, sizeof(float));
|
||||||
js->buttons = calloc(buttonCount + (size_t) hatCount * 4, 1);
|
js->buttons = calloc(buttonCount + (size_t) hatCount * 4, 1);
|
||||||
js->hats = calloc(hatCount, 1);
|
js->hats = calloc(hatCount, 1);
|
||||||
@ -438,6 +437,7 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
|
|||||||
js->buttonCount = buttonCount;
|
js->buttonCount = buttonCount;
|
||||||
js->hatCount = hatCount;
|
js->hatCount = hatCount;
|
||||||
|
|
||||||
|
strncpy(js->name, name, sizeof(js->name) - 1);
|
||||||
strncpy(js->guid, guid, sizeof(js->guid) - 1);
|
strncpy(js->guid, guid, sizeof(js->guid) - 1);
|
||||||
js->mapping = findValidMapping(js);
|
js->mapping = findValidMapping(js);
|
||||||
|
|
||||||
@ -448,7 +448,6 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
|
|||||||
//
|
//
|
||||||
void _glfwFreeJoystick(_GLFWjoystick* js)
|
void _glfwFreeJoystick(_GLFWjoystick* js)
|
||||||
{
|
{
|
||||||
free(js->name);
|
|
||||||
free(js->axes);
|
free(js->axes);
|
||||||
free(js->buttons);
|
free(js->buttons);
|
||||||
free(js->hats);
|
free(js->hats);
|
||||||
|
@ -423,7 +423,7 @@ struct _GLFWwindow
|
|||||||
//
|
//
|
||||||
struct _GLFWmonitor
|
struct _GLFWmonitor
|
||||||
{
|
{
|
||||||
char* name;
|
char name[128];
|
||||||
void* userPointer;
|
void* userPointer;
|
||||||
|
|
||||||
// Physical dimensions in millimeters.
|
// Physical dimensions in millimeters.
|
||||||
@ -484,7 +484,7 @@ struct _GLFWjoystick
|
|||||||
int buttonCount;
|
int buttonCount;
|
||||||
unsigned char* hats;
|
unsigned char* hats;
|
||||||
int hatCount;
|
int hatCount;
|
||||||
char* name;
|
char name[128];
|
||||||
void* userPointer;
|
void* userPointer;
|
||||||
char guid[33];
|
char guid[33];
|
||||||
_GLFWmapping* mapping;
|
_GLFWmapping* mapping;
|
||||||
|
@ -170,8 +170,7 @@ _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM)
|
|||||||
monitor->widthMM = widthMM;
|
monitor->widthMM = widthMM;
|
||||||
monitor->heightMM = heightMM;
|
monitor->heightMM = heightMM;
|
||||||
|
|
||||||
if (name)
|
strncpy(monitor->name, name, sizeof(monitor->name) - 1);
|
||||||
monitor->name = _glfw_strdup(name);
|
|
||||||
|
|
||||||
return monitor;
|
return monitor;
|
||||||
}
|
}
|
||||||
@ -189,7 +188,6 @@ void _glfwFreeMonitor(_GLFWmonitor* monitor)
|
|||||||
_glfwFreeGammaArrays(&monitor->currentRamp);
|
_glfwFreeGammaArrays(&monitor->currentRamp);
|
||||||
|
|
||||||
free(monitor->modes);
|
free(monitor->modes);
|
||||||
free(monitor->name);
|
|
||||||
free(monitor);
|
free(monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,15 +47,13 @@ static void outputHandleGeometry(void* data,
|
|||||||
int32_t transform)
|
int32_t transform)
|
||||||
{
|
{
|
||||||
struct _GLFWmonitor *monitor = data;
|
struct _GLFWmonitor *monitor = data;
|
||||||
char name[1024];
|
|
||||||
|
|
||||||
monitor->wl.x = x;
|
monitor->wl.x = x;
|
||||||
monitor->wl.y = y;
|
monitor->wl.y = y;
|
||||||
monitor->widthMM = physicalWidth;
|
monitor->widthMM = physicalWidth;
|
||||||
monitor->heightMM = physicalHeight;
|
monitor->heightMM = physicalHeight;
|
||||||
|
|
||||||
snprintf(name, sizeof(name), "%s %s", make, model);
|
snprintf(monitor->name, sizeof(monitor->name), "%s %s", make, model);
|
||||||
monitor->name = _glfw_strdup(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void outputHandleMode(void* data,
|
static void outputHandleMode(void* data,
|
||||||
@ -133,7 +131,7 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The actual name of this output will be set in the geometry handler.
|
// The actual name of this output will be set in the geometry handler.
|
||||||
monitor = _glfwAllocMonitor(NULL, 0, 0);
|
monitor = _glfwAllocMonitor("", 0, 0);
|
||||||
|
|
||||||
output = wl_registry_bind(_glfw.wl.registry,
|
output = wl_registry_bind(_glfw.wl.registry,
|
||||||
name,
|
name,
|
||||||
|
Loading…
Reference in New Issue
Block a user