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

Add Display.top() + left(), useful for combining multi-monitor captures #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions src/common/dxgi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,20 @@ impl Display {
pub fn height(&self) -> usize {
self.0.height() as usize
}

pub fn top(&self) -> i32 {
self.0.top()
}

pub fn bottom(&self) -> i32 {
self.0.bottom()
}

pub fn left(&self) -> i32 {
self.0.left()
}

pub fn right(&self) -> i32 {
self.0.right()
}
}
16 changes: 16 additions & 0 deletions src/common/quartz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,20 @@ impl Display {
pub fn height(&self) -> usize {
self.0.height()
}

pub fn top(&self) -> i32 {
self.0.top() as i32
}

pub fn bottom(&self) -> i32 {
(self.0.top() as i32) + (self.0.height() as i32)
}

pub fn left(&self) -> i32 {
self.0.left() as i32
}

pub fn right(&self) -> i32 {
(self.0.left() as i32) + (self.0.width() as i32)
}
}
16 changes: 16 additions & 0 deletions src/common/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,20 @@ impl Display {
pub fn height(&self) -> usize {
self.0.rect().h as usize
}

pub fn top(&self) -> i32 {
self.0.rect().y as i32
}

pub fn bottom(&self) -> i32 {
(self.0.rect().y + self.0.rect().h as i16) as i32
}

pub fn left(&self) -> i32 {
self.0.rect().x as i32
}

pub fn right(&self) -> i32 {
(self.0.rect().x + self.0.rect().w as i16) as i32
}
}
16 changes: 16 additions & 0 deletions src/dxgi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,22 @@ impl Display {
self.desc.DesktopCoordinates.top
}

pub fn top(&self) -> LONG {
self.desc.DesktopCoordinates.top
}

pub fn bottom(&self) -> LONG {
self.desc.DesktopCoordinates.bottom
}

pub fn left(&self) -> LONG {
self.desc.DesktopCoordinates.left
}

pub fn right(&self) -> LONG {
self.desc.DesktopCoordinates.right
}

pub fn rotation(&self) -> DXGI_MODE_ROTATION {
self.desc.Rotation
}
Expand Down
8 changes: 8 additions & 0 deletions src/quartz/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ impl Display {
unsafe { CGDisplayPixelsHigh(self.0) }
}

pub fn top(self) -> f64 {
unsafe { CGDisplayBounds(self.0).origin.y }
}

pub fn left(self) -> f64 {
unsafe { CGDisplayBounds(self.0).origin.x }
}

pub fn is_builtin(self) -> bool {
unsafe { CGDisplayIsBuiltin(self.0) != 0 }
}
Expand Down
27 changes: 27 additions & 0 deletions src/quartz/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,32 @@ pub type FrameAvailableHandler = RcBlock<(
CGDisplayStreamUpdateRef // updateRef
), ()>;

#[cfg(target_pointer_width = "64")]
pub type CGFloat = libc::c_double;
#[cfg(not(target_pointer_width = "64"))]
pub type CGFloat = libc::c_float;

#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub struct CGPoint {
pub x: CGFloat,
pub y: CGFloat,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub struct CGSize {
pub width: CGFloat,
pub height: CGFloat,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Default)]
pub struct CGRect {
pub origin: CGPoint,
pub size: CGSize,
}

#[link(name="System", kind="dylib")]
#[link(name="CoreGraphics", kind="framework")]
#[link(name="CoreFoundation", kind="framework")]
Expand Down Expand Up @@ -159,6 +185,7 @@ extern {
pub fn CGMainDisplayID() -> u32;
pub fn CGDisplayPixelsWide(display: u32) -> usize;
pub fn CGDisplayPixelsHigh(display: u32) -> usize;
pub fn CGDisplayBounds(display: u32) -> CGRect;

pub fn CGGetOnlineDisplayList(
max_displays: u32,
Expand Down