diff options
author | Ville Hakulinen <ville.hakulinen@gmail.com> | 2019-09-29 12:24:26 +0300 |
---|---|---|
committer | Ville Hakulinen <ville.hakulinen@gmail.com> | 2019-09-29 12:24:51 +0300 |
commit | 0e65abef38c330ae39f3ff7fe8e3355d89b6e977 (patch) | |
tree | f71bb81f10ecb30b89ff3a2246dd490829635421 | |
parent | 7b4343d524711ea9d0c63ceb08a196684c33ed41 (diff) |
Make gnvim buildable without webkit2gtk
Fix #8.
Close #112.
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | Cargo.toml | 18 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | examples/build-syntect-pack.rs | 24 | ||||
-rw-r--r-- | src/main.rs | 6 | ||||
-rw-r--r-- | src/ui/mod.rs | 1 | ||||
-rw-r--r-- | src/ui/ui.rs | 126 |
8 files changed, 140 insertions, 58 deletions
diff --git a/.travis.yml b/.travis.yml index 3154e55..d07f601 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,6 @@ before_script: script: - cargo fmt --all -- --check - cargo build + - cargo build --no-default-features # build without webkit2gtk - cargo test + - cargo test --no-default-features # test without webkit2gtk @@ -7,7 +7,16 @@ authors = ["Ville Hakulinen <ville.hakulinen@gmail.com>"] debug = true [features] +default = ["libwebkit2gtk"] + unstable = [] +libwebkit2gtk = [ + "webkit2gtk", + "pulldown-cmark", + "ammonia", + "syntect", + "lazy_static", +] [dependencies] #neovim-lib = "0.6" @@ -21,10 +30,10 @@ glib = "0.8" gdk = "0.11" gdk-pixbuf = "0.7" -pulldown-cmark = { version = "0.2", default-features = false } -ammonia = "2" -syntect = "3" -lazy_static = "1.3.0" +pulldown-cmark = { version = "0.2", default-features = false, optional = true } +ammonia = { version = "2", optional = true } +syntect = { version = "3", optional = true } +lazy_static = {version = "1.3.0", optional = true } [dependencies.gtk] version = "0.7" @@ -33,6 +42,7 @@ features = ["v3_18"] [dependencies.webkit2gtk] version = "0.8" features = ["v2_14"] +optional = true [dependencies.neovim-lib] #git = "https://github.com/vhakulinen/neovim-lib" @@ -2,8 +2,12 @@ ifeq ($(PREFIX),) PREFIX := /usr/local endif +ifdef NOWEBKIT2GTK + FEATURES := --no-default-features +endif + build: - cargo build --release + cargo build --release $(FEATURES) syntect-pack: git submodule update --init @@ -26,8 +26,19 @@ $ sudo apt install libgtk-3-dev libwebkit2gtk-4.0-dev $ # Run (unoptimized version) without installing $ GNVIM_RUNTIME_PATH=/path/to/gnvim/runtime cargo run $ # Install -$ make -$ sudo make install +$ make && sudo make install +``` + +## macOS (without webkit2gtk) + +Webkit2gtk isn't really available for macOS. GNvim is available without said +dependency, but such builds wont have the cursor tooltip feature. To build +without webkit2gtk: + +``` +$ make NOWEBKIT2GTK=1 +$ # or with cargo +$ cargo build --no-default-features ``` ## Features diff --git a/examples/build-syntect-pack.rs b/examples/build-syntect-pack.rs index 88bb124..1013f9e 100644 --- a/examples/build-syntect-pack.rs +++ b/examples/build-syntect-pack.rs @@ -1,14 +1,18 @@ +#[cfg(feature = "libwebkit2gtk")] extern crate syntect; -use syntect::dumps::*; -use syntect::parsing::SyntaxSetBuilder; - fn main() { - let mut builder = SyntaxSetBuilder::new(); - builder.add_plain_text_syntax(); - builder - .add_from_folder("./sublime-syntaxes/syntaxes/", true) - .unwrap(); - let ss = builder.build(); - dump_to_file(&ss, "./sublime-syntaxes/all.pack").unwrap(); + #[cfg(feature = "libwebkit2gtk")] + { + use syntect::dumps::*; + use syntect::parsing::SyntaxSetBuilder; + + let mut builder = SyntaxSetBuilder::new(); + builder.add_plain_text_syntax(); + builder + .add_from_folder("./sublime-syntaxes/syntaxes/", true) + .unwrap(); + let ss = builder.build(); + dump_to_file(&ss, "./sublime-syntaxes/all.pack").unwrap(); + } } diff --git a/src/main.rs b/src/main.rs index 91397f4..222b6c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,14 @@ #![cfg_attr(feature = "unstable", feature(test))] +#[cfg(feature = "libwebkit2gtk")] #[macro_use] extern crate lazy_static; +#[cfg(feature = "libwebkit2gtk")] extern crate ammonia; +#[cfg(feature = "libwebkit2gtk")] extern crate pulldown_cmark; extern crate structopt; +#[cfg(feature = "libwebkit2gtk")] extern crate syntect; extern crate cairo; @@ -16,6 +20,7 @@ extern crate gtk; extern crate neovim_lib; extern crate pango; extern crate pangocairo; +#[cfg(feature = "libwebkit2gtk")] extern crate webkit2gtk; use gio::prelude::*; @@ -33,6 +38,7 @@ use structopt::StructOpt; include!(concat!(env!("OUT_DIR"), "/gnvim_version.rs")); mod nvim_bridge; +#[cfg(feature = "libwebkit2gtk")] mod thread_guard; mod ui; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 8b49295..96a20ee 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -50,6 +50,7 @@ macro_rules! upgrade_weak { mod cmdline; pub mod color; mod common; +#[cfg(feature = "libwebkit2gtk")] mod cursor_tooltip; mod font; mod grid; diff --git a/src/ui/ui.rs b/src/ui/ui.rs index 7dd4f78..5a18cf5 100644 --- a/src/ui/ui.rs +++ b/src/ui/ui.rs @@ -19,6 +19,7 @@ use nvim_bridge::{ }; use ui::cmdline::Cmdline; use ui::color::{Color, Highlight}; +#[cfg(feature = "libwebkit2gtk")] use ui::cursor_tooltip::{CursorTooltip, Gravity}; use ui::font::Font; use ui::grid::Grid; @@ -70,6 +71,7 @@ struct UIState { popupmenu: Popupmenu, cmdline: Cmdline, tabline: Tabline, + #[cfg(feature = "libwebkit2gtk")] cursor_tooltip: CursorTooltip, /// Overlay contains our grid(s) and popupmenu. @@ -263,6 +265,7 @@ impl UI { })); let cmdline = Cmdline::new(&overlay, nvim.clone()); + #[cfg(feature = "libwebkit2gtk")] let cursor_tooltip = CursorTooltip::new(&overlay); window.show_all(); @@ -270,6 +273,7 @@ impl UI { grid.set_im_context(&im_context); cmdline.hide(); + #[cfg(feature = "libwebkit2gtk")] cursor_tooltip.hide(); let mut grids = HashMap::new(); @@ -286,6 +290,7 @@ impl UI { cmdline, overlay, tabline, + #[cfg(feature = "libwebkit2gtk")] cursor_tooltip, resize_source_id: source_id, hl_defs, @@ -349,6 +354,7 @@ fn handle_request( state: &mut UIState, ) -> Result<Value, Value> { match request { + #[cfg(feature = "libwebkit2gtk")] Request::CursorTooltipStyles => { let styles = state.cursor_tooltip.get_styles(); @@ -357,6 +363,10 @@ fn handle_request( Ok(res.into()) } + #[cfg(not(feature = "libwebkit2gtk"))] + Request::CursorTooltipStyles => { + Err("Cursor tooltip is not supported in this build".into()) + } } } @@ -407,34 +417,6 @@ fn handle_gnvim_event( GnvimEvent::CompletionMenuToggleInfo => { state.popupmenu.toggle_show_info() } - GnvimEvent::CursorTooltipLoadStyle(path) => { - if let Err(err) = state.cursor_tooltip.load_style(path.clone()) { - let mut nvim = nvim.borrow_mut(); - nvim.command_async(&format!( - "echom \"Cursor tooltip load style failed: '{}'\"", - err - )) - .cb(|res| match res { - Ok(_) => {} - Err(err) => { - println!("Failed to execute nvim command: {}", err) - } - }) - .call(); - } - } - GnvimEvent::CursorTooltipShow(content, row, col) => { - state.cursor_tooltip.show(content.clone()); - - let grid = state.grids.get(&state.current_grid).unwrap(); - let rect = grid.get_rect_for_cell(*row, *col); - - state.cursor_tooltip.move_to(&rect); - } - GnvimEvent::CursorTooltipHide => state.cursor_tooltip.hide(), - GnvimEvent::CursorTooltipSetStyle(style) => { - state.cursor_tooltip.set_style(style) - } GnvimEvent::PopupmenuWidth(width) => { state.popupmenu.set_width(*width as i32); } @@ -447,6 +429,61 @@ fn handle_gnvim_event( GnvimEvent::Unknown(msg) => { println!("Received unknown GnvimEvent: {}", msg); } + + #[cfg(not(feature = "libwebkit2gtk"))] + GnvimEvent::CursorTooltipLoadStyle(..) + | GnvimEvent::CursorTooltipShow(..) + | GnvimEvent::CursorTooltipHide + | GnvimEvent::CursorTooltipSetStyle(..) => { + let mut nvim = nvim.borrow_mut(); + nvim.command_async( + "echom \"Cursor tooltip not supported in this build\"", + ) + .cb(|res| match res { + Ok(_) => {} + Err(err) => { + println!("Failed to execute nvim command: {}", err) + } + }) + .call(); + } + + #[cfg(feature = "libwebkit2gtk")] + GnvimEvent::CursorTooltipLoadStyle(..) + | GnvimEvent::CursorTooltipShow(..) + | GnvimEvent::CursorTooltipHide + | GnvimEvent::CursorTooltipSetStyle(..) => match event { + GnvimEvent::CursorTooltipLoadStyle(path) => { + if let Err(err) = state.cursor_tooltip.load_style(path.clone()) + { + let mut nvim = nvim.borrow_mut(); + nvim.command_async(&format!( + "echom \"Cursor tooltip load style failed: '{}'\"", + err + )) + .cb(|res| match res { + Ok(_) => {} + Err(err) => { + println!("Failed to execute nvim command: {}", err) + } + }) + .call(); + } + } + GnvimEvent::CursorTooltipShow(content, row, col) => { + state.cursor_tooltip.show(content.clone()); + + let grid = state.grids.get(&state.current_grid).unwrap(); + let rect = grid.get_rect_for_cell(*row, *col); + + state.cursor_tooltip.move_to(&rect); + } + GnvimEvent::CursorTooltipHide => state.cursor_tooltip.hide(), + GnvimEvent::CursorTooltipSetStyle(style) => { + state.cursor_tooltip.set_style(style) + } + _ => unreachable!(), + }, } } @@ -553,6 +590,7 @@ fn handle_redraw_event( grid.redraw(&state.hl_defs); } + #[cfg(feature = "libwebkit2gtk")] state.cursor_tooltip.set_colors(*fg, *bg); }); } @@ -653,6 +691,7 @@ fn handle_redraw_event( state.popupmenu.set_font(opts.font.clone(), &state.hl_defs); state.cmdline.set_font(opts.font.clone(), &state.hl_defs); state.tabline.set_font(opts.font.clone(), &state.hl_defs); + #[cfg(feature = "libwebkit2gtk")] state.cursor_tooltip.set_font(opts.font.clone()); state.cmdline.set_line_space(opts.line_space); @@ -683,18 +722,21 @@ fn handle_redraw_event( // If the cursor tooltip is visible at the same time, move // it out of our way. - if state.cursor_tooltip.is_visible() { - if state.popupmenu.is_above_anchor() { - state - .cursor_tooltip - .force_gravity(Some(Gravity::Down)); - } else { - state - .cursor_tooltip - .force_gravity(Some(Gravity::Up)); - } + #[cfg(feature = "libwebkit2gtk")] + { + if state.cursor_tooltip.is_visible() { + if state.popupmenu.is_above_anchor() { + state + .cursor_tooltip + .force_gravity(Some(Gravity::Down)); + } else { + state + .cursor_tooltip + .force_gravity(Some(Gravity::Up)); + } - state.cursor_tooltip.refresh_position(); + state.cursor_tooltip.refresh_position(); + } } }); } @@ -703,8 +745,10 @@ fn handle_redraw_event( // Undo any force positioning of cursor tool tip that might // have occured on popupmenu show. - state.cursor_tooltip.force_gravity(None); - state.cursor_tooltip.refresh_position(); + #[cfg(feature = "libwebkit2gtk")] { + state.cursor_tooltip.force_gravity(None); + state.cursor_tooltip.refresh_position(); + } } RedrawEvent::PopupmenuSelect(evt) => { evt.iter().for_each(|selected| { |