Skip to content

Commit

Permalink
Fix cursor disappearing in the first tab whenever a new tab is create…
Browse files Browse the repository at this point in the history
…d with NativeTab
  • Loading branch information
raphamorim committed Sep 24, 2023
1 parent 9cb7022 commit 41e1cbc
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 56 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## In progress

- Fix cursor disappearing in the first tab whenever a new tab is created with NativeTab.
- Fix settings for NativeTabs.
- New docs.
- Removal of RIO_CONFIG environment variable.
- Add ToggleFullscreen Action #229 (Ref: https://github.com/raphamorim/rio/pull/249)
Expand Down
3 changes: 1 addition & 2 deletions rio/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ impl RouteWindow {
let winit_window = configure_window(winit_window, config);

let mut screen =
Screen::new(&winit_window, config, event_proxy, font_database, None).await?;
Screen::new(&winit_window, config, event_proxy, font_database).await?;

screen.init(
screen.state.named_colors.background.1,
Expand Down Expand Up @@ -292,7 +292,6 @@ impl RouteWindow {
config,
event_proxy,
font_database,
tab_id,
))
.expect("Screen not created");

Expand Down
11 changes: 10 additions & 1 deletion rio/src/router/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ pub struct Settings {
impl Settings {
pub fn new(db: &Database) -> Self {
let mut font_families_hash = HashMap::new();
// TODO: Ignore families that cannot be loaded instead of manually
// add it to a hashmap of strings
let mut ignored_families = HashMap::new();
ignored_families.insert(String::from("GB18030 Bitmap"), true);

for i in db.faces() {
if !i.families.is_empty() && i.monospaced {
font_families_hash.insert(i.families[0].0.to_owned(), true);
let name = i.families[0].0.to_owned();
if ignored_families.get(&name).is_some() {
continue;
}

font_families_hash.insert(name, true);
}
}

Expand Down
28 changes: 14 additions & 14 deletions rio/src/router/settings/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ pub fn render(sugarloaf: &mut Sugarloaf, settings: &crate::router::settings::Set

let settings_background = vec![
Rect {
position: [0., 100.0],
position: [0., sugarloaf.layout.margin.top_y + 100.0],
color: dim_black,
size: [sugarloaf.layout.width * 2., sugarloaf.layout.height],
},
Rect {
position: [0., 96.0],
position: [0., sugarloaf.layout.margin.top_y + 96.0],
color: blue,
size: [sugarloaf.layout.width * 2., 8.],
},
Rect {
position: [0., 104.0],
position: [0., sugarloaf.layout.margin.top_y + 104.0],
color: yellow,
size: [sugarloaf.layout.width * 2., 8.],
},
Rect {
position: [0., 112.0],
position: [0., sugarloaf.layout.margin.top_y + 112.0],
color: red,
size: [sugarloaf.layout.width * 2., 8.],
},
Rect {
position: [0., 180.0],
position: [0., sugarloaf.layout.margin.top_y + 175.0],
color: [1., 1., 1., 1.],
size: [sugarloaf.layout.width * 2., 50.],
},
Expand All @@ -43,7 +43,7 @@ pub fn render(sugarloaf: &mut Sugarloaf, settings: &crate::router::settings::Set
sugarloaf.pile_rects(settings_background);

sugarloaf.text(
(10., sugarloaf.layout.margin.top_y + 30.),
(10., sugarloaf.layout.margin.top_y + 50.),
"Settings".to_string(),
FONT_ID_BUILTIN,
28.,
Expand All @@ -52,7 +52,7 @@ pub fn render(sugarloaf: &mut Sugarloaf, settings: &crate::router::settings::Set
);

sugarloaf.text(
(10., sugarloaf.layout.margin.top_y + 60.),
(10., sugarloaf.layout.margin.top_y + 80.),
format!(
"{} • v{}",
settings.default_file_path,
Expand All @@ -66,7 +66,7 @@ pub fn render(sugarloaf: &mut Sugarloaf, settings: &crate::router::settings::Set

let items_len = settings.inner.len();
sugarloaf.text(
(10., sugarloaf.layout.margin.top_y + 130.),
(10., sugarloaf.layout.margin.top_y + 140.),
String::from(""),
FONT_ID_ICONS,
16.,
Expand All @@ -82,7 +82,7 @@ pub fn render(sugarloaf: &mut Sugarloaf, settings: &crate::router::settings::Set

if let Some(prev_setting) = settings.inner.get(&previous_item) {
sugarloaf.text(
(10., sugarloaf.layout.margin.top_y + 150.),
(10., sugarloaf.layout.margin.top_y + 160.),
format!(
"{} | \"{}\"",
prev_setting.title, prev_setting.options[prev_setting.current_option],
Expand All @@ -96,7 +96,7 @@ pub fn render(sugarloaf: &mut Sugarloaf, settings: &crate::router::settings::Set

if let Some(active_setting) = settings.inner.get(&settings.state.current) {
sugarloaf.text(
(60., sugarloaf.layout.margin.top_y + 190.),
(60., sugarloaf.layout.margin.top_y + 200.),
format!(
"{} | {:?}",
active_setting.title,
Expand All @@ -112,7 +112,7 @@ pub fn render(sugarloaf: &mut Sugarloaf, settings: &crate::router::settings::Set
sugarloaf.text(
(
sugarloaf.layout.width / sugarloaf.layout.scale_factor - 160.,
sugarloaf.layout.margin.top_y + 225.,
sugarloaf.layout.margin.top_y + 235.,
),
"* restart is needed".to_string(),
FONT_ID_BUILTIN,
Expand All @@ -125,7 +125,7 @@ pub fn render(sugarloaf: &mut Sugarloaf, settings: &crate::router::settings::Set
sugarloaf.text(
(
sugarloaf.layout.width / sugarloaf.layout.scale_factor - 40.,
sugarloaf.layout.margin.top_y + 190.,
sugarloaf.layout.margin.top_y + 200.,
),
"󰁔".to_string(),
FONT_ID_ICONS,
Expand All @@ -135,7 +135,7 @@ pub fn render(sugarloaf: &mut Sugarloaf, settings: &crate::router::settings::Set
);

sugarloaf.text(
(10., sugarloaf.layout.margin.top_y + 190.),
(10., sugarloaf.layout.margin.top_y + 200.),
"󰁍".to_string(),
FONT_ID_ICONS,
28.,
Expand All @@ -160,7 +160,7 @@ pub fn render(sugarloaf: &mut Sugarloaf, settings: &crate::router::settings::Set
}

let settings_iterator = Vec::from_iter(iter);
let mut spacing_between = 230.;
let mut spacing_between = 240.;
for i in settings_iterator {
if i == settings.state.current {
continue;
Expand Down
44 changes: 10 additions & 34 deletions rio/src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ impl Screen {
config: &Rc<rio_config::Config>,
event_proxy: EventProxy,
font_database: &sugarloaf::font::loader::Database,
native_tab_id: Option<String>,
) -> Result<Screen, Box<dyn Error>> {
let size = winit_window.inner_size();
let scale = winit_window.scale_factor();
Expand All @@ -115,6 +114,7 @@ impl Screen {
padding_y_bottom += config.fonts.size
}

#[allow(unused_mut)]
let mut padding_y_top = constants::PADDING_Y;

#[cfg(not(target_os = "macos"))]
Expand All @@ -124,14 +124,6 @@ impl Screen {
}
}

if config.navigation.is_native() {
if native_tab_id.is_some() {
padding_y_top *= 2.0;
}

padding_y_top += 2.0;
}

let sugarloaf_layout = SugarloafLayout::new(
size.width as f32,
size.height as f32,
Expand Down Expand Up @@ -164,7 +156,7 @@ impl Screen {
let clipboard = unsafe { Clipboard::new(raw_display_handle) };

let bindings = bindings::default_key_bindings(
config.bindings.keys.clone(),
config.bindings.keys.to_owned(),
config.navigation.is_plain(),
);
let ime = Ime::new();
Expand All @@ -173,21 +165,17 @@ impl Screen {
let is_native = config.navigation.is_native();
let context_manager_config = context::ContextManagerConfig {
use_current_path: config.navigation.use_current_path,
shell: config.shell.clone(),
shell: config.shell.to_owned(),
spawn_performer: true,
use_fork: config.use_fork,
working_dir: config.working_dir.clone(),
working_dir: config.working_dir.to_owned(),
is_collapsed,
is_native,
// When navigation is collapsed and does not contain any color rule
// does not make sense fetch for foreground process names
should_update_titles: !(is_collapsed
|| is_native && config.navigation.color_automation.is_empty()),
&& config.navigation.color_automation.is_empty()),
};
// let default_cursor_style = CursorStyle {
// shape: state.get_cursor_state(),
// blinking: config.blinking_cursor,
// };
let context_manager = context::ContextManager::start(
(sugarloaf.layout.width_u32, sugarloaf.layout.height_u32),
(sugarloaf.layout.columns, sugarloaf.layout.lines),
Expand Down Expand Up @@ -274,28 +262,19 @@ impl Screen {

#[inline]
#[cfg(target_os = "macos")]
pub fn update_top_y_for_native_tabs(&mut self, tab_num: usize) {
if !self.context_manager.config.is_native {
return;
}

pub fn should_reload_with_updated_margin_top_y(&mut self, tab_num: usize) -> bool {
let expected = if tab_num > 1 {
constants::PADDING_Y_WITH_MANY_NATIVE_TAB
} else {
constants::PADDING_Y_WITH_SINGLE_NATIVE_TAB
};

if self.sugarloaf.layout.margin.top_y == expected {
return;
let should_reload = self.sugarloaf.layout.margin.top_y != expected;
if should_reload {
self.sugarloaf.layout.set_margin_top_y(expected);
}

self.sugarloaf.layout.set_top_y_for_native_tabs(expected);

let width = self.sugarloaf.layout.width_u32 as u16;
let height = self.sugarloaf.layout.height_u32 as u16;
let columns = self.sugarloaf.layout.columns;
let lines = self.sugarloaf.layout.lines;
self.resize_all_contexts(width, height, columns, lines);
should_reload
}

/// update_config is triggered in any configuration file update
Expand Down Expand Up @@ -1253,9 +1232,6 @@ impl Screen {

#[inline]
pub fn selection_is_empty(&self) -> bool {
// let terminal = self.context_manager.current().terminal.lock();
// let is_empty = terminal.selection.is_none();
// drop(terminal);
self.state.selection_range.is_none()
}

Expand Down
16 changes: 13 additions & 3 deletions rio/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,20 @@ impl Sequencer {

#[cfg(target_os = "macos")]
{
if route.window.screen.context_manager.config.is_native {
route.window.screen.update_top_y_for_native_tabs(
route.window.winit_window.num_tabs(),
if route.window.screen.context_manager.config.is_native
&& route
.window
.screen
.should_reload_with_updated_margin_top_y(
route.window.winit_window.num_tabs(),
)
{
route.update_config(
&self.config,
&self.router.font_database,
);
*control_flow = ControlFlow::Wait;
return;
}
}

Expand Down
8 changes: 6 additions & 2 deletions sugarloaf/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ impl SugarloafLayout {
layout
}

#[inline]
pub fn rescale(&mut self, scale_factor: f32) -> &mut Self {
self.scale_factor = scale_factor;
self
}

#[inline]
pub fn resize(&mut self, width: u32, height: u32) -> &mut Self {
self.width_u32 = width;
self.height_u32 = height;
Expand Down Expand Up @@ -153,6 +155,7 @@ impl SugarloafLayout {
false
}

#[inline]
pub fn update(&mut self) -> &mut Self {
update_styles(self);
let (columns, lines) = compute(
Expand All @@ -169,6 +172,7 @@ impl SugarloafLayout {
self
}

#[inline]
pub fn update_columns_lines_per_font_bound(&mut self, font_bound: f32) {
self.font_bound = font_bound / self.scale_factor;

Expand All @@ -192,9 +196,9 @@ impl SugarloafLayout {
}
}

pub fn set_top_y_for_native_tabs(&mut self, top_y: f32) {
#[inline]
pub fn set_margin_top_y(&mut self, top_y: f32) {
self.margin.top_y = top_y;
update_styles(self);
}

// This method will run over the new font and font_size
Expand Down

0 comments on commit 41e1cbc

Please sign in to comment.