Skip to content

[linux] Adds raw key event handler #163

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

Merged
merged 4 commits into from
Dec 6, 2018

Conversation

franciscojma86
Copy link
Contributor

No description provided.

@@ -50,6 +51,7 @@ struct FlutterEmbedderState {
// deleted from the heap.
std::vector<flutter_desktop_embedding::KeyboardHookHandler *>
keyboard_hook_handlers;
std::unique_ptr<flutter_desktop_embedding::KeyEventHandler> key_event_handler;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a quick comment explaining what this is, as you would with a class ivar.

@@ -275,6 +277,10 @@ GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height,
FlutterEmbedderState *state = new FlutterEmbedderState();
state->plugin_handler = std::make_unique<PluginHandler>(engine);
state->engine = engine;

state->key_event_handler = std::make_unique<KeyEventHandler>();
state->key_event_handler->SetBinaryMessenger(state->plugin_handler.get());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you never need to change this, and the handler doesn't really do anything without it, strongly consider making this a constructor argument.

// See the License for the specific language governing permissions and
// limitations under the License.
#include "library/linux/src/internal/key_event_handler.h"
#include "library/linux/src/internal/json_message_codec.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This header should be in its own section after the library headers, per Google style. Only the associated header (key_event_handler.h) goes above.

break;
}
auto message = JsonMessageCodec::GetInstance().EncodeMessage(args);
messenger_->Send(channel_, message->data(), message->size());
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you don't make messenger a constructor argument, you should check that it's not null before using it.

args[kTypeKey] = kKeyUp;
break;
default:
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't getting here be an error, or something that should trigger an early return? As written it would result in a key event being sent without a type.

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LIBRARY_LINUX_SRC_INTERNAL_KEY_EVENT_PLUGIN_H_
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/PLUGIN/HANDLER in all of these guards.

#include "library/linux/include/flutter_desktop_embedding/binary_messenger.h"
#include "library/linux/src/internal/keyboard_hook_handler.h"

#include <memory>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This goes before project headers.

// TODO: This event is not supported by Flutter. Add once it's implemented.
static constexpr char kRepeat[] = "repeat";

namespace flutter_desktop_embedding {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Be consistent about horizontal spacing; if the namespace is going to have a blank line at the end, put one at the start as well. (Same for header.)

void SetBinaryMessenger(BinaryMessenger *messenger);

private:
const BinaryMessenger *messenger_;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you don't make this constructor-initialized, you should initialize it to nullptr here.

void KeyboardHook(GLFWwindow *window, int key, int scancode, int action,
int mods) override;

// KeyboardHookHandler.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just one comment per superclass please; the idea is to group all the methods that are overridden from a specific interface:

// KeyboardHookHandler.
void KeyboardHook(...) override;
void CharHook(...) override;

[other methods here]

@franciscojma86
Copy link
Contributor Author

Comments addressed, PTAL!

@franciscojma86 franciscojma86 merged commit 1888375 into google:master Dec 6, 2018
@franciscojma86 franciscojma86 deleted the keys branch December 6, 2018 23:52
@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.

2 participants