monotonic_start_time needs to be a global symbol, not local to each translation unit

This commit is contained in:
Kovid Goyal 2019-09-28 08:17:54 +05:30
parent 3378175450
commit 97fe38fbbc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 20 additions and 10 deletions

View File

@ -194,6 +194,7 @@ const char *action_text, int32_t timeout, GLFWDBusnotificationcreatedfun callbac
#pragma once
#include <stddef.h>
#include <stdint.h>
#include "monotonic.h"
{}

2
glfw/glfw3.h vendored
View File

@ -1704,7 +1704,7 @@ typedef struct GLFWgamepadstate
*
* @ingroup init
*/
GLFWAPI int glfwInit(void);
GLFWAPI int glfwInit(monotonic_t start_time);
GLFWAPI void glfwRunMainLoop(GLFWtickcallback callback, void *callback_data);
GLFWAPI void glfwStopMainLoop(void);
GLFWAPI unsigned long long glfwAddTimer(monotonic_t interval, bool repeats, GLFWuserdatafun callback, void * callback_data, GLFWuserdatafun free_callback);

4
glfw/init.c vendored
View File

@ -27,6 +27,7 @@
// Please use C89 style variable declarations in this file because VS 2010
//========================================================================
#define MONOTONIC_START_MODULE
#include "internal.h"
#include "mappings.h"
@ -214,10 +215,11 @@ _glfwDebug(const char *format, ...) {
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
GLFWAPI int glfwInit(void)
GLFWAPI int glfwInit(monotonic_t start_time)
{
if (_glfw.initialized)
return true;
monotonic_start_time = start_time;
memset(&_glfw, 0, sizeof(_glfw));
_glfw.hints.init = _glfwInitHints;

View File

@ -5,6 +5,7 @@
* Distributed under terms of the GPL3 license.
*/
#define MONOTONIC_START_MODULE
#ifdef __APPLE__
// Needed for _CS_DARWIN_USER_CACHE_DIR
#define _DARWIN_C_SOURCE

9
kitty/glfw-wrapper.h generated
View File

@ -7,7 +7,7 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include "../kitty/monotonic.h"
#include "monotonic.h"
@ -955,7 +955,7 @@ typedef struct GLFWkeyevent
// Bit field describing which [modifier keys](@ref mods) were held down.
int mods;
// UTF-8 encoded text generated by this key event or empty string.
// UTF-8 encoded text generated by this key event or empty string or NULL
const char *text;
// Used for Input Method events. Zero for normal key events.
@ -1249,7 +1249,8 @@ typedef void (* GLFWscrollfun)(GLFWwindow*,double,double,int);
* the "s" key will generate text "o" and GLFW_KEY_O.
*
* @param[in] window The window that received the event.
* @param[in] ev TODO: blablabla
* @param[in] ev The key event, see GLFWkeyevent. The data in this event is only valid for
* the lifetime of the callback.
*
* @note On X11/Wayland if a modifier other than the modifiers GLFW reports
* (ctrl/shift/alt/super) is used, GLFW will report the shifted key rather
@ -1476,7 +1477,7 @@ typedef void (* GLFWcocoarenderframefun)(GLFWwindow*);
typedef void (*GLFWwaylandframecallbackfunc)(unsigned long long id);
typedef void (*GLFWDBusnotificationcreatedfun)(unsigned long long, uint32_t, void*);
typedef void (*GLFWDBusnotificationactivatedfun)(uint32_t, const char*);
typedef int (*glfwInit_func)(void);
typedef int (*glfwInit_func)(monotonic_t);
glfwInit_func glfwInit_impl;
#define glfwInit glfwInit_impl

View File

@ -792,7 +792,7 @@ glfw_init(PyObject UNUSED *self, PyObject *args) {
glfwDBusSetUserNotificationHandler(dbus_user_notification_activated);
}
#endif
PyObject *ans = glfwInit() ? Py_True: Py_False;
PyObject *ans = glfwInit(monotonic_start_time) ? Py_True: Py_False;
if (ans == Py_True) {
OSWindow w = {0};
set_os_window_dpi(&w);

View File

@ -61,7 +61,12 @@ static inline double monotonic_t_to_s_double(monotonic_t time) {
return (double)time / 1000.0 / 1000.0 / 1000.0;
}
static monotonic_t start_time = 0;
#ifdef MONOTONIC_START_MODULE
monotonic_t monotonic_start_time = 0;
#else
extern monotonic_t monotonic_start_time;
#endif
static inline monotonic_t monotonic_(void) {
struct timespec ts = {0};
@ -76,9 +81,9 @@ static inline monotonic_t monotonic_(void) {
}
static inline monotonic_t monotonic(void) {
return monotonic_() - start_time;
return monotonic_() - monotonic_start_time;
}
static inline void init_monotonic(void) {
start_time = monotonic_();
monotonic_start_time = monotonic_();
}