2019-02-26 18:51:14 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net>
|
|
|
|
*
|
|
|
|
* Distributed under terms of the GPL3 license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
#ifndef GLFW_LOOP_BACKEND
|
|
|
|
#define GLFW_LOOP_BACKEND x11
|
|
|
|
#endif
|
|
|
|
|
2019-07-18 11:55:11 +03:00
|
|
|
static bool keep_going = false;
|
2019-02-26 18:51:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
void _glfwPlatformStopMainLoop(void) {
|
|
|
|
if (keep_going) {
|
2019-07-18 11:55:11 +03:00
|
|
|
keep_going = false;
|
2019-02-26 18:51:14 +03:00
|
|
|
_glfwPlatformPostEmptyEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 12:10:09 +03:00
|
|
|
void _glfwPlatformRunMainLoop(GLFWtickcallback tick_callback, void* data) {
|
2019-07-17 17:15:52 +03:00
|
|
|
keep_going = 1;
|
2019-07-18 11:55:11 +03:00
|
|
|
EventLoopData *eld = &_glfw.GLFW_LOOP_BACKEND.eventLoopData;
|
2019-02-26 18:51:14 +03:00
|
|
|
while(keep_going) {
|
|
|
|
_glfwPlatformWaitEvents();
|
2019-07-18 11:55:11 +03:00
|
|
|
EVDBG("--------- loop tick, wakeups_happened: %d ----------", eld->wakeup_data_read);
|
|
|
|
if (eld->wakeup_data_read) {
|
|
|
|
eld->wakeup_data_read = false;
|
|
|
|
tick_callback(data);
|
|
|
|
}
|
2019-02-26 18:51:14 +03:00
|
|
|
}
|
2019-07-15 18:59:51 +03:00
|
|
|
EVDBG("main loop exiting");
|
2019-02-26 18:51:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long _glfwPlatformAddTimer(double interval, bool repeats, GLFWuserdatafreefun callback, void *callback_data, GLFWuserdatafreefun free_callback) {
|
|
|
|
return addTimer(&_glfw.GLFW_LOOP_BACKEND.eventLoopData, "user timer", interval, 1, repeats, callback, callback_data, free_callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _glfwPlatformRemoveTimer(unsigned long long timer_id) {
|
|
|
|
removeTimer(&_glfw.GLFW_LOOP_BACKEND.eventLoopData, timer_id);
|
|
|
|
}
|
2019-02-27 06:13:47 +03:00
|
|
|
|
2019-06-08 05:42:42 +03:00
|
|
|
void _glfwPlatformUpdateTimer(unsigned long long timer_id, double interval, bool enabled) {
|
2019-02-27 06:13:47 +03:00
|
|
|
changeTimerInterval(&_glfw.GLFW_LOOP_BACKEND.eventLoopData, timer_id, interval);
|
|
|
|
toggleTimer(&_glfw.GLFW_LOOP_BACKEND.eventLoopData, timer_id, enabled);
|
|
|
|
}
|