Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 优化代码 #28

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "display-info"
version = "0.4.5"
version = "0.4.6"
edition = "2021"
description = "Cross-platform get display info"
license-file = "LICENSE"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn main() {
## DisplayInfo struct

- `id` u32 - Unique identifier associated with the display.
- `raw_handle` CGDisplay/HMONITOR/Output - Native display raw handle
- `x` i32 - The display x coordinate.
- `y` i32 - The display y coordinate.
- `width` u32 - The display pixel width.
Expand Down
34 changes: 11 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,27 @@
//! }
//! ```

use anyhow::Result;
#[cfg(target_os = "linux")]
#[path = "linux.rs"]
mod platform;

#[cfg(target_os = "macos")]
mod darwin;
#[cfg(target_os = "macos")]
use core_graphics::display::CGDisplay;
#[cfg(target_os = "macos")]
use darwin::*;
#[path = "macos.rs"]
mod platform;

#[cfg(target_os = "windows")]
mod win32;
#[cfg(target_os = "windows")]
use win32::*;
#[cfg(target_os = "windows")]
use windows::Win32::Graphics::Gdi::HMONITOR;
#[path = "windows.rs"]
mod platform;

#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
use linux::*;
#[cfg(target_os = "linux")]
use xcb::randr::Output;
use anyhow::Result;
use platform::{get_all, get_from_point, ScreenRawHandle};

#[derive(Debug, Clone, Copy)]
pub struct DisplayInfo {
/// Unique identifier associated with the display.
pub id: u32,
#[cfg(target_os = "macos")]
pub raw_handle: CGDisplay,
#[cfg(target_os = "windows")]
pub raw_handle: HMONITOR,
#[cfg(target_os = "linux")]
pub raw_handle: Output,
/// Native screen raw handle
pub raw_handle: ScreenRawHandle,
/// The display x coordinate.
pub x: i32,
/// The display x coordinate.
Expand Down
2 changes: 2 additions & 0 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use xcb::{
Connection, Xid,
};

pub type ScreenRawHandle = Output;

impl DisplayInfo {
fn new(
monitor_info: &MonitorInfo,
Expand Down
2 changes: 2 additions & 0 deletions src/darwin.rs → src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::DisplayInfo;
use anyhow::{anyhow, Result};
use core_graphics::display::{CGDirectDisplayID, CGDisplay, CGError, CGPoint, CGRect};

pub type ScreenRawHandle = CGDisplay;

impl DisplayInfo {
fn new(id: CGDirectDisplayID) -> Self {
let cg_display = CGDisplay::new(id);
Expand Down
2 changes: 2 additions & 0 deletions src/win32.rs → src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ macro_rules! drop_box {
}};
}

pub type ScreenRawHandle = HMONITOR;

impl DisplayInfo {
fn new(h_monitor: HMONITOR, monitor_info_exw: &MONITORINFOEXW) -> Self {
let sz_device = monitor_info_exw.szDevice.as_ptr();
Expand Down