mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Share main loop implementation between wayland and X11
This commit is contained in:
46
glfw/main_loop.h
vendored
Normal file
46
glfw/main_loop.h
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
static GLFWbool keep_going = GLFW_FALSE, tick_callback_requested = GLFW_FALSE;
|
||||||
|
|
||||||
|
void _glfwPlatformRequestTickCallback() {
|
||||||
|
tick_callback_requested = GLFW_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _glfwPlatformStopMainLoop(void) {
|
||||||
|
if (keep_going) {
|
||||||
|
keep_going = GLFW_FALSE;
|
||||||
|
_glfwPlatformPostEmptyEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _glfwPlatformRunMainLoop(GLFWtickcallback callback, void* data) {
|
||||||
|
keep_going = GLFW_TRUE;
|
||||||
|
tick_callback_requested = GLFW_FALSE;
|
||||||
|
while(keep_going) {
|
||||||
|
while (tick_callback_requested) {
|
||||||
|
tick_callback_requested = GLFW_FALSE;
|
||||||
|
callback(data);
|
||||||
|
}
|
||||||
|
_glfwPlatformWaitEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
@@ -65,7 +65,8 @@
|
|||||||
"osmesa_context.h",
|
"osmesa_context.h",
|
||||||
"linux_joystick.h",
|
"linux_joystick.h",
|
||||||
"null_joystick.h",
|
"null_joystick.h",
|
||||||
"linux_notify.h"
|
"linux_notify.h",
|
||||||
|
"main_loop.h"
|
||||||
],
|
],
|
||||||
"protocols": [
|
"protocols": [
|
||||||
"stable/xdg-shell/xdg-shell.xml",
|
"stable/xdg-shell/xdg-shell.xml",
|
||||||
@@ -131,7 +132,8 @@
|
|||||||
"osmesa_context.h",
|
"osmesa_context.h",
|
||||||
"linux_joystick.h",
|
"linux_joystick.h",
|
||||||
"null_joystick.h",
|
"null_joystick.h",
|
||||||
"linux_notify.h"
|
"linux_notify.h",
|
||||||
|
"main_loop.h"
|
||||||
],
|
],
|
||||||
"sources": [
|
"sources": [
|
||||||
"x11_init.c",
|
"x11_init.c",
|
||||||
|
|||||||
3
glfw/wl_init.c
vendored
3
glfw/wl_init.c
vendored
@@ -854,3 +854,6 @@ const char* _glfwPlatformGetVersionString(void)
|
|||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define GLFW_LOOP_BACKEND wl
|
||||||
|
#include "main_loop.h"
|
||||||
|
|||||||
33
glfw/x11_init.c
vendored
33
glfw/x11_init.c
vendored
@@ -770,35 +770,4 @@ const char* _glfwPlatformGetVersionString(void)
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GLFWbool keep_going = GLFW_FALSE, tick_callback_requested = GLFW_FALSE;
|
#include "main_loop.h"
|
||||||
|
|
||||||
void _glfwPlatformRequestTickCallback() {
|
|
||||||
tick_callback_requested = GLFW_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _glfwPlatformStopMainLoop(void) {
|
|
||||||
if (keep_going) {
|
|
||||||
keep_going = GLFW_FALSE;
|
|
||||||
_glfwPlatformPostEmptyEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _glfwPlatformRunMainLoop(GLFWtickcallback callback, void* data) {
|
|
||||||
keep_going = GLFW_TRUE;
|
|
||||||
tick_callback_requested = GLFW_FALSE;
|
|
||||||
while(keep_going) {
|
|
||||||
while (tick_callback_requested) {
|
|
||||||
tick_callback_requested = GLFW_FALSE;
|
|
||||||
callback(data);
|
|
||||||
}
|
|
||||||
_glfwPlatformWaitEvents();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long long _glfwPlatformAddTimer(double interval, bool repeats, GLFWuserdatafreefun callback, void *callback_data, GLFWuserdatafreefun free_callback) {
|
|
||||||
return addTimer(&_glfw.x11.eventLoopData, "user timer", interval, 1, repeats, callback, callback_data, free_callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _glfwPlatformRemoveTimer(unsigned long long timer_id) {
|
|
||||||
removeTimer(&_glfw.x11.eventLoopData, timer_id);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user