mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-11-10 13:04:03 +03:00
Update glfw from upstream
This commit is contained in:
parent
f80f61f84f
commit
44b84ba295
66
glfw/backend_utils.h
vendored
Normal file
66
glfw/backend_utils.h
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
//========================================================================
|
||||
// GLFW 3.3 Wayland - www.glfw.org
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2014 Jonas Ådahl <jadahl@gmail.com>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#pragma once
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef __NetBSD__
|
||||
#define ppoll pollts
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
drainFd(int fd) {
|
||||
static char drain_buf[64];
|
||||
while(read(fd, drain_buf, sizeof(drain_buf)) < 0 && errno == EINTR);
|
||||
}
|
||||
|
||||
|
||||
static inline int
|
||||
pollWithTimeout(struct pollfd *fds, nfds_t nfds, double timeout) {
|
||||
const long seconds = (long) timeout;
|
||||
const long nanoseconds = (long) ((timeout - seconds) * 1e9);
|
||||
struct timespec tv = { seconds, nanoseconds };
|
||||
return ppoll(fds, nfds, &tv, NULL);
|
||||
}
|
||||
|
||||
static inline void
|
||||
initPollData(struct pollfd *fds, int wakeup_fd, int display_fd) {
|
||||
fds[0].fd = wakeup_fd; fds[1].fd = display_fd;
|
||||
fds[0].events = POLLIN; fds[1].events = POLLIN;
|
||||
}
|
||||
|
||||
static inline void
|
||||
closeFds(int *fds, size_t count) {
|
||||
while(count--) {
|
||||
if (*fds > 0) {
|
||||
close(*fds);
|
||||
*fds = -1;
|
||||
}
|
||||
fds++;
|
||||
}
|
||||
}
|
@ -58,6 +58,7 @@
|
||||
"posix_time.h",
|
||||
"posix_thread.h",
|
||||
"xkb_glfw.h",
|
||||
"backend_utils.h",
|
||||
"egl_context.h",
|
||||
"osmesa_context.h",
|
||||
"linux_joystick.h",
|
||||
@ -111,6 +112,7 @@
|
||||
"headers": [
|
||||
"x11_platform.h",
|
||||
"xkb_glfw.h",
|
||||
"backend_utils.h",
|
||||
"posix_time.h",
|
||||
"posix_thread.h",
|
||||
"glx_context.h",
|
||||
|
18
glfw/wl_init.c
vendored
18
glfw/wl_init.c
vendored
@ -26,6 +26,7 @@
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include "internal.h"
|
||||
#include "backend_utils.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <linux/input.h>
|
||||
@ -663,10 +664,7 @@ int _glfwPlatformInit(void)
|
||||
"Wayland: Failed to connect to display");
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
_glfw.wl.eventLoopData.fds[0].fd = _glfw.wl.eventLoopData.wakeupFds[0];
|
||||
_glfw.wl.eventLoopData.fds[1].fd = wl_display_get_fd(_glfw.wl.display);
|
||||
_glfw.wl.eventLoopData.fds[0].events = POLLIN;
|
||||
_glfw.wl.eventLoopData.fds[1].events = POLLIN;
|
||||
initPollData(_glfw.wl.eventLoopData.fds, _glfw.wl.eventLoopData.wakeupFds[0], wl_display_get_fd(_glfw.wl.display));
|
||||
|
||||
_glfw.wl.registry = wl_display_get_registry(_glfw.wl.display);
|
||||
wl_registry_add_listener(_glfw.wl.registry, ®istryListener, NULL);
|
||||
@ -704,17 +702,6 @@ int _glfwPlatformInit(void)
|
||||
|
||||
void _glfwPlatformTerminate(void)
|
||||
{
|
||||
if (_glfw.wl.eventLoopData.wakeupFds[0] > 0)
|
||||
{
|
||||
close(_glfw.wl.eventLoopData.wakeupFds[0]);
|
||||
_glfw.wl.eventLoopData.wakeupFds[0] = -1;
|
||||
}
|
||||
if (_glfw.wl.eventLoopData.wakeupFds[1] > 0)
|
||||
{
|
||||
close(_glfw.wl.eventLoopData.wakeupFds[1]);
|
||||
_glfw.wl.eventLoopData.wakeupFds[1] = -1;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
_glfwTerminateJoysticksLinux();
|
||||
#endif
|
||||
@ -768,6 +755,7 @@ void _glfwPlatformTerminate(void)
|
||||
wl_display_flush(_glfw.wl.display);
|
||||
wl_display_disconnect(_glfw.wl.display);
|
||||
}
|
||||
closeFds(_glfw.wl.eventLoopData.wakeupFds, sizeof(_glfw.wl.eventLoopData.wakeupFds)/sizeof(_glfw.wl.eventLoopData.wakeupFds[0]));
|
||||
}
|
||||
|
||||
const char* _glfwPlatformGetVersionString(void)
|
||||
|
26
glfw/wl_window.c
vendored
26
glfw/wl_window.c
vendored
@ -27,15 +27,14 @@
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include "internal.h"
|
||||
#include "backend_utils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <poll.h>
|
||||
|
||||
|
||||
static void handlePing(void* data,
|
||||
@ -710,16 +709,6 @@ adjustTimeoutForKeyRepeat(double timeout) {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
#ifdef __NetBSD__
|
||||
#define ppoll pollts
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
drainFd(int fd) {
|
||||
static char drain_buf[64];
|
||||
while(read(fd, drain_buf, sizeof(drain_buf)) < 0 && errno == EINTR);
|
||||
}
|
||||
|
||||
static void
|
||||
handleEvents(double timeout)
|
||||
{
|
||||
@ -748,19 +737,16 @@ handleEvents(double timeout)
|
||||
GLFWbool read_ok = GLFW_FALSE;
|
||||
|
||||
if (timeout >= 0) {
|
||||
const long seconds = (long) timeout;
|
||||
const long nanoseconds = (long) ((timeout - seconds) * 1e9);
|
||||
struct timespec tv = { seconds, nanoseconds };
|
||||
const int result = ppoll(_glfw.wl.eventLoopData.fds, 2, &tv, NULL);
|
||||
const int result = pollWithTimeout(_glfw.wl.eventLoopData.fds, 2, timeout);
|
||||
if (result > 0)
|
||||
{
|
||||
if (_glfw.wl.eventLoopData.fds[0].revents && POLLIN) drainFd(_glfw.wl.eventLoopData.fds[0].fd);
|
||||
read_ok = _glfw.wl.eventLoopData.fds[1].revents && POLLIN;
|
||||
if (_glfw.wl.eventLoopData.fds[0].revents & POLLIN) drainFd(_glfw.wl.eventLoopData.fds[0].fd);
|
||||
read_ok = _glfw.wl.eventLoopData.fds[1].revents & POLLIN;
|
||||
}
|
||||
} else {
|
||||
if (poll(_glfw.wl.eventLoopData.fds, 2, -1) > 0) {
|
||||
if (_glfw.wl.eventLoopData.fds[0].revents && POLLIN) drainFd(_glfw.wl.eventLoopData.fds[0].fd);
|
||||
read_ok = _glfw.wl.eventLoopData.fds[1].revents && POLLIN;
|
||||
if (_glfw.wl.eventLoopData.fds[0].revents & POLLIN) drainFd(_glfw.wl.eventLoopData.fds[0].fd);
|
||||
read_ok = _glfw.wl.eventLoopData.fds[1].revents & POLLIN;
|
||||
}
|
||||
}
|
||||
if (read_ok) {
|
||||
|
17
glfw/x11_init.c
vendored
17
glfw/x11_init.c
vendored
@ -27,6 +27,7 @@
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include "internal.h"
|
||||
#include "backend_utils.h"
|
||||
|
||||
#include <X11/Xresource.h>
|
||||
|
||||
@ -625,10 +626,7 @@ int _glfwPlatformInit(void)
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
_glfw.x11.eventLoopData.fds[0].fd = _glfw.x11.eventLoopData.wakeupFds[0];
|
||||
_glfw.x11.eventLoopData.fds[1].fd = ConnectionNumber(_glfw.x11.display);
|
||||
_glfw.x11.eventLoopData.fds[0].events = POLLIN;
|
||||
_glfw.x11.eventLoopData.fds[1].events = POLLIN;
|
||||
initPollData(_glfw.x11.eventLoopData.fds, _glfw.x11.eventLoopData.wakeupFds[0], ConnectionNumber(_glfw.x11.display));
|
||||
_glfw.x11.eventLoopData.fds[2].events = POLLIN;
|
||||
|
||||
_glfw.x11.screen = DefaultScreen(_glfw.x11.display);
|
||||
@ -682,16 +680,6 @@ void _glfwPlatformTerminate(void)
|
||||
{
|
||||
XCloseDisplay(_glfw.x11.display);
|
||||
_glfw.x11.display = NULL;
|
||||
if (_glfw.x11.eventLoopData.wakeupFds[0] > 0)
|
||||
{
|
||||
close(_glfw.x11.eventLoopData.wakeupFds[0]);
|
||||
_glfw.x11.eventLoopData.wakeupFds[0] = -1;
|
||||
}
|
||||
if (_glfw.x11.eventLoopData.wakeupFds[1] > 0)
|
||||
{
|
||||
close(_glfw.x11.eventLoopData.wakeupFds[1]);
|
||||
_glfw.x11.eventLoopData.wakeupFds[1] = -1;
|
||||
}
|
||||
_glfw.x11.eventLoopData.fds[0].fd = -1;
|
||||
}
|
||||
|
||||
@ -739,6 +727,7 @@ void _glfwPlatformTerminate(void)
|
||||
#if defined(__linux__)
|
||||
_glfwTerminateJoysticksLinux();
|
||||
#endif
|
||||
closeFds(_glfw.x11.eventLoopData.wakeupFds, sizeof(_glfw.x11.eventLoopData.wakeupFds)/sizeof(_glfw.x11.eventLoopData.wakeupFds[0]));
|
||||
}
|
||||
|
||||
const char* _glfwPlatformGetVersionString(void)
|
||||
|
20
glfw/x11_window.c
vendored
20
glfw/x11_window.c
vendored
@ -27,6 +27,7 @@
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include "internal.h"
|
||||
#include "backend_utils.h"
|
||||
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/Xmd.h>
|
||||
@ -49,16 +50,6 @@
|
||||
|
||||
#define _GLFW_XDND_VERSION 5
|
||||
|
||||
static inline void
|
||||
drainFd(int fd) {
|
||||
static char drain_buf[64];
|
||||
while(read(fd, drain_buf, sizeof(drain_buf)) < 0 && errno == EINTR);
|
||||
}
|
||||
|
||||
#ifdef __NetBSD__
|
||||
#define ppoll pollts
|
||||
#endif
|
||||
|
||||
// Wait for data to arrive using poll
|
||||
// This avoids blocking other threads via the per-display Xlib lock that also
|
||||
// covers GLX functions
|
||||
@ -79,17 +70,14 @@ static GLFWbool waitForEvent(double* timeout)
|
||||
for (nfds_t i = 0; i < count; i++) _glfw.x11.eventLoopData.fds[i].revents = 0;
|
||||
if (timeout)
|
||||
{
|
||||
const long seconds = (long) *timeout;
|
||||
const long nanoseconds = (long) ((*timeout - seconds) * 1e9);
|
||||
struct timespec tv = { seconds, nanoseconds };
|
||||
const uint64_t base = _glfwPlatformGetTimerValue();
|
||||
const int result = ppoll(_glfw.x11.eventLoopData.fds, count, &tv, NULL);
|
||||
const int result = pollWithTimeout(_glfw.x11.eventLoopData.fds, count, *timeout);
|
||||
*timeout -= (_glfwPlatformGetTimerValue() - base) /
|
||||
(double) _glfwPlatformGetTimerFrequency();
|
||||
|
||||
if (result > 0)
|
||||
{
|
||||
if (_glfw.x11.eventLoopData.fds[0].revents && POLLIN) drainFd(_glfw.x11.eventLoopData.fds[0].fd);
|
||||
if (_glfw.x11.eventLoopData.fds[0].revents & POLLIN) drainFd(_glfw.x11.eventLoopData.fds[0].fd);
|
||||
return GLFW_TRUE;
|
||||
}
|
||||
if (result == 0)
|
||||
@ -101,7 +89,7 @@ static GLFWbool waitForEvent(double* timeout)
|
||||
const int result = poll(_glfw.x11.eventLoopData.fds, count, -1);
|
||||
if (result > 0)
|
||||
{
|
||||
if (_glfw.x11.eventLoopData.fds[0].revents && POLLIN) drainFd(_glfw.x11.eventLoopData.fds[0].fd);
|
||||
if (_glfw.x11.eventLoopData.fds[0].revents & POLLIN) drainFd(_glfw.x11.eventLoopData.fds[0].fd);
|
||||
return GLFW_TRUE;
|
||||
}
|
||||
if (result == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user