feat: rewrite to use windows-rs instead of winsafe & add json feature#16
Merged
feat: rewrite to use windows-rs instead of winsafe & add json feature#16
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:GetDisplayConfigBufferSizesQueryDisplayConfigSetDisplayConfigImproved error handling
Enhanced error reporting with contextual, descriptive messages for easier debugging and diagnostics.
New Features
JSON output support
Added an optional
jsonfeature flag enabling JSON serialization of display information viaserde.Enhanced display metadata
Display information now includes:
Consolidated configuration application
Replaced per-display
apply()calls with a centralizedDisplaySet::apply()method to ensure consistent, atomic updates.Architecture Changes
Centralized type definitions
Introduced a new
types.rsmodule defining:Separated JSON serialization
Added a dedicated
json.rsmodule to clearly separate serialization concerns from core logic.Refactored DisplayProperties
Display properties are now derived directly from
DISPLAYCONFIG_PATH_INFOandDISPLAYCONFIG_MODE_INFOstructures.Updated examples
All examples have been revised to reflect the new API patterns and usage model.
Technical Details