Skip to content

feat: rewrite to use windows-rs instead of winsafe & add json feature#16

Merged
michidk merged 4 commits intomainfrom
claude/switch-to-windows-rs-9GS07
Dec 29, 2025
Merged

feat: rewrite to use windows-rs instead of winsafe & add json feature#16
michidk merged 4 commits intomainfrom
claude/switch-to-windows-rs-9GS07

Conversation

@michidk
Copy link
Copy Markdown
Owner

@michidk michidk commented Dec 29, 2025

Summary

This change delivers a full modernization of the Windows API integration by migrating from the legacy winsafe crate to windows-rs, introducing newer display configuration APIs, improving reliability, and adding structured JSON output. The update preserves core functionality while significantly improving maintainability, extensibility, and diagnostics.

Closing #1

Core API Migration

  • Replaced winsafe with windows-rs
    Adopted the modern, actively maintained Windows API bindings provided by windows-rs.

  • Adopted DisplayConfig API
    Migrated from legacy EnumDisplayDevices–based logic to the modern DisplayConfig APIs:

    • GetDisplayConfigBufferSizes
    • QueryDisplayConfig
    • SetDisplayConfig
  • Improved error handling
    Enhanced error reporting with contextual, descriptive messages for easier debugging and diagnostics.

New Features

  • JSON output support
    Added an optional json feature flag enabling JSON serialization of display information via serde.

  • Enhanced display metadata
    Display information now includes:

    • Connector type (e.g., HDMI, DisplayPort)
    • Target availability and status
  • Consolidated configuration application
    Replaced per-display apply() calls with a centralized DisplaySet::apply() method to ensure consistent, atomic updates.

Architecture Changes

  • Centralized type definitions
    Introduced a new types.rs module defining:

    • Position
    • Resolution
    • Frequency
    • Orientation
    • Scaling
    • BitDepth
    • ScanlineOrdering
    • ConnectorType
  • Separated JSON serialization
    Added a dedicated json.rs module to clearly separate serialization concerns from core logic.

  • Refactored DisplayProperties
    Display properties are now derived directly from DISPLAYCONFIG_PATH_INFO and DISPLAYCONFIG_MODE_INFO structures.

  • Updated examples
    All examples have been revised to reflect the new API patterns and usage model.

Technical Details

  • Display configuration now relies on modern DisplayConfig path and mode structures.
  • Configuration updates are applied atomically across all displays.
  • Improved compatibility with Windows 11 24H2 behavior.
  • Enhanced logging across all display operations.

claude and others added 2 commits December 29, 2025 13:28
Replace winsafe dependency with windows-rs (v0.57) to enable use of
the newer DisplayConfig API as requested in issue #1.

Major changes:
- Updated Cargo.toml to use windows-rs v0.57 with required features
- Migrated all Windows API calls from winsafe to windows-rs equivalents
- Updated type usage to match windows-rs patterns (wrapper types, unions)
- Changed POINT to POINTL for display position coordinates
- Updated error handling to work with windows-rs types

All display functionality remains the same, but now uses the
official Microsoft windows-rs bindings which provide better support
for modern Windows APIs including DisplayConfig.

Resolves #1
@michidk michidk changed the title Replace winsafe with windows-rs library feat: rewrite to use windows-rs instead of winsafe Dec 29, 2025
@michidk michidk marked this pull request as ready for review December 29, 2025 15:39
@michidk michidk changed the title feat: rewrite to use windows-rs instead of winsafe feat: rewrite to use windows-rs instead of winsafe & add json feature Dec 29, 2025
@michidk michidk merged commit d388584 into main Dec 29, 2025
4 checks passed
@michidk michidk deleted the claude/switch-to-windows-rs-9GS07 branch December 29, 2025 16:02
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