AtlatestRepositorysigil-app
1
/*2
* desktop-internal.h - Internal header for the Sigil desktop host layer3
*4
* Application state for the window, GL context, input, frame clock and5
* quit handling. The host is GLFW (vendored under vendor/glfw); the6
* platform (Wayland or X11 on Linux, Win32, Cocoa) is picked at startup7
* and every platform library is loaded at runtime by GLFW itself.8
*/10
#ifndef SIGIL_DESKTOP_INTERNAL_H11
#define SIGIL_DESKTOP_INTERNAL_H13
#include <sigil/sigil.h>14
#include <stdbool.h>16
/* GLFW_KEY_LAST is 348; sokol_app's table was 512 and the key symbols17
* only ever map into the GLFW range, so the same size is kept. */18
#define SIGIL_DESKTOP_MAX_KEYS 51219
#define SIGIL_DESKTOP_MAX_MOUSE_BUTTONS 321
struct GLFWwindow;23
/*24
* Application state25
*/26
typedef struct {27
SigilVM *vm;29
/* Callbacks from Scheme */30
Value init_callback;31
Value frame_callback;32
Value cleanup_callback;34
/* The window and its GL context */35
struct GLFWwindow *window;37
/* Sizes: the framebuffer in pixels (what GL draws into and what38
* frame-width/frame-height report), the window in screen units (what39
* GLFW reports cursor positions in). They differ on a scaled Wayland40
* output; framebuffer / window is the device pixel ratio. */41
int fb_width;42
int fb_height;43
int win_width;44
int win_height;46
/* Frame timing */47
double last_time; /* glfwGetTime() at the previous frame */48
double frame_time; /* Seconds since last frame */49
double time_elapsed; /* Seconds since app start */51
/* Input state - current frame */52
bool keys_down[SIGIL_DESKTOP_MAX_KEYS];53
bool keys_pressed[SIGIL_DESKTOP_MAX_KEYS];54
bool keys_released[SIGIL_DESKTOP_MAX_KEYS];56
bool mouse_buttons[SIGIL_DESKTOP_MAX_MOUSE_BUTTONS];57
bool mouse_pressed[SIGIL_DESKTOP_MAX_MOUSE_BUTTONS];58
bool mouse_released[SIGIL_DESKTOP_MAX_MOUSE_BUTTONS];59
/* Cursor position in window (screen) units as GLFW reports it;60
* mouse-x / mouse-y scale it into framebuffer pixels on read. */61
double cursor_x;62
double cursor_y;63
/* The wheel since the last frame (0.10.2): GLFW's scroll offsets64
* summed, cleared with the other per-frame input; + is up/right. */65
double wheel_x;66
double wheel_y;68
/* Quit handling */69
bool quit_requested;70
} DesktopState;72
/* Global state - initialized by app module */73
extern DesktopState *g_desktop;75
/* Initialize/shutdown app state */76
void sigil_desktop_state_init(SigilVM *vm);77
void sigil_desktop_state_shutdown(void);79
/* Input handling helpers */80
void sigil_desktop_clear_frame_input(void);81
int sigil_desktop_key_code_from_symbol(SigilVM *vm, Value sym);83
/* Framebuffer size in pixels (1x1 before the window exists). */84
int sigil_desktop_framebuffer_width(void);85
int sigil_desktop_framebuffer_height(void);87
#if defined(__linux__)88
/* dl-search.c: the directories the interposed dlopen falls back to. */89
const char *sigil_desktop_dlopen_search_summary(void);90
#endif92
#endif /* SIGIL_DESKTOP_INTERNAL_H */