Skip to content

Commit 3c13e05

Browse files
committed
feat: allow configuring terminal pane borders
1 parent aa0785a commit 3c13e05

4 files changed

Lines changed: 76 additions & 24 deletions

File tree

i18n/en/cosmic_term.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use-bright-bold = Make bold text brighter
5858
### Splits
5959
splits = Splits
6060
focus-follow-mouse = Typing focus follows mouse
61+
show-pane-borders = Show pane borders
6162
6263
### Advanced
6364
advanced = Advanced

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ pub struct Config {
231231
pub opacity: u8,
232232
pub profiles: BTreeMap<ProfileId, Profile>,
233233
pub show_headerbar: bool,
234+
pub show_pane_borders: bool,
234235
pub use_bright_bold: bool,
235236
pub syntax_theme_dark: String,
236237
pub syntax_theme_light: String,
@@ -257,6 +258,7 @@ impl Default for Config {
257258
opacity: 100,
258259
profiles: BTreeMap::new(),
259260
show_headerbar: true,
261+
show_pane_borders: false,
260262
syntax_theme_dark: COSMIC_THEME_DARK.to_string(),
261263
syntax_theme_light: COSMIC_THEME_LIGHT.to_string(),
262264
use_bright_bold: false,

src/main.rs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ pub enum Message {
425425
SelectAll(Option<segmented_button::Entity>),
426426
ShowAdvancedFontSettings(bool),
427427
ShowHeaderBar(bool),
428+
ShowPaneBorders(bool),
428429
SyntaxTheme(ColorSchemeKind, usize),
429430
SystemThemeChange,
430431
TabActivate(segmented_button::Entity),
@@ -1481,10 +1482,16 @@ impl App {
14811482
font_section = font_section.add(advanced_font_settings());
14821483
}
14831484

1484-
let splits_section = widget::settings::section().title(fl!("splits")).add(
1485-
widget::settings::item::builder(fl!("focus-follow-mouse"))
1486-
.toggler(self.config.focus_follow_mouse, Message::FocusFollowMouse),
1487-
);
1485+
let splits_section = widget::settings::section()
1486+
.title(fl!("splits"))
1487+
.add(
1488+
widget::settings::item::builder(fl!("focus-follow-mouse"))
1489+
.toggler(self.config.focus_follow_mouse, Message::FocusFollowMouse),
1490+
)
1491+
.add(
1492+
widget::settings::item::builder(fl!("show-pane-borders"))
1493+
.toggler(self.config.show_pane_borders, Message::ShowPaneBorders),
1494+
);
14881495

14891496
let advanced_section = widget::settings::section().title(fl!("advanced")).add(
14901497
widget::settings::item::builder(fl!("show-headerbar"))
@@ -2719,6 +2726,11 @@ impl Application for App {
27192726
return self.update_config();
27202727
}
27212728
}
2729+
Message::ShowPaneBorders(show_pane_borders) => {
2730+
if show_pane_borders != self.config.show_pane_borders {
2731+
config_set!(show_pane_borders, show_pane_borders);
2732+
}
2733+
}
27222734
Message::UseBrightBold(use_bright_bold) => {
27232735
if use_bright_bold != self.config.use_bright_bold {
27242736
config_set!(use_bright_bold, use_bright_bold);
@@ -3350,8 +3362,22 @@ impl Application for App {
33503362

33513363
/// Creates a view after each update.
33523364
fn view(&self) -> Element<'_, Self::Message> {
3353-
let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing;
3354-
3365+
let cosmic = self.core().system_theme().cosmic();
3366+
let cosmic_theme::Spacing {
3367+
space_xxxs,
3368+
space_xxs,
3369+
..
3370+
} = cosmic.spacing;
3371+
3372+
let show_pane_borders =
3373+
self.config.show_pane_borders && self.pane_model.panes.panes.len() > 1;
3374+
let pane_corner_radius: iced::border::Radius = {
3375+
let pad = f32::from(space_xxxs) / 2.0;
3376+
cosmic
3377+
.radius_s()
3378+
.map(|r| if r > 0.0 { r + pad } else { 0.0 })
3379+
.into()
3380+
};
33553381
let pane_grid = PaneGrid::new(&self.pane_model.panes, |pane, tab_model, _is_maximized| {
33563382
let mut tab_column = widget::column::with_capacity(1);
33573383

@@ -3403,7 +3429,8 @@ impl Application for App {
34033429
.opacity(self.config.opacity_ratio())
34043430
.padding(space_xxs)
34053431
.sharp_corners(self.core.window.sharp_corners)
3406-
.show_headerbar(self.config.show_headerbar);
3432+
.show_headerbar(self.config.show_headerbar)
3433+
.pane_border_radius(show_pane_borders.then_some(pane_corner_radius));
34073434

34083435
if self.config.focus_follow_mouse {
34093436
terminal_box = terminal_box.on_mouse_enter(move || Message::MouseEnter(pane));
@@ -3537,7 +3564,21 @@ impl Application for App {
35373564
.on_drag(Message::PaneDragged);
35383565

35393566
//TODO: apply window border radius xs at bottom of window
3540-
pane_grid.into()
3567+
if show_pane_borders {
3568+
let bg_divider = Color::from(cosmic.bg_divider());
3569+
let pane_grid = pane_grid.spacing(space_xxxs);
3570+
widget::container(pane_grid)
3571+
.width(Length::Fill)
3572+
.height(Length::Fill)
3573+
.padding(space_xxxs)
3574+
.style(move |_theme| widget::container::Style {
3575+
background: Some(bg_divider.into()),
3576+
..Default::default()
3577+
})
3578+
.into()
3579+
} else {
3580+
pane_grid.into()
3581+
}
35413582
}
35423583

35433584
fn system_theme_update(

src/terminal_box.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use cosmic::{
1111
Renderer,
1212
cosmic_theme::palette::{WithAlpha, blend::Compose},
1313
iced::core::{
14-
Border, Shell,
14+
Border, Shell, border::Radius,
1515
clipboard::Clipboard,
1616
keyboard::key::Named,
1717
layout::{self, Layout},
@@ -111,6 +111,7 @@ pub struct TerminalBox<'a, Message> {
111111
border: Border,
112112
padding: Padding,
113113
show_headerbar: bool,
114+
pane_border_radius: Option<Radius>,
114115
click_timing: Duration,
115116
context_menu: Option<Point>,
116117
on_context_menu: Option<Box<dyn Fn(Option<MenuState>) -> Message + 'a>>,
@@ -137,6 +138,7 @@ where
137138
border: Border::default(),
138139
padding: Padding::new(0.0),
139140
show_headerbar: true,
141+
pane_border_radius: None,
140142
click_timing: Duration::from_millis(500),
141143
context_menu: None,
142144
on_context_menu: None,
@@ -173,6 +175,11 @@ where
173175
self
174176
}
175177

178+
pub fn pane_border_radius(mut self, pane_border_radius: Option<Radius>) -> Self {
179+
self.pane_border_radius = pane_border_radius;
180+
self
181+
}
182+
176183
pub fn click_timing(mut self, click_timing: Duration) -> Self {
177184
self.click_timing = click_timing;
178185
self
@@ -368,13 +375,22 @@ where
368375
let state = tree.state.downcast_ref::<State>();
369376

370377
let cosmic_theme = theme.cosmic();
371-
// matches the corners to the window border
372-
let corner_radius = if self.sharp_corners {
378+
let corner_radius = if let Some(r) = self.pane_border_radius {
379+
r.into()
380+
} else if self.sharp_corners {
381+
// matches the corners to the window border
373382
cosmic_theme.radius_0()
374383
} else {
375-
cosmic_theme.radius_s()
376-
}
377-
.map(|x| if x < 4.0 { x - 1.0 } else { x + 3.0 });
384+
cosmic_theme
385+
.radius_s()
386+
.map(|x| if x < 4.0 { x - 1.0 } else { x + 3.0 })
387+
};
388+
// When there's a headerbar and no pane border, only round the bottom corners
389+
let border_radius: Radius = if self.show_headerbar && self.pane_border_radius.is_none() {
390+
[0.0, 0.0, corner_radius[2], corner_radius[3]].into()
391+
} else {
392+
corner_radius.into()
393+
};
378394
let scrollbar_w = f32::from(cosmic_theme.spacing.space_xxs);
379395

380396
let view_position = layout.position() + [self.padding.left, self.padding.top].into();
@@ -393,11 +409,7 @@ where
393409
Quad {
394410
bounds: layout.bounds(),
395411
border: Border {
396-
radius: if self.show_headerbar {
397-
[0.0, 0.0, corner_radius[2], corner_radius[3]].into()
398-
} else {
399-
corner_radius.into()
400-
},
412+
radius: border_radius,
401413
width: self.border.width,
402414
color: self.border.color,
403415
},
@@ -437,11 +449,7 @@ where
437449
Quad {
438450
bounds: layout.bounds(),
439451
border: Border {
440-
radius: if self.show_headerbar {
441-
[0.0, 0.0, corner_radius[2], corner_radius[3]].into()
442-
} else {
443-
corner_radius.into()
444-
},
452+
radius: border_radius,
445453
width: self.border.width,
446454
color: self.border.color,
447455
},

0 commit comments

Comments
 (0)