AtlatestRepositorysigil-desktop
sigil-desktop / tree / src / cdesktop-internal.h
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
/* The windowed geometry kept while the window is fullscreen47
* (set-fullscreen!), in screen units, restored when it leaves. */48
bool have_windowed;49
int windowed_x;50
int windowed_y;51
int windowed_w;52
int windowed_h;54
/* Frame timing */55
double last_time; /* glfwGetTime() at the previous frame */56
double frame_time; /* Seconds since last frame */57
double time_elapsed; /* Seconds since app start */59
/* Input state - current frame */60
bool keys_down[SIGIL_DESKTOP_MAX_KEYS];61
bool keys_pressed[SIGIL_DESKTOP_MAX_KEYS];62
bool keys_released[SIGIL_DESKTOP_MAX_KEYS];64
bool mouse_buttons[SIGIL_DESKTOP_MAX_MOUSE_BUTTONS];65
bool mouse_pressed[SIGIL_DESKTOP_MAX_MOUSE_BUTTONS];66
bool mouse_released[SIGIL_DESKTOP_MAX_MOUSE_BUTTONS];67
/* Cursor position in window (screen) units as GLFW reports it;68
* mouse-x / mouse-y scale it into framebuffer pixels on read. */69
double cursor_x;70
double cursor_y;71
/* The wheel since the last frame (0.10.2): GLFW's scroll offsets72
* summed, cleared with the other per-frame input; + is up/right. */73
double wheel_x;74
double wheel_y;75
/* Mouse motion since the last frame (0.12.0), in framebuffer pixels:76
* the cursor callback's position differences, summed, cleared with the77
* other per-frame input. It keeps counting while the cursor is78
* captured, when the position itself no longer means a place on the79
* window. A capture change re-reads the position instead of trusting80
* the last callback's; skip_motion drops the position reported with81
* the pointer entering the window, which is a jump from wherever it82
* left. */83
double motion_x;84
double motion_y;85
bool skip_motion;86
/* Cursor capture (set-cursor-captured!): the cursor hidden and held,87
* motion unbounded (GLFW_CURSOR_DISABLED, raw motion when the platform88
* has it). Released when the window loses focus, and on Escape unless89
* the app asked to keep it. Whether it holds is read from GLFW's input90
* mode, not remembered. */91
bool escape_releases;93
/* Quit handling */94
bool quit_requested;95
} DesktopState;97
/* Global state - initialized by app module */98
extern DesktopState *g_desktop;100
/* Initialize/shutdown app state */101
void sigil_desktop_state_init(SigilVM *vm);102
void sigil_desktop_state_shutdown(void);104
/* Input handling helpers */105
void sigil_desktop_clear_frame_input(void);106
int sigil_desktop_key_code_from_symbol(SigilVM *vm, Value sym);108
/* Framebuffer size in pixels (1x1 before the window exists). */109
int sigil_desktop_framebuffer_width(void);110
int sigil_desktop_framebuffer_height(void);112
#if defined(__linux__)113
/* dl-search.c: the directories the interposed dlopen falls back to. */114
const char *sigil_desktop_dlopen_search_summary(void);115
#endif117
#endif /* SIGIL_DESKTOP_INTERNAL_H */