class Fusuma::Plugin::Filters::LibinputDeviceFilter

Filter device log

def config_param_sample

def config_param_sample
  <<~SAMPLE
    ```config.yml
    plugin:
      filters:
        libinput_device_filter:
          keep_device_names:
            - "DEVICE NAME PATTERN"
    ```
  SAMPLE
end

def config_param_types

def config_param_types
  {
    source: String,
    keep_device_names: [Array, String]
  }
end

def keep?(record)

Returns:
  • (FalseClass) - when discarding it
  • (TrueClass) - when keeping it
def keep?(record)
  # NOTE: purge cache when found new device
  if record.to_s =~ /\sDEVICE_ADDED\s/ && keep_device.match_pattern?(record.to_s)
    keep_device.reset
    return false
  end
  keep_device.all.map(&:id).any? { |device_id| record.to_s =~ /^[\s-]?#{device_id}\s/ }
end

def keep_device

def keep_device
  @keep_device ||= begin
    from_config = Array(config_params(:keep_device_names))
    KeepDevice.new(name_patterns: from_config)
  end
end