Update ncurses backend to use mouse_v1

This commit is contained in:
Alexandre Bury 2018-11-01 14:37:21 -07:00
parent b0a86ceb61
commit 3b81305b16
3 changed files with 21 additions and 30 deletions

View File

@ -10,6 +10,7 @@ name = "cursive"
readme = "Readme.md"
repository = "https://github.com/gyscos/Cursive"
version = "0.9.3-alpha.0"
build = "build.rs"
[badges.travis-ci]
repository = "gyscos/Cursive"
@ -17,6 +18,9 @@ repository = "gyscos/Cursive"
[badges.appveyor]
repository = "gyscos/Cursive"
[build-dependencies]
ncurses = {optional = true, version = "5.96"}
[dependencies]
enum-map = "0.4"
enumset = "0.3"
@ -45,7 +49,7 @@ version = "1.3"
[dependencies.ncurses]
features = ["wide"]
optional = true
version = "5.91"
version = "5.96"
[dependencies.pancurses]
features = ["wide"]

9
build.rs Normal file
View File

@ -0,0 +1,9 @@
fn main() {
#[cfg(feature = "ncurses-backend")]
{
extern crate ncurses;
if ncurses::NCURSES_MOUSE_VERSION == 1 {
print!(r#"cargo:rustc-cfg=feature="ncurses.mouse_v1""#);
}
}
}

View File

@ -420,6 +420,7 @@ fn get_mouse_button(bare_event: i32) -> MouseButton {
| ncurses::BUTTON4_CLICKED
| ncurses::BUTTON4_DOUBLE_CLICKED
| ncurses::BUTTON4_TRIPLE_CLICKED => MouseButton::Button4,
#[cfg(not(feature = "ncurses.mouse_v1"))]
ncurses::BUTTON5_RELEASED
| ncurses::BUTTON5_PRESSED
| ncurses::BUTTON5_CLICKED
@ -442,41 +443,18 @@ where
{
let button = get_mouse_button(bare_event);
match bare_event {
ncurses::BUTTON4_PRESSED => f(MouseEvent::WheelUp),
ncurses::BUTTON5_PRESSED => f(MouseEvent::WheelDown),
ncurses::BUTTON1_RELEASED
| ncurses::BUTTON2_RELEASED
| ncurses::BUTTON3_RELEASED
| ncurses::BUTTON4_RELEASED
| ncurses::BUTTON5_RELEASED => f(MouseEvent::Release(button)),
| ncurses::BUTTON4_RELEASED => f(MouseEvent::Release(button)),
#[cfg(not(feature = "ncurses.mouse_v1"))]
ncurses::BUTTON5_RELEASED => f(MouseEvent::Release(button)),
ncurses::BUTTON1_PRESSED
| ncurses::BUTTON2_PRESSED
| ncurses::BUTTON3_PRESSED => f(MouseEvent::Press(button)),
ncurses::BUTTON1_CLICKED
| ncurses::BUTTON2_CLICKED
| ncurses::BUTTON3_CLICKED
| ncurses::BUTTON4_CLICKED
| ncurses::BUTTON5_CLICKED => {
f(MouseEvent::Press(button));
f(MouseEvent::Release(button));
}
// Well, we disabled click detection
ncurses::BUTTON1_DOUBLE_CLICKED
| ncurses::BUTTON2_DOUBLE_CLICKED
| ncurses::BUTTON3_DOUBLE_CLICKED
| ncurses::BUTTON4_DOUBLE_CLICKED
| ncurses::BUTTON5_DOUBLE_CLICKED => for _ in 0..2 {
f(MouseEvent::Press(button));
f(MouseEvent::Release(button));
},
ncurses::BUTTON1_TRIPLE_CLICKED
| ncurses::BUTTON2_TRIPLE_CLICKED
| ncurses::BUTTON3_TRIPLE_CLICKED
| ncurses::BUTTON4_TRIPLE_CLICKED
| ncurses::BUTTON5_TRIPLE_CLICKED => for _ in 0..3 {
f(MouseEvent::Press(button));
f(MouseEvent::Release(button));
},
ncurses::BUTTON4_PRESSED => f(MouseEvent::WheelUp),
#[cfg(not(feature = "ncurses.mouse_v1"))]
ncurses::BUTTON5_PRESSED => f(MouseEvent::WheelDown),
_ => debug!("Unknown event: {:032b}", bare_event),
}
}