Compare commits
No commits in common. "a1350283c5d5ac53601759b0a594f2b479bb074c" and "179c8ac9eeb478f76fae8775e230d19fb113ff18" have entirely different histories.
a1350283c5
...
179c8ac9ee
78
src/main.rs
78
src/main.rs
|
@ -7,12 +7,20 @@ fn main() {
|
||||||
|
|
||||||
let window = conn.generate_id();
|
let window = conn.generate_id();
|
||||||
|
|
||||||
|
let width = screen.width_in_pixels();
|
||||||
|
let height = screen.height_in_pixels();
|
||||||
|
|
||||||
|
println!("width {} height {}", width, height);
|
||||||
|
|
||||||
let values = [
|
let values = [
|
||||||
// ?RGB. First 4 bytes appear to do nothing
|
// ?RGB. First 4 bytes appear to do nothing
|
||||||
(xcb::CW_BACK_PIXEL, 0x00_00_00_00),
|
(xcb::CW_BACK_PIXEL, 0x00_00_00_00),
|
||||||
(
|
(
|
||||||
xcb::CW_EVENT_MASK,
|
xcb::CW_EVENT_MASK,
|
||||||
xcb::EVENT_MASK_EXPOSURE | xcb::EVENT_MASK_KEY_PRESS, // we'll need this later
|
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::CW_OVERRIDE_REDIRECT, 1 as u32), // Don't be window managed
|
(xcb::CW_OVERRIDE_REDIRECT, 1 as u32), // Don't be window managed
|
||||||
];
|
];
|
||||||
|
@ -46,80 +54,44 @@ fn main() {
|
||||||
title.as_bytes(),
|
title.as_bytes(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let font = conn.generate_id();
|
|
||||||
xcb::open_font(&conn, font, "cursor");
|
|
||||||
|
|
||||||
// TODO: create cursor with a Pixmap
|
|
||||||
// https://stackoverflow.com/questions/40578969/how-to-create-a-cursor-in-x11-from-raw-data-c
|
|
||||||
let cursor = conn.generate_id();
|
|
||||||
xcb::create_glyph_cursor(&conn, cursor, font, font, 0, 30, 0, 0, 0, 0, 0, 0);
|
|
||||||
|
|
||||||
xcb::grab_pointer(
|
xcb::grab_pointer(
|
||||||
&conn,
|
&conn,
|
||||||
true,
|
true,
|
||||||
screen.root(),
|
screen.root(),
|
||||||
(xcb::EVENT_MASK_BUTTON_RELEASE
|
(xcb::EVENT_MASK_BUTTON_RELEASE | xcb::EVENT_MASK_BUTTON_PRESS) as u16,
|
||||||
| xcb::EVENT_MASK_BUTTON_PRESS
|
|
||||||
| xcb::EVENT_MASK_BUTTON_MOTION) as u16,
|
|
||||||
xcb::GRAB_MODE_ASYNC as u8,
|
xcb::GRAB_MODE_ASYNC as u8,
|
||||||
xcb::GRAB_MODE_ASYNC as u8,
|
xcb::GRAB_MODE_ASYNC as u8,
|
||||||
xcb::NONE,
|
xcb::NONE,
|
||||||
cursor,
|
xcb::NONE,
|
||||||
xcb::CURRENT_TIME,
|
xcb::CURRENT_TIME,
|
||||||
).get_reply()
|
).get_reply()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
conn.flush();
|
conn.flush();
|
||||||
|
|
||||||
// TODO formalise the fact that motion comes after press?
|
|
||||||
let mut start_x = 0;
|
|
||||||
let mut start_y = 0;
|
|
||||||
|
|
||||||
let mut x = 0;
|
|
||||||
let mut y = 0;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let ev = conn.wait_for_event().unwrap();
|
let ev = conn.wait_for_event().unwrap();
|
||||||
match ev.response_type() {
|
match ev.response_type() {
|
||||||
xcb::BUTTON_PRESS => {
|
xcb::BUTTON_PRESS => {
|
||||||
let button_press: &xcb::ButtonPressEvent = unsafe { xcb::cast_event(&ev) };
|
let button_press: &xcb::ButtonPressEvent = unsafe { xcb::cast_event(&ev) };
|
||||||
|
println!(
|
||||||
if button_press.detail() == 3 {
|
"Mouse press: x={}, y={}",
|
||||||
println!("Exiting due to right click");
|
button_press.event_x(),
|
||||||
return;
|
button_press.event_y()
|
||||||
}
|
);
|
||||||
|
|
||||||
start_x = button_press.event_x();
|
|
||||||
start_y = button_press.event_y();
|
|
||||||
|
|
||||||
// For the case where there is no motion
|
|
||||||
x = start_x;
|
|
||||||
y = start_y;
|
|
||||||
}
|
|
||||||
xcb::KEY_PRESS => {
|
|
||||||
println!("Exiting due to key press");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
xcb::MOTION_NOTIFY => {
|
|
||||||
let motion: &xcb::MotionNotifyEvent = unsafe { xcb::cast_event(&ev) };
|
|
||||||
x = motion.event_x();
|
|
||||||
y = motion.event_y();
|
|
||||||
// TODO draw rectangles (and guides)
|
|
||||||
}
|
}
|
||||||
xcb::BUTTON_RELEASE => {
|
xcb::BUTTON_RELEASE => {
|
||||||
let motion: &xcb::ButtonReleaseEvent = unsafe { xcb::cast_event(&ev) };
|
let button_release: &xcb::ButtonReleaseEvent = unsafe { xcb::cast_event(&ev) };
|
||||||
match motion.detail() {
|
println!(
|
||||||
5 => continue, // Scroll wheel down
|
"Mouse release: x={}, y={}",
|
||||||
4 => continue, // Scroll wheel up
|
button_release.event_x(),
|
||||||
_ => break, // Move on after mouse released
|
button_release.event_y()
|
||||||
}
|
);
|
||||||
|
break; // Move on after mouse released
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we have taken coordinates, we use them
|
// Now we have taken coordinates, we use them
|
||||||
let width = (x - start_x).abs();
|
// TODO
|
||||||
let height = (y - start_y).abs();
|
|
||||||
println!("{}x{}+{}+{}", width, height, start_x, start_y);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue