diff --git a/Cargo.toml b/Cargo.toml index 053c3c8..b63113c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..f5af504 --- /dev/null +++ b/build.rs @@ -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""#); + } + } +} diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index fe2e6ca..85d6621 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -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), } }