Class: UinputKeyboard

Inherits:
Ruinput::UinputDevice
  • Object
show all
Includes:
Ruinput
Defined in:
lib/fusuma/plugin/remap/uinput_keyboard.rb

Instance Method Summary collapse

Instance Method Details

#create(name = DEFAULT_DEVICE_NAME, id = DEFAULT_INPUT_ID) ⇒ Object

create virtual event divece

name

device name

id

InputId (“struct input_id” on input.h)



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fusuma/plugin/remap/uinput_keyboard.rb', line 9

def create name = DEFAULT_DEVICE_NAME, id = DEFAULT_INPUT_ID
  if !name.is_a? String
    raise ArgumentError, "1st arg expect String"
  elsif !id.is_a? Revdev::InputId
    raise ArgumentError, "2nd arg expect Revdev::InputId"
  end

  uud = Ruinput::UinputUserDev.new({
    name: name,
    id: id,
    ff_effects_max: 0,
    absmax: [],
    absmin: [],
    absfuzz: [],
    absflat: []
  })

  @file.syswrite uud.to_byte_string

  set_all_events

  @file.ioctl UI_DEV_CREATE, nil
  @is_created = true
end

#set_all_eventsObject



34
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
86
87
88
89
90
91
92
93
94
# File 'lib/fusuma/plugin/remap/uinput_keyboard.rb', line 34

def set_all_events
  raise "invalid method call: this uinput is already created" if @is_created

  mouse_btns = [
    Revdev::BTN_0,
    Revdev::BTN_MISC,
    Revdev::BTN_1,
    Revdev::BTN_2,
    Revdev::BTN_3,
    Revdev::BTN_4,
    Revdev::BTN_5,
    Revdev::BTN_6,
    Revdev::BTN_7,
    Revdev::BTN_8,
    Revdev::BTN_9,
    Revdev::BTN_LEFT,
    Revdev::BTN_MOUSE,
    Revdev::BTN_MIDDLE,
    Revdev::BTN_RIGHT,
    Revdev::BTN_SIDE,
    Revdev::BTN_EXTRA,
    Revdev::BTN_FORWARD,
    Revdev::BTN_BACK,
    Revdev::BTN_TASK
    # Revdev::BTN_TRIGGER, # libinput recognized as joystick if set
  ].freeze

  keyboard_keys = Revdev.constants.select { |c| c.start_with? "KEY_" }.map { |c| Revdev.const_get(c) }.freeze

  @file.ioctl UI_SET_EVBIT, Revdev::EV_KEY
  @counter = 0
  Revdev::KEY_CNT.times do |i|
    # https://github.com/mooz/xkeysnail/pull/101/files
    if keyboard_keys.include?(i) || mouse_btns.include?(i)
      # puts "setting #{i} (#{Revdev::REVERSE_MAPS[:KEY][i]})"
      @file.ioctl UI_SET_KEYBIT, i
    end
  end

  # @file.ioctl UI_SET_EVBIT, Revdev::EV_MSC
  # Revdev::MSC_CNT.times do |i|
  #   @file.ioctl UI_SET_MSCBIT, i
  # end

  mouse_rel = [
    Revdev::REL_X,
    Revdev::REL_Y,
    Revdev::REL_WHEEL,
    Revdev::REL_HWHEEL
  ].freeze

  @file.ioctl UI_SET_EVBIT, Revdev::EV_REL
  Revdev::REL_CNT.times do |i|
    if mouse_rel.include?(i)
      # puts "setting #{i} (#{Revdev::REVERSE_MAPS[:REL][i]})"
      @file.ioctl UI_SET_RELBIT, i
    end
  end

  @file.ioctl UI_SET_EVBIT, Revdev::EV_REP
end