Skip to content

Commit 6b26e23

Browse files
Address review comments (documentation, alignment, constructor
parameters)
1 parent 6072494 commit 6b26e23

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

library/linux/src/embedder.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ struct FlutterEmbedderState {
5151
// deleted from the heap.
5252
std::vector<flutter_desktop_embedding::KeyboardHookHandler *>
5353
keyboard_hook_handlers;
54+
// Handles raw key interactions from GLFW.
55+
// TODO: Move key_event_handler once
56+
// https://github.com/google/flutter-desktop-embedding/issues/102 is resolved.
5457
std::unique_ptr<flutter_desktop_embedding::KeyEventHandler> key_event_handler;
5558
};
5659

@@ -275,8 +278,8 @@ GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height,
275278
state->plugin_handler = std::make_unique<PluginHandler>(engine);
276279
state->engine = engine;
277280

278-
state->key_event_handler = std::make_unique<KeyEventHandler>();
279-
state->key_event_handler->SetBinaryMessenger(state->plugin_handler.get());
281+
state->key_event_handler =
282+
std::make_unique<KeyEventHandler>(state->plugin_handler.get());
280283
state->keyboard_hook_handlers.push_back(state->key_event_handler.get());
281284
auto input_plugin = std::make_unique<TextInputPlugin>();
282285
state->keyboard_hook_handlers.push_back(input_plugin.get());

library/linux/src/internal/key_event_handler.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
#include "library/linux/src/internal/key_event_handler.h"
15-
#include "library/linux/src/internal/json_message_codec.h"
1615

17-
#include <flutter_embedder.h>
1816
#include <json/json.h>
1917
#include <iostream>
2018

19+
#include "library/linux/src/internal/json_message_codec.h"
20+
2121
static constexpr char kChannelName[] = "flutter/keyevent";
2222

2323
static constexpr char kKeyCodeKey[] = "keyCode";
@@ -31,17 +31,16 @@ static constexpr char kKeyDown[] = "keydown";
3131
static constexpr char kRepeat[] = "repeat";
3232

3333
namespace flutter_desktop_embedding {
34-
KeyEventHandler::KeyEventHandler() : channel_(kChannelName) {}
35-
KeyEventHandler::~KeyEventHandler() {}
3634

37-
void KeyEventHandler::SetBinaryMessenger(BinaryMessenger *messenger) {
38-
messenger_ = messenger;
39-
}
35+
KeyEventHandler::KeyEventHandler(const BinaryMessenger *messenger)
36+
: messenger_(messenger), channel_(kChannelName) {}
37+
38+
KeyEventHandler::~KeyEventHandler() {}
4039

4140
void KeyEventHandler::CharHook(GLFWwindow *window, unsigned int code_point) {}
4241

4342
void KeyEventHandler::KeyboardHook(GLFWwindow *window, int key, int scancode,
44-
int action, int mods) {
43+
int action, int mods) {
4544
// TODO: Translate to a cross-platform key code system rather than passing
4645
// the native key code.
4746
Json::Value args;
@@ -56,7 +55,8 @@ void KeyEventHandler::KeyboardHook(GLFWwindow *window, int key, int scancode,
5655
args[kTypeKey] = kKeyUp;
5756
break;
5857
default:
59-
break;
58+
std::cerr << "Unknown key event action: " << action << std::endl;
59+
return;
6060
}
6161
auto message = JsonMessageCodec::GetInstance().EncodeMessage(args);
6262
messenger_->Send(channel_, message->data(), message->size());

library/linux/src/internal/key_event_handler.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,34 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
#ifndef LIBRARY_LINUX_SRC_INTERNAL_KEY_EVENT_PLUGIN_H_
15-
#define LIBRARY_LINUX_SRC_INTERNAL_kEY_EVENT_PLUGIN_H_
14+
#ifndef LIBRARY_LINUX_SRC_INTERNAL_KEY_EVENT_HANDLER_H_
15+
#define LIBRARY_LINUX_SRC_INTERNAL_kEY_EVENT_HANDLER_H_
1616

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

20-
#include <memory>
21-
2220
namespace flutter_desktop_embedding {
21+
2322
// Implements a KeyboardHookHandler
2423
//
2524
// Handles key events and forwards them to the Flutter engine.
2625
class KeyEventHandler : public KeyboardHookHandler {
2726
public:
28-
explicit KeyEventHandler();
27+
explicit KeyEventHandler(const BinaryMessenger *messenger);
2928
virtual ~KeyEventHandler();
3029

3130
// KeyboardHookHandler.
3231
void KeyboardHook(GLFWwindow *window, int key, int scancode, int action,
3332
int mods) override;
34-
35-
// KeyboardHookHandler.
3633
void CharHook(GLFWwindow *window, unsigned int code_point) override;
3734

35+
private:
3836
// Binds this plugin to the given caller-owned binary messenger. It must
3937
// remain valid for the life of the plugin.
40-
void SetBinaryMessenger(BinaryMessenger *messenger);
41-
42-
private:
4338
const BinaryMessenger *messenger_;
4439
std::string channel_;
4540
};
4641

4742
} // namespace flutter_desktop_embedding
4843

49-
#endif // LIBRARY_LINUX_SRC_INTERNAL_KEY_EVENT_PLUGIN_H_
44+
#endif // LIBRARY_LINUX_SRC_INTERNAL_KEY_EVENT_HANDLER_H_

0 commit comments

Comments
 (0)