Skip to content

[linux] Adds raw key events plugin. #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

franciscojma86
Copy link
Contributor

Copy link
Contributor

@krisgiesing krisgiesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM although I'm not entirely sure about the code added to the JSON method codec.

AddPlugin(window, std::move(input_plugin));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: whitespace

auto input_plugin = std::make_unique<TextInputPlugin>();
state->keyboard_hook_handlers.push_back(input_plugin.get());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: whitespace

// See the License for the specific language governing permissions and
// limitations under the License.
#include "library/linux/src/internal/key_event_plugin.h"
#include <flutter_embedder.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: whitespace before system includes

void KeyEventPlugin::KeyboardHook(GLFWwindow *window, int key, int scancode,
int action, int mods) {
Json::Value args;
args[kKeyCodeKey] = key;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a TODO comment to translate to a cross-platform key code system rather than just reflecting the platform-specific one up to the Dart layer?

@@ -58,6 +58,10 @@ std::unique_ptr<MethodCall> JsonMethodCodec::DecodeMethodCallInternal(
std::unique_ptr<std::vector<uint8_t>> JsonMethodCodec::EncodeMethodCallInternal(
const MethodCall &method_call) const {
Json::Value message(Json::objectValue);
if (method_call.method_name().empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this code necessary now? Is this unrelated cleanup?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change shouldn't be made to MethodCodec.

The issue here is that flutter/keyevent is a MessageChannel, not a MethodChannel, on the Dart side. MethodChannel is essentially a layer over MessageChannel that establishes the name/argument structure. Making *MethodCodec allow non-Method-structured messages goes against that distinction.

The right fix, which would align with the overall work of #102 is to split out JsonMessageCodec from JsonMethodCodec, but that will also require building out support for Message-based plugins. The next step of plugin refactoring that I have planned would help lay the foundation for that.

Is support for raw key events on Linux time critical, or is this something we can revisit once I'm further along with #102? If the former, I think the best way forward in the short term to support the direction of #102 would be:

  • Split MessageCodec out from MethodCodec
  • Add a new class above Plugin (this would be temporary, since Plugin will be significantly changed or even eliminated as part of Make the plugin API structure match the existing Flutter plugin API #102 eventually anyway) that operates on generic data messages.
  • Make Plugin do the conversion from data to method call, then forward to the existing Plugin methods.
  • Change PluginHandler to take in that new superclass instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably wait. We were trying to get the overall raw key event feature to work in a short term time frame, but we can wait on the Linux implementation side.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let's let this PR wait for a bit then. I'm hoping to do more work on plugin refactoring next week, and then we can re-evaluate.

If someone wants to do the MessageCodec/MethodCodec split in the mean time that would be useful parallel work that we'll need regardless.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting SGTM.

@@ -58,6 +58,10 @@ std::unique_ptr<MethodCall> JsonMethodCodec::DecodeMethodCallInternal(
std::unique_ptr<std::vector<uint8_t>> JsonMethodCodec::EncodeMethodCallInternal(
const MethodCall &method_call) const {
Json::Value message(Json::objectValue);
if (method_call.method_name().empty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change shouldn't be made to MethodCodec.

The issue here is that flutter/keyevent is a MessageChannel, not a MethodChannel, on the Dart side. MethodChannel is essentially a layer over MessageChannel that establishes the name/argument structure. Making *MethodCodec allow non-Method-structured messages goes against that distinction.

The right fix, which would align with the overall work of #102 is to split out JsonMessageCodec from JsonMethodCodec, but that will also require building out support for Message-based plugins. The next step of plugin refactoring that I have planned would help lay the foundation for that.

Is support for raw key events on Linux time critical, or is this something we can revisit once I'm further along with #102? If the former, I think the best way forward in the short term to support the direction of #102 would be:

  • Split MessageCodec out from MethodCodec
  • Add a new class above Plugin (this would be temporary, since Plugin will be significantly changed or even eliminated as part of Make the plugin API structure match the existing Flutter plugin API #102 eventually anyway) that operates on generic data messages.
  • Make Plugin do the conversion from data to method call, then forward to the existing Plugin methods.
  • Change PluginHandler to take in that new superclass instead.

@stuartmorgan-g
Copy link
Collaborator

I didn't end up having much time to work on 102 this week, but in starting to look at it, I found a more minimal set of incremental steps to take to unblock this, and just sent both for review:

  • Creating JsonMessageCodec (without tackling the broader refactoring, just making it an internal helper class for now)
  • Making PluginHandler a BinaryMessenger, taking over the core logic of sending messages to the engine.

With those two landed, what you should be able to do here is change your new key handler to not inherit from Plugin, and just have it take a BinaryMessenger in its constructor or as a setter. Then instead of InvokeMethod, you'll call Send on the messenger after using JsonMessageCodec to encode your message.

Since it won't be a plugin you'll need to have something own it; I'm fine with just adding it to FlutterEmbedderState. (Eventually, once 102 is finished, it will end up re-aligned with whatever Plugins turn into, so it won't stay they permanently.)

@franciscojma86 franciscojma86 deleted the keys branch November 29, 2018 22:22
@franciscojma86 franciscojma86 restored the keys branch November 29, 2018 22:46
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants