Skip to content

Commit 2272449

Browse files
committed
feat: allow configuring terminal pane borders
1 parent 8ae5918 commit 2272449

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
@@ -429,6 +429,7 @@ pub enum Message {
429429
SelectAll(Option<segmented_button::Entity>),
430430
ShowAdvancedFontSettings(bool),
431431
ShowHeaderBar(bool),
432+
ShowPaneBorders(bool),
432433
SyntaxTheme(ColorSchemeKind, usize),
433434
SystemThemeChange,
434435
TabActivate(segmented_button::Entity),
@@ -1478,10 +1479,16 @@ impl App {
14781479
font_section = font_section.add(advanced_font_settings());
14791480
}
14801481

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

14861493
let advanced_section = widget::settings::section().title(fl!("advanced")).add(
14871494
widget::settings::item::builder(fl!("show-headerbar"))
@@ -2720,6 +2727,11 @@ impl Application for App {
27202727
return self.update_config();
27212728
}
27222729
}
2730+
Message::ShowPaneBorders(show_pane_borders) => {
2731+
if show_pane_borders != self.config.show_pane_borders {
2732+
config_set!(show_pane_borders, show_pane_borders);
2733+
}
2734+
}
27232735
Message::UseBrightBold(use_bright_bold) => {
27242736
if use_bright_bold != self.config.use_bright_bold {
27252737
config_set!(use_bright_bold, use_bright_bold);
@@ -3248,8 +3260,22 @@ impl Application for App {
32483260

32493261
/// Creates a view after each update.
32503262
fn view(&self) -> Element<'_, Self::Message> {
3251-
let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing;
3252-
3263+
let cosmic = self.core().system_theme().cosmic();
3264+
let cosmic_theme::Spacing {
3265+
space_xxxs,
3266+
space_xxs,
3267+
..
3268+
} = cosmic.spacing;
3269+
3270+
let show_pane_borders =
3271+
self.config.show_pane_borders && self.pane_model.panes.panes.len() > 1;
3272+
let pane_corner_radius: iced::border::Radius = {
3273+
let pad = f32::from(space_xxxs) / 2.0;
3274+
cosmic
3275+
.radius_s()
3276+
.map(|r| if r > 0.0 { r + pad } else { 0.0 })
3277+
.into()
3278+
};
32533279
let pane_grid = PaneGrid::new(&self.pane_model.panes, |pane, tab_model, _is_maximized| {
32543280
let mut tab_column = widget::column::with_capacity(1);
32553281

@@ -3301,7 +3327,8 @@ impl Application for App {
33013327
.opacity(self.config.opacity_ratio())
33023328
.padding(space_xxs)
33033329
.sharp_corners(self.core.window.sharp_corners)
3304-
.show_headerbar(self.config.show_headerbar);
3330+
.show_headerbar(self.config.show_headerbar)
3331+
.pane_border_radius(show_pane_borders.then_some(pane_corner_radius));
33053332

33063333
if self.config.focus_follow_mouse {
33073334
terminal_box = terminal_box.on_mouse_enter(move || Message::MouseEnter(pane));
@@ -3412,7 +3439,21 @@ impl Application for App {
34123439
.on_drag(Message::PaneDragged);
34133440

34143441
//TODO: apply window border radius xs at bottom of window
3415-
pane_grid.into()
3442+
if show_pane_borders {
3443+
let bg_divider = Color::from(cosmic.bg_divider());
3444+
let pane_grid = pane_grid.spacing(space_xxxs);
3445+
widget::container(pane_grid)
3446+
.width(Length::Fill)
3447+
.height(Length::Fill)
3448+
.padding(space_xxxs)
3449+
.style(move |_theme| widget::container::Style {
3450+
background: Some(bg_divider.into()),
3451+
..Default::default()
3452+
})
3453+
.into()
3454+
} else {
3455+
pane_grid.into()
3456+
}
34163457
}
34173458

34183459
fn system_theme_update(

src/terminal_box.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use cosmic::{
1919
window::RedrawRequest,
2020
},
2121
iced_core::{
22-
Border, Shell,
22+
Border, Shell, border::Radius,
2323
clipboard::Clipboard,
2424
keyboard::key::Named,
2525
layout::{self, Layout},
@@ -112,6 +112,7 @@ pub struct TerminalBox<'a, Message> {
112112
border: Border,
113113
padding: Padding,
114114
show_headerbar: bool,
115+
pane_border_radius: Option<Radius>,
115116
click_timing: Duration,
116117
context_menu: Option<Point>,
117118
on_context_menu: Option<Box<dyn Fn(Option<MenuState>) -> Message + 'a>>,
@@ -138,6 +139,7 @@ where
138139
border: Border::default(),
139140
padding: Padding::new(0.0),
140141
show_headerbar: true,
142+
pane_border_radius: None,
141143
click_timing: Duration::from_millis(500),
142144
context_menu: None,
143145
on_context_menu: None,
@@ -174,6 +176,11 @@ where
174176
self
175177
}
176178

179+
pub fn pane_border_radius(mut self, pane_border_radius: Option<Radius>) -> Self {
180+
self.pane_border_radius = pane_border_radius;
181+
self
182+
}
183+
177184
pub fn click_timing(mut self, click_timing: Duration) -> Self {
178185
self.click_timing = click_timing;
179186
self
@@ -369,13 +376,22 @@ where
369376
let state = tree.state.downcast_ref::<State>();
370377

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

381397
let view_position = layout.position() + [self.padding.left, self.padding.top].into();
@@ -394,11 +410,7 @@ where
394410
Quad {
395411
bounds: layout.bounds(),
396412
border: Border {
397-
radius: if self.show_headerbar {
398-
[0.0, 0.0, corner_radius[2], corner_radius[3]].into()
399-
} else {
400-
corner_radius.into()
401-
},
413+
radius: border_radius,
402414
width: self.border.width,
403415
color: self.border.color,
404416
},
@@ -438,11 +450,7 @@ where
438450
Quad {
439451
bounds: layout.bounds(),
440452
border: Border {
441-
radius: if self.show_headerbar {
442-
[0.0, 0.0, corner_radius[2], corner_radius[3]].into()
443-
} else {
444-
corner_radius.into()
445-
},
453+
radius: border_radius,
446454
width: self.border.width,
447455
color: self.border.color,
448456
},

0 commit comments

Comments
 (0)