diff --git a/Cargo.lock b/Cargo.lock index cd61a23..e0be115 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1100,7 +1100,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "atomicwrites", "cosmic-config-derive", @@ -1119,7 +1119,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "quote", "syn 1.0.109", @@ -1158,7 +1158,7 @@ dependencies = [ [[package]] name = "cosmic-files" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-files.git#ddd99525c56cf37e91e966d068110a3947fe9f8f" +source = "git+https://github.com/pop-os/cosmic-files.git#6572faec5c7646cf7a6d87f0b86e66ec8d97630d" dependencies = [ "chrono", "dirs", @@ -1205,7 +1205,7 @@ dependencies = [ [[package]] name = "cosmic-text" version = "0.11.2" -source = "git+https://github.com/pop-os/cosmic-text.git#cd1cd0a337d7bfd7d2586b28a4102827517bbf60" +source = "git+https://github.com/pop-os/cosmic-text.git#69d5aec7fc995a1748682af1cd3cc25847c05c95" dependencies = [ "bitflags 2.5.0", "cosmic_undo_2", @@ -1230,7 +1230,7 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "almost", "cosmic-config", @@ -2594,7 +2594,7 @@ dependencies = [ [[package]] name = "iced" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "dnd", "iced_accessibility", @@ -2612,7 +2612,7 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "accesskit", "accesskit_winit", @@ -2621,7 +2621,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "bitflags 2.5.0", "dnd", @@ -2641,7 +2641,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "futures", "iced_core", @@ -2654,7 +2654,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "bitflags 2.5.0", "bytemuck", @@ -2678,7 +2678,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -2690,7 +2690,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "dnd", "iced_core", @@ -2702,7 +2702,7 @@ dependencies = [ [[package]] name = "iced_style" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "iced_core", "once_cell", @@ -2712,7 +2712,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "bytemuck", "cosmic-text", @@ -2729,7 +2729,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "bitflags 2.5.0", "bytemuck", @@ -2755,7 +2755,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "dnd", "iced_renderer", @@ -2771,7 +2771,7 @@ dependencies = [ [[package]] name = "iced_winit" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "dnd", "iced_graphics", @@ -3250,7 +3250,7 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic.git#892d9003adf5e0f68791457b693ae98ea8468b81" +source = "git+https://github.com/pop-os/libcosmic.git#f1aad68b712650b3c697834e1043f3dcc943c9e7" dependencies = [ "apply", "ashpd", diff --git a/src/main.rs b/src/main.rs index ded50dd..6efc33b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,6 +80,16 @@ pub fn icon_cache_get(name: &'static str, size: u16) -> icon::Icon { } fn main() -> Result<(), Box> { + #[cfg(all(unix, not(target_os = "redox")))] + match fork::daemon(true, true) { + Ok(fork::Fork::Child) => (), + Ok(fork::Fork::Parent(_child_pid)) => process::exit(0), + Err(err) => { + eprintln!("failed to daemonize: {:?}", err); + process::exit(1); + } + } + ICON_CACHE.get_or_init(|| Mutex::new(IconCache::new())); LINE_NUMBER_CACHE.get_or_init(|| Mutex::new(LineNumberCache::new())); SWASH_CACHE.get_or_init(|| Mutex::new(SwashCache::new())); @@ -121,16 +131,6 @@ fn main() -> Result<(), Box> { } }); - #[cfg(all(unix, not(target_os = "redox")))] - match fork::daemon(true, true) { - Ok(fork::Fork::Child) => (), - Ok(fork::Fork::Parent(_child_pid)) => process::exit(0), - Err(err) => { - eprintln!("failed to daemonize: {:?}", err); - process::exit(1); - } - } - env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("warn")).init(); localize::localize(); diff --git a/src/text_box.rs b/src/text_box.rs index 709fa9e..a6b54fd 100644 --- a/src/text_box.rs +++ b/src/text_box.rs @@ -296,7 +296,11 @@ where let y_logical = p.y - self.padding.top; let x = x_logical * scale_factor - editor_offset_x as f32; let y = y_logical * scale_factor; - if x >= 0.0 && x < buffer_size.0 && y >= 0.0 && y < buffer_size.1 { + if x >= 0.0 + && x < buffer_size.0.unwrap_or(0.0) + && y >= 0.0 + && y < buffer_size.1.unwrap_or(0.0) + { return mouse::Interaction::Text; } } @@ -410,8 +414,8 @@ where buffer.set_metrics_and_size( font_system.raw(), metrics, - (image_w - editor_offset_x) as f32, - image_h as f32, + Some((image_w - editor_offset_x) as f32), + Some(image_h as f32), ) }); @@ -622,7 +626,9 @@ where ); state.scrollbar_v_rect.set(rect); - let (buffer_w, buffer_h) = buffer.size(); + let (buffer_w_opt, buffer_h_opt) = buffer.size(); + let buffer_w = buffer_w_opt.unwrap_or(0.0); + let buffer_h = buffer_h_opt.unwrap_or(0.0); let scrollbar_h_width = image_w as f32 / scale_factor - scrollbar_w as f32; if buffer_w < max_line_width { let rect = Rectangle::new( @@ -1014,7 +1020,11 @@ where if matches!(state.dragging, Some(Dragging::ScrollbarH { .. })) { // The horizontal scrollbar is on top of the buffer, // so we need to ignore clicks when it is being dragged - } else if x >= 0.0 && x < buffer_size.0 && y >= 0.0 && y < buffer_size.1 { + } else if x >= 0.0 + && x < buffer_size.0.unwrap_or(0.0) + && y >= 0.0 + && y < buffer_size.1.unwrap_or(0.0) + { x += buffer_scroll.horizontal; let click_kind = if let Some((click_kind, click_time)) = state.click.take() { @@ -1056,8 +1066,10 @@ where { editor.with_buffer_mut(|buffer| { let mut scroll = buffer.scroll(); - let scroll_line = - ((y / buffer.size().1) * buffer.lines.len() as f32) as i32; + //TODO: if buffer height is undefined, what should this do? + let scroll_line = ((y / buffer.size().1.unwrap_or(1.0)) + * buffer.lines.len() as f32) + as i32; scroll.line = scroll_line.try_into().unwrap_or_default(); buffer.set_scroll(scroll); state.dragging = Some(Dragging::ScrollbarV { @@ -1108,7 +1120,9 @@ where } => { editor.with_buffer_mut(|buffer| { let mut scroll = buffer.scroll(); - let scroll_offset = (((y - start_y) / buffer.size().1) + //TODO: if buffer size is undefined, what should this do? + let scroll_offset = (((y - start_y) + / buffer.size().1.unwrap_or(1.0)) * buffer.lines.len() as f32) as i32; scroll.line = (start_scroll.line as i32 + scroll_offset) @@ -1127,7 +1141,7 @@ where } } - let buffer_w = buffer.size().0; + let buffer_w = buffer.size().0.unwrap_or(0.0); let mut scroll = buffer.scroll(); scroll.horizontal = (((x - start_x) / buffer_w) * max_line_width)