Skip to content

Commit

Permalink
fix interceptor binding and therefore keyboard input on flutter 3
Browse files Browse the repository at this point in the history
  • Loading branch information
hansihe committed Dec 5, 2022
1 parent 231fd4f commit b1c6db2
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 62 deletions.
1 change: 1 addition & 0 deletions compositor_dart/lib/keyboard/platform_keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class PlatformKeyboard {

case 'TextInput.setClient':
// arg: [client_id, https://api.flutter.dev/flutter/services/TextInputConfiguration-class.html]
assert(_keyboardClient == null);
_keyboardClient = KeyboardClientController(
connectionId: methodCall.arguments[0] as int,
platformKeyboard: this,
Expand Down
23 changes: 8 additions & 15 deletions compositor_dart/lib/platform/interceptor_widgets_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@ import 'package:flutter/services.dart';
class InterceptorWidgetsBinding extends WidgetsFlutterBinding {
InterceptorBinaryMessenger? _binaryMessenger;

static WidgetsBinding? instance;

@override
void initInstances() {
super.initInstances();
_binaryMessenger = InterceptorBinaryMessenger(super.defaultBinaryMessenger);
instance = this;
}

@override
BinaryMessenger get defaultBinaryMessenger {
return _binaryMessenger == null
? super.defaultBinaryMessenger
: _binaryMessenger!;
_binaryMessenger ??= InterceptorBinaryMessenger(super.defaultBinaryMessenger);
return _binaryMessenger!;
}

static WidgetsBinding ensureInitialized() {
if (InterceptorWidgetsBinding.instance == null) {
InterceptorWidgetsBinding();
try {
return WidgetsBinding.instance;
} on FlutterError {
var constructedBinding = InterceptorWidgetsBinding();
assert(constructedBinding == WidgetsBinding.instance);
return WidgetsBinding.instance;
}
return InterceptorWidgetsBinding.instance!;
}

static void runApp(Widget app) {
Expand Down
36 changes: 20 additions & 16 deletions demo/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,31 @@ class _MyAppState extends State<MyApp> {
KeyboardClientController? keyboardClient;
bool shown = false;

void _setClient(KeyboardClientController? client) {
print("setclient");
SchedulerBinding.instance!.addPostFrameCallback((duration) {
setState(() {
keyboardClient = client;
print(client?.inputConfiguration);
});
});
}

void _setShown(bool shown) {
SchedulerBinding.instance!.addPostFrameCallback((duration) {
setState(() {
this.shown = shown;
});
});
}

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return PlatformKeyboardWidget(
callbacks: PlatformKeyboardCallbacks(
setClient: (client) {
print("setclient");
SchedulerBinding.instance!.addPostFrameCallback((duration) {
setState(() {
keyboardClient = client;
print(client?.inputConfiguration);
});
});
},
setShown: (shown) {
SchedulerBinding.instance!.addPostFrameCallback((duration) {
setState(() {
this.shown = shown;
});
});
},
setClient: _setClient,
setShown: _setShown,
),
child: Stack(
textDirection: TextDirection.ltr,
Expand Down
8 changes: 8 additions & 0 deletions demo/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
)

set(PLUGIN_BUNDLED_LIBRARIES)

foreach(plugin ${FLUTTER_PLUGIN_LIST})
Expand All @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)

foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
40 changes: 13 additions & 27 deletions demo/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,21 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
Expand Down Expand Up @@ -63,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -101,28 +94,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.2"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -134,7 +127,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -155,35 +148,28 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "0.4.12"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
sdks:
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.17.0"
2 changes: 2 additions & 0 deletions include/platform_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum json_value_type {
kJsonNull,
kJsonTrue,
kJsonFalse,
kJsonInteger,
kJsonNumber,
kJsonString,
kJsonArray,
Expand All @@ -41,6 +42,7 @@ struct json_value {
enum json_value_type type;
union {
double number_value;
int64_t integer_value;
char *string_value;
struct {
size_t size;
Expand Down
1 change: 1 addition & 0 deletions src/flutter_wlroots.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ static void engine_cb_platform_message(

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

message_free(&name);
Expand Down
6 changes: 3 additions & 3 deletions src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ static void send_key_to_flutter(struct fwr_keyboard *keyboard, struct wlr_event_
| (keyboard_state_is_capslock_active(kb_state) << 1)
| (keyboard_state_is_ctrl_active(kb_state) << 2)
| (keyboard_state_is_alt_active(kb_state) << 3)
| (keyboard_state_is_numlock_active(kb_state) << 4)
| (keyboard_state_is_meta_active(kb_state) << 28);
| (keyboard_state_is_numlock_active(kb_state) << 4);
//| (keyboard_state_is_meta_active(kb_state) << 28);
uint16_t scan_code = (uint16_t)event->keycode + 8;
xkb_keysym_t key_code = xkb_state_key_get_one_sym(kb_state, scan_code);
uint32_t unicode = xkb_state_key_get_utf32(kb_state, scan_code);
Expand Down Expand Up @@ -373,7 +373,7 @@ static void send_key_to_flutter(struct fwr_keyboard *keyboard, struct wlr_event_
/* unicodeScalarValues */ {.type = kJsonNumber, .number_value = (flType == kFlutterKeyEventTypeDown ? unicode : 0x0)},
/* keyCode */ {.type = kJsonNumber, .number_value = (uint32_t) key_code},
/* scanCode */ {.type = kJsonNumber, .number_value = scan_code},
/* modifiers */ {.type = kJsonNumber, .number_value = modifiers},
/* modifiers */ {.type = kJsonInteger, .number_value = modifiers},
/* type */ {.type = kJsonString, .string_value = type}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/platform_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,17 @@ int platch_write_value_to_buffer_std(struct std_value* value, uint8_t **pbuffer)
size_t platch_calc_value_size_json(struct json_value *value) {
size_t size = 0;

char numBuffer[32];

switch (value->type) {
case kJsonNull:
case kJsonTrue:
return 4;
case kJsonFalse:
return 5;
case kJsonInteger:
return sprintf(numBuffer, "%ld", value->integer_value);
case kJsonNumber: ;
char numBuffer[32];
return sprintf(numBuffer, "%g", value->number_value);
case kJsonString:
size = 2;
Expand Down Expand Up @@ -503,6 +506,9 @@ int platch_write_value_to_buffer_json(struct json_value* value, uint8_t **pbuffe
case kJsonFalse:
*pbuffer += sprintf((char*) *pbuffer, "false");
break;
case kJsonInteger:
*pbuffer += sprintf((char*) *pbuffer, "%ld", value->integer_value);
break;
case kJsonNumber:
*pbuffer += sprintf((char*) *pbuffer, "%g", value->number_value);
break;
Expand Down

0 comments on commit b1c6db2

Please sign in to comment.