Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Pointing Stick Input for HHKB Studio #4

Merged
merged 3 commits into from
Sep 14, 2024

Conversation

iberianpig
Copy link
Owner

@iberianpig iberianpig commented Sep 13, 2024

Input Handling for Pointing Stick Devices Using HIDRAW

We have added new input handling for pointing stick devices using HIDRAW interface.
Now, it can process detailed touch information from pointing stick that libinput and evdev cannot handle.
This means you can map F and D keys to click actions while using the pointing stick.

Currently, this feature only supports HHKB Studio, but we plan to support other devices in the future.

image

Implementation Details

Handling HIDRAW Devices

  • We use IOCTL commands to get information like the device name, bus type, vendor ID, and product ID for the pointing stick device connected through HIDRAW.
  • HIDRAW receives data through device files named /dev/hidraw*.
  • HHKB Studio can connect either via Bluetooth or USB, and we have implemented the correct processing based on each report descriptor.
  • We handle events when switching between USB and Bluetooth, and when the device is connected or disconnected.

Processing Pointing Stick Events

  • This feature works as a Fusuma InputPlugin. It creates a thread to wait for HIDRAW events.
  • Fusuma analyze byte stream from /dev/hidraw* to determine the state of the pointing stick and generate touch (begin/update/end) events.
  • Touch events are produced from PointingStickInput plugin and processed in Fusuma's main thread using IO.select.
  • Fusuma's main thread detects touches using existing ThumbsenseDetector.
  • It sends requests to change virtual keyboard layer to update key mappings in Fusuma's remap process.
  • While using the pointing stick, the click events for the F and D keys are mapped to BTN_LEFT and BTN_RIGHT.

Setting Up Udev Rules

To make PointingStickInput work, users need to set up udev rules like following:

$ sudo vi /etc/udev/rules.d/60-udev-fusuma-thumbsense-hhkb-studio.rules
# /etc/udev/rules.d/60-udev-fusuma-thumbsense-hhkb-studio.rules
# HHKB Studio (USB)
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="04fe", ATTRS{idProduct}=="0016", MODE="0666"
# HHKB Studio (Bluetooth)
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ENV{DEVPATH}=="/devices/virtual/misc/uhid/*:04FE:0016.*/hidraw*", MODE="0666"
$ sudo udevadm control --reload-rules && sudo udevadm trigger

After this, Fusuma will be able to read the HHKB Studio as a HIDRAW device.

User Configuration Example

Here is an example of how you might configure your ~/.config/fusuma/config.yml . Please add this section to end of config.yml.

---
context:
  thumbsense: true

remap:
  F: BTN_LEFT
  E: BTN_MIDDLE
  D: BTN_RIGHT

  J: BTN_LEFT
  I: BTN_MIDDLE
  K: BTN_RIGHT

  # Translate in Google Chrome
  T: { sendkey: ["LEFTSHIFT+F10", "T", "ENTER", "ESC"] }

- Pointing stick devices (only HHKB Studio for now) can now be used as input devices
- Modified thumbsense_buffer.rb to handle pointing stick events
- Added new files for HID raw device handling, including Bluetooth and USB parsers for HHKB
- Introduced PointingStickInput for integrating with pointing stick devices
- Added YAML configuration for pointing stick inputs
- Added specs for device and parser functionalities
- Do not detect thumbsense when a modifier key is pressed after touch is released
- This prevents the extension of timeout when operating pointing stick
- For example, when you press SHIFT while operating pointing stick,
  release pointing stick, and then press F, it is converted to a
  click event
@iberianpig iberianpig changed the title Support pointing stick for HHKB Studio Support Pointing Stick Input for HHKB Studio Sep 13, 2024
@iberianpig iberianpig changed the title Support Pointing Stick Input for HHKB Studio Support pointing stick for HHKB Studio Sep 13, 2024
@iberianpig iberianpig changed the title Support pointing stick for HHKB Studio Support Pointing Stick Input for HHKB Studio Sep 13, 2024
@iberianpig iberianpig marked this pull request as ready for review September 13, 2024 15:43
@iberianpig iberianpig added the enhancement New feature or request label Sep 14, 2024
@iberianpig iberianpig self-assigned this Sep 14, 2024
@iberianpig iberianpig merged commit bfb1e80 into main Sep 14, 2024
4 checks passed
@iberianpig iberianpig deleted the feature/pointing-stick branch September 25, 2024 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant