aboutsummaryrefslogtreecommitdiffstats
path: root/source/platform/platform.h
blob: 66d5ac8b4427a0add45bee2375b08728f89294f9 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef PLATFORM_H
#define PLATFORM_H

//- window

typedef enum PlatformAnchor {
	PLATFORM_ANCHOR_TOP    = 1,
	PLATFORM_ANCHOR_BOTTOM = 2,
	PLATFORM_ANCHOR_LEFT   = 4,
	PLATFORM_ANCHOR_RIGHT  = 8,
} PlatformAnchor;

typedef struct WindowParams WindowParams;
struct WindowParams {
	cstring name;     // app id (matches the .desktop file) and layer namespace
	cstring title;
	u32     min_width;
	u32     min_height;
	u32     width;    // logical pixels
	u32     height;
	b32     layer;    // wlr layer shell surface instead of an xdg toplevel
	u32     anchor;   // PlatformAnchor flags, 0 = centered
	s32     margin;
};

typedef struct PlatformWindow PlatformWindow;

//- input
// NOTE: everything is in logical pixels, the renderer multiplies by the buffer scale

typedef struct PlatformButton PlatformButton;
struct PlatformButton {
	s32 half_transition_count;
	b32 ended_down;
};

typedef enum PlatformModifier {
	PLATFORM_MOD_SHIFT = 1,
	PLATFORM_MOD_CTRL  = 2,
	PLATFORM_MOD_ALT   = 4,
} PlatformModifier;

typedef struct PlatformKeyEvent PlatformKeyEvent;
struct PlatformKeyEvent {
	u32 keysym; // xkb keysym, layout aware
	u32 mods;
	b32 repeat;
};

#define PLATFORM_MAX_KEY_EVENTS 64

typedef struct PlatformInput PlatformInput;
struct PlatformInput {
	PlatformButton mouse[3]; // left, right, middle
	f32 mouse_x;
	f32 mouse_y;
	b32 mouse_in_window;
	f32 scroll_y; // wheel notches this frame, positive = down

	PlatformKeyEvent keys[PLATFORM_MAX_KEY_EVENTS];
	u32 key_count;
	u8  text[128]; // utf8 typed this frame
	u32 text_size;
	u32 mods;
	b32 focused;
	b32 changed; // any input or window event since the last pump, i.e. worth a redraw
};

typedef enum PlatformCursor {
	PLATFORM_CURSOR_DEFAULT,
	PLATFORM_CURSOR_POINTER,
	PLATFORM_CURSOR_GRABBING,
	PLATFORM_CURSOR_RESIZE_X,
	PLATFORM_CURSOR_RESIZE_Y,
} PlatformCursor;

#define ButtonPressed(button)  ((button).ended_down && (button).half_transition_count > 0)
#define ButtonReleased(button) (!(button).ended_down && (button).half_transition_count > 0)

#endif // PLATFORM_H