aboutsummaryrefslogtreecommitdiff
path: root/config.h
blob: efbd74fd1b30b4e71cd464164e0b9371561ef7f5 (plain) (blame)
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
/*
 * config.h - configuration: defaults, file parsing, and CLI overrides all flow
 * through config_set(), so the file and the command line share one vocabulary.
 *
 * Colours are stored 0xAARRGGBB and written in the config as #RRGGBB or
 * #RRGGBBAA. Key bindings are single ASCII characters; cancel (Esc) and undo
 * (Backspace) are fixed.
 */
#ifndef MOUSEBOARD_CONFIG_H
#define MOUSEBOARD_CONFIG_H

#include <stdint.h>

#define MB_MAX_GRID_DIM 200
#define MB_MAX_FONT_SCALE 64

struct config {
	char alphabet[64];	/* label characters, most-preferred first */
	int cell_size;		/* target coarse-cell size in px (if cols/rows 0) */
	int cols, rows;		/* explicit grid; 0 means derive from cell_size */
	int font_scale;		/* label scale; 0 means auto-fit per cell */

	int opacity_bg;		/* backdrop opacity 0..100 (100 = solid) */
	int opacity_fg;		/* labels/grid/crosshair opacity 0..100 */
	uint32_t color_bg;	/* full-screen backdrop */
	uint32_t color_grid;	/* grid lines */
	uint32_t color_label;	/* label glyphs */
	uint32_t color_typed;	/* already-typed portion of a label */
	uint32_t color_active;	/* refine box and crosshair */

	char k_tl, k_tr, k_bl, k_br;	/* refine: keep TL/TR/BL/BR quadrant */
	char k_left, k_middle, k_right;	/* click buttons */
	char k_double, k_drag;		/* double-click; start/finish drag */
};

void config_defaults(struct config *c);

/* Apply one "key value" pair. Returns 0 on success, -1 unknown key,
 * -2 bad value. */
int config_set(struct config *c, const char *key, const char *val);

/* Return NULL if the complete configuration is usable, otherwise a short
 * diagnostic. Call after file and command-line overrides have been applied. */
const char *config_validate(const struct config *c);

/* Scale color_bg's alpha by opacity_bg/100 and the other colours' by
 * opacity_fg/100. Call exactly once, after all file and command-line
 * overrides. The default colours carry full alpha, so 100 means solid. */
void config_apply_opacity(struct config *c);

/* Parse a config file. Returns 0 on success, -1 if it does not exist (not an
 * error), -2 on a parse error (message printed to stderr). */
int config_load_file(struct config *c, const char *path);

/* Default config path: $XDG_CONFIG_HOME/mouseboard/config, falling back to
 * %APPDATA%/mouseboard/config (Windows), then ~/.config/mouseboard/config.
 * Static buffer. */
const char *config_default_path(void);

#endif /* MOUSEBOARD_CONFIG_H */