config: store font names in Arc
This commit is contained in:
parent
ca134e683b
commit
d9eb14e2bc
6 changed files with 21 additions and 14 deletions
|
|
@ -13,7 +13,7 @@ use {
|
|||
output_schedule::map_cursor_hz,
|
||||
scale::Scale,
|
||||
state::{ConnectorData, DeviceHandlerData, DrmDevData, OutputData, State},
|
||||
theme::{Color, ThemeSized, DEFAULT_FONT},
|
||||
theme::{Color, ThemeSized},
|
||||
tree::{
|
||||
move_ws_to_output, ContainerNode, ContainerSplit, FloatNode, Node, NodeVisitorBase,
|
||||
OutputNode, TearingMode, VrrMode, WsMoveConfig,
|
||||
|
|
@ -57,7 +57,7 @@ use {
|
|||
},
|
||||
libloading::Library,
|
||||
log::Level,
|
||||
std::{cell::Cell, ops::Deref, rc::Rc, time::Duration},
|
||||
std::{cell::Cell, ops::Deref, rc::Rc, sync::Arc, time::Duration},
|
||||
thiserror::Error,
|
||||
uapi::{c, fcntl_dupfd_cloexec, OwnedFd},
|
||||
};
|
||||
|
|
@ -1525,15 +1525,18 @@ impl ConfigProxyHandler {
|
|||
}
|
||||
|
||||
fn handle_reset_font(&self) {
|
||||
*self.state.theme.font.borrow_mut() = DEFAULT_FONT.to_string();
|
||||
self.state
|
||||
.theme
|
||||
.font
|
||||
.set(self.state.theme.default_font.clone());
|
||||
}
|
||||
|
||||
fn handle_set_font(&self, font: &str) {
|
||||
*self.state.theme.font.borrow_mut() = font.to_string();
|
||||
self.state.theme.font.set(Arc::new(font.to_string()));
|
||||
}
|
||||
|
||||
fn handle_get_font(&self) {
|
||||
let font = self.state.theme.font.borrow_mut().clone();
|
||||
let font = self.state.theme.font.get().to_string();
|
||||
self.respond(Response::GetFont { font });
|
||||
}
|
||||
|
||||
|
|
|
|||
14
src/theme.rs
14
src/theme.rs
|
|
@ -1,7 +1,6 @@
|
|||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
cmp::Ordering,
|
||||
ops::Mul,
|
||||
use {
|
||||
crate::utils::clonecell::CloneCell,
|
||||
std::{cell::Cell, cmp::Ordering, ops::Mul, sync::Arc},
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
|
|
@ -290,15 +289,18 @@ pub const DEFAULT_FONT: &str = "monospace 8";
|
|||
pub struct Theme {
|
||||
pub colors: ThemeColors,
|
||||
pub sizes: ThemeSizes,
|
||||
pub font: RefCell<String>,
|
||||
pub font: CloneCell<Arc<String>>,
|
||||
pub default_font: Arc<String>,
|
||||
}
|
||||
|
||||
impl Default for Theme {
|
||||
fn default() -> Self {
|
||||
let default_font = Arc::new(DEFAULT_FONT.to_string());
|
||||
Self {
|
||||
colors: Default::default(),
|
||||
sizes: Default::default(),
|
||||
font: RefCell::new(DEFAULT_FONT.to_string()),
|
||||
font: CloneCell::new(default_font.clone()),
|
||||
default_font,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -673,7 +673,7 @@ impl ContainerNode {
|
|||
let theme = &self.state.theme;
|
||||
let th = theme.sizes.title_height.get();
|
||||
let bw = theme.sizes.border_width.get();
|
||||
let font = theme.font.borrow_mut();
|
||||
let font = theme.font.get();
|
||||
let cwidth = self.width.get();
|
||||
let cheight = self.height.get();
|
||||
let ctx = self.state.render_ctx.get();
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ impl FloatNode {
|
|||
false => theme.colors.unfocused_title_text.get(),
|
||||
};
|
||||
let bw = theme.sizes.border_width.get();
|
||||
let font = theme.font.borrow_mut();
|
||||
let font = theme.font.get();
|
||||
let title = self.title.borrow_mut();
|
||||
let pos = self.position.get();
|
||||
if pos.width() <= 2 * bw || title.is_empty() {
|
||||
|
|
|
|||
|
|
@ -377,7 +377,7 @@ impl OutputNode {
|
|||
rd.active_workspace = None;
|
||||
rd.status = None;
|
||||
let mut pos = 0;
|
||||
let font = self.state.theme.font.borrow_mut();
|
||||
let font = self.state.theme.font.get();
|
||||
let theme = &self.state.theme;
|
||||
let th = theme.sizes.title_height.get();
|
||||
let scale = self.global.persistent.scale.get();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use {
|
|||
fmt::{Debug, Formatter},
|
||||
mem,
|
||||
rc::{Rc, Weak},
|
||||
sync::Arc,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -83,6 +84,7 @@ unsafe impl<T: UnsafeCellCloneSafe> UnsafeCellCloneSafe for Option<T> {}
|
|||
|
||||
unsafe impl<T: ?Sized> UnsafeCellCloneSafe for Rc<T> {}
|
||||
unsafe impl<T: ?Sized> UnsafeCellCloneSafe for Weak<T> {}
|
||||
unsafe impl<T: ?Sized> UnsafeCellCloneSafe for Arc<T> {}
|
||||
|
||||
unsafe impl<T> UnsafeCellCloneSafe for NodeRef<T> {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue