Skip to content

Commit db61f7a

Browse files
authored
Merge pull request #31 from ardera/feature-keyboard-input
implement keyboard input
2 parents 5406980 + 7801482 commit db61f7a

16 files changed

+1541
-45
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
out
22
.vscode
3-
build.sh
3+
build.sh
4+
compile_commands.json
5+
.clang-format

Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
CC = cc
22
LD = cc
3-
REAL_CFLAGS = -I./include $(shell pkg-config --cflags dri gbm libdrm glesv2 egl) -DBUILD_ELM327PLUGIN $(CFLAGS)
3+
REAL_CFLAGS = -I./include $(shell pkg-config --cflags dri gbm libdrm glesv2 egl) -DBUILD_ELM327_PLUGIN -DBUILD_TEST_PLUGIN -ggdb $(CFLAGS)
44
REAL_LDFLAGS = $(shell pkg-config --libs dri gbm libdrm glesv2 egl) -lrt -lflutter_engine -lpthread -ldl $(LDFLAGS)
55

6-
SOURCES = src/flutter-pi.c src/platformchannel.c src/pluginregistry.c src/plugins/elm327plugin.c src/plugins/services-plugin.c src/plugins/testplugin.c
6+
SOURCES = src/flutter-pi.c src/platformchannel.c src/pluginregistry.c src/console_keyboard.c \
7+
src/plugins/elm327plugin.c src/plugins/services-plugin.c src/plugins/testplugin.c src/plugins/text_input.c \
8+
src/plugins/raw_keyboard.c
79
OBJECTS = $(patsubst src/%.c,out/obj/%.o,$(SOURCES))
810

911
all: out/flutter-pi

include/console_keyboard.h

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#ifndef _CONSOLE_KEYBOARD_H
2+
#define _CONSOLE_KEYBOARD_H
3+
4+
#include <stdlib.h>
5+
#include <linux/input-event-codes.h>
6+
7+
// small subset of the GLFW key ids.
8+
// (only the ones needed for text input)
9+
10+
typedef enum {
11+
GLFW_KEY_UNKNOWN = -1,
12+
GLFW_KEY_SPACE = 32,
13+
GLFW_KEY_APOSTROPHE = 39,
14+
GLFW_KEY_COMMA = 44,
15+
GLFW_KEY_MINUS = 45,
16+
GLFW_KEY_PERIOD = 46,
17+
GLFW_KEY_SLASH = 47,
18+
GLFW_KEY_0 = 48,
19+
GLFW_KEY_1 = 49,
20+
GLFW_KEY_2 = 50,
21+
GLFW_KEY_3 = 51,
22+
GLFW_KEY_4 = 52,
23+
GLFW_KEY_5 = 53,
24+
GLFW_KEY_6 = 54,
25+
GLFW_KEY_7 = 55,
26+
GLFW_KEY_8 = 56,
27+
GLFW_KEY_9 = 57,
28+
GLFW_KEY_SEMICOLON = 59,
29+
GLFW_KEY_EQUAL = 61,
30+
GLFW_KEY_A = 65,
31+
GLFW_KEY_B = 66,
32+
GLFW_KEY_C = 67,
33+
GLFW_KEY_D = 68,
34+
GLFW_KEY_E = 69,
35+
GLFW_KEY_F = 70,
36+
GLFW_KEY_G = 71,
37+
GLFW_KEY_H = 72,
38+
GLFW_KEY_I = 73,
39+
GLFW_KEY_J = 74,
40+
GLFW_KEY_K = 75,
41+
GLFW_KEY_L = 76,
42+
GLFW_KEY_M = 77,
43+
GLFW_KEY_N = 78,
44+
GLFW_KEY_O = 79,
45+
GLFW_KEY_P = 80,
46+
GLFW_KEY_Q = 81,
47+
GLFW_KEY_R = 82,
48+
GLFW_KEY_S = 83,
49+
GLFW_KEY_T = 84,
50+
GLFW_KEY_U = 85,
51+
GLFW_KEY_V = 86,
52+
GLFW_KEY_W = 87,
53+
GLFW_KEY_X = 88,
54+
GLFW_KEY_Y = 89,
55+
GLFW_KEY_Z = 90,
56+
GLFW_KEY_LEFT_BRACKET = 91,
57+
GLFW_KEY_BACKSLASH = 92,
58+
GLFW_KEY_RIGHT_BRACKET = 93,
59+
GLFW_KEY_GRAVE_ACCENT = 96,
60+
GLFW_KEY_WORLD_1 = 161,
61+
GLFW_KEY_WORLD_2 = 162,
62+
GLFW_KEY_ESCAPE = 256,
63+
GLFW_KEY_ENTER = 257,
64+
GLFW_KEY_TAB = 258,
65+
GLFW_KEY_BACKSPACE = 259,
66+
GLFW_KEY_INSERT = 260,
67+
GLFW_KEY_DELETE = 261,
68+
GLFW_KEY_RIGHT = 262,
69+
GLFW_KEY_LEFT = 263,
70+
GLFW_KEY_DOWN = 264,
71+
GLFW_KEY_UP = 265,
72+
GLFW_KEY_PAGE_UP = 266,
73+
GLFW_KEY_PAGE_DOWN = 267,
74+
GLFW_KEY_HOME = 268,
75+
GLFW_KEY_END = 269,
76+
GLFW_KEY_CAPS_LOCK = 280,
77+
GLFW_KEY_SCROLL_LOCK = 281,
78+
GLFW_KEY_NUM_LOCK = 282,
79+
GLFW_KEY_PRINT_SCREEN = 283,
80+
GLFW_KEY_PAUSE = 284,
81+
GLFW_KEY_F1 = 290,
82+
GLFW_KEY_F2 = 291,
83+
GLFW_KEY_F3 = 292,
84+
GLFW_KEY_F4 = 293,
85+
GLFW_KEY_F5 = 294,
86+
GLFW_KEY_F6 = 295,
87+
GLFW_KEY_F7 = 296,
88+
GLFW_KEY_F8 = 297,
89+
GLFW_KEY_F9 = 298,
90+
GLFW_KEY_F10 = 299,
91+
GLFW_KEY_F11 = 300,
92+
GLFW_KEY_F12 = 301,
93+
GLFW_KEY_F13 = 302,
94+
GLFW_KEY_F14 = 303,
95+
GLFW_KEY_F15 = 304,
96+
GLFW_KEY_F16 = 305,
97+
GLFW_KEY_F17 = 306,
98+
GLFW_KEY_F18 = 307,
99+
GLFW_KEY_F19 = 308,
100+
GLFW_KEY_F20 = 309,
101+
GLFW_KEY_F21 = 310,
102+
GLFW_KEY_F22 = 311,
103+
GLFW_KEY_F23 = 312,
104+
GLFW_KEY_F24 = 313,
105+
GLFW_KEY_F25 = 314,
106+
GLFW_KEY_KP_0 = 320,
107+
GLFW_KEY_KP_1 = 321,
108+
GLFW_KEY_KP_2 = 322,
109+
GLFW_KEY_KP_3 = 323,
110+
GLFW_KEY_KP_4 = 324,
111+
GLFW_KEY_KP_5 = 325,
112+
GLFW_KEY_KP_6 = 326,
113+
GLFW_KEY_KP_7 = 327,
114+
GLFW_KEY_KP_8 = 328,
115+
GLFW_KEY_KP_9 = 329,
116+
GLFW_KEY_KP_DECIMAL = 330,
117+
GLFW_KEY_KP_DIVIDE = 331,
118+
GLFW_KEY_KP_MULTIPLY = 332,
119+
GLFW_KEY_KP_SUBTRACT = 333,
120+
GLFW_KEY_KP_ADD = 334,
121+
GLFW_KEY_KP_ENTER = 335,
122+
GLFW_KEY_KP_EQUAL = 336,
123+
GLFW_KEY_LEFT_SHIFT = 340,
124+
GLFW_KEY_LEFT_CONTROL = 341,
125+
GLFW_KEY_LEFT_ALT = 342,
126+
GLFW_KEY_LEFT_SUPER = 343,
127+
GLFW_KEY_RIGHT_SHIFT = 344,
128+
GLFW_KEY_RIGHT_CONTROL = 345,
129+
GLFW_KEY_RIGHT_ALT = 346,
130+
GLFW_KEY_RIGHT_SUPER = 347,
131+
GLFW_KEY_MENU = 348,
132+
} glfw_key;
133+
134+
#define GLFW_KEY_LAST 348
135+
136+
typedef enum {
137+
GLFW_RELEASE = 0,
138+
GLFW_PRESS = 1,
139+
GLFW_REPEAT = 2
140+
} glfw_key_action;
141+
142+
typedef enum {
143+
GLFW_MOD_SHIFT = 1,
144+
GLFW_MOD_CONTROL = 2,
145+
GLFW_MOD_ALT = 4,
146+
GLFW_MOD_SUPER = 8,
147+
GLFW_MOD_CAPS_LOCK = 16,
148+
GLFW_MOD_NUM_LOCK = 32
149+
} glfw_keymod;
150+
151+
#define GLFW_KEYMOD_FOR_KEY(keycode) \
152+
(((keycode == GLFW_KEY_LEFT_SHIFT) || (keycode == GLFW_KEY_RIGHT_SHIFT)) ? GLFW_MOD_SHIFT : \
153+
((keycode == GLFW_KEY_LEFT_CONTROL) || (keycode == GLFW_KEY_RIGHT_CONTROL)) ? GLFW_MOD_CONTROL : \
154+
((keycode == GLFW_KEY_LEFT_ALT) || (keycode == GLFW_KEY_RIGHT_ALT)) ? GLFW_MOD_ALT : \
155+
((keycode == GLFW_KEY_LEFT_SUPER) || (keycode == GLFW_KEY_RIGHT_SUPER)) ? GLFW_MOD_SUPER : \
156+
(keycode == GLFW_KEY_CAPS_LOCK) ? GLFW_MOD_CAPS_LOCK : \
157+
(keycode == GLFW_KEY_NUM_LOCK) ? GLFW_MOD_NUM_LOCK : 0);
158+
159+
#define GLFW_KEY_IS_RIGHTSIDED(keycode) \
160+
((keycode == GLFW_KEY_RIGHT_SHIFT) ? true : \
161+
(keycode == GLFW_KEY_RIGHT_CONTROL) ? true : \
162+
(keycode == GLFW_KEY_RIGHT_ALT) ? true : \
163+
(keycode == GLFW_KEY_RIGHT_SUPER) ? true : false)
164+
165+
typedef uint8_t glfw_keymod_map;
166+
167+
extern char *glfw_key_control_sequence[GLFW_KEY_LAST+1];
168+
extern glfw_key evdev_code_glfw_key[KEY_CNT];
169+
170+
#define EVDEV_KEY_TO_GLFW_KEY(key) evdev_code_glfw_key[key]
171+
172+
173+
int console_flush_stdin(void);
174+
int console_make_raw(void);
175+
int console_restore(void);
176+
177+
/// tries to parse the console input represented by the string `input`
178+
/// as a keycode ()
179+
size_t utf8_symbol_length(char *c);
180+
181+
static inline char *utf8_symbol_at(char *utf8str, unsigned int symbol_index) {
182+
for (; symbol_index && *utf8str; symbol_index--)
183+
utf8str += utf8_symbol_length(utf8str);
184+
185+
return symbol_index? NULL : utf8str;
186+
}
187+
188+
glfw_key console_try_get_key(char *input, char **input_out);
189+
char *console_try_get_utf8char(char *input, char **input_out);
190+
191+
#endif

include/flutter-pi.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct mousepointer_mtslot {
7474
FlutterPointerPhase phase;
7575
};
7676

77+
7778
#define INPUT_BUSTYPE_FRIENDLY_NAME(bustype) ( \
7879
(bustype) == BUS_PCI ? "PCI/e" : \
7980
(bustype) == BUS_USB ? "USB" : \
@@ -91,6 +92,14 @@ struct mousepointer_mtslot {
9192
(code) == BTN_BACK ? kFlutterPointerButtonMouseBack : \
9293
(code) == BTN_TOUCH ? (1 << 8) : 0)
9394

95+
#define MODIFIER_KEY_FROM_EVENT_CODE(code) ((uint16_t) \
96+
((code) == KEY_LEFTCTRL) || ((code) == KEY_RIGHTCTRL) ? kControlModifier : \
97+
((code) == KEY_LEFTSHIFT) || ((code) == KEY_RIGHTSHIFT) ? kShiftModifier : \
98+
((code) == KEY_LEFTALT) || ((code) == KEY_RIGHTALT) ? kAltModifier : \
99+
((code) == KEY_LEFTMETA) || ((code) == KEY_RIGHTMETA) ? kMetaModifier : \
100+
((code) == KEY_CAPSLOCK) ? kCapsLockModifier : \
101+
((code) == KEY_NUMLOCK) ? kNumLockModifier : 0)
102+
94103
#define POINTER_PHASE_AS_STRING(phase) ( \
95104
(phase) == kCancel ? "kCancel" : \
96105
(phase) == kUp ? "kUp" : \
@@ -126,7 +135,6 @@ struct input_device {
126135
size_t n_mtslots;
127136
size_t i_active_mtslot;
128137
struct mousepointer_mtslot *mtslots;
129-
//struct mousepointer_mtslot *active_mtslot;
130138

131139
// currently pressed buttons (for mouse, touchpad, stylus)
132140
// (active_buttons & 0xFF) will be the value of the "buttons" field

include/platformchannel.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ typedef int (*PlatformMessageResponseCallback)(struct ChannelObject *object, voi
193193
/// you'd have to manually deep-copy it.
194194
int PlatformChannel_decode(uint8_t *buffer, size_t size, enum ChannelCodec codec, struct ChannelObject *object_out);
195195

196+
/// decodes a JSON String into a JSONMsgCodecValue
197+
int PlatformChannel_decodeJSON(char *string, struct JSONMsgCodecValue *out);
198+
196199
/// Encodes a generic ChannelObject into a buffer (that is, too, allocated by PlatformChannel_encode)
197200
/// A pointer to the buffer is put into buffer_out and the size of that buffer into size_out.
198201
/// The lifetime of the buffer is independent of the ChannelObject, so contents of the ChannelObject
@@ -246,9 +249,11 @@ int PlatformChannel_respondError(FlutterPlatformMessageResponseHandle *handle, e
246249
/// not freeing ChannelObjects may result in a memory leak.
247250
int PlatformChannel_free(struct ChannelObject *object);
248251

252+
int PlatformChannel_freeJSONMsgCodecValue(struct JSONMsgCodecValue *value, bool shallow);
253+
249254
/// returns true if values a and b are equal.
250255
/// for JS arrays, the order of the values is relevant
251-
/// (so two arrays are only equal if the same values in appear in exactly same order)
256+
/// (so two arrays are only equal if the same values appear in exactly same order)
252257
/// for objects, the order of the entries is irrelevant.
253258
bool jsvalue_equals(struct JSONMsgCodecValue *a, struct JSONMsgCodecValue *b);
254259

0 commit comments

Comments
 (0)