AtlatestRepositorysigil-app

sigil-app / tree / src / cdesktop-internal.h

1/*
2 * desktop-internal.h - Internal header for the Sigil desktop host layer
3 *
4 * Application state for the window, GL context, input, frame clock and
5 * quit handling. The host is GLFW (vendored under vendor/glfw); the
6 * platform (Wayland or X11 on Linux, Win32, Cocoa) is picked at startup
7 * and every platform library is loaded at runtime by GLFW itself.
8 */
9
10#ifndef SIGIL_DESKTOP_INTERNAL_H
11#define SIGIL_DESKTOP_INTERNAL_H
13#include <sigil/sigil.h>
14#include <stdbool.h>
16/* GLFW_KEY_LAST is 348; sokol_app's table was 512 and the key symbols
17 * only ever map into the GLFW range, so the same size is kept. */
18#define SIGIL_DESKTOP_MAX_KEYS 512
19#define SIGIL_DESKTOP_MAX_MOUSE_BUTTONS 3
21struct GLFWwindow;
23/*
24 * Application state
25 */
26typedef 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 what
38 * frame-width/frame-height report), the window in screen units (what
39 * GLFW reports cursor positions in). They differ on a scaled Wayland
40 * 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 offsets
64 * 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 */
73extern DesktopState *g_desktop;
75/* Initialize/shutdown app state */
76void sigil_desktop_state_init(SigilVM *vm);
77void sigil_desktop_state_shutdown(void);
79/* Input handling helpers */
80void sigil_desktop_clear_frame_input(void);
81int sigil_desktop_key_code_from_symbol(SigilVM *vm, Value sym);
83/* Framebuffer size in pixels (1x1 before the window exists). */
84int sigil_desktop_framebuffer_width(void);
85int sigil_desktop_framebuffer_height(void);
87#if defined(__linux__)
88/* dl-search.c: the directories the interposed dlopen falls back to. */
89const char *sigil_desktop_dlopen_search_summary(void);
90#endif
92#endif /* SIGIL_DESKTOP_INTERNAL_H */