mirror of
https://github.com/glfw/glfw.git
synced 2026-09-21 08:39:45 +00:00
Merge branch 'master' into showwindow
Conflicts: src/window.c
This commit is contained in:
@@ -528,7 +528,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
|
||||
// Get joystick axis positions
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
|
||||
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -556,12 +556,12 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
|
||||
long readScale = axes->maxReport - axes->minReport;
|
||||
|
||||
if (readScale == 0)
|
||||
pos[i] = axes->value;
|
||||
axes[i] = axes->value;
|
||||
else
|
||||
pos[i] = (2.0f * (axes->value - axes->minReport) / readScale) - 1.0f;
|
||||
axes[i] = (2.0f * (axes->value - axes->minReport) / readScale) - 1.0f;
|
||||
|
||||
if (i & 1)
|
||||
pos[i] = -pos[i];
|
||||
axes[i] = -axes[i];
|
||||
}
|
||||
|
||||
return numaxes;
|
||||
|
||||
+1
-1
@@ -276,7 +276,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window);
|
||||
|
||||
// Joystick input
|
||||
int _glfwPlatformGetJoystickParam(int joy, int param);
|
||||
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes);
|
||||
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes);
|
||||
int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
|
||||
|
||||
// Time input
|
||||
|
||||
+4
-4
@@ -61,7 +61,7 @@ GLFWAPI int glfwGetJoystickParam(int joy, int param)
|
||||
// Get joystick axis positions
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes)
|
||||
GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -77,7 +77,7 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pos == NULL || numaxes < 0)
|
||||
if (axes == NULL || numaxes < 0)
|
||||
{
|
||||
_glfwSetError(GLFW_INVALID_VALUE, NULL);
|
||||
return 0;
|
||||
@@ -85,9 +85,9 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes)
|
||||
|
||||
// Clear positions
|
||||
for (i = 0; i < numaxes; i++)
|
||||
pos[i] = 0.0f;
|
||||
axes[i] = 0.0f;
|
||||
|
||||
return _glfwPlatformGetJoystickPos(joy, pos, numaxes);
|
||||
return _glfwPlatformGetJoystickAxes(joy, axes, numaxes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
|
||||
// Get joystick axis positions
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
|
||||
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes)
|
||||
{
|
||||
JOYCAPS jc;
|
||||
JOYINFOEX ji;
|
||||
@@ -137,22 +137,22 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes)
|
||||
// Get position values for all axes
|
||||
axis = 0;
|
||||
if (axis < numaxes)
|
||||
pos[axis++] = calcJoystickPos(ji.dwXpos, jc.wXmin, jc.wXmax);
|
||||
axes[axis++] = calcJoystickPos(ji.dwXpos, jc.wXmin, jc.wXmax);
|
||||
|
||||
if (axis < numaxes)
|
||||
pos[axis++] = -calcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax);
|
||||
axes[axis++] = -calcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax);
|
||||
|
||||
if (axis < numaxes && jc.wCaps & JOYCAPS_HASZ)
|
||||
pos[axis++] = calcJoystickPos(ji.dwZpos, jc.wZmin, jc.wZmax);
|
||||
axes[axis++] = calcJoystickPos(ji.dwZpos, jc.wZmin, jc.wZmax);
|
||||
|
||||
if (axis < numaxes && jc.wCaps & JOYCAPS_HASR)
|
||||
pos[axis++] = calcJoystickPos(ji.dwRpos, jc.wRmin, jc.wRmax);
|
||||
axes[axis++] = calcJoystickPos(ji.dwRpos, jc.wRmin, jc.wRmax);
|
||||
|
||||
if (axis < numaxes && jc.wCaps & JOYCAPS_HASU)
|
||||
pos[axis++] = calcJoystickPos(ji.dwUpos, jc.wUmin, jc.wUmax);
|
||||
axes[axis++] = calcJoystickPos(ji.dwUpos, jc.wUmin, jc.wUmax);
|
||||
|
||||
if (axis < numaxes && jc.wCaps & JOYCAPS_HASV)
|
||||
pos[axis++] = -calcJoystickPos(ji.dwVpos, jc.wVmin, jc.wVmax);
|
||||
axes[axis++] = -calcJoystickPos(ji.dwVpos, jc.wVmin, jc.wVmax);
|
||||
|
||||
return axis;
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ typedef struct _GLFWlibraryWin32
|
||||
|
||||
// Timer data
|
||||
struct {
|
||||
GLboolean hasPerformanceCounter;
|
||||
GLboolean hasPC;
|
||||
double resolution;
|
||||
unsigned int t0_32;
|
||||
__int64 t0_64;
|
||||
|
||||
+4
-4
@@ -45,13 +45,13 @@ void _glfwInitTimer(void)
|
||||
|
||||
if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq))
|
||||
{
|
||||
_glfwLibrary.Win32.timer.hasPerformanceCounter = GL_TRUE;
|
||||
_glfwLibrary.Win32.timer.hasPC = GL_TRUE;
|
||||
_glfwLibrary.Win32.timer.resolution = 1.0 / (double) freq;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*) &_glfwLibrary.Win32.timer.t0_64);
|
||||
}
|
||||
else
|
||||
{
|
||||
_glfwLibrary.Win32.timer.hasPerformanceCounter = GL_FALSE;
|
||||
_glfwLibrary.Win32.timer.hasPC = GL_FALSE;
|
||||
_glfwLibrary.Win32.timer.resolution = 0.001; // winmm resolution is 1 ms
|
||||
_glfwLibrary.Win32.timer.t0_32 = _glfw_timeGetTime();
|
||||
}
|
||||
@@ -71,7 +71,7 @@ double _glfwPlatformGetTime(void)
|
||||
double t;
|
||||
__int64 t_64;
|
||||
|
||||
if (_glfwLibrary.Win32.timer.hasPerformanceCounter)
|
||||
if (_glfwLibrary.Win32.timer.hasPC)
|
||||
{
|
||||
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
|
||||
t = (double)(t_64 - _glfwLibrary.Win32.timer.t0_64);
|
||||
@@ -91,7 +91,7 @@ void _glfwPlatformSetTime(double t)
|
||||
{
|
||||
__int64 t_64;
|
||||
|
||||
if (_glfwLibrary.Win32.timer.hasPerformanceCounter)
|
||||
if (_glfwLibrary.Win32.timer.hasPC)
|
||||
{
|
||||
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
|
||||
_glfwLibrary.Win32.timer.t0_64 = t_64 - (__int64) (t / _glfwLibrary.Win32.timer.resolution);
|
||||
|
||||
@@ -85,6 +85,12 @@ void _glfwSetDefaultWindowHints(void)
|
||||
// The default is to show the window and allow window resizing
|
||||
_glfwLibrary.hints.resizable = GL_TRUE;
|
||||
_glfwLibrary.hints.visible = GL_TRUE;
|
||||
|
||||
// The default is 24 bits of depth, 8 bits of color
|
||||
_glfwLibrary.hints.depthBits = 24;
|
||||
_glfwLibrary.hints.redBits = 8;
|
||||
_glfwLibrary.hints.greenBits = 8;
|
||||
_glfwLibrary.hints.blueBits = 8;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+20
-7
@@ -36,6 +36,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -109,6 +110,7 @@ static void pollJoystickEvents(void)
|
||||
{
|
||||
#ifdef _GLFW_USE_LINUX_JOYSTICKS
|
||||
int i;
|
||||
ssize_t result;
|
||||
struct js_event e;
|
||||
|
||||
for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
|
||||
@@ -117,8 +119,17 @@ static void pollJoystickEvents(void)
|
||||
continue;
|
||||
|
||||
// Read all queued events (non-blocking)
|
||||
while (read(_glfwLibrary.X11.joystick[i].fd, &e, sizeof(e)) > 0)
|
||||
for (;;)
|
||||
{
|
||||
errno = 0;
|
||||
result = read(_glfwLibrary.X11.joystick[i].fd, &e, sizeof(e));
|
||||
|
||||
if (errno == ENODEV)
|
||||
_glfwLibrary.X11.joystick[i].present = GL_FALSE;
|
||||
|
||||
if (result < sizeof(e))
|
||||
break;
|
||||
|
||||
// We don't care if it's an init event or not
|
||||
e.type &= ~JS_EVENT_INIT;
|
||||
|
||||
@@ -221,6 +232,8 @@ void _glfwTerminateJoysticks(void)
|
||||
|
||||
int _glfwPlatformGetJoystickParam(int joy, int param)
|
||||
{
|
||||
pollJoystickEvents();
|
||||
|
||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||
return 0;
|
||||
|
||||
@@ -247,20 +260,20 @@ int _glfwPlatformGetJoystickParam(int joy, int param)
|
||||
// Get joystick axis positions
|
||||
//========================================================================
|
||||
|
||||
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numAxes)
|
||||
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numAxes)
|
||||
{
|
||||
int i;
|
||||
|
||||
pollJoystickEvents();
|
||||
|
||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||
return 0;
|
||||
|
||||
pollJoystickEvents();
|
||||
|
||||
if (_glfwLibrary.X11.joystick[joy].numAxes < numAxes)
|
||||
numAxes = _glfwLibrary.X11.joystick[joy].numAxes;
|
||||
|
||||
for (i = 0; i < numAxes; i++)
|
||||
pos[i] = _glfwLibrary.X11.joystick[joy].axis[i];
|
||||
axes[i] = _glfwLibrary.X11.joystick[joy].axis[i];
|
||||
|
||||
return numAxes;
|
||||
}
|
||||
@@ -275,11 +288,11 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
|
||||
{
|
||||
int i;
|
||||
|
||||
pollJoystickEvents();
|
||||
|
||||
if (!_glfwLibrary.X11.joystick[joy].present)
|
||||
return 0;
|
||||
|
||||
pollJoystickEvents();
|
||||
|
||||
if (_glfwLibrary.X11.joystick[joy].numButtons < numButtons)
|
||||
numButtons = _glfwLibrary.X11.joystick[joy].numButtons;
|
||||
|
||||
|
||||
@@ -473,17 +473,10 @@ static void processSingleEvent(void)
|
||||
// A keyboard key was pressed
|
||||
window = findWindow(event.xkey.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for KeyPress event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Translate and report key press
|
||||
_glfwInputKey(window, translateKey(event.xkey.keycode), GLFW_PRESS);
|
||||
|
||||
// Translate and report character input
|
||||
_glfwInputChar(window, translateChar(&event.xkey));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -492,10 +485,7 @@ static void processSingleEvent(void)
|
||||
// A keyboard key was released
|
||||
window = findWindow(event.xkey.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for KeyRelease event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not report key releases for key repeats. For key repeats we
|
||||
// will get KeyRelease/KeyPress pairs with similar or identical
|
||||
@@ -523,9 +513,7 @@ static void processSingleEvent(void)
|
||||
}
|
||||
}
|
||||
|
||||
// Translate and report key release
|
||||
_glfwInputKey(window, translateKey(event.xkey.keycode), GLFW_RELEASE);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -534,10 +522,7 @@ static void processSingleEvent(void)
|
||||
// A mouse button was pressed or a scrolling event occurred
|
||||
window = findWindow(event.xbutton.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for ButtonPress event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.xbutton.button == Button1)
|
||||
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS);
|
||||
@@ -566,10 +551,7 @@ static void processSingleEvent(void)
|
||||
// A mouse button was released
|
||||
window = findWindow(event.xbutton.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for ButtonRelease event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.xbutton.button == Button1)
|
||||
{
|
||||
@@ -597,10 +579,7 @@ static void processSingleEvent(void)
|
||||
// The cursor entered the window
|
||||
window = findWindow(event.xcrossing.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for EnterNotify event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
||||
hideCursor(window);
|
||||
@@ -614,10 +593,7 @@ static void processSingleEvent(void)
|
||||
// The cursor left the window
|
||||
window = findWindow(event.xcrossing.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for LeaveNotify event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (window->cursorMode == GLFW_CURSOR_HIDDEN)
|
||||
showCursor(window);
|
||||
@@ -631,10 +607,7 @@ static void processSingleEvent(void)
|
||||
// The cursor was moved
|
||||
window = findWindow(event.xmotion.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for MotionNotify event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.xmotion.x != window->X11.cursorPosX ||
|
||||
event.xmotion.y != window->X11.cursorPosY)
|
||||
@@ -672,10 +645,7 @@ static void processSingleEvent(void)
|
||||
// The window configuration changed somehow
|
||||
window = findWindow(event.xconfigure.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for ConfigureNotify event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwInputWindowSize(window,
|
||||
event.xconfigure.width,
|
||||
@@ -693,10 +663,7 @@ static void processSingleEvent(void)
|
||||
// Custom client message, probably from the window manager
|
||||
window = findWindow(event.xclient.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for ClientMessage event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((Atom) event.xclient.data.l[0] == _glfwLibrary.X11.wmDeleteWindow)
|
||||
{
|
||||
@@ -727,10 +694,7 @@ static void processSingleEvent(void)
|
||||
// The window was mapped
|
||||
window = findWindow(event.xmap.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for MapNotify event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwInputWindowVisibility(window, GL_TRUE);
|
||||
_glfwInputWindowIconify(window, GL_FALSE);
|
||||
@@ -742,10 +706,7 @@ static void processSingleEvent(void)
|
||||
// The window was unmapped
|
||||
window = findWindow(event.xmap.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for UnmapNotify event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwInputWindowVisibility(window, GL_FALSE);
|
||||
_glfwInputWindowIconify(window, GL_TRUE);
|
||||
@@ -757,10 +718,7 @@ static void processSingleEvent(void)
|
||||
// The window gained focus
|
||||
window = findWindow(event.xfocus.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for FocusIn event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwInputWindowFocus(window, GL_TRUE);
|
||||
|
||||
@@ -775,10 +733,7 @@ static void processSingleEvent(void)
|
||||
// The window lost focus
|
||||
window = findWindow(event.xfocus.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for FocusOut event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwInputWindowFocus(window, GL_FALSE);
|
||||
|
||||
@@ -793,10 +748,7 @@ static void processSingleEvent(void)
|
||||
// The window's contents was damaged
|
||||
window = findWindow(event.xexpose.window);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Cannot find GLFW window structure for Expose event\n");
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwInputWindowDamage(window);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user