diff --git a/Cargo.lock b/Cargo.lock index 8edf1bd..91a3132 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,7 +41,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -96,9 +96,9 @@ dependencies = [ [[package]] name = "color-eyre" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ebf286c900a6d5867aeff75cfee3192857bb7f24b547d4f0df2ed6baa812c90" +checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" dependencies = [ "backtrace", "color-spantrace", @@ -135,17 +135,38 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ - "atty", "humantime", + "is-terminal", "log", "regex", "termcolor", ] +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "eyre" version = "0.6.8" @@ -180,6 +201,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "humantime" version = "2.1.0" @@ -192,6 +219,29 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -200,18 +250,21 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.146" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" + +[[package]] +name = "linux-raw-sys" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "log" -version = "0.4.17" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" [[package]] name = "memchr" @@ -264,7 +317,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.96", "version_check", ] @@ -281,18 +334,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.18" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] @@ -320,6 +373,20 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +[[package]] +name = "rustix" +version = "0.37.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "sharded-slab" version = "0.1.4" @@ -356,7 +423,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.96", ] [[package]] @@ -370,6 +437,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "termcolor" version = "1.1.3" @@ -390,22 +468,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.18", ] [[package]] @@ -526,8 +604,74 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "winsafe" -version = "0.0.10" +version = "0.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac97bb0cb7c33e34890fbd50ca7aeac738530ba3ba967d456d075703d36007f1" +checksum = "5f7f49f787625d514b564aac6ba73648d4464347b4f38ed71ea15316c2228c12" diff --git a/Cargo.toml b/Cargo.toml index 00351e1..5ed9bde 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,11 @@ keywords = ["display", "settings", "cli"] categories = ["command-line-utilities", "config"] [dependencies] -color-eyre = "0.6.1" -env_logger = "0.9.0" -log = "0.4.17" +color-eyre = "0.6.2" +env_logger = "0.10.0" +log = "0.4.18" structopt = "0.3.26" -thiserror = "1.0.31" -winsafe = { version = "0.0.10", features = ["user"] } +thiserror = "1.0.40" + +[target.'cfg(target_os = "windows")'.dependencies] +winsafe = { version = "0.0.16", features = ["user"] } diff --git a/examples/find.rs b/examples/find.rs index ccbf399..d57bb74 100644 --- a/examples/find.rs +++ b/examples/find.rs @@ -1,6 +1,8 @@ +#[cfg(windows)] use displayz::query_displays; /// Finds displays by name and index +#[cfg(windows)] fn main() -> Result<(), Box> { let display_set = query_displays()?; println!("Discovered displays:\n{}", display_set); @@ -32,3 +34,6 @@ fn main() -> Result<(), Box> { Ok(()) } + +#[cfg(not(windows))] +fn main() {} diff --git a/examples/primary.rs b/examples/primary.rs index 7c76a72..c181ad4 100644 --- a/examples/primary.rs +++ b/examples/primary.rs @@ -1,6 +1,8 @@ +#[cfg(windows)] use displayz::{query_displays, refresh}; /// Sets a display to be the new primary display +#[cfg(windows)] fn main() -> Result<(), Box> { let display_set = query_displays()?; println!("Discovered displays:\n{}", display_set); @@ -22,3 +24,6 @@ fn main() -> Result<(), Box> { Ok(()) } + +#[cfg(not(windows))] +fn main() {} diff --git a/examples/resolution.rs b/examples/resolution.rs index 103d857..c53b964 100644 --- a/examples/resolution.rs +++ b/examples/resolution.rs @@ -1,6 +1,8 @@ +#[cfg(windows)] use displayz::{query_displays, refresh, Resolution}; /// Prints and changes the current resolution of the primary display +#[cfg(windows)] fn main() -> Result<(), Box> { let display_set = query_displays()?; println!("Discovered displays:\n{}", display_set); @@ -25,3 +27,6 @@ fn main() -> Result<(), Box> { Ok(()) } + +#[cfg(not(windows))] +fn main() {} diff --git a/examples/upside-down.rs b/examples/upside-down.rs index e99f32f..51a88c7 100644 --- a/examples/upside-down.rs +++ b/examples/upside-down.rs @@ -1,6 +1,8 @@ +#[cfg(windows)] use displayz::{query_displays, refresh, Orientation}; /// Turns the primary display upside-down +#[cfg(windows)] fn main() -> Result<(), Box> { let display_set = query_displays()?; println!("Discovered displays:\n{}", display_set); @@ -28,3 +30,6 @@ fn main() -> Result<(), Box> { Ok(()) } + +#[cfg(not(windows))] +fn main() {} diff --git a/src/common/mod.rs b/src/common/mod.rs new file mode 100644 index 0000000..48eb6a9 --- /dev/null +++ b/src/common/mod.rs @@ -0,0 +1,13 @@ +//! Common helpers for `displayz` + +pub type Resolution = (usize, usize); +pub type Position = (usize, usize); + +pub type Displays = Vec; + +pub trait DisplayOutput { + fn is_primary(&self) -> bool; + fn is_active(&self) -> bool; + fn get_position(&self) -> Position; + fn get_resolution(&self) -> Resolution; +} diff --git a/src/lib.rs b/src/lib.rs index 357f510..a1b7c6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,36 @@ //! A library to interact with the Windows API for display settings. //! //! This library provides an abstraction around some `winuser.h` calls relevant for modifying display settings. +#![deny( + warnings, + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + clippy::all, + clippy::cargo, + clippy::pedantic, + trivial_casts, + trivial_numeric_casts, + unused_import_braces, + unused_qualifications, + unused_extern_crates, + variant_size_differences +)] -mod display; -mod properties; +#[cfg_attr( + any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ), + path = "platforms/linux/mod.rs" +)] +#[cfg_attr(target_os = "windows", path = "platforms/windows/mod.rs")] +#[cfg_attr(target_os = "macos", path = "platforms/macos/mod.rs")] +mod platform; +pub use crate::platform::*; -pub use display::*; -pub use properties::*; +mod common; +pub use crate::common::*; diff --git a/src/platforms/linux/mod.rs b/src/platforms/linux/mod.rs new file mode 100644 index 0000000..08faf49 --- /dev/null +++ b/src/platforms/linux/mod.rs @@ -0,0 +1,12 @@ +#[cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd"))] +mod x11; +pub use x11::*; + +#[cfg(target_os = "linux")] +mod wayland; +pub use wayland::*; diff --git a/src/platforms/linux/wayland/mod.rs b/src/platforms/linux/wayland/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/platforms/linux/x11/mod.rs b/src/platforms/linux/x11/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/platforms/macos/mod.rs b/src/platforms/macos/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/display.rs b/src/platforms/windows/display.rs similarity index 100% rename from src/display.rs rename to src/platforms/windows/display.rs diff --git a/src/main.rs b/src/platforms/windows/misc.rs similarity index 100% rename from src/main.rs rename to src/platforms/windows/misc.rs diff --git a/src/platforms/windows/mod.rs b/src/platforms/windows/mod.rs new file mode 100644 index 0000000..b93bdeb --- /dev/null +++ b/src/platforms/windows/mod.rs @@ -0,0 +1,4 @@ +mod display; +mod properties; + +pub use self::*::*; diff --git a/src/properties.rs b/src/platforms/windows/properties.rs similarity index 100% rename from src/properties.rs rename to src/platforms/windows/properties.rs