Class: Fusuma::Plugin::Detectors::ThumbsenseDetector
- Inherits:
-
Detector
- Object
- Detector
- Fusuma::Plugin::Detectors::ThumbsenseDetector
- Defined in:
- lib/fusuma/plugin/detectors/thumbsense_detector.rb
Overview
Detect Thumbsense context and change remap layer of fusuma-plugin-remap
Constant Summary collapse
- SOURCES =
keypress buffer is used to detect modifier keys
%w[thumbsense keypress].freeze
- MODIFIER_KEYS =
Set.new(%w[ CAPSLOCK LEFTALT LEFTCTRL LEFTMETA LEFTSHIFT RIGHTALT RIGHTCTRL RIGHTSHIFT RIGHTMETA ])
- LAYER_CONTEXT =
{thumbsense: true}.freeze
Instance Method Summary collapse
-
#detect(buffers) ⇒ Event, ...
Detect Context event and change remap layer of fusuma-plugin-remap.
Instance Method Details
#detect(buffers) ⇒ Event, ...
Detect Context event and change remap layer of fusuma-plugin-remap
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fusuma/plugin/detectors/thumbsense_detector.rb', line 35 def detect(buffers) @thumbsense_buffer ||= find_buffer(buffers, "thumbsense") @keypress_buffer ||= find_buffer(buffers, "keypress") layer_manager = Fusuma::Plugin::Remap::LayerManager.instance # layer is thumbsense => create thumbsense context and remap index # touch is touching => create thumbsense context and remap index # touch is released => remove thumbsense context # keypress -> touch => remove thumbsense context if touch_released? && !thumbsense_layer? MultiLogger.debug("thumbsense layer removed") layer_manager.send_layer(layer: LAYER_CONTEXT, remove: true) return end # When keypress event is first: # If current layer is thumbsense, the layer should not be changed # If current layer is not thumbsense, it should remain a normal key # In other words, if the key event comes first, do nothing if keypress_first? MultiLogger.debug("keypress event is first") return end MultiLogger.debug("thumbsense context created") unless thumbsense_layer? layer_manager.send_layer(layer: LAYER_CONTEXT) # create thumbsense context context = create_event( record: Events::Records::ContextRecord.new( name: :thumbsense, value: true ) ) # TODO: Threshold # create remap index index = if (keys = pressed_codes) && !keys.empty? MultiLogger.debug("thumbsense remap index created: #{keys}") combined_keys = keys.join("+") create_event( record: Events::Records::IndexRecord.new( index: Config::Index.new([:remap, combined_keys]) ) ) end [context, index].compact end |