Skip to content

Add macOS support with native Cocoa overlay window#23

Draft
m31-galaxy wants to merge 1 commit into
mainfrom
macos
Draft

Add macOS support with native Cocoa overlay window#23
m31-galaxy wants to merge 1 commit into
mainfrom
macos

Conversation

@m31-galaxy

Copy link
Copy Markdown
Owner

Summary

This PR adds full macOS support to Hexecute by implementing a native Cocoa backend alongside the existing Wayland/Linux implementation. The app now runs on both Linux and macOS with platform-specific windowing and input handling.

Key Changes

  • New Cocoa Backend (pkg/cocoa/): Implements a transparent, borderless fullscreen overlay window using native macOS APIs

    • cocoa.m: Core Cocoa implementation with OpenGL 4.1 context, event handling, and input management
    • cocoa.h: C header defining the public Cocoa API
    • cocoa.go: Go wrapper providing the platform-agnostic CocoaWindow type
  • Platform Abstraction Layer (internal/platform/): Introduces a Window interface to decouple platform-specific code from the rest of the application

    • window.go: Defines the common Window interface
    • window_linux.go: Linux implementation using Wayland backend
    • window_darwin.go: macOS implementation using Cocoa backend
  • Updated Core Modules: Refactored to use the platform-agnostic Window interface instead of directly depending on wayland.WaylandWindow

    • internal/draw/draw.go
    • internal/update/update.go
    • internal/execute/execute.go
    • cmd/hexecute/main.go
  • Build System Updates (flake.nix): Extended Nix flake to support multiple platforms

    • Added support for x86_64-linux, aarch64-linux, x86_64-darwin, and aarch64-darwin
    • Conditional dependencies: Wayland/X11 libs only on Linux; Cocoa/OpenGL frameworks provided by macOS stdenv
    • macOS-specific postInstall step to create a proper .app bundle with metadata
  • macOS App Bundle: Added proper application metadata and icon

    • macos/Info.plist: Bundle configuration (version, identifier, minimum OS, etc.)
    • macos/Hexecute.icon/: Icon asset definition and PNG source
  • CI/CD Updates (.github/workflows/build.yml): Extended to build on both Ubuntu and macOS

    • Separate artifact uploads for each platform
    • macOS builds produce a .tar.gz of the .app bundle (preserving executable bits)
  • Documentation Updates (README.md): Added macOS build and usage instructions

Implementation Details

  • Coordinate System Consistency: The Cocoa backend uses logical points (not backing pixels) to match the Wayland backend's coordinate space, ensuring gl_FragCoord, resolution uniforms, and cursor coordinates all align
  • Key Mapping: macOS virtual key codes are translated to XKB keysyms for cross-platform consistency
  • Input Handling: Supports mouse movement, button clicks, and keyboard input (currently Escape key) with an input disable mechanism for exit animations
  • Window Properties: Borderless, fullscreen, transparent overlay with status window level; hides system cursor while active
  • Build-Tagged Files: Platform-specific code is cleanly separated using Go build tags (//go:build darwin and //go:build linux)

https://claude.ai/code/session_01LjKPHZaHPxMhLXGe55hMeW

Introduce a platform-agnostic windowing/input/GL-surface interface so the
gesture engine no longer depends on the Wayland backend directly, and add
a macOS (Cocoa) implementation alongside it.

- internal/platform: Window interface with per-OS NewWindow (build-tagged
  window_linux.go / window_darwin.go); the Wayland backend is gated behind
  //go:build linux.
- pkg/cocoa: a transparent, borderless, fullscreen NSWindow overlay with an
  OpenGL 4.1 core context. Renders in logical points (not backing pixels) so
  gl_FragCoord, the resolution uniform, and cursor coordinates line up with
  the Wayland backend on Retina displays. Handles mouse move/drag/click and
  the Escape key, and hides the system cursor while active.
- Core modules (draw/execute/update/main) consume platform.Window instead of
  wayland.WaylandWindow. On macOS, launching draws a gesture once and exits,
  matching the Linux per-launch model.
- flake.nix builds on x86_64/aarch64 for both Linux and Darwin (Cocoa/OpenGL
  come from the macOS stdenv; Wayland/X11 deps are Linux-only); CI builds on
  Ubuntu and macOS.
- macos/ carries the app icon assets for future bundling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LjKPHZaHPxMhLXGe55hMeW
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.

2 participants