This commit is contained in:
expectocode 2018-11-24 02:06:11 +00:00
commit caa4102856
4 changed files with 114 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

39
Cargo.lock generated Normal file
View File

@ -0,0 +1,39 @@
[[package]]
name = "cfg-if"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hacksaw"
version = "0.1.0"
dependencies = [
"xcb 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "xcb"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
"checksum libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)" = "10923947f84a519a45c8fefb7dd1b3e8c08747993381adee176d7a82b4195311"
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
"checksum xcb 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5e917a3f24142e9ff8be2414e36c649d47d6cc2ba81f16201cdef96e533e02de"

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "hacksaw"
version = "0.1.0"
authors = ["expectocode <expectocode@gmail.com>"]
[dependencies]
xcb = {version = "0.8.2", features = ["xkb"]}

66
src/main.rs Normal file
View File

@ -0,0 +1,66 @@
extern crate xcb;
fn main() {
let (conn, screen_num) = xcb::Connection::connect(None).unwrap();
let setup = conn.get_setup();
let screen = setup.roots().nth(screen_num as usize).unwrap();
let window = conn.generate_id();
let values = [
(xcb::CW_BACK_PIXEL, screen.white_pixel()),
(
xcb::CW_EVENT_MASK,
xcb::EVENT_MASK_EXPOSURE
| xcb::EVENT_MASK_KEY_PRESS // we'll need this later
| xcb::EVENT_MASK_BUTTON_PRESS
| xcb::EVENT_MASK_BUTTON_RELEASE,
),
];
xcb::create_window(
&conn,
xcb::COPY_FROM_PARENT as u8,
window,
screen.root(),
0,
0,
150,
150,
10,
xcb::WINDOW_CLASS_INPUT_OUTPUT as u16,
screen.root_visual(),
&values,
);
xcb::map_window(&conn, window);
conn.flush();
loop {
let ev = conn.wait_for_event();
match ev {
None => {
break;
}
Some(ev) => {
let r = ev.response_type();
if r == xcb::BUTTON_PRESS as u8 {
let button_press: &xcb::ButtonPressEvent = unsafe { xcb::cast_event(&ev) };
println!(
"Mouse press: x={}, y={}",
button_press.event_x(),
button_press.event_y()
);
} else if r == xcb::BUTTON_RELEASE as u8 {
let button_release: &xcb::ButtonReleaseEvent = unsafe { xcb::cast_event(&ev) };
println!(
"Mouse release: x={}, y={}",
button_release.event_x(),
button_release.event_y()
);
break; // Move on after mouse released
}
}
};
}
}