From 97fe38fbbc96009d985819b4eb6f31a3616464fa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 28 Sep 2019 08:17:54 +0530 Subject: [PATCH] monotonic_start_time needs to be a global symbol, not local to each translation unit --- glfw/glfw.py | 1 + glfw/glfw3.h | 2 +- glfw/init.c | 4 +++- kitty/data-types.c | 1 + kitty/glfw-wrapper.h | 9 +++++---- kitty/glfw.c | 2 +- kitty/monotonic.h | 11 ++++++++--- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/glfw/glfw.py b/glfw/glfw.py index 1027ba1ed..b8857caa4 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -194,6 +194,7 @@ const char *action_text, int32_t timeout, GLFWDBusnotificationcreatedfun callbac #pragma once #include #include +#include "monotonic.h" {} diff --git a/glfw/glfw3.h b/glfw/glfw3.h index f3c70eb38..2675d3c8b 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -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); diff --git a/glfw/init.c b/glfw/init.c index 696d35f1f..332102f5d 100644 --- a/glfw/init.c +++ b/glfw/init.c @@ -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; diff --git a/kitty/data-types.c b/kitty/data-types.c index fb06820cc..2d4e477b9 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -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 diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index 9529feada..6e6ce1b63 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -7,7 +7,7 @@ #pragma once #include #include -#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 diff --git a/kitty/glfw.c b/kitty/glfw.c index 7978910df..62edb54d6 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -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); diff --git a/kitty/monotonic.h b/kitty/monotonic.h index 3efbd5534..7be3c11aa 100644 --- a/kitty/monotonic.h +++ b/kitty/monotonic.h @@ -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_(); }