librime 1.2
Rime Input Method Engine, the core library
key_binding_processor.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5#ifndef RIME_KEY_BINDING_PROCESSOR_H_
6#define RIME_KEY_BINDING_PROCESSOR_H_
7
8#include <rime/common.h>
9#include <rime/config.h>
10#include <rime/context.h>
11#include <rime/key_event.h>
12#include <rime/processor.h>
13
14namespace rime {
15
16template <class T, int N = 1>
18 public:
19 typedef bool Handler(Context* ctx);
20 using HandlerPtr = bool (T::*)(Context* ctx);
21
23 None = 0,
24 ShiftAsControl = (1 << 0),
25 IgnoreShift = (1 << 1),
27 };
28
29 struct ActionDef {
30 const char* name;
32 };
33
34 static const ActionDef kActionNoop;
35
36 explicit KeyBindingProcessor(ActionDef* action_definitions)
37 : action_definitions_(action_definitions) {}
38
39 ProcessResult ProcessKeyEvent(const KeyEvent& key_event,
40 Context* ctx,
41 int keymap_selector = 0,
42 int fallback_options = FallbackOptions::None);
43 void LoadConfig(Config* config,
44 const string& section,
45 int kemap_selector = 0);
46
47 protected:
48 struct Keymap : map<KeyEvent, HandlerPtr> {
49 void Bind(KeyEvent key_event, HandlerPtr action);
50 };
51
52 Keymap& get_keymap(int keymap_selector = 0);
53
54 bool Accept(const KeyEvent& key_event, Context* ctx, Keymap& keymap);
55
56 private:
57 ActionDef* action_definitions_;
58 Keymap keymaps_[N];
59};
60
61} // namespace rime
62
64
65#endif // RIME_KEY_BINDING_PROCESSOR_H_
Definition algebra.cc:12
ProcessResult
Definition processor.h:18
Definition config_component.h:21
Definition context.h:19
bool Accept(const KeyEvent &key_event, Context *ctx, Keymap &keymap)
Definition key_binding_processor_impl.h:56
Keymap & get_keymap(int keymap_selector=0)
Definition key_binding_processor_impl.h:50
bool(T::*)(Context *ctx) HandlerPtr
Definition key_binding_processor.h:20
void LoadConfig(Config *config, const string &section, int kemap_selector=0)
Definition key_binding_processor_impl.h:81
KeyBindingProcessor(ActionDef *action_definitions)
Definition key_binding_processor.h:36
FallbackOptions
Definition key_binding_processor.h:22
@ ShiftAsControl
Definition key_binding_processor.h:24
@ IgnoreShift
Definition key_binding_processor.h:25
@ None
Definition key_binding_processor.h:23
@ All
Definition key_binding_processor.h:26
bool Handler(Context *ctx)
Definition key_binding_processor.h:19
static const ActionDef kActionNoop
Definition key_binding_processor.h:34
ProcessResult ProcessKeyEvent(const KeyEvent &key_event, Context *ctx, int keymap_selector=0, int fallback_options=FallbackOptions::None)
Definition key_binding_processor_impl.h:13
Definition key_binding_processor.h:29
HandlerPtr action
Definition key_binding_processor.h:31
const char * name
Definition key_binding_processor.h:30
Definition key_binding_processor.h:48
void Bind(KeyEvent key_event, HandlerPtr action)
Definition key_binding_processor_impl.h:71
Definition key_event.h:17