fusuma-plugin-sendkey 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 863f4caf17a75bd03010d34cc01a493ad7dfc327a4e4c9c05ed3ecae91f57286
4
- data.tar.gz: 6a64a753da83d4561c5d7384366d3596aac6b4d8c7aaad082187d943f4771d91
3
+ metadata.gz: 0512b4f118bd0b676616741f47a643a759d8eb123eb581bb3136b38a34f0acc4
4
+ data.tar.gz: 45cafd5f8b3f8cd1e44643c20438b04ce59065854548123285ea5eea1e5585fc
5
5
  SHA512:
6
- metadata.gz: e016af2afb00bc864a57dc0c5cc36935e6d35d132cb268de9c18e1aa8062c896fcc8febc952f7a1b823f055bb7eb51b2e4e81bbef1a8002807dfc136cc938884
7
- data.tar.gz: 896772bbd1dc67818cff10a3d8bacc1d582370b5075af0df0e9d4a6f32f497a2024c5cf80d5794367d69547b334d95202dfa50ef5888576b26f4e3fd84b1d105
6
+ metadata.gz: 264b5e7d2ae3729ccc1f3fe0db02dab1ee1999e089fab2cd2df9f97f3994ff0c20976e37a6e2105c141161dc70db20d4058098529bba5372427bfe242d6d10d5
7
+ data.tar.gz: b1cb6a075c279a15e63f7685d5887dc0b2c4c767915fb4066b2d929788b725c2d8127d766e5045ee5b1c49f2f40e9882793066e6607f56d2dae967347d89667a
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Fusuma::Plugin::Sendkey [![Gem Version](https://badge.fury.io/rb/fusuma-plugin-sendkey.svg)](https://badge.fury.io/rb/fusuma-plugin-sendkey) [![Build Status](https://travis-ci.com/iberianpig/fusuma-plugin-sendkey.svg?branch=master)](https://travis-ci.com/iberianpig/fusuma-plugin-sendkey)
1
+ # Fusuma::Plugin::Sendkey [![Gem Version](https://badge.fury.io/rb/fusuma-plugin-sendkey.svg)](https://badge.fury.io/rb/fusuma-plugin-sendkey) [![Build Status](https://github.com/iberianpig/fusuma-plugin-sendkey/actions/workflows/main.yml/badge.svg)](https://github.com/iberianpig/fusuma-plugin-sendkey/actions/workflows/main.yml)
2
2
 
3
3
  [Fusuma](https://github.com/iberianpig/fusuma) plugin to send keyboard events
4
4
 
@@ -85,6 +85,20 @@ swipe:
85
85
  sendkey: "LEFTCTRL+W" # close tab
86
86
  ```
87
87
 
88
+ ### clearmodifiers
89
+
90
+ - `clearmodifiers: true` option clears other modifier keys before sending
91
+
92
+ ```yaml
93
+ swipe:
94
+ 4:
95
+ up:
96
+ keypress:
97
+ LEFTSHIFT:
98
+ sendkey: "LEFTMETA+DOWN"
99
+ clearmodifiers: true # clear LEFTSHIFT before sending LEFTMETA+DOWN
100
+ ```
101
+
88
102
 
89
103
  ### Specify keyboard by device name
90
104
 
@@ -105,6 +119,9 @@ plugin:
105
119
  device_name: 'YOUR KEYBOARD NAME'
106
120
  ```
107
121
 
122
+ **If [fusuma-plugin-remap](https://github.com/iberianpig/fusuma-plugin-remap) is available, it will be automatically connected to `fusuma_virtual_keyboard`, so `device_name` option is not required.**
123
+
124
+
108
125
  ## Contributing
109
126
 
110
127
  Bug reports and pull requests are welcome on GitHub at https://github.com/iberianpig/fusuma-plugin-sendkey. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/bin/console CHANGED
@@ -4,9 +4,7 @@ require "bundler/setup"
4
4
  require 'fusuma/plugin/executors/executor'
5
5
  require "fusuma/plugin/sendkey"
6
6
 
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
7
+ Fusuma::Plugin::Manager.require_base_plugins
9
8
 
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- require "pry"
12
- Pry.start
9
+ require "irb"
10
+ IRB.start(__FILE__)
@@ -5,8 +5,13 @@ require_relative "../sendkey/keyboard"
5
5
  module Fusuma
6
6
  module Plugin
7
7
  module Executors
8
- # Control Window or Workspaces by executing wctrl
8
+ # Execute to send key event to device
9
9
  class SendkeyExecutor < Executor
10
+ def initialize
11
+ @device_name = config_params(:device_name)
12
+ super
13
+ end
14
+
10
15
  def execute_keys
11
16
  [:sendkey]
12
17
  end
@@ -22,21 +27,10 @@ module Fusuma
22
27
  # @return [nil]
23
28
  def execute(event)
24
29
  MultiLogger.info(sendkey: search_param(event))
25
- pid = fork do
26
- Process.daemon(true)
27
- _execute(event)
28
- end
29
-
30
- Process.detach(pid)
31
- end
32
-
33
- # execute sendkey command
34
- # @param event [Event]
35
- # @return [nil]
36
- def _execute(event)
37
30
  keyboard.type(
38
31
  param: search_param(event),
39
- keep: search_keypress(event)
32
+ keep: search_keypress(event),
33
+ clear: clearmodifiers(event)
40
34
  )
41
35
  end
42
36
 
@@ -52,10 +46,7 @@ module Fusuma
52
46
  private
53
47
 
54
48
  def keyboard
55
- @keyboard ||= begin
56
- name_pattren = config_params(:device_name)
57
- Sendkey::Keyboard.new(name_pattern: name_pattren)
58
- end
49
+ @keyboard ||= Sendkey::Keyboard.new(name_pattern: @device_name)
59
50
  end
60
51
 
61
52
  def search_param(event)
@@ -63,14 +54,28 @@ module Fusuma
63
54
  Config.search(index)
64
55
  end
65
56
 
57
+ # search keypress from config for keep modifiers when sendkey
66
58
  # @param event [Event]
67
59
  # @return [String]
68
60
  def search_keypress(event)
61
+ # if fusuma_virtual_keyboard exists, don't have to keep modifiers
62
+ return "" if keyboard.use_virtual_keyboard?
63
+
69
64
  keys = event.record.index.keys
70
65
  keypress_index = keys.find_index { |k| k.symbol == :keypress }
71
66
  code = keypress_index && keys[keypress_index + 1].symbol
72
67
  code.to_s
73
68
  end
69
+
70
+ # clearmodifiers from config
71
+ # @param event [Event]
72
+ # @return [String, TrueClass, Symbole]
73
+ def clearmodifiers(event)
74
+ @clearmodifiers ||= {}
75
+ index = event.record.index
76
+ @clearmodifiers[index.cache_key] ||=
77
+ Config.search(Config::Index.new([*index.keys, "clearmodifiers"])) || :none
78
+ end
74
79
  end
75
80
  end
76
81
  end
@@ -24,33 +24,57 @@ module Fusuma
24
24
  KEY_RIGHTMETA
25
25
  ].freeze
26
26
 
27
+ DEFAULT_NAME_PATTERN = "keyboard|Keyboard|KEYBOARD"
28
+ VIRTUAL_KEYBOARD = "fusuma_virtual_keyboard" # fusuma-plugin-remap creates uinput device
29
+
27
30
  def self.find_device(name_pattern:)
31
+ Fusuma::Device.reset
28
32
  Fusuma::Device.all.find { |d| d.name.match(/#{name_pattern}/) }
29
33
  end
30
34
 
31
35
  def initialize(name_pattern: nil)
32
- name_pattern ||= "keyboard|Keyboard|KEYBOARD"
33
- device = Keyboard.find_device(name_pattern: name_pattern)
36
+ device = if name_pattern
37
+ Keyboard.find_device(name_pattern: name_pattern)
38
+ else
39
+ Keyboard.find_device(name_pattern: VIRTUAL_KEYBOARD) || Keyboard.find_device(name_pattern: DEFAULT_NAME_PATTERN)
40
+ end
34
41
 
35
42
  if device.nil?
36
43
  warn "sendkey: Keyboard: /#{name_pattern}/ is not found"
37
44
  exit(1)
38
45
  end
46
+ MultiLogger.info "sendkey: Keyboard: #{device.name}"
39
47
 
48
+ @use_virtual_keyboard = device.name.match(/#{VIRTUAL_KEYBOARD}/o)
40
49
  @device = Device.new(path: "/dev/input/#{device.id}")
41
50
  end
42
51
 
43
- # @param param [String]
44
- # @param keep [String]
45
- def type(param:, keep: "")
52
+ def use_virtual_keyboard?
53
+ @use_virtual_keyboard
54
+ end
55
+
56
+ # @param param [String] key names separated by '+' to type
57
+ # @param keep [String] key names separated by '+' to keep
58
+ # @param clear [String, Symbol, TrueClass] key names separated by '+' to clear or :all to relase all modifiers
59
+ def type(param:, keep: "", clear: :none)
46
60
  return unless param.is_a?(String)
47
61
 
48
62
  param_keycodes = param_to_keycodes(param)
49
- keep_keycodes = param_to_keycodes(keep)
63
+ type_keycodes = param_keycodes - param_to_keycodes(keep)
64
+
65
+ clear_keycodes =
66
+ case clear
67
+ when true
68
+ MODIFIER_KEY_CODES
69
+ when :none, false
70
+ []
71
+ else
72
+ # release keys specified by clearmodifiers
73
+ param_to_keycodes(clear)
74
+ end
75
+
76
+ clear_modifiers(clear_keycodes - param_keycodes)
50
77
 
51
- type_keycodes = param_keycodes - keep_keycodes
52
- # release other modifier keys before sending key
53
- clear_modifiers(MODIFIER_KEY_CODES - param_keycodes)
54
78
  type_keycodes.each { |keycode| keydown(keycode) && key_sync }
55
79
  type_keycodes.reverse_each { |keycode| keyup(keycode) && key_sync }
56
80
  end
@@ -122,7 +146,7 @@ module Fusuma
122
146
  end
123
147
 
124
148
  def keycode_const(keycode)
125
- Object.const_get "LinuxInput::#{keycode}"
149
+ Object.const_get "Revdev::#{keycode}"
126
150
  end
127
151
 
128
152
  # @param [Array<String>] keycodes to be released
@@ -3,7 +3,7 @@
3
3
  module Fusuma
4
4
  module Plugin
5
5
  module Sendkey
6
- VERSION = "0.7.1"
6
+ VERSION = "0.8.0"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusuma-plugin-sendkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iberianpig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-16 00:00:00.000000000 Z
11
+ date: 2023-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fusuma