forked from tigerkelly/fbcurses
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfbcurses_internal.h
More file actions
117 lines (95 loc) · 4.08 KB
/
fbcurses_internal.h
File metadata and controls
117 lines (95 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef FBCURSES_INTERNAL_H
#define FBCURSES_INTERNAL_H
/*
* Copyright (c) 2026 Richard Kelly Wiles (rkwiles@twc.com)
*/
#include "fbcurses.h"
#include "fonts.h"
#include <linux/fb.h>
#include <termios.h>
#include <wchar.h>
/* ─── Error codes ────────────────────────────────────────────────── */
#define FB_ERR_NONE 0
#define FB_ERR_OPEN 1
#define FB_ERR_IOCTL 2
#define FB_ERR_MMAP 3
#define FB_ERR_ALLOC 4
#define FB_ERR_PARAM 5
#define FB_ERR_IO 6
void _fbSetError(int code, const char *msg);
/* ─── Legacy VGA 8×16 raw bitmap table (font8x16.c) ─────────────── */
#define FB_FONT_W 8
#define FB_FONT_H 16
extern const uint8_t _fbFont[256][16];
/* ─── Cell (one character position in a window) ──────────────────── */
typedef struct {
wchar_t ch;
fbColor fg;
fbColor bg;
uint8_t attr;
bool dirty;
} fbCell;
/* ─── Screen context ─────────────────────────────────────────────── */
struct fbScreen {
int fd; /* framebuffer device fd */
int ttyFd; /* controlling console tty fd */
uint8_t *fbMem;
uint8_t *savedFb; /* snapshot of framebuffer taken at fbInit */
uint32_t *backBuf;
size_t memLen;
struct fb_var_screeninfo var;
struct fb_fix_screeninfo fix;
int pixelW, pixelH;
int bpp, lineLen;
int cols, rows; /* character grid at the default VGA font */
struct termios origTermios;
bool rawMode;
bool cursorWasVisible; /* cursor state before fbInit */
int kdMode; /* original KD_TEXT/KD_GRAPHICS mode */
int vtNum; /* VT number this process is running on */
};
/* ─── Window context ─────────────────────────────────────────────── */
struct fbWindow {
fbScreen *scr;
int col, row; /* position in character cells */
int cols, rows; /* size in character cells */
fbCell *cells;
int cursorCol, cursorRow;
fbColor fg, bg;
uint8_t attr;
const fbFont *font; /* active font; never NULL */
};
/* ─── Inline pixel helpers ───────────────────────────────────────── */
static inline void
_fbPutPixelBack(fbScreen *scr, int x, int y, fbColor color)
{
if (x < 0 || y < 0 || x >= scr->pixelW || y >= scr->pixelH) return;
scr->backBuf[y * scr->pixelW + x] = color;
}
static inline fbColor
_fbGetPixelBack(const fbScreen *scr, int x, int y)
{
if (x < 0 || y < 0 || x >= scr->pixelW || y >= scr->pixelH)
return FB_BLACK;
return scr->backBuf[y * scr->pixelW + x];
}
static inline fbCell *
_fbGetCell(fbWindow *win, int col, int row)
{
return &win->cells[row * win->cols + col];
}
/* ─── Renderers ──────────────────────────────────────────────────── */
/* Main glyph dispatcher: tries box-draw first, falls back to bitmap. */
void _fbRenderGlyph(fbScreen *scr, int pixX, int pixY,
wchar_t ch, fbColor fg, fbColor bg, uint8_t attr,
const fbFont *font);
/* Vector renderer for box/block/braille codepoints. */
bool _fbDrawBoxChar(fbScreen *scr, int px0, int py0,
wchar_t ch, fbColor fg, fbColor bg,
int fw, int fh);
/* ─── Border character tables ────────────────────────────────────── */
typedef struct {
wchar_t tl, tr, bl, br, h, v;
} _fbBorderChars;
extern const _fbBorderChars _fbBorderTable[];
#endif /* FBCURSES_INTERNAL_H */