Skip to content

Commit b1c6db2

Browse files
committed
fix interceptor binding and therefore keyboard input on flutter 3
1 parent 231fd4f commit b1c6db2

File tree

9 files changed

+63
-62
lines changed

9 files changed

+63
-62
lines changed

compositor_dart/lib/keyboard/platform_keyboard.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class PlatformKeyboard {
137137

138138
case 'TextInput.setClient':
139139
// arg: [client_id, https://api.flutter.dev/flutter/services/TextInputConfiguration-class.html]
140+
assert(_keyboardClient == null);
140141
_keyboardClient = KeyboardClientController(
141142
connectionId: methodCall.arguments[0] as int,
142143
platformKeyboard: this,

compositor_dart/lib/platform/interceptor_widgets_binding.dart

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,20 @@ import 'package:flutter/services.dart';
55
class InterceptorWidgetsBinding extends WidgetsFlutterBinding {
66
InterceptorBinaryMessenger? _binaryMessenger;
77

8-
static WidgetsBinding? instance;
9-
10-
@override
11-
void initInstances() {
12-
super.initInstances();
13-
_binaryMessenger = InterceptorBinaryMessenger(super.defaultBinaryMessenger);
14-
instance = this;
15-
}
16-
178
@override
189
BinaryMessenger get defaultBinaryMessenger {
19-
return _binaryMessenger == null
20-
? super.defaultBinaryMessenger
21-
: _binaryMessenger!;
10+
_binaryMessenger ??= InterceptorBinaryMessenger(super.defaultBinaryMessenger);
11+
return _binaryMessenger!;
2212
}
2313

2414
static WidgetsBinding ensureInitialized() {
25-
if (InterceptorWidgetsBinding.instance == null) {
26-
InterceptorWidgetsBinding();
15+
try {
16+
return WidgetsBinding.instance;
17+
} on FlutterError {
18+
var constructedBinding = InterceptorWidgetsBinding();
19+
assert(constructedBinding == WidgetsBinding.instance);
20+
return WidgetsBinding.instance;
2721
}
28-
return InterceptorWidgetsBinding.instance!;
2922
}
3023

3124
static void runApp(Widget app) {

demo/lib/main.dart

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,31 @@ class _MyAppState extends State<MyApp> {
6767
KeyboardClientController? keyboardClient;
6868
bool shown = false;
6969

70+
void _setClient(KeyboardClientController? client) {
71+
print("setclient");
72+
SchedulerBinding.instance!.addPostFrameCallback((duration) {
73+
setState(() {
74+
keyboardClient = client;
75+
print(client?.inputConfiguration);
76+
});
77+
});
78+
}
79+
80+
void _setShown(bool shown) {
81+
SchedulerBinding.instance!.addPostFrameCallback((duration) {
82+
setState(() {
83+
this.shown = shown;
84+
});
85+
});
86+
}
87+
7088
// This widget is the root of your application.
7189
@override
7290
Widget build(BuildContext context) {
7391
return PlatformKeyboardWidget(
7492
callbacks: PlatformKeyboardCallbacks(
75-
setClient: (client) {
76-
print("setclient");
77-
SchedulerBinding.instance!.addPostFrameCallback((duration) {
78-
setState(() {
79-
keyboardClient = client;
80-
print(client?.inputConfiguration);
81-
});
82-
});
83-
},
84-
setShown: (shown) {
85-
SchedulerBinding.instance!.addPostFrameCallback((duration) {
86-
setState(() {
87-
this.shown = shown;
88-
});
89-
});
90-
},
93+
setClient: _setClient,
94+
setShown: _setShown,
9195
),
9296
child: Stack(
9397
textDirection: TextDirection.ltr,

demo/linux/flutter/generated_plugins.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
list(APPEND FLUTTER_PLUGIN_LIST
66
)
77

8+
list(APPEND FLUTTER_FFI_PLUGIN_LIST
9+
)
10+
811
set(PLUGIN_BUNDLED_LIBRARIES)
912

1013
foreach(plugin ${FLUTTER_PLUGIN_LIST})
@@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
1316
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
1417
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
1518
endforeach(plugin)
19+
20+
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
21+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
22+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
23+
endforeach(ffi_plugin)

demo/pubspec.lock

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.8.2"
10+
version: "2.9.0"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
@@ -21,21 +21,14 @@ packages:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.2.0"
25-
charcode:
26-
dependency: transitive
27-
description:
28-
name: charcode
29-
url: "https://pub.dartlang.org"
30-
source: hosted
31-
version: "1.3.1"
24+
version: "1.2.1"
3225
clock:
3326
dependency: transitive
3427
description:
3528
name: clock
3629
url: "https://pub.dartlang.org"
3730
source: hosted
38-
version: "1.1.0"
31+
version: "1.1.1"
3932
collection:
4033
dependency: transitive
4134
description:
@@ -63,7 +56,7 @@ packages:
6356
name: fake_async
6457
url: "https://pub.dartlang.org"
6558
source: hosted
66-
version: "1.3.0"
59+
version: "1.3.1"
6760
flutter:
6861
dependency: "direct main"
6962
description: flutter
@@ -101,28 +94,28 @@ packages:
10194
name: matcher
10295
url: "https://pub.dartlang.org"
10396
source: hosted
104-
version: "0.12.11"
97+
version: "0.12.12"
10598
material_color_utilities:
10699
dependency: transitive
107100
description:
108101
name: material_color_utilities
109102
url: "https://pub.dartlang.org"
110103
source: hosted
111-
version: "0.1.3"
104+
version: "0.1.5"
112105
meta:
113106
dependency: transitive
114107
description:
115108
name: meta
116109
url: "https://pub.dartlang.org"
117110
source: hosted
118-
version: "1.7.0"
111+
version: "1.8.0"
119112
path:
120113
dependency: transitive
121114
description:
122115
name: path
123116
url: "https://pub.dartlang.org"
124117
source: hosted
125-
version: "1.8.0"
118+
version: "1.8.2"
126119
sky_engine:
127120
dependency: transitive
128121
description: flutter
@@ -134,7 +127,7 @@ packages:
134127
name: source_span
135128
url: "https://pub.dartlang.org"
136129
source: hosted
137-
version: "1.8.1"
130+
version: "1.9.0"
138131
stack_trace:
139132
dependency: transitive
140133
description:
@@ -155,35 +148,28 @@ packages:
155148
name: string_scanner
156149
url: "https://pub.dartlang.org"
157150
source: hosted
158-
version: "1.1.0"
151+
version: "1.1.1"
159152
term_glyph:
160153
dependency: transitive
161154
description:
162155
name: term_glyph
163156
url: "https://pub.dartlang.org"
164157
source: hosted
165-
version: "1.2.0"
158+
version: "1.2.1"
166159
test_api:
167160
dependency: transitive
168161
description:
169162
name: test_api
170163
url: "https://pub.dartlang.org"
171164
source: hosted
172-
version: "0.4.9"
173-
typed_data:
174-
dependency: transitive
175-
description:
176-
name: typed_data
177-
url: "https://pub.dartlang.org"
178-
source: hosted
179-
version: "1.3.0"
165+
version: "0.4.12"
180166
vector_math:
181167
dependency: transitive
182168
description:
183169
name: vector_math
184170
url: "https://pub.dartlang.org"
185171
source: hosted
186-
version: "2.1.1"
172+
version: "2.1.2"
187173
sdks:
188174
dart: ">=2.17.0-0 <3.0.0"
189175
flutter: ">=1.17.0"

include/platform_channel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum json_value_type {
3232
kJsonNull,
3333
kJsonTrue,
3434
kJsonFalse,
35+
kJsonInteger,
3536
kJsonNumber,
3637
kJsonString,
3738
kJsonArray,
@@ -41,6 +42,7 @@ struct json_value {
4142
enum json_value_type type;
4243
union {
4344
double number_value;
45+
int64_t integer_value;
4446
char *string_value;
4547
struct {
4648
size_t size;

src/flutter_wlroots.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static void engine_cb_platform_message(
219219

220220
error:
221221
// TODO(hansihe): Handle messages
222+
//wlr_log(WLR_INFO, "Unhandled platform message: channel: %s %.*s", engine_message->channel, engine_message->message_size, engine_message->message);
222223
wlr_log(WLR_INFO, "Unhandled platform message: channel: %s", engine_message->channel);
223224

224225
message_free(&name);

src/input.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ static void send_key_to_flutter(struct fwr_keyboard *keyboard, struct wlr_event_
316316
| (keyboard_state_is_capslock_active(kb_state) << 1)
317317
| (keyboard_state_is_ctrl_active(kb_state) << 2)
318318
| (keyboard_state_is_alt_active(kb_state) << 3)
319-
| (keyboard_state_is_numlock_active(kb_state) << 4)
320-
| (keyboard_state_is_meta_active(kb_state) << 28);
319+
| (keyboard_state_is_numlock_active(kb_state) << 4);
320+
//| (keyboard_state_is_meta_active(kb_state) << 28);
321321
uint16_t scan_code = (uint16_t)event->keycode + 8;
322322
xkb_keysym_t key_code = xkb_state_key_get_one_sym(kb_state, scan_code);
323323
uint32_t unicode = xkb_state_key_get_utf32(kb_state, scan_code);
@@ -373,7 +373,7 @@ static void send_key_to_flutter(struct fwr_keyboard *keyboard, struct wlr_event_
373373
/* unicodeScalarValues */ {.type = kJsonNumber, .number_value = (flType == kFlutterKeyEventTypeDown ? unicode : 0x0)},
374374
/* keyCode */ {.type = kJsonNumber, .number_value = (uint32_t) key_code},
375375
/* scanCode */ {.type = kJsonNumber, .number_value = scan_code},
376-
/* modifiers */ {.type = kJsonNumber, .number_value = modifiers},
376+
/* modifiers */ {.type = kJsonInteger, .number_value = modifiers},
377377
/* type */ {.type = kJsonString, .string_value = type}
378378
}
379379
}

src/platform_channel.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,17 @@ int platch_write_value_to_buffer_std(struct std_value* value, uint8_t **pbuffer)
441441
size_t platch_calc_value_size_json(struct json_value *value) {
442442
size_t size = 0;
443443

444+
char numBuffer[32];
445+
444446
switch (value->type) {
445447
case kJsonNull:
446448
case kJsonTrue:
447449
return 4;
448450
case kJsonFalse:
449451
return 5;
452+
case kJsonInteger:
453+
return sprintf(numBuffer, "%ld", value->integer_value);
450454
case kJsonNumber: ;
451-
char numBuffer[32];
452455
return sprintf(numBuffer, "%g", value->number_value);
453456
case kJsonString:
454457
size = 2;
@@ -503,6 +506,9 @@ int platch_write_value_to_buffer_json(struct json_value* value, uint8_t **pbuffe
503506
case kJsonFalse:
504507
*pbuffer += sprintf((char*) *pbuffer, "false");
505508
break;
509+
case kJsonInteger:
510+
*pbuffer += sprintf((char*) *pbuffer, "%ld", value->integer_value);
511+
break;
506512
case kJsonNumber:
507513
*pbuffer += sprintf((char*) *pbuffer, "%g", value->number_value);
508514
break;

0 commit comments

Comments
 (0)