sigh
This commit is contained in:
parent
b8a5fb9aeb
commit
c7fc13ed64
8 changed files with 64 additions and 7 deletions
17
src/gui.rs
17
src/gui.rs
|
@ -4,8 +4,8 @@ use xlib::{Display, EventKind, Visual, Window};
|
|||
use errors::ScreenshotError;
|
||||
use Options;
|
||||
use Rectangle;
|
||||
use SelectWindow;
|
||||
use Region;
|
||||
use SelectWindow;
|
||||
|
||||
pub struct GUI {
|
||||
pub(crate) display: Display,
|
||||
|
@ -36,8 +36,8 @@ impl GUI {
|
|||
y = region.y;
|
||||
width = region.width;
|
||||
height = region.height;
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
Image2::create_from_drawable(window, 0, x, y, width as i32, height as i32, true)
|
||||
|
@ -60,10 +60,19 @@ impl GUI {
|
|||
let root_im = root.get_image();
|
||||
|
||||
let mut done = 0;
|
||||
let mut button_press = false;
|
||||
while done == 0 && self.display.pending()? > 0 {
|
||||
let ev = self.display.next_event()?;
|
||||
match ev.kind() {
|
||||
EventKind::ButtonPress => (),
|
||||
EventKind::ButtonPress => {
|
||||
button_press = true;
|
||||
}
|
||||
EventKind::ButtonRelease => {
|
||||
if button_press {
|
||||
done = 1;
|
||||
}
|
||||
button_press = false;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@ mod window;
|
|||
pub mod imlib2;
|
||||
pub mod xlib;
|
||||
|
||||
use errors::ScreenshotError;
|
||||
use structopt::StructOpt;
|
||||
use xlib::Rectangle;
|
||||
use errors::ScreenshotError;
|
||||
|
||||
pub use capture::capture;
|
||||
pub use options::{Options, Region};
|
||||
|
|
13
src/xlib/cursor.rs
Normal file
13
src/xlib/cursor.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use x11::xlib as x;
|
||||
|
||||
/// Mouse pointer
|
||||
pub struct Cursor {
|
||||
pub(crate) display: *mut x::Display,
|
||||
pub(crate) inner: x::Cursor,
|
||||
}
|
||||
|
||||
impl Drop for Cursor {
|
||||
fn drop(&mut self) {
|
||||
unsafe { x::XFreeCursor(self.display, self.inner) };
|
||||
}
|
||||
}
|
5
src/xlib/cursorfont.rs
Normal file
5
src/xlib/cursorfont.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
pub const XC_crosshair: u32 = 34;
|
||||
pub const XC_ll_angle: u32 = 76;
|
||||
pub const XC_lr_angle: u32 = 78;
|
||||
pub const XC_ul_angle: u32 = 144;
|
||||
pub const XC_ur_angle: u32 = 148;
|
|
@ -3,7 +3,7 @@ use std::ffi::CString;
|
|||
use libc;
|
||||
use x11::xlib as x;
|
||||
|
||||
use xlib::{Event, Visual, Window, X11Error};
|
||||
use xlib::{Cursor, Event, Visual, Window, X11Error};
|
||||
|
||||
/// A connection to an X server.
|
||||
pub struct Display {
|
||||
|
@ -30,6 +30,18 @@ impl Display {
|
|||
Ok(Display { inner })
|
||||
}
|
||||
|
||||
/// Wrapper around XCreateFontCursor
|
||||
pub fn create_font_cursor(&self, shape: u32) -> Result<Cursor, X11Error> {
|
||||
let cursor = unsafe { x::XCreateFontCursor(self.inner, shape) as x::Cursor };
|
||||
if cursor == 0 {
|
||||
return Err(X11Error::CreateCursorError);
|
||||
}
|
||||
Ok(Cursor {
|
||||
display: self.inner,
|
||||
inner: cursor,
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the next event, blocks until an event is reached.
|
||||
pub fn next_event(&self) -> Result<Event, X11Error> {
|
||||
let event =
|
||||
|
@ -117,6 +129,11 @@ impl Display {
|
|||
Ok((rx, ry, child))
|
||||
}
|
||||
|
||||
/// Sync
|
||||
pub fn sync(&self, discard: bool) {
|
||||
unsafe { x::XSync(self.inner, if discard { 1 } else { 0 }) };
|
||||
}
|
||||
|
||||
/// eturns the focus window and the current focus state.
|
||||
pub fn get_input_focus(&self) -> Result<(Window, i32), X11Error> {
|
||||
let mut focus_return: x::Window = 0;
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum X11Error {
|
||||
#[fail(display = "failed to create cursor")]
|
||||
CreateCursorError,
|
||||
|
||||
#[fail(display = "failed to open display")]
|
||||
DisplayOpenError,
|
||||
|
||||
|
|
|
@ -11,9 +11,12 @@ pub struct Event {
|
|||
|
||||
/// Type of event
|
||||
pub enum EventKind {
|
||||
/// Was a button pressed
|
||||
/// A mouse button was pressed
|
||||
ButtonPress,
|
||||
|
||||
/// A mouse button was released
|
||||
ButtonRelease,
|
||||
|
||||
/// None event
|
||||
None,
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
//!
|
||||
//! I need this for my project.
|
||||
|
||||
mod cursor;
|
||||
mod display;
|
||||
mod drawable;
|
||||
mod errors;
|
||||
|
@ -12,6 +13,12 @@ mod rect;
|
|||
mod visual;
|
||||
mod window;
|
||||
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[allow(missing_docs)]
|
||||
mod cursorfont;
|
||||
|
||||
pub use self::cursor::Cursor;
|
||||
pub use self::cursorfont::*;
|
||||
pub use self::display::{Display, GetDisplay};
|
||||
pub use self::drawable::Drawable;
|
||||
pub use self::errors::X11Error;
|
||||
|
|
Loading…
Reference in a new issue