forked from michael/leanshot
cargo clippy + cargo fmt
This commit is contained in:
parent
f6a1d572f5
commit
15220bed4b
8 changed files with 601 additions and 558 deletions
996
Cargo.lock
generated
996
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -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"
|
||||||
|
|
|
@ -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" }
|
||||||
|
|
|
@ -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> {
|
||||||
|
|
35
src/gui.rs
35
src/gui.rs
|
@ -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,8 +245,9 @@ impl GUI {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
evl.poll_events(|event| match event {
|
evl.poll_events(|event| {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
if let Event::WindowEvent { event, .. } = event {
|
||||||
|
match event {
|
||||||
WindowEvent::Destroyed => running = false,
|
WindowEvent::Destroyed => running = false,
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
input:
|
||||||
|
@ -260,8 +257,10 @@ impl GUI {
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
} => match (virtual_keycode, state) {
|
} => {
|
||||||
(Some(VirtualKeyCode::Escape), ElementState::Released) => {
|
if let (Some(VirtualKeyCode::Escape), ElementState::Released) =
|
||||||
|
(virtual_keycode, state)
|
||||||
|
{
|
||||||
if down {
|
if down {
|
||||||
down = false;
|
down = false;
|
||||||
rectw = 0.0;
|
rectw = 0.0;
|
||||||
|
@ -276,8 +275,7 @@ impl GUI {
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
}
|
||||||
},
|
|
||||||
WindowEvent::CursorMoved { position, .. } => {
|
WindowEvent::CursorMoved { position, .. } => {
|
||||||
mx = position.x;
|
mx = position.x;
|
||||||
my = position.y;
|
my = position.y;
|
||||||
|
@ -293,8 +291,8 @@ impl GUI {
|
||||||
recth = my - dy;
|
recth = my - dy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::MouseInput { button, state, .. } => match button {
|
WindowEvent::MouseInput { button, state, .. } => {
|
||||||
MouseButton::Left => {
|
if let MouseButton::Left = button {
|
||||||
down = match state {
|
down = match state {
|
||||||
ElementState::Pressed => {
|
ElementState::Pressed => {
|
||||||
delayed_down = true;
|
delayed_down = true;
|
||||||
|
@ -317,13 +315,12 @@ impl GUI {
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
}
|
||||||
_ => (),
|
}
|
||||||
},
|
|
||||||
_ => (),
|
|
||||||
});
|
});
|
||||||
win.swap_buffers().expect("couldn't swap buffers");
|
win.swap_buffers().expect("couldn't swap buffers");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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};
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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>"]
|
||||||
|
|
Loading…
Reference in a new issue