Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linux latest updates #457

Merged
merged 12 commits into from
Feb 21, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
- Compute layout updates only if layout is different.
- Introduced renderer level (`0` for elementary and `1` for advanced).
- Reduced font size to `16.0`.
- Update rust to 1.75.0
- Rewrite hash logic to use `BuildHasher::hash_one`.
- Support to font ligatures.
- Report focus change https://terminalguide.namepad.de/mode/p1004/.
- Updated wgpu to 0.19.0.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ authors = ["Raphael Amorim <[email protected]>"]
edition = "2021"
license = "MIT"
keywords = ["graphics", "terminal"]
rust-version = "1.73.0"
rust-version = "1.75.0"
repository = "https://github.com/raphamorim/rio"
homepage = "https://raphamorim.io/rio"
documentation = "https://github.com/raphamorim/rio#readme"
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ run:
cargo run --release

dev:
RIO_LOG_LEVEL=debug cargo run -p rioterm
cargo run -p rioterm

dev-wayland:
dev-debug:
RIO_LOG_LEVEL=debug make dev

dev-debug-wayland:
RIO_LOG_LEVEL=debug cargo run -p rioterm --no-default-features --features=wayland

dev-x11:
dev-debug-x11:
RIO_LOG_LEVEL=debug cargo run -p rioterm --no-default-features --features=x11

run-wasm:
Expand Down
3 changes: 2 additions & 1 deletion corcovado/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Re-export the io::Result / Error types for convenience
pub use std::io::{Error, ErrorKind, Read, Result, Write};
// pub use std::io::{Error, ErrorKind, Read, Result, Write};
pub use std::io::{ErrorKind, Result};

// TODO: Delete this
/// A helper trait to provide the map_non_block function on Results.
Expand Down
3 changes: 2 additions & 1 deletion corcovado/src/sys/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(all(unix, not(target_os = "fuchsia")))]
pub use self::unix::{pipe, set_nonblock, Awakener, EventedFd, Events, Io, Selector};
pub use self::unix::{Awakener, EventedFd, Events, Selector};
// pub use self::unix::{pipe, set_nonblock, Awakener, EventedFd, Events, Io, Selector};

#[cfg(all(unix, not(target_os = "fuchsia")))]
pub use self::unix::READY_ALL;
Expand Down
5 changes: 3 additions & 2 deletions corcovado/src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ mod uds;

pub use self::awakener::Awakener;
pub use self::eventedfd::EventedFd;
pub use self::io::{set_nonblock, Io};
// pub use self::io::{set_nonblock, Io};
pub use self::io::Io;
pub use self::ready::{UnixReady, READY_ALL};

#[cfg(feature = "with-deprecated")]
pub use self::uds::UnixSocket;

pub use iovec::IoVec;
// pub use iovec::IoVec;

use std::os::unix::io::FromRawFd;

Expand Down
2 changes: 1 addition & 1 deletion frontends/rioterm/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Scheduler {
}
}

self.timers.get(0).map(|timer| timer.deadline)
self.timers.front().map(|timer| timer.deadline)
}

/// Schedule a new event.
Expand Down
6 changes: 2 additions & 4 deletions frontends/rioterm/src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,6 @@ impl Screen {
self.mouse
.set_multiplier_and_divider(config.scroll.multiplier, config.scroll.divider);

self.resize_all_contexts();

let mut bg_color = self.state.named_colors.background.1;

if config.window.background_opacity < 1. {
Expand All @@ -326,7 +324,7 @@ impl Screen {
self.sugarloaf.set_background_image(image);
}

self.render();
self.resize_all_contexts();
}

#[inline]
Expand All @@ -346,7 +344,6 @@ impl Screen {
// and then updates again with correct bounds
// TODO: Refactor this logic
self.sugarloaf.layout_next().update();
self.resize_all_contexts();
}

#[inline]
Expand All @@ -364,6 +361,7 @@ impl Screen {
) -> &mut Self {
self.sugarloaf.rescale(new_scale);
self.sugarloaf.resize(new_size.width, new_size.height);
self.resize_all_contexts();
self
}

Expand Down
3 changes: 2 additions & 1 deletion rio-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ x11 = [
"copypasta/x11"
]
wayland = [
"copypasta/wayland"
"copypasta/wayland",
"sugarloaf/render_equal_updates"
]
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# If you see this, run "rustup self update" to get rustup 1.23 or newer.

[toolchain]
channel = "1.73.0"
channel = "1.75.0"
components = ["rustfmt", "clippy"]
targets = ["wasm32-unknown-unknown"]
4 changes: 4 additions & 0 deletions sugarloaf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ criterion = "0.5.1"
futures = "0.3.29"
once_cell = "1.18.0"

[features]
default = []
render_equal_updates = []

[[bench]]
name = "bench_sugar_pile"
path = "benches/bench_sugar_pile.rs"
Expand Down
14 changes: 12 additions & 2 deletions sugarloaf/src/components/rich_text/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@

use crate::components::rich_text::batch::BatchManager;
pub use crate::components::rich_text::batch::{
Command, DisplayList, Pipeline, Rect, Vertex,
// Command, DisplayList, Pipeline, Rect, Vertex,
Command,
DisplayList,
Rect,
Vertex,
};
pub use crate::components::rich_text::image_cache::{
AddImage, Epoch, ImageData, ImageId, ImageLocation, TextureEvent, TextureId,
AddImage,
Epoch,
ImageId,
ImageLocation,
TextureEvent,
TextureId,
// AddImage, Epoch, ImageData, ImageId, ImageLocation, TextureEvent, TextureId,
};
use crate::components::rich_text::image_cache::{GlyphCache, ImageCache};
use crate::components::rich_text::text::*;
Expand Down
3 changes: 2 additions & 1 deletion sugarloaf/src/components/rich_text/image_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ impl PixelFormat {
}

pub use cache::ImageCache;
pub use glyph::{GlyphCache, GlyphCacheSession, GlyphEntry};
// pub use glyph::{GlyphCache, GlyphCacheSession, GlyphEntry};
pub use glyph::GlyphCache;

/// Frame counter for managing resource lifetimes.
#[derive(Copy, Clone, Default)]
Expand Down
6 changes: 1 addition & 5 deletions sugarloaf/src/components/text/glyph/brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,7 @@ where
VF: Fn(GlyphVertex<X>) -> V + Copy,
{
let draw_info = LastDrawInfo {
text_state: {
let mut s = self.section_hasher.build_hasher();
self.section_buffer.hash(&mut s);
s.finish()
},
text_state: { self.section_hasher.hash_one(&self.section_buffer) },
};

let result = if !self.cache_redraws
Expand Down
7 changes: 1 addition & 6 deletions sugarloaf/src/components/text/glyph/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

mod geometry;

/// Re-exported ab_glyph types.
pub mod ab_glyph {
pub use ab_glyph::*;
}

pub use geometry::Rectangle;

use ::ab_glyph::*;
Expand Down Expand Up @@ -828,7 +823,7 @@ impl DrawCache {
// The first (tallest) glyph height is used to calculate work magnitude.
let work_magnitude = {
let tallest_h = draw_and_upload
.get(0)
.first()
.map(|(r, _)| r.height() as usize)
.unwrap_or(0);
glyph_count
Expand Down
8 changes: 2 additions & 6 deletions sugarloaf/src/components/text/glyph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ pub type DefaultSectionHasher = std::hash::BuildHasherDefault<twox_hash::XxHash>

#[test]
fn default_section_hasher() {
use std::hash::{BuildHasher, Hash, Hasher};
use std::hash::BuildHasher;

let section_a = Section::default().add_text(Text::new("Hovered Tile: Some((0, 0))"));
let section_b = Section::default().add_text(Text::new("Hovered Tile: Some((1, 0))"));
let hash = |s: &Section| {
let mut hasher = DefaultSectionHasher::default().build_hasher();
s.hash(&mut hasher);
hasher.finish()
};
let hash = |s: &Section| DefaultSectionHasher::default().hash_one(s);
assert_ne!(hash(&section_a), hash(&section_b));
}
6 changes: 3 additions & 3 deletions sugarloaf/src/font/loader/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ fn load_fontconfig(database: &mut Database) {
} in fontconfig.aliases
{
let name = prefer
.get(0)
.or_else(|| accept.get(0))
.or_else(|| default.get(0));
.first()
.or_else(|| accept.first())
.or_else(|| default.first());

if let Some(name) = name {
match alias.to_lowercase().as_str() {
Expand Down
11 changes: 8 additions & 3 deletions sugarloaf/src/sugarloaf/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub struct SugarLine {
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b3face22f8c64b25803fa213be6a858f

// inner: [Sugar; SUGAR_LINE_MAX_CONTENT_SIZE],
// pub len: usize,
pub raw_len: usize,
inner: Vec<Sugar>,
first_non_default: usize,
last_non_default: usize,
Expand All @@ -145,6 +145,7 @@ impl PartialEq for SugarLine {
// if self.len != other.len
let len = self.inner.len();
if len != other.inner.len()
|| self.raw_len != other.raw_len
|| self.first_non_default != other.first_non_default
|| self.last_non_default != other.last_non_default
|| self.non_default_count != other.non_default_count
Expand All @@ -166,6 +167,7 @@ impl Default for SugarLine {
fn default() -> Self {
Self {
// hash: 00000000000000,
raw_len: 0,
last_non_default: 0,
first_non_default: 0,
non_default_count: 0,
Expand Down Expand Up @@ -209,6 +211,7 @@ impl SugarLine {
let len = self.inner.len();

if len > 0 && equal_without_consider_repeat(&self.inner[len - 1], sugar) {
self.raw_len += 1;
self.inner[len - 1].repeated += 1;
return;
}
Expand All @@ -225,19 +228,20 @@ impl SugarLine {

self.non_default_count += 1;
}

self.raw_len += 1;
}

#[inline]
pub fn insert_empty(&mut self) {
// self.inner[self.len] = self.default_sugar;
self.inner.push(self.default_sugar);
// self.len += 1;
self.raw_len += 1;
}

#[inline]
pub fn len(&self) -> usize {
self.inner.len()
// self.len += 1;
}

// #[inline]
Expand Down Expand Up @@ -412,6 +416,7 @@ pub mod test {

assert!(line_a.is_empty());
assert_eq!(line_a.len(), 1);
assert_eq!(line_a.raw_len, 6);
}

#[test]
Expand Down
13 changes: 13 additions & 0 deletions sugarloaf/src/sugarloaf/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ impl SugarState {
rect_brush: &mut RectBrush,
context: &mut super::Context,
) -> bool {
// TODO: Fix drop of rendering context on wayland if diff is equal
#[cfg(not(feature = "render_equal_updates"))]
if self.latest_change == SugarTreeDiff::Equal {
return false;
}
Expand Down Expand Up @@ -297,6 +299,8 @@ impl SugarState {

self.compositors.elementary.set_should_resize();
self.reset_next();
self.latest_change = SugarTreeDiff::LayoutIsDifferent;
log::info!("current_has_empty_dimensions, will try to find...");
return;
}

Expand All @@ -320,6 +324,13 @@ impl SugarState {
should_clean_blocks = true;
should_update = true;
}
SugarTreeDiff::ColumnsLengthIsDifferent(_) => {
should_update = true;
}
SugarTreeDiff::LineLengthIsDifferent(_) => {
should_update = true;
should_compute_dimensions = true;
}
SugarTreeDiff::Changes(_changes) => {
should_update = true;
}
Expand All @@ -328,6 +339,8 @@ impl SugarState {
}
}

log::info!("state compute_changes result: {:?}", self.latest_change);

if should_update {
std::mem::swap(&mut self.current, &mut self.next);

Expand Down
9 changes: 9 additions & 0 deletions sugarloaf/src/sugarloaf/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ impl SugarTree {
for line_number in 0..current_len {
let line: &SugarLine = &self.lines[line_number];
let next_line: &SugarLine = &next.lines[line_number];

// .width stands for column size and .len() sugar elements
// this needs to be differenciated
// if line.width != next_line.width {
// return SugarTreeDiff::ColumnsLengthIsDifferent(
// line.width as i32 - next_line.width as i32,
// );
// }

if line.len() != next_line.len() {
return SugarTreeDiff::ColumnsLengthIsDifferent(
line.len() as i32 - next_line.len() as i32,
Expand Down
Loading