forked from michael/leanshot
i think i fixed it
This commit is contained in:
parent
568498c043
commit
96ad7bf6cf
3 changed files with 9 additions and 9 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -367,7 +367,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "leanshot"
|
name = "leanshot"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"gl 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"gl 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -12,7 +12,6 @@ pub fn capture(opt: &Options) -> Result<(), ScreenshotError> {
|
||||||
_ => gui.display.get_default_root_window()?,
|
_ => gui.display.get_default_root_window()?,
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{}", window_to_capture.as_raw());
|
|
||||||
let capture = gui.capture_window(&opt, window_to_capture)?;
|
let capture = gui.capture_window(&opt, window_to_capture)?;
|
||||||
capture.save_image(&opt.outfile)?;
|
capture.save_image(&opt.outfile)?;
|
||||||
|
|
||||||
|
|
15
src/gui.rs
15
src/gui.rs
|
@ -23,7 +23,6 @@ impl GUI {
|
||||||
let mut height = attr.get_height();
|
let mut height = attr.get_height();
|
||||||
let root = attr.get_root();
|
let root = attr.get_root();
|
||||||
let (mut x, mut y, _) = self.display.translate_coordinates(window, 0, 0, root)?;
|
let (mut x, mut y, _) = self.display.translate_coordinates(window, 0, 0, root)?;
|
||||||
println!("{} {}", window.as_raw(), root.as_raw());
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -89,7 +88,7 @@ impl GUI {
|
||||||
use gl;
|
use gl;
|
||||||
use glutin::{
|
use glutin::{
|
||||||
self,
|
self,
|
||||||
dpi::LogicalSize,
|
dpi::{PhysicalSize, PhysicalPosition},
|
||||||
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,
|
||||||
|
@ -112,8 +111,9 @@ impl GUI {
|
||||||
let wb = WindowBuilder::new()
|
let wb = WindowBuilder::new()
|
||||||
.with_x11_window_type(XWindowType::Splash)
|
.with_x11_window_type(XWindowType::Splash)
|
||||||
.with_decorations(false)
|
.with_decorations(false)
|
||||||
|
.with_visibility(false)
|
||||||
.with_always_on_top(true)
|
.with_always_on_top(true)
|
||||||
.with_dimensions(LogicalSize::new(width.into(), height.into()))
|
.with_dimensions(PhysicalSize::new(width.into(), height.into()).to_logical(mon.get_hidpi_factor()))
|
||||||
.with_fullscreen(Some(mon));
|
.with_fullscreen(Some(mon));
|
||||||
let ctx = glutin::ContextBuilder::new()
|
let ctx = glutin::ContextBuilder::new()
|
||||||
.with_vsync(false)
|
.with_vsync(false)
|
||||||
|
@ -135,20 +135,16 @@ impl GUI {
|
||||||
let raw_data;
|
let raw_data;
|
||||||
{
|
{
|
||||||
let _g = x.grab();
|
let _g = x.grab();
|
||||||
println!("grabbed");
|
|
||||||
// let img = Image2::create_from_drawable(window, 0, 0, 0, width as i32, height as i32, true)?;
|
// let img = Image2::create_from_drawable(window, 0, 0, 0, width as i32, height as i32, true)?;
|
||||||
imlib2::context_set_image(&capture);
|
imlib2::context_set_image(&capture);
|
||||||
println!("set contexted");
|
|
||||||
len = (width * height) as usize;
|
len = (width * height) as usize;
|
||||||
// println!("{}", window.as_raw());
|
// println!("{}", window.as_raw());
|
||||||
raw_data = unsafe { slice::from_raw_parts(imlib2::image_get_data(), len) };
|
raw_data = unsafe { slice::from_raw_parts(imlib2::image_get_data(), len) };
|
||||||
println!("captured");
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
win.make_current().expect("couldn't make window");
|
win.make_current().expect("couldn't make window");
|
||||||
gl::load_with(|sym| win.get_proc_address(sym) as *const _);
|
gl::load_with(|sym| win.get_proc_address(sym) as *const _);
|
||||||
}
|
}
|
||||||
println!("maked");
|
|
||||||
}
|
}
|
||||||
mem::forget(x);
|
mem::forget(x);
|
||||||
|
|
||||||
|
@ -193,6 +189,9 @@ impl GUI {
|
||||||
let mut recth = 0.0f64;
|
let mut recth = 0.0f64;
|
||||||
let mut delayed_down = false;
|
let mut delayed_down = false;
|
||||||
let mut redraw = true;
|
let mut redraw = true;
|
||||||
|
|
||||||
|
win.show();
|
||||||
|
win.set_position(PhysicalPosition::new(0.0, 0.0).to_logical(f));
|
||||||
while running {
|
while running {
|
||||||
if redraw {
|
if redraw {
|
||||||
// let size = win.get_inner_size().unwrap();
|
// let size = win.get_inner_size().unwrap();
|
||||||
|
@ -267,6 +266,8 @@ impl GUI {
|
||||||
(Some(VirtualKeyCode::Escape), ElementState::Released) => {
|
(Some(VirtualKeyCode::Escape), ElementState::Released) => {
|
||||||
if down {
|
if down {
|
||||||
down = false;
|
down = false;
|
||||||
|
rectw = 0.0;
|
||||||
|
recth = 0.0;
|
||||||
} else {
|
} else {
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue