Skip to content

Conversation

@jackielii
Copy link
Owner

Summary

  • Fixes Cannot start, I keep getting Failed to copy CFString #19 - "Cannot start, I keep getting Failed to copy CFString"
  • Adds null check for CFStringCreateWithCharacters return value
  • Logs errors for keycodes that fail to convert
  • Allows skhd to continue initializing with remaining valid keycodes

Root Cause

When skhd initializes, it queries the macOS keyboard layout to build a mapping of keys to keycodes. On certain keyboard layouts, CFStringCreateWithCharacters can return NULL for some keycodes, but the code wasn't checking for this before attempting to copy the CFString. This caused a crash during initialization.

Changes

  • Added null check in src/Keycodes.zig:202-205
  • Log error message when CFString creation fails
  • Skip problematic keycodes and continue with initialization
  • Use unwrapped value key_cfstring.? when confirmed non-null

Test Plan

  • All existing tests pass (zig build test)
  • Release build compiles successfully (zig build -Doptimize=ReleaseFast)
  • User confirmation that skhd now starts on their system

Fixes #19

When skhd initializes, it queries the macOS keyboard layout to build
a mapping of keys to keycodes. On certain keyboard layouts,
CFStringCreateWithCharacters can return NULL for some keycodes, but
the code wasn't checking for this before attempting to copy the
CFString.

This commit adds a null check that:
- Detects when CFString creation fails
- Logs the failure as an error
- Skips the problematic keycode and continues initialization
- Uses the unwrapped value when confirmed non-null

This prevents the "Failed to copy CFString" error that was preventing
skhd from starting on some systems.
@jackielii jackielii merged commit a00ef42 into main Nov 18, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot start, I keep getting Failed to copy CFString

1 participant