From d043f45b0f05aa9cfd1d1710687c297409f5f0b3 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 31 Jan 2024 15:05:21 -0700 Subject: [PATCH] Fix selection when using window background as terminal background --- src/main.rs | 16 +++++++++++++--- src/terminal.rs | 9 +++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 36ebba1..3c0a1bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use cosmic::{ futures::SinkExt, keyboard::{Event as KeyEvent, KeyCode, Modifiers}, subscription::{self, Subscription}, - window, Alignment, Event, Length, Limits, Padding, Point, + window, Alignment, Color, Event, Length, Limits, Padding, Point, }, style, widget::{self, button, container, pane_grid, segmented_button, PaneGrid}, @@ -25,7 +25,7 @@ use std::{ any::TypeId, collections::{BTreeMap, BTreeSet, HashMap}, env, process, - sync::Mutex, + sync::{atomic::Ordering, Mutex}, time::Duration, }; use tokio::sync::mpsc; @@ -1413,7 +1413,17 @@ impl Application for App { /// Creates a view after each update. fn view(&self) -> Element { - let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing; + let cosmic_theme = self.core().system_theme().cosmic(); + let cosmic_theme::Spacing { space_xxs, .. } = cosmic_theme.spacing; + { + let color = Color::from(cosmic_theme.bg_color()); + let bytes = color.into_rgba8(); + let data = (bytes[0] as u32) + | ((bytes[1] as u32) << 8) + | ((bytes[2] as u32) << 16) + | 0xFF000000; + terminal::WINDOW_BG_COLOR.store(data, Ordering::SeqCst); + } let pane_grid = PaneGrid::new(&self.pane_model.panes, |pane, tab_model, _is_maximized| { let mut tab_column = widget::column::with_capacity(1); diff --git a/src/terminal.rs b/src/terminal.rs index 272fbad..36f0e4d 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -28,7 +28,10 @@ use std::{ borrow::Cow, collections::HashMap, mem, - sync::{Arc, Weak}, + sync::{ + atomic::{AtomicU32, Ordering}, + Arc, Weak, + }, time::Instant, }; use tokio::sync::mpsc; @@ -98,6 +101,8 @@ fn as_dim(mut color: Color) -> Color { color } +pub static WINDOW_BG_COLOR: AtomicU32 = AtomicU32::new(0xFF000000); + fn convert_color(colors: &Colors, color: Color) -> cosmic_text::Color { let rgb = match color { Color::Named(named_color) => match colors[named_color] { @@ -105,7 +110,7 @@ fn convert_color(colors: &Colors, color: Color) -> cosmic_text::Color { None => match named_color { NamedColor::Background => { // Allow using an unset background - return cosmic_text::Color(0); + return cosmic_text::Color(WINDOW_BG_COLOR.load(Ordering::SeqCst)); } _ => { log::warn!("missing named color {:?}", named_color);