text: render text asynchronously
This commit is contained in:
parent
d9eb14e2bc
commit
12f358c0d9
12 changed files with 893 additions and 421 deletions
|
|
@ -4,6 +4,7 @@ use {
|
|||
cursor::KnownCursor,
|
||||
cursor_user::CursorUser,
|
||||
fixed::Fixed,
|
||||
gfx_api::GfxTexture,
|
||||
ifs::wl_seat::{
|
||||
collect_kb_foci, collect_kb_foci2,
|
||||
tablet::{TabletTool, TabletToolChanges, TabletToolId},
|
||||
|
|
@ -14,21 +15,23 @@ use {
|
|||
renderer::Renderer,
|
||||
scale::Scale,
|
||||
state::State,
|
||||
text::{self, TextTexture},
|
||||
text::TextTexture,
|
||||
tree::{
|
||||
walker::NodeVisitor, ContainingNode, Direction, FindTreeResult, FindTreeUsecase,
|
||||
FoundNode, Node, NodeId, ToplevelData, ToplevelNode, ToplevelNodeBase, WorkspaceNode,
|
||||
},
|
||||
utils::{
|
||||
asyncevent::AsyncEvent,
|
||||
clonecell::CloneCell,
|
||||
double_click_state::DoubleClickState,
|
||||
errorfmt::ErrorFmt,
|
||||
hash_map_ext::HashMapExt,
|
||||
linkedlist::{LinkedList, LinkedNode, NodeRef},
|
||||
numcell::NumCell,
|
||||
on_drop_event::OnDropEvent,
|
||||
rc_eq::rc_eq,
|
||||
scroller::Scroller,
|
||||
smallmap::{SmallMap, SmallMapMut},
|
||||
smallmap::SmallMapMut,
|
||||
threshold_counter::ThresholdCounter,
|
||||
},
|
||||
},
|
||||
|
|
@ -81,7 +84,7 @@ tree_id!(ContainerNodeId);
|
|||
pub struct ContainerTitle {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub tex: TextTexture,
|
||||
pub tex: Rc<dyn GfxTexture>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -109,7 +112,8 @@ pub struct ContainerNode {
|
|||
pub content_height: Cell<i32>,
|
||||
pub sum_factors: Cell<f64>,
|
||||
layout_scheduled: Cell<bool>,
|
||||
compute_render_data_scheduled: Cell<bool>,
|
||||
compute_render_positions_scheduled: Cell<bool>,
|
||||
render_titles_scheduled: Cell<bool>,
|
||||
num_children: NumCell<usize>,
|
||||
pub children: LinkedList<ContainerChild>,
|
||||
focus_history: LinkedList<NodeRef<ContainerChild>>,
|
||||
|
|
@ -134,7 +138,7 @@ pub struct ContainerChild {
|
|||
pub active: Cell<bool>,
|
||||
pub attention_requested: Cell<bool>,
|
||||
title: RefCell<String>,
|
||||
pub title_tex: SmallMap<Scale, TextTexture, 2>,
|
||||
pub title_tex: RefCell<SmallMapMut<Scale, TextTexture, 2>>,
|
||||
pub title_rect: Cell<Rect>,
|
||||
focus_history: Cell<Option<LinkedNode<NodeRef<ContainerChild>>>>,
|
||||
|
||||
|
|
@ -213,7 +217,8 @@ impl ContainerNode {
|
|||
content_height: Cell::new(0),
|
||||
sum_factors: Cell::new(1.0),
|
||||
layout_scheduled: Cell::new(false),
|
||||
compute_render_data_scheduled: Cell::new(false),
|
||||
compute_render_positions_scheduled: Cell::new(false),
|
||||
render_titles_scheduled: Cell::new(false),
|
||||
num_children: NumCell::new(1),
|
||||
children,
|
||||
focus_history: Default::default(),
|
||||
|
|
@ -351,7 +356,8 @@ impl ContainerNode {
|
|||
|
||||
pub fn on_colors_changed(self: &Rc<Self>) {
|
||||
// log::info!("on_colors_changed");
|
||||
self.schedule_compute_render_data();
|
||||
self.schedule_render_titles();
|
||||
self.schedule_compute_render_positions();
|
||||
}
|
||||
|
||||
fn damage(&self) {
|
||||
|
|
@ -387,7 +393,8 @@ impl ContainerNode {
|
|||
}
|
||||
self.state.tree_changed();
|
||||
// log::info!("perform_layout");
|
||||
self.schedule_compute_render_data();
|
||||
self.schedule_render_titles();
|
||||
self.schedule_compute_render_positions();
|
||||
}
|
||||
|
||||
fn perform_mono_layout(self: &Rc<Self>, child: &ContainerChild) {
|
||||
|
|
@ -660,23 +667,115 @@ impl ContainerNode {
|
|||
self.tl_title_changed();
|
||||
}
|
||||
|
||||
pub fn schedule_compute_render_data(self: &Rc<Self>) {
|
||||
if !self.compute_render_data_scheduled.replace(true) {
|
||||
self.state.pending_container_render_data.push(self.clone());
|
||||
pub fn schedule_render_titles(self: &Rc<Self>) {
|
||||
if !self.render_titles_scheduled.replace(true) {
|
||||
self.state.pending_container_render_title.push(self.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_render_data(&self) {
|
||||
self.compute_render_data_scheduled.set(false);
|
||||
fn render_titles(&self) -> Rc<AsyncEvent> {
|
||||
let on_completed = Rc::new(OnDropEvent::default());
|
||||
let Some(ctx) = self.state.render_ctx.get() else {
|
||||
return on_completed.event();
|
||||
};
|
||||
let theme = &self.state.theme;
|
||||
let th = theme.sizes.title_height.get();
|
||||
let font = theme.font.get();
|
||||
let last_active = self.focus_history.last().map(|v| v.node.node_id());
|
||||
let have_active = self.children.iter().any(|c| c.active.get());
|
||||
let scales = self.state.scales.lock();
|
||||
for child in self.children.iter() {
|
||||
let rect = child.title_rect.get();
|
||||
let color = if child.active.get() {
|
||||
theme.colors.focused_title_text.get()
|
||||
} else if child.attention_requested.get() {
|
||||
theme.colors.unfocused_title_text.get()
|
||||
} else if !have_active && last_active == Some(child.node.node_id()) {
|
||||
theme.colors.focused_inactive_title_text.get()
|
||||
} else {
|
||||
theme.colors.unfocused_title_text.get()
|
||||
};
|
||||
let title = child.title.borrow_mut();
|
||||
let tt = &mut *child.title_tex.borrow_mut();
|
||||
for (scale, _) in scales.iter() {
|
||||
let tex = tt
|
||||
.get_or_insert_with(*scale, || TextTexture::new(&self.state.cpu_worker, &ctx));
|
||||
let mut th = th;
|
||||
let mut scalef = None;
|
||||
let mut width = rect.width();
|
||||
if *scale != 1 {
|
||||
let scale = scale.to_f64();
|
||||
th = (th as f64 * scale).round() as _;
|
||||
width = (width as f64 * scale).round() as _;
|
||||
scalef = Some(scale);
|
||||
}
|
||||
tex.schedule_render(
|
||||
on_completed.clone(),
|
||||
1,
|
||||
None,
|
||||
width,
|
||||
th,
|
||||
1,
|
||||
&font,
|
||||
title.deref(),
|
||||
color,
|
||||
true,
|
||||
false,
|
||||
scalef,
|
||||
);
|
||||
}
|
||||
}
|
||||
on_completed.event()
|
||||
}
|
||||
|
||||
fn compute_title_data(&self) {
|
||||
let rd = &mut *self.render_data.borrow_mut();
|
||||
for (_, v) in rd.titles.iter_mut() {
|
||||
v.clear();
|
||||
}
|
||||
let abs_x = self.abs_x1.get();
|
||||
let abs_y = self.abs_y1.get();
|
||||
for child in self.children.iter() {
|
||||
let rect = child.title_rect.get();
|
||||
if self.toplevel_data.visible.get() {
|
||||
self.state.damage(rect.move_(abs_x, abs_y));
|
||||
}
|
||||
let title = child.title.borrow_mut();
|
||||
let tt = &*child.title_tex.borrow();
|
||||
for (scale, tex) in tt {
|
||||
if let Err(e) = tex.flip() {
|
||||
log::error!("Could not render title {}: {}", title, ErrorFmt(e));
|
||||
}
|
||||
if let Some(tex) = tex.texture() {
|
||||
let titles = rd.titles.get_or_default_mut(*scale);
|
||||
titles.push(ContainerTitle {
|
||||
x: rect.x1(),
|
||||
y: rect.y1(),
|
||||
tex,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
rd.titles.remove_if(|_, v| v.is_empty());
|
||||
}
|
||||
|
||||
fn schedule_compute_render_positions(self: &Rc<Self>) {
|
||||
if !self.compute_render_positions_scheduled.replace(true) {
|
||||
self.state
|
||||
.pending_container_render_positions
|
||||
.push(self.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_render_positions(&self) {
|
||||
self.compute_render_positions_scheduled.set(false);
|
||||
let mut rd = self.render_data.borrow_mut();
|
||||
let rd = rd.deref_mut();
|
||||
let theme = &self.state.theme;
|
||||
let th = theme.sizes.title_height.get();
|
||||
let bw = theme.sizes.border_width.get();
|
||||
let font = theme.font.get();
|
||||
let cwidth = self.width.get();
|
||||
let cheight = self.height.get();
|
||||
let ctx = self.state.render_ctx.get();
|
||||
for (_, v) in rd.titles.iter_mut() {
|
||||
v.clear();
|
||||
}
|
||||
|
|
@ -690,7 +789,6 @@ impl ContainerNode {
|
|||
let mono = self.mono_child.is_some();
|
||||
let split = self.split.get();
|
||||
let have_active = self.children.iter().any(|c| c.active.get());
|
||||
let scales = self.state.scales.lock();
|
||||
let abs_x = self.abs_x1.get();
|
||||
let abs_y = self.abs_y1.get();
|
||||
for (i, child) in self.children.iter().enumerate() {
|
||||
|
|
@ -708,64 +806,28 @@ impl ContainerNode {
|
|||
};
|
||||
rd.border_rects.push(rect.unwrap());
|
||||
}
|
||||
let color = if child.active.get() {
|
||||
if child.active.get() {
|
||||
rd.active_title_rects.push(rect);
|
||||
theme.colors.focused_title_text.get()
|
||||
} else if child.attention_requested.get() {
|
||||
rd.attention_title_rects.push(rect);
|
||||
theme.colors.unfocused_title_text.get()
|
||||
} else if !have_active && last_active == Some(child.node.node_id()) {
|
||||
rd.last_active_rect = Some(rect);
|
||||
theme.colors.focused_inactive_title_text.get()
|
||||
} else {
|
||||
rd.title_rects.push(rect);
|
||||
theme.colors.unfocused_title_text.get()
|
||||
};
|
||||
}
|
||||
if !mono {
|
||||
let rect = Rect::new_sized(rect.x1(), rect.y2(), rect.width(), 1).unwrap();
|
||||
rd.underline_rects.push(rect);
|
||||
}
|
||||
let title = child.title.borrow_mut();
|
||||
for (scale, _) in scales.iter() {
|
||||
let old_tex = child.title_tex.remove(scale);
|
||||
let titles = rd.titles.get_or_default_mut(*scale);
|
||||
'render_title: {
|
||||
let mut th = th;
|
||||
let mut scalef = None;
|
||||
let mut width = rect.width();
|
||||
if *scale != 1 {
|
||||
let scale = scale.to_f64();
|
||||
th = (th as f64 * scale).round() as _;
|
||||
width = (width as f64 * scale).round() as _;
|
||||
scalef = Some(scale);
|
||||
}
|
||||
if th == 0 || width == 0 || title.is_empty() {
|
||||
break 'render_title;
|
||||
}
|
||||
if let Some(ctx) = &ctx {
|
||||
match text::render(
|
||||
ctx,
|
||||
old_tex,
|
||||
width,
|
||||
th,
|
||||
&font,
|
||||
title.deref(),
|
||||
color,
|
||||
scalef,
|
||||
) {
|
||||
Ok(t) => {
|
||||
child.title_tex.insert(*scale, t.clone());
|
||||
titles.push(ContainerTitle {
|
||||
x: rect.x1(),
|
||||
y: rect.y1(),
|
||||
tex: t,
|
||||
})
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Could not render title {}: {}", title, ErrorFmt(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
let tt = &*child.title_tex.borrow();
|
||||
for (scale, tex) in tt {
|
||||
if let Some(tex) = tex.texture() {
|
||||
let titles = rd.titles.get_or_default_mut(*scale);
|
||||
titles.push(ContainerTitle {
|
||||
x: rect.x1(),
|
||||
y: rect.y1(),
|
||||
tex,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1010,7 +1072,7 @@ impl ContainerNode {
|
|||
}
|
||||
self.update_title();
|
||||
// log::info!("node_child_title_changed");
|
||||
self.schedule_compute_render_data();
|
||||
self.schedule_render_titles();
|
||||
}
|
||||
|
||||
fn update_child_active(
|
||||
|
|
@ -1027,7 +1089,8 @@ impl ContainerNode {
|
|||
.set(Some(self.focus_history.add_last(node.clone())));
|
||||
}
|
||||
// log::info!("node_child_active_changed");
|
||||
self.schedule_compute_render_data();
|
||||
self.schedule_render_titles();
|
||||
self.schedule_compute_render_positions();
|
||||
if let Some(parent) = self.toplevel_data.parent.get() {
|
||||
parent.node_child_active_changed(self.deref(), active, depth + 1);
|
||||
}
|
||||
|
|
@ -1175,11 +1238,22 @@ pub async fn container_layout(state: Rc<State>) {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn container_render_data(state: Rc<State>) {
|
||||
pub async fn container_render_positions(state: Rc<State>) {
|
||||
loop {
|
||||
let container = state.pending_container_render_data.pop().await;
|
||||
if container.compute_render_data_scheduled.get() {
|
||||
container.compute_render_data();
|
||||
let container = state.pending_container_render_positions.pop().await;
|
||||
if container.compute_render_positions_scheduled.get() {
|
||||
container.compute_render_positions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn container_render_titles(state: Rc<State>) {
|
||||
loop {
|
||||
let container = state.pending_container_render_title.pop().await;
|
||||
if container.render_titles_scheduled.get() {
|
||||
container.render_titles_scheduled.set(false);
|
||||
container.render_titles().triggered().await;
|
||||
container.compute_title_data();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1562,7 +1636,7 @@ impl ContainingNode for ContainerNode {
|
|||
return;
|
||||
}
|
||||
self.mod_attention_requests(set);
|
||||
self.schedule_compute_render_data();
|
||||
self.schedule_compute_render_positions();
|
||||
}
|
||||
|
||||
fn cnode_workspace(self: Rc<Self>) -> Rc<WorkspaceNode> {
|
||||
|
|
|
|||
|
|
@ -12,14 +12,15 @@ use {
|
|||
renderer::Renderer,
|
||||
scale::Scale,
|
||||
state::State,
|
||||
text::{self, TextTexture},
|
||||
text::TextTexture,
|
||||
tree::{
|
||||
walker::NodeVisitor, ContainingNode, Direction, FindTreeResult, FindTreeUsecase,
|
||||
FoundNode, Node, NodeId, StackedNode, ToplevelNode, WorkspaceNode,
|
||||
},
|
||||
utils::{
|
||||
clonecell::CloneCell, copyhashmap::CopyHashMap, double_click_state::DoubleClickState,
|
||||
errorfmt::ErrorFmt, linkedlist::LinkedNode,
|
||||
asyncevent::AsyncEvent, clonecell::CloneCell, double_click_state::DoubleClickState,
|
||||
errorfmt::ErrorFmt, linkedlist::LinkedNode, on_drop_event::OnDropEvent,
|
||||
smallmap::SmallMapMut,
|
||||
},
|
||||
},
|
||||
ahash::AHashMap,
|
||||
|
|
@ -47,7 +48,7 @@ pub struct FloatNode {
|
|||
pub layout_scheduled: Cell<bool>,
|
||||
pub render_titles_scheduled: Cell<bool>,
|
||||
pub title: RefCell<String>,
|
||||
pub title_textures: CopyHashMap<Scale, TextTexture>,
|
||||
pub title_textures: RefCell<SmallMapMut<Scale, TextTexture, 2>>,
|
||||
cursors: RefCell<AHashMap<CursorType, CursorState>>,
|
||||
pub attention_requested: Cell<bool>,
|
||||
}
|
||||
|
|
@ -96,7 +97,9 @@ pub async fn float_titles(state: Rc<State>) {
|
|||
loop {
|
||||
let node = state.pending_float_titles.pop().await;
|
||||
if node.render_titles_scheduled.get() {
|
||||
node.render_title();
|
||||
node.render_titles_scheduled.set(false);
|
||||
node.render_title_phase1().triggered().await;
|
||||
node.render_title_phase2();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -182,8 +185,8 @@ impl FloatNode {
|
|||
}
|
||||
}
|
||||
|
||||
fn render_title(&self) {
|
||||
self.render_titles_scheduled.set(false);
|
||||
fn render_title_phase1(&self) -> Rc<AsyncEvent> {
|
||||
let on_completed = Rc::new(OnDropEvent::default());
|
||||
let theme = &self.state.theme;
|
||||
let th = theme.sizes.title_height.get();
|
||||
let tc = match self.active.get() {
|
||||
|
|
@ -194,17 +197,19 @@ impl FloatNode {
|
|||
let font = theme.font.get();
|
||||
let title = self.title.borrow_mut();
|
||||
let pos = self.position.get();
|
||||
if pos.width() <= 2 * bw || title.is_empty() {
|
||||
return;
|
||||
if pos.width() <= 2 * bw {
|
||||
return on_completed.event();
|
||||
}
|
||||
let ctx = match self.state.render_ctx.get() {
|
||||
Some(c) => c,
|
||||
_ => return,
|
||||
_ => return on_completed.event(),
|
||||
};
|
||||
let scales = self.state.scales.lock();
|
||||
let tr = Rect::new_sized(pos.x1() + bw, pos.y1() + bw, pos.width() - 2 * bw, th).unwrap();
|
||||
let tt = &mut *self.title_textures.borrow_mut();
|
||||
for (scale, _) in scales.iter() {
|
||||
let old_tex = self.title_textures.remove(scale);
|
||||
let tex =
|
||||
tt.get_or_insert_with(*scale, || TextTexture::new(&self.state.cpu_worker, &ctx));
|
||||
let mut th = tr.height();
|
||||
let mut scalef = None;
|
||||
let mut width = tr.width();
|
||||
|
|
@ -217,16 +222,39 @@ impl FloatNode {
|
|||
if th == 0 || width == 0 {
|
||||
continue;
|
||||
}
|
||||
let texture = match text::render(&ctx, old_tex, width, th, &font, &title, tc, scalef) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
log::error!("Could not render title {}: {}", title, ErrorFmt(e));
|
||||
return;
|
||||
}
|
||||
};
|
||||
self.title_textures.set(*scale, texture);
|
||||
tex.schedule_render(
|
||||
on_completed.clone(),
|
||||
1,
|
||||
None,
|
||||
width,
|
||||
th,
|
||||
1,
|
||||
&font,
|
||||
&title,
|
||||
tc,
|
||||
true,
|
||||
false,
|
||||
scalef,
|
||||
);
|
||||
}
|
||||
if self.visible.get() {
|
||||
on_completed.event()
|
||||
}
|
||||
|
||||
fn render_title_phase2(&self) {
|
||||
let theme = &self.state.theme;
|
||||
let th = theme.sizes.title_height.get();
|
||||
let bw = theme.sizes.border_width.get();
|
||||
let title = self.title.borrow();
|
||||
let tt = &*self.title_textures.borrow();
|
||||
for (_, tt) in tt {
|
||||
if let Err(e) = tt.flip() {
|
||||
log::error!("Could not render title {}: {}", title, ErrorFmt(e));
|
||||
}
|
||||
}
|
||||
let pos = self.position.get();
|
||||
if self.visible.get() && pos.width() >= 2 * bw {
|
||||
let tr =
|
||||
Rect::new_sized(pos.x1() + bw, pos.y1() + bw, pos.width() - 2 * bw, th).unwrap();
|
||||
self.state.damage(tr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,15 +30,16 @@ use {
|
|||
renderer::Renderer,
|
||||
scale::Scale,
|
||||
state::State,
|
||||
text::{self, TextTexture},
|
||||
text::TextTexture,
|
||||
tree::{
|
||||
walker::NodeVisitor, Direction, FindTreeResult, FindTreeUsecase, FoundNode, Node,
|
||||
NodeId, StackedNode, WorkspaceNode,
|
||||
},
|
||||
utils::{
|
||||
clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt,
|
||||
event_listener::EventSource, hash_map_ext::HashMapExt, linkedlist::LinkedList,
|
||||
scroller::Scroller, transform_ext::TransformExt,
|
||||
asyncevent::AsyncEvent, clonecell::CloneCell, copyhashmap::CopyHashMap,
|
||||
errorfmt::ErrorFmt, event_listener::EventSource, hash_map_ext::HashMapExt,
|
||||
linkedlist::LinkedList, on_drop_event::OnDropEvent, scroller::Scroller,
|
||||
transform_ext::TransformExt,
|
||||
},
|
||||
wire::{JayOutputId, JayScreencastId, ZwlrScreencopyFrameV1Id},
|
||||
},
|
||||
|
|
@ -114,12 +115,14 @@ pub enum PointerType {
|
|||
|
||||
pub async fn output_render_data(state: Rc<State>) {
|
||||
loop {
|
||||
let container = state.pending_output_render_data.pop().await;
|
||||
if container.global.destroyed.get() {
|
||||
let output = state.pending_output_render_data.pop().await;
|
||||
if output.global.destroyed.get() {
|
||||
continue;
|
||||
}
|
||||
if container.update_render_data_scheduled.get() {
|
||||
container.update_render_data();
|
||||
if output.update_render_data_scheduled.get() {
|
||||
output.update_render_data_scheduled.set(false);
|
||||
output.update_render_data_phase1().triggered().await;
|
||||
output.update_render_data_phase2();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -367,16 +370,11 @@ impl OutputNode {
|
|||
}
|
||||
}
|
||||
|
||||
fn update_render_data(&self) {
|
||||
self.update_render_data_scheduled.set(false);
|
||||
let mut rd = self.render_data.borrow_mut();
|
||||
rd.titles.clear();
|
||||
rd.inactive_workspaces.clear();
|
||||
rd.attention_requested_workspaces.clear();
|
||||
rd.captured_inactive_workspaces.clear();
|
||||
rd.active_workspace = None;
|
||||
rd.status = None;
|
||||
let mut pos = 0;
|
||||
fn update_render_data_phase1(self: &Rc<Self>) -> Rc<AsyncEvent> {
|
||||
let on_completed = Rc::new(OnDropEvent::default());
|
||||
let Some(ctx) = self.state.render_ctx.get() else {
|
||||
return on_completed.event();
|
||||
};
|
||||
let font = self.state.theme.font.get();
|
||||
let theme = &self.state.theme;
|
||||
let th = theme.sizes.title_height.get();
|
||||
|
|
@ -391,40 +389,72 @@ impl OutputNode {
|
|||
texture_height = (th as f64 * scale).round() as _;
|
||||
}
|
||||
let active_id = self.workspace.get().map(|w| w.id);
|
||||
for ws in self.workspaces.iter() {
|
||||
let tex = &mut *ws.title_texture.borrow_mut();
|
||||
let tex = tex.get_or_insert_with(|| TextTexture::new(&self.state.cpu_worker, &ctx));
|
||||
let tc = match active_id == Some(ws.id) {
|
||||
true => theme.colors.focused_title_text.get(),
|
||||
false => theme.colors.unfocused_title_text.get(),
|
||||
};
|
||||
tex.schedule_render_fitting(
|
||||
on_completed.clone(),
|
||||
Some(texture_height),
|
||||
&font,
|
||||
&ws.name,
|
||||
tc,
|
||||
false,
|
||||
scale,
|
||||
);
|
||||
}
|
||||
let mut rd = self.render_data.borrow_mut();
|
||||
let tex = rd.status.get_or_insert_with(|| OutputStatus {
|
||||
tex_x: 0,
|
||||
tex: TextTexture::new(&self.state.cpu_worker, &ctx),
|
||||
});
|
||||
let status = self.status.get();
|
||||
let tc = self.state.theme.colors.bar_text.get();
|
||||
tex.tex.schedule_render_fitting(
|
||||
on_completed.clone(),
|
||||
Some(texture_height),
|
||||
&font,
|
||||
&status,
|
||||
tc,
|
||||
true,
|
||||
scale,
|
||||
);
|
||||
on_completed.event()
|
||||
}
|
||||
|
||||
fn update_render_data_phase2(&self) {
|
||||
let mut rd = self.render_data.borrow_mut();
|
||||
rd.titles.clear();
|
||||
rd.inactive_workspaces.clear();
|
||||
rd.attention_requested_workspaces.clear();
|
||||
rd.captured_inactive_workspaces.clear();
|
||||
rd.active_workspace = None;
|
||||
let mut pos = 0;
|
||||
let theme = &self.state.theme;
|
||||
let th = theme.sizes.title_height.get();
|
||||
let scale = self.global.persistent.scale.get();
|
||||
let scale = if scale != 1 {
|
||||
Some(scale.to_f64())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let active_id = self.workspace.get().map(|w| w.id);
|
||||
let non_exclusive_rect = self.non_exclusive_rect.get();
|
||||
let output_width = non_exclusive_rect.width();
|
||||
rd.underline = Rect::new_sized(0, th, output_width, 1).unwrap();
|
||||
for ws in self.workspaces.iter() {
|
||||
let old_tex = ws.title_texture.take();
|
||||
let mut title_width = th;
|
||||
'create_texture: {
|
||||
if let Some(ctx) = self.state.render_ctx.get() {
|
||||
if th == 0 || ws.name.is_empty() {
|
||||
break 'create_texture;
|
||||
}
|
||||
let tc = match active_id == Some(ws.id) {
|
||||
true => theme.colors.focused_title_text.get(),
|
||||
false => theme.colors.unfocused_title_text.get(),
|
||||
};
|
||||
let title = match text::render_fitting(
|
||||
&ctx,
|
||||
old_tex,
|
||||
Some(texture_height),
|
||||
&font,
|
||||
&ws.name,
|
||||
tc,
|
||||
false,
|
||||
scale,
|
||||
) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
log::error!("Could not render title {}: {}", ws.name, ErrorFmt(e));
|
||||
break 'create_texture;
|
||||
}
|
||||
};
|
||||
ws.title_texture.set(Some(title.clone()));
|
||||
let title = &*ws.title_texture.borrow();
|
||||
if let Some(title) = title {
|
||||
if let Err(e) = title.flip() {
|
||||
log::error!("Could not render title: {}", ErrorFmt(e));
|
||||
}
|
||||
if let Some(texture) = title.texture() {
|
||||
let mut x = pos + 1;
|
||||
let (mut width, _) = title.texture.size();
|
||||
let (mut width, _) = texture.size();
|
||||
if let Some(scale) = scale {
|
||||
width = (width as f64 / scale).round() as _;
|
||||
}
|
||||
|
|
@ -438,7 +468,7 @@ impl OutputNode {
|
|||
x2: pos + title_width,
|
||||
tex_x: x,
|
||||
tex_y: 0,
|
||||
tex: title.texture,
|
||||
tex: texture,
|
||||
ws: ws.deref().clone(),
|
||||
});
|
||||
}
|
||||
|
|
@ -461,43 +491,18 @@ impl OutputNode {
|
|||
}
|
||||
pos += title_width;
|
||||
}
|
||||
'set_status: {
|
||||
let old_tex = rd.status.take().map(|s| s.tex);
|
||||
let ctx = match self.state.render_ctx.get() {
|
||||
Some(ctx) => ctx,
|
||||
_ => break 'set_status,
|
||||
};
|
||||
let status = self.status.get();
|
||||
if status.is_empty() {
|
||||
break 'set_status;
|
||||
if let Some(status) = &mut rd.status {
|
||||
if let Err(e) = status.tex.flip() {
|
||||
log::error!("Could not render status: {}", ErrorFmt(e));
|
||||
}
|
||||
let tc = self.state.theme.colors.bar_text.get();
|
||||
let title = match text::render_fitting(
|
||||
&ctx,
|
||||
old_tex,
|
||||
Some(texture_height),
|
||||
&font,
|
||||
&status,
|
||||
tc,
|
||||
true,
|
||||
scale,
|
||||
) {
|
||||
Ok(t) => t,
|
||||
Err(e) => {
|
||||
log::error!("Could not render status {}: {}", status, ErrorFmt(e));
|
||||
break 'set_status;
|
||||
if let Some(texture) = status.tex.texture() {
|
||||
let (mut width, _) = texture.size();
|
||||
if let Some(scale) = scale {
|
||||
width = (width as f64 / scale).round() as _;
|
||||
}
|
||||
};
|
||||
let (mut width, _) = title.texture.size();
|
||||
if let Some(scale) = scale {
|
||||
width = (width as f64 / scale).round() as _;
|
||||
let pos = output_width - width - 1;
|
||||
status.tex_x = pos;
|
||||
}
|
||||
let pos = output_width - width - 1;
|
||||
rd.status = Some(OutputStatus {
|
||||
tex_x: pos,
|
||||
tex_y: 0,
|
||||
tex: title,
|
||||
});
|
||||
}
|
||||
if self.title_visible.get() {
|
||||
let title_rect = Rect::new_sized(
|
||||
|
|
@ -945,7 +950,6 @@ pub struct OutputTitle {
|
|||
|
||||
pub struct OutputStatus {
|
||||
pub tex_x: i32,
|
||||
pub tex_y: i32,
|
||||
pub tex: TextTexture,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,22 @@ use {
|
|||
renderer::Renderer,
|
||||
scale::Scale,
|
||||
state::State,
|
||||
text::{self, TextTexture},
|
||||
text::TextTexture,
|
||||
tree::{
|
||||
Direction, FindTreeResult, FindTreeUsecase, FoundNode, Node, NodeId, NodeVisitor,
|
||||
ToplevelData, ToplevelNode, ToplevelNodeBase,
|
||||
},
|
||||
utils::{errorfmt::ErrorFmt, smallmap::SmallMap},
|
||||
utils::{
|
||||
asyncevent::AsyncEvent, errorfmt::ErrorFmt, on_drop_event::OnDropEvent,
|
||||
smallmap::SmallMapMut,
|
||||
},
|
||||
},
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
ops::Deref,
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
},
|
||||
std::{cell::Cell, ops::Deref, rc::Rc},
|
||||
};
|
||||
|
||||
tree_id!(PlaceholderNodeId);
|
||||
|
|
@ -24,7 +32,18 @@ pub struct PlaceholderNode {
|
|||
id: PlaceholderNodeId,
|
||||
toplevel: ToplevelData,
|
||||
destroyed: Cell<bool>,
|
||||
pub textures: SmallMap<Scale, TextTexture, 2>,
|
||||
update_textures_scheduled: Cell<bool>,
|
||||
state: Rc<State>,
|
||||
pub textures: RefCell<SmallMapMut<Scale, TextTexture, 2>>,
|
||||
}
|
||||
|
||||
pub async fn placeholder_render_textures(state: Rc<State>) {
|
||||
loop {
|
||||
let container = state.pending_placeholder_render_textures.pop().await;
|
||||
container.update_textures_scheduled.set(false);
|
||||
container.update_texture_phase1().triggered().await;
|
||||
container.update_texture_phase2();
|
||||
}
|
||||
}
|
||||
|
||||
impl PlaceholderNode {
|
||||
|
|
@ -37,6 +56,8 @@ impl PlaceholderNode {
|
|||
node.node_client(),
|
||||
),
|
||||
destroyed: Default::default(),
|
||||
update_textures_scheduled: Cell::new(false),
|
||||
state: state.clone(),
|
||||
textures: Default::default(),
|
||||
}
|
||||
}
|
||||
|
|
@ -45,39 +66,53 @@ impl PlaceholderNode {
|
|||
self.destroyed.get()
|
||||
}
|
||||
|
||||
pub fn update_texture(&self) {
|
||||
if let Some(ctx) = self.toplevel.state.render_ctx.get() {
|
||||
let scales = self.toplevel.state.scales.lock();
|
||||
let rect = self.toplevel.pos.get();
|
||||
for (scale, _) in scales.iter() {
|
||||
let old_tex = self.textures.remove(scale);
|
||||
let mut width = rect.width();
|
||||
let mut height = rect.height();
|
||||
if *scale != 1 {
|
||||
let scale = scale.to_f64();
|
||||
width = (width as f64 * scale).round() as _;
|
||||
height = (height as f64 * scale).round() as _;
|
||||
}
|
||||
if width != 0 && height != 0 {
|
||||
let font = format!("monospace {}", width / 10);
|
||||
match text::render_fitting(
|
||||
&ctx,
|
||||
old_tex,
|
||||
Some(height),
|
||||
&font,
|
||||
"Fullscreen",
|
||||
self.toplevel.state.theme.colors.unfocused_title_text.get(),
|
||||
false,
|
||||
None,
|
||||
) {
|
||||
Ok(t) => {
|
||||
self.textures.insert(*scale, t);
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("Could not render fullscreen texture: {}", ErrorFmt(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn schedule_update_texture(self: &Rc<Self>) {
|
||||
if !self.update_textures_scheduled.replace(true) {
|
||||
self.state
|
||||
.pending_placeholder_render_textures
|
||||
.push(self.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn update_texture_phase1(&self) -> Rc<AsyncEvent> {
|
||||
let on_completed = Rc::new(OnDropEvent::default());
|
||||
let Some(ctx) = self.toplevel.state.render_ctx.get() else {
|
||||
return on_completed.event();
|
||||
};
|
||||
let scales = self.toplevel.state.scales.lock();
|
||||
let rect = self.toplevel.pos.get();
|
||||
let mut textures = self.textures.borrow_mut();
|
||||
for (scale, _) in scales.iter() {
|
||||
let tex = textures
|
||||
.get_or_insert_with(*scale, || TextTexture::new(&self.state.cpu_worker, &ctx));
|
||||
let mut width = rect.width();
|
||||
let mut height = rect.height();
|
||||
if *scale != 1 {
|
||||
let scale = scale.to_f64();
|
||||
width = (width as f64 * scale).round() as _;
|
||||
height = (height as f64 * scale).round() as _;
|
||||
}
|
||||
if width != 0 && height != 0 {
|
||||
let font = Arc::new(format!("monospace {}", width / 10));
|
||||
tex.schedule_render_fitting(
|
||||
on_completed.clone(),
|
||||
Some(height),
|
||||
&font,
|
||||
"Fullscreen",
|
||||
self.toplevel.state.theme.colors.unfocused_title_text.get(),
|
||||
false,
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
on_completed.event()
|
||||
}
|
||||
|
||||
fn update_texture_phase2(&self) {
|
||||
let textures = &*self.textures.borrow();
|
||||
for (_, texture) in textures {
|
||||
if let Err(e) = texture.flip() {
|
||||
log::warn!("Could not render fullscreen texture: {}", ErrorFmt(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -162,7 +197,7 @@ impl ToplevelNodeBase for PlaceholderNode {
|
|||
if let Some(p) = self.toplevel.parent.get() {
|
||||
p.node_child_size_changed(self.deref(), rect.width(), rect.height());
|
||||
}
|
||||
self.update_texture();
|
||||
self.schedule_update_texture();
|
||||
}
|
||||
|
||||
fn tl_close(self: Rc<Self>) {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ pub struct WorkspaceNode {
|
|||
pub jay_workspaces: CopyHashMap<(ClientId, JayWorkspaceId), Rc<JayWorkspace>>,
|
||||
pub may_capture: Cell<bool>,
|
||||
pub has_capture: Cell<bool>,
|
||||
pub title_texture: Cell<Option<TextTexture>>,
|
||||
pub title_texture: RefCell<Option<TextTexture>>,
|
||||
pub attention_requests: ThresholdCounter,
|
||||
pub render_highlight: NumCell<u32>,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue