main_loop.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net>
  3. *
  4. * Distributed under terms of the GPL3 license.
  5. */
  6. #pragma once
  7. #include "internal.h"
  8. #include "../kitty/monotonic.h"
  9. #ifndef GLFW_LOOP_BACKEND
  10. #define GLFW_LOOP_BACKEND x11
  11. #endif
  12. static bool keep_going = false;
  13. void _glfwPlatformStopMainLoop(void) {
  14. if (keep_going) {
  15. keep_going = false;
  16. _glfwPlatformPostEmptyEvent();
  17. }
  18. }
  19. void _glfwPlatformRunMainLoop(GLFWtickcallback tick_callback, void* data) {
  20. keep_going = 1;
  21. EventLoopData *eld = &_glfw.GLFW_LOOP_BACKEND.eventLoopData;
  22. while(keep_going) {
  23. _glfwPlatformWaitEvents();
  24. EVDBG("--------- loop tick, wakeups_happened: %d ----------", eld->wakeup_data_read);
  25. if (eld->wakeup_data_read) {
  26. eld->wakeup_data_read = false;
  27. tick_callback(data);
  28. }
  29. }
  30. EVDBG("main loop exiting");
  31. }
  32. unsigned long long _glfwPlatformAddTimer(monotonic_t interval, bool repeats, GLFWuserdatafreefun callback, void *callback_data, GLFWuserdatafreefun free_callback) {
  33. return addTimer(&_glfw.GLFW_LOOP_BACKEND.eventLoopData, "user timer", interval, 1, repeats, callback, callback_data, free_callback);
  34. }
  35. void _glfwPlatformRemoveTimer(unsigned long long timer_id) {
  36. removeTimer(&_glfw.GLFW_LOOP_BACKEND.eventLoopData, timer_id);
  37. }
  38. void _glfwPlatformUpdateTimer(unsigned long long timer_id, monotonic_t interval, bool enabled) {
  39. changeTimerInterval(&_glfw.GLFW_LOOP_BACKEND.eventLoopData, timer_id, interval);
  40. toggleTimer(&_glfw.GLFW_LOOP_BACKEND.eventLoopData, timer_id, enabled);
  41. }