cargo clippy + cargo fmt

This commit is contained in:
Michael Zhang 2020-06-15 21:25:28 -05:00
parent f6a1d572f5
commit 15220bed4b
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
8 changed files with 601 additions and 558 deletions

996
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
[package] [package]
name = "leanshot" name = "leanshot"
description = "Screenshot capture for Linux." description = "Screenshot capture for Linux."
version = "0.3.3" version = "0.4.0"
repository = "https://github.com/iptq/leanshot" repository = "https://github.com/iptq/leanshot"
license-file = "LICENSE" license-file = "LICENSE"
authors = ["Michael Zhang <failed.down@gmail.com>"] authors = ["Michael Zhang <failed.down@gmail.com>"]
@ -14,7 +14,7 @@ failure = "0.1"
gl = "0.11" gl = "0.11"
glutin = "0.19" glutin = "0.19"
imlib2 = { version = "0.1", path = "./imlib2" } imlib2 = { version = "0.1", path = "./imlib2" }
leanshot_xlib = { version = "0.1", path = "./xlib" } leanshot_xlib = { version = "0.2", path = "./xlib" }
nanovg = { version = "1.0.2", features = ["gl3"] } nanovg = { version = "1.0.2", features = ["gl3"] }
png = "0.14" png = "0.14"
structopt = "0.2" structopt = "0.2"

View file

@ -8,4 +8,4 @@ authors = ["Michael Zhang <failed.down@gmail.com>"]
[dependencies] [dependencies]
failure = "0.1" failure = "0.1"
imlib2-sys = { version = "0.1", path = "imlib2-sys" } imlib2-sys = { version = "0.1", path = "imlib2-sys" }
leanshot_xlib = { version = "0.1", path = "../xlib" } leanshot_xlib = { version = "0.2", path = "../xlib" }

View file

@ -1,8 +1,8 @@
use crate::errors::ScreenshotError; use crate::errors::ScreenshotError;
use crate::gui::GUI; use crate::gui::GUI;
use imlib2;
use crate::options::{Options, Region}; use crate::options::{Options, Region};
use imlib2;
/// The main capture routine. /// The main capture routine.
pub fn capture(opt: &Options) -> Result<(), ScreenshotError> { pub fn capture(opt: &Options) -> Result<(), ScreenshotError> {

View file

@ -1,5 +1,5 @@
use imlib2::{self, Image as Image2};
use crate::xlib::{Display, Visual, Window}; use crate::xlib::{Display, Visual, Window};
use imlib2::{self, Image as Image2};
use crate::errors::ScreenshotError; use crate::errors::ScreenshotError;
use crate::Options; use crate::Options;
@ -24,7 +24,6 @@ impl GUI {
let root = attr.get_root(); let root = attr.get_root();
let (x, y, _) = self.display.translate_coordinates(window, 0, 0, root)?; let (x, y, _) = self.display.translate_coordinates(window, 0, 0, root)?;
imlib2::context_set_display(&self.display); imlib2::context_set_display(&self.display);
let visual = Visual::default(&self.display, 0); let visual = Visual::default(&self.display, 0);
imlib2::context_set_visual(&visual); imlib2::context_set_visual(&visual);
@ -80,17 +79,14 @@ impl GUI {
// } // }
// } // }
use gl;
use glutin::{ use glutin::{
self,
dpi::{PhysicalPosition, PhysicalSize}, dpi::{PhysicalPosition, PhysicalSize},
os::unix::{WindowBuilderExt, WindowExt, XWindowType}, os::unix::{WindowBuilderExt, WindowExt, XWindowType},
ElementState, Event, EventsLoop, GlContext, GlWindow, KeyboardInput, MouseButton, ElementState, Event, EventsLoop, GlContext, GlWindow, KeyboardInput, MouseButton,
MouseCursor, VirtualKeyCode, WindowBuilder, WindowEvent, MouseCursor, VirtualKeyCode, WindowBuilder, WindowEvent,
}; };
use nanovg::{self, Image, ImagePattern, PathOptions, StrokeOptions}; use nanovg::{Image, ImagePattern, PathOptions, StrokeOptions};
use std::{f32::consts, mem, slice}; use std::{f32::consts, mem, slice};
use x11;
// let attr = window.get_attributes()?; // let attr = window.get_attributes()?;
// let width = attr.get_width(); // let width = attr.get_width();
@ -249,81 +245,82 @@ impl GUI {
}); });
} }
evl.poll_events(|event| match event { evl.poll_events(|event| {
Event::WindowEvent { event, .. } => match event { if let Event::WindowEvent { event, .. } = event {
WindowEvent::Destroyed => running = false, match event {
WindowEvent::KeyboardInput { WindowEvent::Destroyed => running = false,
input: WindowEvent::KeyboardInput {
KeyboardInput { input:
virtual_keycode, KeyboardInput {
state, virtual_keycode,
.. state,
}, ..
.. },
} => match (virtual_keycode, state) { ..
(Some(VirtualKeyCode::Escape), ElementState::Released) => { } => {
if let (Some(VirtualKeyCode::Escape), ElementState::Released) =
(virtual_keycode, state)
{
if down {
down = false;
rectw = 0.0;
recth = 0.0;
} else {
unsafe {
x11::xlib::XDestroyWindow(
self.display.as_raw(),
win.get_xlib_window().unwrap(),
)
};
running = false;
}
}
}
WindowEvent::CursorMoved { position, .. } => {
mx = position.x;
my = position.y;
if down { if down {
down = false; if delayed_down {
rectw = 0.0; dx = mx;
recth = 0.0; dy = my;
} else { delayed_down = false;
unsafe { } else {
x11::xlib::XDestroyWindow( redraw = true;
self.display.as_raw(), }
win.get_xlib_window().unwrap(), rectw = mx - dx;
) recth = my - dy;
}; }
running = false; }
WindowEvent::MouseInput { button, state, .. } => {
if let MouseButton::Left = button {
down = match state {
ElementState::Pressed => {
delayed_down = true;
if mx < 0.0 || my < 0.0 {
} else {
dx = mx;
dy = my;
}
true
}
ElementState::Released => {
if down && rectw.abs() > 0.0 && recth.abs() > 0.0 {
unsafe {
x11::xlib::XDestroyWindow(
self.display.as_raw(),
win.get_xlib_window().unwrap(),
)
};
running = false;
}
false
}
}
} }
} }
_ => (), _ => (),
},
WindowEvent::CursorMoved { position, .. } => {
mx = position.x;
my = position.y;
if down {
if delayed_down {
dx = mx;
dy = my;
delayed_down = false;
} else {
redraw = true;
}
rectw = mx - dx;
recth = my - dy;
}
} }
WindowEvent::MouseInput { button, state, .. } => match button { }
MouseButton::Left => {
down = match state {
ElementState::Pressed => {
delayed_down = true;
if mx < 0.0 || my < 0.0 {
} else {
dx = mx;
dy = my;
}
true
}
ElementState::Released => {
if down && rectw.abs() > 0.0 && recth.abs() > 0.0 {
unsafe {
x11::xlib::XDestroyWindow(
self.display.as_raw(),
win.get_xlib_window().unwrap(),
)
};
running = false;
}
false
}
};
}
_ => (),
},
_ => (),
},
_ => (),
}); });
win.swap_buffers().expect("couldn't swap buffers"); win.swap_buffers().expect("couldn't swap buffers");
} }

View file

@ -21,8 +21,8 @@ mod gui;
mod options; mod options;
use crate::errors::ScreenshotError; use crate::errors::ScreenshotError;
use structopt::StructOpt;
use crate::xlib::Rectangle; use crate::xlib::Rectangle;
use structopt::StructOpt;
pub use crate::capture::capture; pub use crate::capture::capture;
pub use crate::options::{Options, Region}; pub use crate::options::{Options, Region};

View file

@ -10,7 +10,7 @@ pub enum Region {
Selection, Selection,
} }
/// Optiosn for screenshot /// Options for screenshot
#[derive(StructOpt)] #[derive(StructOpt)]
pub struct Options { pub struct Options {
/// The region to select (fullscreen | window | select) /// The region to select (fullscreen | window | select)

View file

@ -1,6 +1,6 @@
[package] [package]
name = "leanshot_xlib" name = "leanshot_xlib"
version = "0.1.1" version = "0.2.0"
description = "xlib bindings" description = "xlib bindings"
license-file = "../LICENSE" license-file = "../LICENSE"
authors = ["Michael Zhang <failed.down@gmail.com>"] authors = ["Michael Zhang <failed.down@gmail.com>"]