Skip to content

Commit 989adeb

Browse files
committed
chore(lint): make clippy happy
1 parent a5a4764 commit 989adeb

File tree

4 files changed

+72
-41
lines changed

4 files changed

+72
-41
lines changed

src/common/mod.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,3 @@ pub trait PlatformApi: Send {
99
fn capture_window_screenshot(&self, window_id: WindowId) -> Result<ImageOnHeap>;
1010
fn get_active_window(&self) -> Result<WindowId>;
1111
}
12-
13-
#[derive(Debug)]
14-
pub struct Margin {
15-
pub top: u16,
16-
pub right: u16,
17-
pub bottom: u16,
18-
pub left: u16,
19-
}
20-
21-
impl Margin {
22-
pub fn new(top: u16, right: u16, bottom: u16, left: u16) -> Self {
23-
Self {
24-
top,
25-
right,
26-
bottom,
27-
left,
28-
}
29-
}
30-
31-
pub fn new_equal(margin: u16) -> Self {
32-
Self::new(margin, margin, margin, margin)
33-
}
34-
35-
pub fn zero() -> Self {
36-
Self::new_equal(0)
37-
}
38-
39-
pub fn is_zero(&self) -> bool {
40-
self.top == 0
41-
&& self.right == self.left
42-
&& self.left == self.bottom
43-
&& self.bottom == self.top
44-
}
45-
}

src/linux/mod.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,70 @@ use x11_api::X11Api;
66
pub fn setup() -> Result<Box<dyn PlatformApi>> {
77
Ok(Box::new(X11Api::new()?))
88
}
9+
10+
#[derive(Debug)]
11+
pub struct Margin {
12+
pub top: u16,
13+
pub right: u16,
14+
pub bottom: u16,
15+
pub left: u16,
16+
}
17+
18+
impl Margin {
19+
pub fn new(top: u16, right: u16, bottom: u16, left: u16) -> Self {
20+
Self {
21+
top,
22+
right,
23+
bottom,
24+
left,
25+
}
26+
}
27+
28+
pub fn new_equal(margin: u16) -> Self {
29+
Self::new(margin, margin, margin, margin)
30+
}
31+
32+
pub fn zero() -> Self {
33+
Self::new_equal(0)
34+
}
35+
36+
pub fn is_zero(&self) -> bool {
37+
self.top == 0
38+
&& self.right == self.left
39+
&& self.left == self.bottom
40+
&& self.bottom == self.top
41+
}
42+
}
43+
44+
#[cfg(test)]
45+
mod test {
46+
use super::*;
47+
48+
#[test]
49+
fn margin_new() {
50+
let m = Margin::new(1, 2, 3, 4);
51+
assert_eq!(m.top, 1);
52+
assert_eq!(m.right, 2);
53+
assert_eq!(m.bottom, 3);
54+
assert_eq!(m.left, 4);
55+
}
56+
57+
#[test]
58+
fn margin_new_equal() {
59+
let m = Margin::new_equal(1);
60+
assert_eq!(m.top, 1);
61+
assert_eq!(m.right, 1);
62+
assert_eq!(m.bottom, 1);
63+
assert_eq!(m.left, 1);
64+
}
65+
66+
#[test]
67+
fn margin_zero() {
68+
let m = Margin::zero();
69+
assert_eq!(m.top, 0);
70+
assert_eq!(m.right, 0);
71+
assert_eq!(m.bottom, 0);
72+
assert_eq!(m.left, 0);
73+
assert!(m.is_zero());
74+
}
75+
}

src/linux/x11_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::common::Margin;
1+
use crate::linux::Margin;
22
use crate::{ImageOnHeap, PlatformApi, Result, WindowId, WindowList};
33
use anyhow::Context;
44
use image::flat::{SampleLayout, View};

src/macos/window_id.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ pub fn window_list() -> Result<WindowList> {
5656
}
5757
let window_owner = get_from_dict(dic_ref, "kCGWindowOwnerName");
5858
let window_id = get_from_dict(dic_ref, "kCGWindowNumber");
59-
// let is_onscreen = get_from_dict(dic_ref, "kCGWindowIsOnscreen");
60-
match (window_owner, window_id) {
61-
(DictEntryValue::_String(name), DictEntryValue::_Number(win_id)) => {
62-
win_list.push((Some(name), win_id as u64));
63-
}
64-
_ => {}
59+
if let (DictEntryValue::_String(name), DictEntryValue::_Number(win_id)) =
60+
(window_owner, window_id)
61+
{
62+
win_list.push((Some(name), win_id as u64));
6563
}
6664
}
6765

0 commit comments

Comments
 (0)