Handy icon indicating copy to clipboard operation
Handy copied to clipboard

feat: expose transcription over dbus for wayland support

Open tbezman opened this issue 2 months ago • 5 comments

Add Wayland/Hyprland Support via D-Bus

What This Does

Adds support for Wayland/Hyprland! I implemented most of this PR with Claude Sonnet 4.5 and it works consistently in my testing.

The Problem

I'm on Hyprland (Wayland) and ran into two major issues:

  1. Global keyboard shortcuts don't work - Wayland handles shortcuts differently than X11
  2. Chrome ignores the transcription - Chrome/Chromium on Wayland blocks synthetic keyboard input for security, so even when transcription completed, nothing would paste into the browser

The Solution

D-Bus Interface

Added a D-Bus service so you can trigger transcription via system commands instead of global shortcuts:

# Start transcription
busctl --user call com.pais.Handy /com/pais/Handy com.pais.Handy.Transcription StartTranscription

# Stop transcription  
busctl --user call com.pais.Handy /com/pais/Handy com.pais.Handy.Transcription StopTranscription

You can bind these to keys in your Hyprland config:

bind = SUPER, R, exec, busctl --user call com.pais.Handy /com/pais/Handy com.pais.Handy.Transcription StartTranscription
bindrt = SUPER, R, exec, busctl --user call com.pais.Handy /com/pais/Handy com.pais.Handy.Transcription StopTranscription

wtype Integration for Chrome

Chrome blocks synthetic input from libraries like enigo, so I added support for wtype (a Wayland-native text input tool). When you set the paste method to "Direct Input" in settings, it automatically uses wtype on Wayland, which Chrome trusts.

Install with: sudo pacman -S wtype (or your distro's equivalent)

Focus Handling

The app now captures which window has focus before showing the overlay, then restores it before pasting. This ensures the text goes to the right place (using hyprctl for Hyprland).

What Changed

  • New files:

    • src-tauri/src/dbus.rs - D-Bus interface implementation
  • Modified files:

    • src-tauri/src/clipboard.rs - Added wtype support
    • src-tauri/src/overlay.rs - Added focus capture/restore
    • src-tauri/src/actions.rs - Calls focus restoration before pasting
    • src-tauri/src/shortcut.rs - Detects Wayland and disables shortcuts
    • src-tauri/src/lib.rs - Initializes D-Bus service
    • src-tauri/Cargo.toml - Added zbus dependencies

Automatic Behavior

The app automatically:

  • Detects Wayland sessions (via WAYLAND_DISPLAY env var)
  • Disables keyboard shortcuts on Wayland (they don't work anyway)
  • Shows helpful log messages about using D-Bus instead
  • Uses wtype when available and on Wayland

On X11, everything works exactly as before - no changes to the existing behavior.

Question for Maintainer

I'm disabling the old keybinding system on Wayland since I'm pretty sure they don't work for anyone on Wayland (that's the whole reason I needed D-Bus). But I'm not 100% certain - it could just be my setup. Let me know if you think this should be optional instead of automatic!

Testing

Tested on Arch Linux with Hyprland. Works consistently with:

  • VSCode ✅
  • Discord ✅
  • Chrome/Chromium ✅ (with wtype)

tbezman avatar Oct 30 '25 03:10 tbezman

Wow big thank you for this! I won't be able to test near-term, but I definitely will try and get a build kicked off sometime soon so others can test

I'm going to mention this in the discord so people can test there too

cjpais avatar Oct 30 '25 04:10 cjpais

@tbezman could you also take a look at #281

im curious if adding the Wayland flag to enigo will obviate the need for paste_via_wtype?

might slim down this change a bit

cjpais avatar Oct 31 '25 23:10 cjpais

@cjpais heads up my wife is in labor so i won't be carrying this one over the finish line anytime soon 😂

tbezman avatar Nov 01 '25 00:11 tbezman

@tbezman hahahha congratulations! hope it goes well!

cjpais avatar Nov 01 '25 00:11 cjpais

@tbezman could you also take a look at #281

im curious if adding the Wayland flag to enigo will obviate the need for paste_via_wtype?

might slim down this change a bit

FYI, enigo wayland feature is a deadend as discussed in https://github.com/cjpais/Handy/pull/320#issuecomment-3508924115.

lhotari avatar Nov 10 '25 08:11 lhotari