Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e11c8cd
fix(linux-editor): draw the style scheme the user picked, not its lig…
sedax90 Nov 8, 2026
a7dd976
docs(linux-editor): add the changelog entry
sedax90 Nov 8, 2026
293e213
feat(linux-grid): draw the data grid in the editor scheme's colours
sedax90 Nov 8, 2026
d25a532
fix(linux-editor): keep scheme choices and content colors consistent
datlechin Nov 8, 2026
a6b07ea
docs(linux-grid): add the changelog entry
sedax90 Nov 8, 2026
93bd165
fix(linux-editor): scope the scheme handler and exercise numeric plac…
datlechin Nov 8, 2026
1e7fb59
chore(linux-grid): build scheme colors on the shared editor resolver
datlechin Nov 8, 2026
cf1d384
fix(linux-grid): keep scheme colors readable and scoped to each grid
datlechin Nov 8, 2026
caa3bd0
fix(linux-grid): satisfy scheme module and import lints
datlechin Nov 8, 2026
54177b6
fix(linux-grid): keep modified text in the scheme palette
datlechin Nov 8, 2026
3323409
test(linux-grid): load app styles in isolated widget suites
datlechin Nov 8, 2026
f4a5d5c
Merge branch 'main' into feat/linux-grid-scheme-colors
datlechin Nov 9, 2026
fd84fb7
fix(linux-workspace): drop the unfulfilled too_many_lines expectation…
datlechin Nov 9, 2026
b7dbd99
fix(linux-grid): colour the inline editor inside its cell viewport
datlechin Nov 9, 2026
be9250f
Merge remote-tracking branch 'origin/main' into feat/linux-grid-schem…
datlechin Nov 9, 2026
bf51220
fix(linux-grid): pass the NULL text to field_value in the row details…
datlechin Nov 9, 2026
4c1d746
fix(linux-grid): pass the NULL text when the row details filter fields
datlechin Nov 9, 2026
d93303e
Merge remote-tracking branch 'origin/main' into feat/linux-grid-schem…
datlechin Nov 9, 2026
9bca285
Merge remote-tracking branch 'origin/main' into feat/linux-grid-schem…
datlechin Nov 10, 2026
8b764d1
Merge remote-tracking branch 'origin/main' into feat/linux-grid-schem…
datlechin Nov 10, 2026
8533395
Merge branch 'main' into feat/linux-grid-scheme-colors
datlechin Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions linux/changelog.d/4128.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The data grid draws in the colours of the editor's style scheme.
2 changes: 2 additions & 0 deletions linux/crates/app/src/ui/data_grid/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub struct DataGrid {
pub(super) display_watch: RefCell<Option<HandlerGuard>>,
pub(super) applied_marks: Cell<Option<bool>>,
pub(super) applied_null: RefCell<Option<String>>,
pub(super) scheme_style: RefCell<Option<super::scheme_colors::SchemeStyle>>,
pub(super) applied_date_format: Cell<Option<tablepro_linux_platform::settings::DateFormat>>,
pub(super) cell_font: RefCell<Option<super::cell_font::CellFont>>,
}
Expand Down Expand Up @@ -139,6 +140,7 @@ impl ObjectImpl for DataGrid {
drop(self.font_watch.take());
drop(self.cell_font.take());
drop(self.display_watch.take());
drop(self.scheme_style.take());
if let Some(menus) = self.menus.get() {
menus.unparent();
}
Expand Down
2 changes: 2 additions & 0 deletions linux/crates/app/src/ui/data_grid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod reversed_list;
mod row_detail;
mod row_json_dialog;
mod row_number_column;
mod scheme_colors;
mod selection;
mod selection_summary;
mod server_sorter;
Expand Down Expand Up @@ -95,6 +96,7 @@ impl DataGrid {
imp.detail_pane.attach(&grid);
grid.watch_display_settings();
grid.set_columns(columns, sorting, rules);
scheme_colors::follow(&grid);
grid.watch_fonts();
grid
}
Expand Down
207 changes: 207 additions & 0 deletions linux/crates/app/src/ui/data_grid/scheme_colors/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
use gtk4::{self as gtk, gdk, glib};
use libadwaita as adw;
use tablepro_linux_platform::settings::keys;

use super::DataGrid;
use crate::ui::handler_guard::HandlerGuard;
use crate::ui::style_scheme_resolver;

#[derive(Debug, Clone)]
struct SelectionColors {
background: gdk::RGBA,
foreground: gdk::RGBA,
}

impl SelectionColors {
fn from_style(style: Option<sourceview5::Style>, background: gdk::RGBA, foreground: gdk::RGBA) -> Self {
let (selected_background, selected_foreground) = colors(style);
let Some(mut selected_background) = selected_background else {
return Self {
background: foreground,
foreground: background,
};
};
// GtkSourceView's fix_broken_selection keeps unchanged text readable
// over a selection that supplies only an opaque background.
if selected_foreground.is_none() && selected_background.alpha() >= 1.0 {
selected_background.set_alpha(0.3);
}
Self {
background: selected_background,
foreground: selected_foreground.unwrap_or(foreground),
}
}
}

#[derive(Debug, Clone)]
struct Palette {
background: gdk::RGBA,
foreground: gdk::RGBA,
selection: SelectionColors,
unfocused_selection: SelectionColors,
}

impl Palette {
fn from_scheme(scheme: &sourceview5::StyleScheme) -> Option<Self> {
let (background, foreground) = colors(scheme.style("text"));
// A partial pair could put scheme text on the opposite desktop color.
let (background, foreground) = (background?, foreground?);
let selection = scheme.style("selection");
let unfocused = scheme.style("selection-unfocused").or_else(|| selection.clone());
Some(Self {
background,
foreground,
selection: SelectionColors::from_style(selection, background, foreground),
unfocused_selection: SelectionColors::from_style(unfocused, background, foreground),
})
}

fn css(&self, class: &str) -> String {
let Self {
background,
foreground,
selection,
unfocused_selection,
} = self;
let (selected_background, selected_foreground) = (&selection.background, &selection.foreground);
let (unfocused_background, unfocused_foreground) =
(&unfocused_selection.background, &unfocused_selection.foreground);
// Native high-contrast styling takes precedence over a saved palette.
format!(
"@media (prefers-contrast: no-preference) {{
.{class} {{
--view-bg-color: {background};
--view-fg-color: {foreground};
--accent-color: currentColor;
color: var(--view-fg-color);
}}
columnview.{class} {{ background-color: var(--view-bg-color); }}
columnview.{class} > listview > row:selected {{
background-color: {selected_background};
color: {selected_foreground};
}}
columnview.{class}:not(:focus-within) > listview > row:selected {{
background-color: {unfocused_background};
color: {unfocused_foreground};
}}
columnview.{class} tp-grid-cell > label.warning {{ color: inherit; }}
columnview.{class} tp-grid-cell > viewport > text {{
background-color: var(--view-bg-color);
color: var(--view-fg-color);
}}
columnview.{class} tp-grid-cell > viewport > text selection {{
background-color: {selected_background};
color: {selected_foreground};
}}
columnview.{class} tp-grid-cell > viewport > text:not(:focus) selection {{
background-color: {unfocused_background};
color: {unfocused_foreground};
}}
columnview.{class} tp-grid-cell > viewport > text.error {{
background-color: var(--error-bg-color);
color: var(--error-fg-color);
}}
columnview.{class} tp-grid-cell > viewport > text.error selection {{
background-color: var(--error-fg-color);
color: var(--error-bg-color);
}}
}}"
)
}
}

fn colors(style: Option<sourceview5::Style>) -> (Option<gdk::RGBA>, Option<gdk::RGBA>) {
let tag = gtk::TextTag::new(None);
if let Some(style) = style {
style.apply(&tag);
}
// Transparent selection foregrounds tell GtkSourceView to keep syntax
// colors; CSS text needs an actual foreground instead.
let visible = |color: &gdk::RGBA| color.alpha() > 0.0;
(
tag.background_rgba().filter(visible),
tag.foreground_rgba().filter(visible),
)
}

pub(super) struct SchemeStyle {
display: gdk::Display,
provider: gtk::CssProvider,
class: String,
_handlers: Vec<HandlerGuard>,
}

impl Drop for SchemeStyle {
fn drop(&mut self) {
gtk::style_context_remove_provider_for_display(&self.display, &self.provider);
}
}

pub(super) fn follow(grid: &DataGrid) {
let Some(settings) = grid.config().map(|config| config.settings.clone()) else {
return;
};
let display = grid.display();
let provider = gtk::CssProvider::new();
let class = format!("tp-grid-scheme-{}", uuid::Uuid::new_v4().simple());
grid.column_view().add_css_class(&class);
grid.imp().empty_page.add_css_class(&class);
gtk::style_context_add_provider_for_display(&display, &provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION + 1);

// GSettings emits changes only after a read while a handler is connected.
let setting_handler = settings.gio().connect_changed(
Some(keys::STYLE_SCHEME),
glib::clone!(
#[weak]
grid,
move |_, _| refresh(&grid)
),
);
let style = adw::StyleManager::default();
let dark_handler = style.connect_dark_notify(glib::clone!(
#[weak]
grid,
move |_| refresh(&grid)
));
let contrast_handler = style.connect_high_contrast_notify(glib::clone!(
#[weak]
grid,
move |_| refresh(&grid)
));
grid.imp().scheme_style.replace(Some(SchemeStyle {
display,
provider,
class,
_handlers: vec![
HandlerGuard::new(settings.gio(), setting_handler),
HandlerGuard::new(&style, dark_handler),
HandlerGuard::new(&style, contrast_handler),
],
}));
refresh(grid);
}

fn refresh(grid: &DataGrid) {
let binding = grid.imp().scheme_style.borrow();
let (Some(binding), Some(config)) = (binding.as_ref(), grid.config()) else {
return;
};
binding
.provider
.set_prefers_contrast(if adw::StyleManager::default().is_high_contrast() {
gtk::InterfaceContrast::More
} else {
gtk::InterfaceContrast::NoPreference
});
let css = style_scheme_resolver::scheme(&config.settings.style_scheme())
.as_ref()
.and_then(Palette::from_scheme)
.map(|palette| palette.css(&binding.class))
.unwrap_or_default();
binding.provider.load_from_string(&css);
}

#[cfg(test)]
mod tests;
Loading