Convert some declarations to C99 style

From upstream: 0c6b505619
This commit is contained in:
Kovid Goyal 2019-07-01 08:32:47 +05:30
parent 6db768d1a3
commit 2ef0391b08
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 86 additions and 128 deletions

View File

@ -299,40 +299,38 @@ static inline void createDisplayLink(CGDirectDisplayID displayID) {
// //
void _glfwPollMonitorsNS(void) void _glfwPollMonitorsNS(void)
{ {
uint32_t i, j, displayCount, disconnectedCount; uint32_t displayCount;
CGDirectDisplayID* displays;
_GLFWmonitor** disconnected = NULL;
CGGetOnlineDisplayList(0, NULL, &displayCount); CGGetOnlineDisplayList(0, NULL, &displayCount);
displays = calloc(displayCount, sizeof(CGDirectDisplayID)); CGDirectDisplayID* displays = calloc(displayCount, sizeof(CGDirectDisplayID));
CGGetOnlineDisplayList(displayCount, displays, &displayCount); CGGetOnlineDisplayList(displayCount, displays, &displayCount);
_glfwClearDisplayLinks(); _glfwClearDisplayLinks();
for (i = 0; i < _glfw.monitorCount; i++) for (uint32_t i = 0; i < _glfw.monitorCount; i++)
_glfw.monitors[i]->ns.screen = nil; _glfw.monitors[i]->ns.screen = nil;
disconnectedCount = _glfw.monitorCount; uint32_t disconnectedCount = _glfw.monitorCount;
if (disconnectedCount) if (disconnectedCount)
{ {
_GLFWmonitor** disconnected = NULL;
disconnected = calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*)); disconnected = calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*));
memcpy(disconnected, memcpy(disconnected,
_glfw.monitors, _glfw.monitors,
_glfw.monitorCount * sizeof(_GLFWmonitor*)); _glfw.monitorCount * sizeof(_GLFWmonitor*));
} }
for (i = 0; i < displayCount; i++) for (uint32_t i = 0; i < displayCount; i++)
{ {
_GLFWmonitor* monitor;
const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]);
if (CGDisplayIsAsleep(displays[i])) if (CGDisplayIsAsleep(displays[i]))
continue; continue;
for (j = 0; j < disconnectedCount; j++)
{
// HACK: Compare unit numbers instead of display IDs to work around // HACK: Compare unit numbers instead of display IDs to work around
// display replacement on machines with automatic graphics // display replacement on machines with automatic graphics
// switching // switching
const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]);
for (uint32_t j = 0; j < disconnectedCount; j++)
{
if (disconnected[j] && disconnected[j]->ns.unitNumber == unitNumber) if (disconnected[j] && disconnected[j]->ns.unitNumber == unitNumber)
{ {
disconnected[j] = NULL; disconnected[j] = NULL;
@ -345,7 +343,7 @@ void _glfwPollMonitorsNS(void)
if (!name) if (!name)
name = _glfw_strdup("Unknown"); name = _glfw_strdup("Unknown");
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];
monitor->ns.unitNumber = unitNumber; monitor->ns.unitNumber = unitNumber;
createDisplayLink(monitor->ns.displayID); createDisplayLink(monitor->ns.displayID);
@ -355,7 +353,7 @@ void _glfwPollMonitorsNS(void)
_glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST); _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST);
} }
for (i = 0; i < disconnectedCount; i++) for (uint32_t i = 0; i < disconnectedCount; i++)
{ {
if (disconnected[i]) if (disconnected[i])
_glfwInputMonitor(disconnected[i], GLFW_DISCONNECTED, 0); _glfwInputMonitor(disconnected[i], GLFW_DISCONNECTED, 0);
@ -370,24 +368,20 @@ void _glfwPollMonitorsNS(void)
// //
void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired) void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{ {
CFArrayRef modes;
CFIndex count, i;
CVDisplayLinkRef link;
CGDisplayModeRef native = NULL;
GLFWvidmode current; GLFWvidmode current;
const GLFWvidmode* best; const GLFWvidmode* best = _glfwChooseVideoMode(monitor, desired);
best = _glfwChooseVideoMode(monitor, desired);
_glfwPlatformGetVideoMode(monitor, &current); _glfwPlatformGetVideoMode(monitor, &current);
if (_glfwCompareVideoModes(&current, best) == 0) if (_glfwCompareVideoModes(&current, best) == 0)
return; return;
CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link); CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL); CFArrayRef modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
count = CFArrayGetCount(modes); const CFIndex count = CFArrayGetCount(modes);
CGDisplayModeRef native = NULL;
for (i = 0; i < count; i++) for (CFIndex i = 0; i < count; i++)
{ {
CGDisplayModeRef dm = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i); CGDisplayModeRef dm = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
if (!modeIsGood(dm)) if (!modeIsGood(dm))
@ -487,20 +481,16 @@ void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count) GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
{ {
CFArrayRef modes;
CFIndex found, i, j;
GLFWvidmode* result;
CVDisplayLinkRef link;
*count = 0; *count = 0;
CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link); CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL); CFArrayRef modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL);
found = CFArrayGetCount(modes); const CFIndex found = CFArrayGetCount(modes);
result = calloc(found, sizeof(GLFWvidmode)); GLFWvidmode* result = calloc(found, sizeof(GLFWvidmode));
for (i = 0; i < found; i++) for (CFIndex i = 0; i < found; i++)
{ {
CGDisplayModeRef dm = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i); CGDisplayModeRef dm = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
if (!modeIsGood(dm)) if (!modeIsGood(dm))
@ -508,7 +498,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
const GLFWvidmode mode = vidmodeFromCGDisplayMode(dm, link); const GLFWvidmode mode = vidmodeFromCGDisplayMode(dm, link);
for (j = 0; j < *count; j++) for (CFIndex j = 0; j < *count; j++)
{ {
if (_glfwCompareVideoModes(result + j, &mode) == 0) if (_glfwCompareVideoModes(result + j, &mode) == 0)
break; break;
@ -529,21 +519,20 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode) void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode)
{ {
CGDisplayModeRef displayMode;
CVDisplayLinkRef link; CVDisplayLinkRef link;
CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link); CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link);
displayMode = CGDisplayCopyDisplayMode(monitor->ns.displayID); CGDisplayModeRef native = CGDisplayCopyDisplayMode(monitor->ns.displayID);
*mode = vidmodeFromCGDisplayMode(displayMode, link); *mode = vidmodeFromCGDisplayMode(native, link);
CGDisplayModeRelease(displayMode); CGDisplayModeRelease(native);
CVDisplayLinkRelease(link); CVDisplayLinkRelease(link);
} }
bool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) bool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
{ {
uint32_t i, size = CGDisplayGammaTableCapacity(monitor->ns.displayID); uint32_t size = CGDisplayGammaTableCapacity(monitor->ns.displayID);
CGGammaValue* values = calloc(size * 3, sizeof(CGGammaValue)); CGGammaValue* values = calloc(size * 3, sizeof(CGGammaValue));
CGGetDisplayTransferByTable(monitor->ns.displayID, CGGetDisplayTransferByTable(monitor->ns.displayID,
@ -555,7 +544,7 @@ bool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
_glfwAllocGammaArrays(ramp, size); _glfwAllocGammaArrays(ramp, size);
for (i = 0; i < size; i++) for (uint32_t i = 0; i < size; i++)
{ {
ramp->red[i] = (unsigned short) (values[i] * 65535); ramp->red[i] = (unsigned short) (values[i] * 65535);
ramp->green[i] = (unsigned short) (values[i + size] * 65535); ramp->green[i] = (unsigned short) (values[i + size] * 65535);
@ -568,10 +557,9 @@ bool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{ {
int i;
CGGammaValue* values = calloc(ramp->size * 3, sizeof(CGGammaValue)); CGGammaValue* values = calloc(ramp->size * 3, sizeof(CGGammaValue));
for (i = 0; i < ramp->size; i++) for (int i = 0; i < ramp->size; i++)
{ {
values[i] = ramp->red[i] / 65535.f; values[i] = ramp->red[i] / 65535.f;
values[i + ramp->size] = ramp->green[i] / 65535.f; values[i + ramp->size] = ramp->green[i] / 65535.f;

View File

@ -992,10 +992,9 @@ is_ascii_control_char(char x) {
- (void)scrollWheel:(NSEvent *)event - (void)scrollWheel:(NSEvent *)event
{ {
double deltaX, deltaY; double deltaX = [event scrollingDeltaX];
double deltaY = [event scrollingDeltaY];
deltaX = [event scrollingDeltaX];
deltaY = [event scrollingDeltaY];
int flags = [event hasPreciseScrollingDeltas] ? 1 : 0; int flags = [event hasPreciseScrollingDeltas] ? 1 : 0;
if (flags) { if (flags) {
float xscale = 1, yscale = 1; float xscale = 1, yscale = 1;

49
glfw/linux_joystick.c vendored
View File

@ -104,9 +104,7 @@ static void handleAbsEvent(_GLFWjoystick* js, int code, int value)
// //
static void pollAbsState(_GLFWjoystick* js) static void pollAbsState(_GLFWjoystick* js)
{ {
int code; for (int code = 0; code < ABS_CNT; code++)
for (code = 0; code < ABS_CNT; code++)
{ {
if (js->linjs.absMap[code] < 0) if (js->linjs.absMap[code] < 0)
continue; continue;
@ -126,18 +124,7 @@ static void pollAbsState(_GLFWjoystick* js)
// //
static bool openJoystickDevice(const char* path) static bool openJoystickDevice(const char* path)
{ {
int jid, code; for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
char name[256] = "";
char guid[33] = "";
char evBits[(EV_CNT + 7) / 8] = {0};
char keyBits[(KEY_CNT + 7) / 8] = {0};
char absBits[(ABS_CNT + 7) / 8] = {0};
int axisCount = 0, buttonCount = 0, hatCount = 0;
struct input_id id;
_GLFWjoystickLinux linjs = {0};
_GLFWjoystick* js = NULL;
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{ {
if (!_glfw.joysticks[jid].present) if (!_glfw.joysticks[jid].present)
continue; continue;
@ -145,10 +132,16 @@ static bool openJoystickDevice(const char* path)
return false; return false;
} }
_GLFWjoystickLinux linjs = {0};
linjs.fd = open(path, O_RDONLY | O_NONBLOCK); linjs.fd = open(path, O_RDONLY | O_NONBLOCK);
if (linjs.fd == -1) if (linjs.fd == -1)
return false; return false;
char evBits[(EV_CNT + 7) / 8] = {0};
char keyBits[(KEY_CNT + 7) / 8] = {0};
char absBits[(ABS_CNT + 7) / 8] = {0};
struct input_id id;
if (ioctl(linjs.fd, EVIOCGBIT(0, sizeof(evBits)), evBits) < 0 || if (ioctl(linjs.fd, EVIOCGBIT(0, sizeof(evBits)), evBits) < 0 ||
ioctl(linjs.fd, EVIOCGBIT(EV_KEY, sizeof(keyBits)), keyBits) < 0 || ioctl(linjs.fd, EVIOCGBIT(EV_KEY, sizeof(keyBits)), keyBits) < 0 ||
ioctl(linjs.fd, EVIOCGBIT(EV_ABS, sizeof(absBits)), absBits) < 0 || ioctl(linjs.fd, EVIOCGBIT(EV_ABS, sizeof(absBits)), absBits) < 0 ||
@ -168,9 +161,13 @@ static bool openJoystickDevice(const char* path)
return false; return false;
} }
char name[256] = "";
if (ioctl(linjs.fd, EVIOCGNAME(sizeof(name)), name) < 0) if (ioctl(linjs.fd, EVIOCGNAME(sizeof(name)), name) < 0)
strncpy(name, "Unknown", sizeof(name)); strncpy(name, "Unknown", sizeof(name));
char guid[33] = "";
// Generate a joystick GUID that matches the SDL 2.0.5+ one // Generate a joystick GUID that matches the SDL 2.0.5+ one
if (id.vendor && id.product && id.version) if (id.vendor && id.product && id.version)
{ {
@ -189,7 +186,9 @@ static bool openJoystickDevice(const char* path)
name[8], name[9], name[10]); name[8], name[9], name[10]);
} }
for (code = BTN_MISC; code < KEY_CNT; code++) int axisCount = 0, buttonCount = 0, hatCount = 0;
for (int code = BTN_MISC; code < KEY_CNT; code++)
{ {
if (!isBitSet(code, keyBits)) if (!isBitSet(code, keyBits))
continue; continue;
@ -198,7 +197,7 @@ static bool openJoystickDevice(const char* path)
buttonCount++; buttonCount++;
} }
for (code = 0; code < ABS_CNT; code++) for (int code = 0; code < ABS_CNT; code++)
{ {
linjs.absMap[code] = -1; linjs.absMap[code] = -1;
if (!isBitSet(code, absBits)) if (!isBitSet(code, absBits))
@ -221,7 +220,7 @@ static bool openJoystickDevice(const char* path)
} }
} }
js = _glfwAllocJoystick(name, guid, axisCount, buttonCount, hatCount); _GLFWjoystick* js = _glfwAllocJoystick(name, guid, axisCount, buttonCount, hatCount);
if (!js) if (!js)
{ {
close(linjs.fd); close(linjs.fd);
@ -266,8 +265,6 @@ static int compareJoysticks(const void* fp, const void* sp)
// //
bool _glfwInitJoysticksLinux(void) bool _glfwInitJoysticksLinux(void)
{ {
DIR* dir;
int count = 0;
const char* dirname = "/dev/input"; const char* dirname = "/dev/input";
_glfw.linjs.inotify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); _glfw.linjs.inotify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
@ -289,7 +286,9 @@ bool _glfwInitJoysticksLinux(void)
return false; return false;
} }
dir = opendir(dirname); int count = 0;
DIR* dir = opendir(dirname);
if (dir) if (dir)
{ {
struct dirent* entry; struct dirent* entry;
@ -344,12 +343,12 @@ void _glfwTerminateJoysticksLinux(void)
void _glfwDetectJoystickConnectionLinux(void) void _glfwDetectJoystickConnectionLinux(void)
{ {
ssize_t offset = 0;
char buffer[16384];
if (_glfw.linjs.inotify <= 0) if (_glfw.linjs.inotify <= 0)
return; return;
ssize_t offset = 0;
char buffer[16384];
const ssize_t size = read(_glfw.linjs.inotify, buffer, sizeof(buffer)); const ssize_t size = read(_glfw.linjs.inotify, buffer, sizeof(buffer));
while (size > offset) while (size > offset)
@ -369,9 +368,7 @@ void _glfwDetectJoystickConnectionLinux(void)
openJoystickDevice(path); openJoystickDevice(path);
else if (e->mask & IN_DELETE) else if (e->mask & IN_DELETE)
{ {
int jid; for (int jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++)
{ {
if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0) if (strcmp(_glfw.joysticks[jid].linjs.path, path) == 0)
{ {

3
glfw/x11_init.c vendored
View File

@ -46,10 +46,9 @@ static Atom getSupportedAtom(Atom* supportedAtoms,
unsigned long atomCount, unsigned long atomCount,
const char* atomName) const char* atomName)
{ {
unsigned long i;
const Atom atom = XInternAtom(_glfw.x11.display, atomName, False); const Atom atom = XInternAtom(_glfw.x11.display, atomName, False);
for (i = 0; i < atomCount; i++) for (unsigned long i = 0; i < atomCount; i++)
{ {
if (supportedAtoms[i] == atom) if (supportedAtoms[i] == atom)
return atom; return atom;

76
glfw/x11_monitor.c vendored
View File

@ -54,9 +54,7 @@ static int calculateRefreshRate(const XRRModeInfo* mi)
// //
static const XRRModeInfo* getModeInfo(const XRRScreenResources* sr, RRMode id) static const XRRModeInfo* getModeInfo(const XRRScreenResources* sr, RRMode id)
{ {
int i; for (int i = 0; i < sr->nmode; i++)
for (i = 0; i < sr->nmode; i++)
{ {
if (sr->modes[i].id == id) if (sr->modes[i].id == id)
return sr->modes + i; return sr->modes + i;
@ -102,7 +100,7 @@ void _glfwPollMonitorsX11(void)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{ {
int i, j, disconnectedCount, screenCount = 0; int disconnectedCount, screenCount = 0;
_GLFWmonitor** disconnected = NULL; _GLFWmonitor** disconnected = NULL;
XineramaScreenInfo* screens = NULL; XineramaScreenInfo* screens = NULL;
XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display,
@ -122,14 +120,11 @@ void _glfwPollMonitorsX11(void)
_glfw.monitorCount * sizeof(_GLFWmonitor*)); _glfw.monitorCount * sizeof(_GLFWmonitor*));
} }
for (i = 0; i < sr->noutput; i++) for (int i = 0; i < sr->noutput; i++)
{ {
int type, widthMM, heightMM; int j, type, widthMM, heightMM;
XRROutputInfo* oi;
XRRCrtcInfo* ci;
_GLFWmonitor* monitor;
oi = XRRGetOutputInfo(_glfw.x11.display, sr, sr->outputs[i]); XRROutputInfo* oi = XRRGetOutputInfo(_glfw.x11.display, sr, sr->outputs[i]);
if (oi->connection != RR_Connected || oi->crtc == None) if (oi->connection != RR_Connected || oi->crtc == None)
{ {
XRRFreeOutputInfo(oi); XRRFreeOutputInfo(oi);
@ -152,7 +147,7 @@ void _glfwPollMonitorsX11(void)
continue; continue;
} }
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, oi->crtc); XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, oi->crtc);
if (!ci) if (!ci)
{ {
XRRFreeOutputInfo(oi); XRRFreeOutputInfo(oi);
@ -169,7 +164,7 @@ void _glfwPollMonitorsX11(void)
heightMM = oi->mm_height; heightMM = oi->mm_height;
} }
monitor = _glfwAllocMonitor(oi->name, widthMM, heightMM); _GLFWmonitor* monitor = _glfwAllocMonitor(oi->name, widthMM, heightMM);
monitor->x11.output = sr->outputs[i]; monitor->x11.output = sr->outputs[i];
monitor->x11.crtc = oi->crtc; monitor->x11.crtc = oi->crtc;
@ -201,7 +196,7 @@ void _glfwPollMonitorsX11(void)
if (screens) if (screens)
XFree(screens); XFree(screens);
for (i = 0; i < disconnectedCount; i++) for (int i = 0; i < disconnectedCount; i++)
{ {
if (disconnected[i]) if (disconnected[i])
_glfwInputMonitor(disconnected[i], GLFW_DISCONNECTED, 0); _glfwInputMonitor(disconnected[i], GLFW_DISCONNECTED, 0);
@ -226,24 +221,19 @@ void _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{ {
XRRScreenResources* sr;
XRRCrtcInfo* ci;
XRROutputInfo* oi;
GLFWvidmode current; GLFWvidmode current;
const GLFWvidmode* best;
RRMode native = None; RRMode native = None;
int i;
best = _glfwChooseVideoMode(monitor, desired); const GLFWvidmode* best = _glfwChooseVideoMode(monitor, desired);
_glfwPlatformGetVideoMode(monitor, &current); _glfwPlatformGetVideoMode(monitor, &current);
if (_glfwCompareVideoModes(&current, best) == 0) if (_glfwCompareVideoModes(&current, best) == 0)
return; return;
sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root);
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output); XRROutputInfo* oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output);
for (i = 0; i < oi->nmode; i++) for (int i = 0; i < oi->nmode; i++)
{ {
const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]); const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]);
if (!modeIsGood(mi)) if (!modeIsGood(mi))
@ -284,14 +274,11 @@ void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{ {
XRRScreenResources* sr;
XRRCrtcInfo* ci;
if (monitor->x11.oldMode == None) if (monitor->x11.oldMode == None)
return; return;
sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root);
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
XRRSetCrtcConfig(_glfw.x11.display, XRRSetCrtcConfig(_glfw.x11.display,
sr, monitor->x11.crtc, sr, monitor->x11.crtc,
@ -322,11 +309,9 @@ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{ {
XRRScreenResources* sr;
XRRCrtcInfo* ci;
sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root);
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
if (ci) if (ci)
{ {
if (xpos) if (xpos)
@ -355,11 +340,9 @@ void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, int* xpos, int* ypos
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{ {
XRRScreenResources* sr;
XRRCrtcInfo* ci;
sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root);
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
areaX = ci->x; areaX = ci->x;
areaY = ci->y; areaY = ci->y;
@ -451,24 +434,20 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{ {
int i, j; XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root);
XRRScreenResources* sr; XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
XRRCrtcInfo* ci; XRROutputInfo* oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output);
XRROutputInfo* oi;
sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root);
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output);
result = calloc(oi->nmode, sizeof(GLFWvidmode)); result = calloc(oi->nmode, sizeof(GLFWvidmode));
for (i = 0; i < oi->nmode; i++) for (int i = 0; i < oi->nmode; i++)
{ {
const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]); const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]);
if (!modeIsGood(mi)) if (!modeIsGood(mi))
continue; continue;
const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci); const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci);
int j;
for (j = 0; j < *count; j++) for (j = 0; j < *count; j++)
{ {
@ -502,11 +481,9 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{ {
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{ {
XRRScreenResources* sr;
XRRCrtcInfo* ci;
sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root);
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc);
if (ci) { if (ci) {
const XRRModeInfo* mi = getModeInfo(sr, ci->mode); const XRRModeInfo* mi = getModeInfo(sr, ci->mode);
@ -620,4 +597,3 @@ GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* handle)
_GLFW_REQUIRE_INIT_OR_RETURN(None); _GLFW_REQUIRE_INIT_OR_RETURN(None);
return monitor->x11.output; return monitor->x11.output;
} }

5
glfw/x11_window.c vendored
View File

@ -852,7 +852,6 @@ static void handleSelectionRequest(XEvent* event)
static const char* getSelectionString(Atom selection) static const char* getSelectionString(Atom selection)
{ {
size_t i;
char** selectionString = NULL; char** selectionString = NULL;
const Atom targets[] = { _glfw.x11.UTF8_STRING, XA_STRING }; const Atom targets[] = { _glfw.x11.UTF8_STRING, XA_STRING };
const size_t targetCount = sizeof(targets) / sizeof(targets[0]); const size_t targetCount = sizeof(targets) / sizeof(targets[0]);
@ -873,7 +872,7 @@ static const char* getSelectionString(Atom selection)
free(*selectionString); free(*selectionString);
*selectionString = NULL; *selectionString = NULL;
for (i = 0; i < targetCount; i++) for (size_t i = 0; i < targetCount; i++)
{ {
char* data; char* data;
Atom actualType; Atom actualType;
@ -1070,7 +1069,6 @@ static void onConfigChange(void)
// //
static void processEvent(XEvent *event) static void processEvent(XEvent *event)
{ {
_GLFWwindow* window = NULL;
static bool keymap_dirty = false; static bool keymap_dirty = false;
#define UPDATE_KEYMAP_IF_NEEDED if (keymap_dirty) { keymap_dirty = false; glfw_xkb_compile_keymap(&_glfw.x11.xkb, NULL); } #define UPDATE_KEYMAP_IF_NEEDED if (keymap_dirty) { keymap_dirty = false; glfw_xkb_compile_keymap(&_glfw.x11.xkb, NULL); }
@ -1165,6 +1163,7 @@ static void processEvent(XEvent *event)
return; return;
} }
_GLFWwindow* window = NULL;
if (XFindContext(_glfw.x11.display, if (XFindContext(_glfw.x11.display,
event->xany.window, event->xany.window,
_glfw.x11.context, _glfw.x11.context,