aboutsummaryrefslogtreecommitdiff
path: root/subprojects/d2tk/src/base_internal.h
blob: 35c06919f06680a9a806dc5e00f576020c4d78ae (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (c) 2018-2019 Hanspeter Portner (dev@open-music-kontrollers.ch)
 *
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the Artistic License 2.0 as published by
 * The Perl Foundation.
 *
 * This source is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Artistic License 2.0 for more details.
 *
 * You should have received a copy of the Artistic License 2.0
 * along the source as a COPYING file. If not, obtain it from
 * http://www.perlfoundation.org/artistic_license_2_0.
 */

#include <stdatomic.h>

#include <d2tk/base.h>
#include <d2tk/hash.h>
#include "core_internal.h"

#define _D2TK_MAX_ATOM 0x1000
#define _D2TK_MASK_ATOMS (_D2TK_MAX_ATOM - 1)

typedef enum _d2tk_atom_type_t {
	D2TK_ATOM_NONE,
	D2TK_ATOM_SCROLL,
	D2TK_ATOM_PANE,
	D2TK_ATOM_FLOW,
	D2TK_ATOM_FLOW_NODE,
	D2TK_ATOM_FLOW_ARC,
#if D2TK_PTY
	D2TK_ATOM_PTY,
#endif
#if D2TK_EVDEV
	D2TK_ATOM_VKB,
#endif
} d2tk_atom_type_t;

typedef enum _d2tk_atom_event_type_t {
	D2TK_ATOM_EVENT_NONE,
	D2TK_ATOM_EVENT_FD,
	D2TK_ATOM_EVENT_DEINIT
} d2tk_atom_event_type_t;

typedef struct _d2tk_flip_t d2tk_flip_t;
typedef struct _d2tk_atom_t d2tk_atom_t;
typedef int (*d2tk_atom_event_t)(d2tk_atom_event_type_t event, void *data);

struct _d2tk_flip_t {
	d2tk_id_t old;
	d2tk_id_t cur;
};

struct _d2tk_atom_t {
	d2tk_id_t id;
	d2tk_atom_type_t type;
	void *body;
	d2tk_atom_event_t event;
};

struct _d2tk_base_t {
	d2tk_flip_t hotitem;
	d2tk_flip_t activeitem;
	d2tk_flip_t focusitem;
	d2tk_id_t lastitem;

	bool not_first_time;

	struct {
		d2tk_coord_t x;
		d2tk_coord_t y;
		d2tk_coord_t ox;
		d2tk_coord_t oy;
		d2tk_coord_t dx;
		d2tk_coord_t dy;
		d2tk_butmask_t mask;
		d2tk_butmask_t mask_prev;
	} mouse;

	struct {
		int32_t odx;
		int32_t ody;
		int32_t dx;
		int32_t dy;
	} scroll;

	struct {
		size_t nchars;
		utf8_int32_t chars [32];
		unsigned keymod;
		d2tk_keymask_t mask;
		d2tk_keymask_t mask_prev;
		d2tk_modmask_t mod;
	} keys;

	struct {
		char text_in [1024];
		char text_out [1024];
	} edit;

	const d2tk_style_t *style;

	atomic_bool again;
	bool clear_focus;
	bool focused;

	d2tk_core_t *core;

	d2tk_atom_t atoms [_D2TK_MAX_ATOM];
};

extern const size_t d2tk_atom_body_flow_sz;
extern const size_t d2tk_atom_body_pane_sz;
extern const size_t d2tk_atom_body_scroll_sz;
#if D2TK_PTY
extern const size_t d2tk_atom_body_pty_sz;
#endif
#if D2TK_EVDEV
extern const size_t d2tk_atom_body_vkb_sz;
#endif

void *
_d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type,
	d2tk_atom_event_t event);

d2tk_state_t
_d2tk_base_is_active_hot_vertical_scroll(d2tk_base_t *base);

d2tk_state_t
_d2tk_base_is_active_hot_horizontal_scroll(d2tk_base_t *base);

void
_d2tk_base_clear_chars(d2tk_base_t *base);