Skip to content
Draft
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
14 changes: 13 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ license = "MIT"
keywords = ["display", "settings", "cli"]
categories = ["command-line-utilities", "config"]

[features]
default = []
unix-wayland = [ "wayland-client", "wayland-protocols-wlr", "wayland-protocols-plasma" ]
unix-x11 = []

[dependencies]
color-eyre = "0.6.3"
env_logger = "0.11.6"
log = "0.4.26"
structopt = "0.3.26"
thiserror = "2.0.12"
winsafe = { version = "0.0.10", features = ["user"] }

[target.'cfg(target_os = "windows")'.dependencies]
winsafe = { version = "0.0.16", features = ["user"] }

[target.'cfg(target_family = "unix")'.dependencies]
wayland-client = { version = "=0.30.0", features = ["log", "calloop"], optional = true }
wayland-protocols-wlr = { version = "=0.1.0", features = ["client"], optional = true }
wayland-protocols-plasma = { version = "=0.2.0", features = ["client"], optional = true }
5 changes: 5 additions & 0 deletions examples/find.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(windows)]
use displayz::query_displays;

/// Finds displays by name and index
#[cfg(windows)]
fn main() -> Result<(), Box<dyn std::error::Error>> {
let display_set = query_displays()?;
println!("Discovered displays:\n{}", display_set);
Expand Down Expand Up @@ -32,3 +34,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[cfg(not(windows))]
fn main() {}
5 changes: 5 additions & 0 deletions examples/primary.rs
Original file line number Diff line number Diff line change
@@ -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<dyn std::error::Error>> {
let display_set = query_displays()?;
println!("Discovered displays:\n{}", display_set);
Expand All @@ -22,3 +24,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[cfg(not(windows))]
fn main() {}
7 changes: 6 additions & 1 deletion examples/resolution.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use displayz::{Resolution, query_displays, refresh};
#[cfg(windows)]
use displayz::{query_displays, refresh, Resolution};

/// Prints and changes the current resolution of the primary display
#[cfg(windows)]
fn main() -> Result<(), Box<dyn std::error::Error>> {
let display_set = query_displays()?;
println!("Discovered displays:\n{}", display_set);
Expand All @@ -25,3 +27,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[cfg(not(windows))]
fn main() {}
9 changes: 7 additions & 2 deletions examples/upside-down.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use displayz::{Orientation, query_displays, refresh};
#[cfg(windows)]
use displayz::{query_displays, refresh, Orientation};

/// Turns the primary display upside-down
#[cfg(windows)]
fn main() -> Result<(), Box<dyn std::error::Error>> {
let display_set = query_displays()?;
println!("Discovered displays:\n{}", display_set);

if let Some(settings) = display_set.primary().settings() {
{
let settings = &mut *settings.borrow_mut();
let mut settings = &mut *settings.borrow_mut();
println!("Current orientation: {:?}", settings.orientation);

settings.orientation = match settings.orientation {
Expand All @@ -28,3 +30,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

Ok(())
}

#[cfg(not(windows))]
fn main() {}
76 changes: 76 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//! Common helpers for `displayz`

use std::fmt::{self, Debug, Display, Formatter};

/// Height and Width of a Display (`i32`)
#[derive(Default, Clone)]
pub struct Resolution(i32, i32);

/// X/Y positions of a display.
#[derive(Default, Clone)]
pub struct Position(i32, i32);

/// `Vec` type of the `Display` type, exposed on a platform-dependent basis.
pub type Displays = Vec<crate::Display>;

/// `Vec` type of the `Resolution` type, generally exposing a collection of available resolutions.
#[derive(Default, Clone)]
pub struct Resolutions(Vec<Resolution>);

impl Display for Resolution {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}x{}", self.0, self.1)
}
}

impl Debug for Resolution {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Resolution of Display is: {}x{}", self.0, self.1)
}
}

impl Debug for Resolutions {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_list()
.entries(self.0.iter())
.finish()
}
}

impl Display for Position {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{},{}", self.0, self.1)
}
}

impl Debug for Position {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Position of Display is: {},{}", self.0, self.1)
}
}

/// `DisplayOutput` defines the Trait specification of a platform's `Display`.
/// A `Display` may contain:
/// - An EDID.
/// - State, including if the `Display` is active, primary, or has a fault.
/// - Other helper methods, returning data stored in-memory state.
pub trait DisplayOutput {
/// Returns a boolean result, if the `Display` is the 'primary display' or not.
fn is_primary(&self) -> bool;
/// Returns a boolean result, if the `Display` is currently active or not.
fn is_active(&self) -> bool;
/// Returns the `Position` custom type of the `Display`.
fn get_position(&self) -> Position {
Position::default()
}
/// Returns the current `Resolution` of the `Display`.
fn get_resolution(&self) -> Resolution {
Resolution::default()
}
/// Returns the current supported `Resolutions` of the `Display`.
fn get_supported_resolutions(&self) -> Resolutions {
Resolutions::default()
}
/// Returns the EDID `&str` of the `Display.
fn get_edid(&self) -> Option<&str>;
}
21 changes: 17 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
//! 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.
#[cfg_attr(
any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
),
path = "platforms/unix/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::*;

mod display;
mod properties;
mod common;
pub use crate::common::*;

pub use display::*;
pub use properties::*;
pub type Display = Box<dyn DisplayOutput>;
1 change: 1 addition & 0 deletions src/platforms/macos/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

11 changes: 11 additions & 0 deletions src/platforms/unix/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[cfg(feature = "unix-x11")]
mod x11;

#[cfg(feature = "unix-x11")]
pub use x11::*;

#[cfg(feature = "unix-wayland")]
mod wayland;

#[cfg(feature = "unix-wayland")]
pub use wayland::*;
2 changes: 2 additions & 0 deletions src/platforms/unix/wayland/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(Debug)]
struct WaylandBackend;
1 change: 1 addition & 0 deletions src/platforms/unix/x11/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions src/platforms/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod display;
mod properties;

pub use crate::windows::*;
File renamed without changes.