theme: add ThemeColor enum
This commit is contained in:
parent
c75b6ef66e
commit
cf8b696f03
4 changed files with 82 additions and 41 deletions
|
|
@ -27,7 +27,7 @@ use {
|
||||||
scale::Scale,
|
scale::Scale,
|
||||||
state::{ConnectorData, DeviceHandlerData, DrmDevData, OutputData, State},
|
state::{ConnectorData, DeviceHandlerData, DrmDevData, OutputData, State},
|
||||||
tagged_acceptor::TaggedAcceptorError,
|
tagged_acceptor::TaggedAcceptorError,
|
||||||
theme::{Color, ThemeSized},
|
theme::{ThemeColor, ThemeSized},
|
||||||
tree::{
|
tree::{
|
||||||
ContainerNode, ContainerSplit, FloatNode, Node, NodeVisitorBase, OutputNode,
|
ContainerNode, ContainerSplit, FloatNode, Node, NodeVisitorBase, OutputNode,
|
||||||
TearingMode, TileState, ToplevelData, ToplevelNode, VrrMode, WorkspaceNode,
|
TearingMode, TileState, ToplevelData, ToplevelNode, VrrMode, WorkspaceNode,
|
||||||
|
|
@ -2433,23 +2433,6 @@ impl ConfigProxyHandler {
|
||||||
self.state.icons.update_sizes(&self.state);
|
self.state.icons.update_sizes(&self.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn colors_changed(&self) {
|
|
||||||
struct V;
|
|
||||||
impl NodeVisitorBase for V {
|
|
||||||
fn visit_container(&mut self, node: &Rc<ContainerNode>) {
|
|
||||||
node.on_colors_changed();
|
|
||||||
node.node_visit_children(self);
|
|
||||||
}
|
|
||||||
fn visit_float(&mut self, node: &Rc<FloatNode>) {
|
|
||||||
node.on_colors_changed();
|
|
||||||
node.node_visit_children(self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.state.root.clone().node_visit(&mut V);
|
|
||||||
self.state.damage(self.state.root.extents.get());
|
|
||||||
self.state.icons.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_sized(&self, sized: Resizable) -> Result<ThemeSized, CphError> {
|
fn get_sized(&self, sized: Resizable) -> Result<ThemeSized, CphError> {
|
||||||
use jay_config::theme::sized::*;
|
use jay_config::theme::sized::*;
|
||||||
let sized = match sized {
|
let sized = match sized {
|
||||||
|
|
@ -2485,8 +2468,7 @@ impl ConfigProxyHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_reset_colors(&self) {
|
fn handle_reset_colors(&self) {
|
||||||
self.state.theme.colors.reset();
|
self.state.reset_colors();
|
||||||
self.colors_changed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_reset_sizes(&self) {
|
fn handle_reset_sizes(&self) {
|
||||||
|
|
@ -2524,34 +2506,37 @@ impl ConfigProxyHandler {
|
||||||
self.respond(Response::GetFont { font });
|
self.respond(Response::GetFont { font });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_color(&self, colorable: Colorable) -> Result<&Cell<Color>, CphError> {
|
fn get_color(&self, colorable: Colorable) -> Result<ThemeColor, CphError> {
|
||||||
let colors = &self.state.theme.colors;
|
|
||||||
use jay_config::theme::colors::*;
|
use jay_config::theme::colors::*;
|
||||||
let colorable = match colorable {
|
let colorable = match colorable {
|
||||||
UNFOCUSED_TITLE_BACKGROUND_COLOR => &colors.unfocused_title_background,
|
UNFOCUSED_TITLE_BACKGROUND_COLOR => ThemeColor::unfocused_title_background,
|
||||||
FOCUSED_TITLE_BACKGROUND_COLOR => &colors.focused_title_background,
|
FOCUSED_TITLE_BACKGROUND_COLOR => ThemeColor::focused_title_background,
|
||||||
CAPTURED_UNFOCUSED_TITLE_BACKGROUND_COLOR => {
|
CAPTURED_UNFOCUSED_TITLE_BACKGROUND_COLOR => {
|
||||||
&colors.captured_unfocused_title_background
|
ThemeColor::captured_unfocused_title_background
|
||||||
}
|
}
|
||||||
CAPTURED_FOCUSED_TITLE_BACKGROUND_COLOR => &colors.captured_focused_title_background,
|
CAPTURED_FOCUSED_TITLE_BACKGROUND_COLOR => {
|
||||||
FOCUSED_INACTIVE_TITLE_BACKGROUND_COLOR => &colors.focused_inactive_title_background,
|
ThemeColor::captured_focused_title_background
|
||||||
BACKGROUND_COLOR => &colors.background,
|
}
|
||||||
BAR_BACKGROUND_COLOR => &colors.bar_background,
|
FOCUSED_INACTIVE_TITLE_BACKGROUND_COLOR => {
|
||||||
SEPARATOR_COLOR => &colors.separator,
|
ThemeColor::focused_inactive_title_background
|
||||||
BORDER_COLOR => &colors.border,
|
}
|
||||||
UNFOCUSED_TITLE_TEXT_COLOR => &colors.unfocused_title_text,
|
BACKGROUND_COLOR => ThemeColor::background,
|
||||||
FOCUSED_TITLE_TEXT_COLOR => &colors.focused_title_text,
|
BAR_BACKGROUND_COLOR => ThemeColor::bar_background,
|
||||||
FOCUSED_INACTIVE_TITLE_TEXT_COLOR => &colors.focused_inactive_title_text,
|
SEPARATOR_COLOR => ThemeColor::separator,
|
||||||
BAR_STATUS_TEXT_COLOR => &colors.bar_text,
|
BORDER_COLOR => ThemeColor::border,
|
||||||
ATTENTION_REQUESTED_BACKGROUND_COLOR => &colors.attention_requested_background,
|
UNFOCUSED_TITLE_TEXT_COLOR => ThemeColor::unfocused_title_text,
|
||||||
HIGHLIGHT_COLOR => &colors.highlight,
|
FOCUSED_TITLE_TEXT_COLOR => ThemeColor::focused_title_text,
|
||||||
|
FOCUSED_INACTIVE_TITLE_TEXT_COLOR => ThemeColor::focused_inactive_title_text,
|
||||||
|
BAR_STATUS_TEXT_COLOR => ThemeColor::bar_text,
|
||||||
|
ATTENTION_REQUESTED_BACKGROUND_COLOR => ThemeColor::attention_requested_background,
|
||||||
|
HIGHLIGHT_COLOR => ThemeColor::highlight,
|
||||||
_ => return Err(CphError::UnknownColor(colorable.0)),
|
_ => return Err(CphError::UnknownColor(colorable.0)),
|
||||||
};
|
};
|
||||||
Ok(colorable)
|
Ok(colorable)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_get_color(&self, colorable: Colorable) -> Result<(), CphError> {
|
fn handle_get_color(&self, colorable: Colorable) -> Result<(), CphError> {
|
||||||
let color = self.get_color(colorable)?.get();
|
let color = self.get_color(colorable)?.field(&self.state.theme).get();
|
||||||
let [r, g, b, a] = color.to_array(Eotf::Gamma22);
|
let [r, g, b, a] = color.to_array(Eotf::Gamma22);
|
||||||
let color = jay_config::theme::Color::new_f32_premultiplied(r, g, b, a);
|
let color = jay_config::theme::Color::new_f32_premultiplied(r, g, b, a);
|
||||||
self.respond(Response::GetColor { color });
|
self.respond(Response::GetColor { color });
|
||||||
|
|
@ -2563,8 +2548,8 @@ impl ConfigProxyHandler {
|
||||||
colorable: Colorable,
|
colorable: Colorable,
|
||||||
color: jay_config::theme::Color,
|
color: jay_config::theme::Color,
|
||||||
) -> Result<(), CphError> {
|
) -> Result<(), CphError> {
|
||||||
self.get_color(colorable)?.set(color.into());
|
self.state
|
||||||
self.colors_changed();
|
.set_color(self.get_color(colorable)?, color.into());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
35
src/state.rs
35
src/state.rs
|
|
@ -93,7 +93,7 @@ use {
|
||||||
scale::Scale,
|
scale::Scale,
|
||||||
security_context_acceptor::SecurityContextAcceptors,
|
security_context_acceptor::SecurityContextAcceptors,
|
||||||
tagged_acceptor::TaggedAcceptors,
|
tagged_acceptor::TaggedAcceptors,
|
||||||
theme::{Color, Theme},
|
theme::{Color, Theme, ThemeColor},
|
||||||
time::Time,
|
time::Time,
|
||||||
tree::{
|
tree::{
|
||||||
ContainerNode, ContainerSplit, Direction, DisplayNode, FindTreeUsecase, FloatNode,
|
ContainerNode, ContainerSplit, Direction, DisplayNode, FindTreeUsecase, FloatNode,
|
||||||
|
|
@ -1696,6 +1696,39 @@ impl State {
|
||||||
logger.set_level(level);
|
logger.set_level(level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn colors_changed(&self) {
|
||||||
|
struct V;
|
||||||
|
impl NodeVisitorBase for V {
|
||||||
|
fn visit_container(&mut self, node: &Rc<ContainerNode>) {
|
||||||
|
node.on_colors_changed();
|
||||||
|
node.node_visit_children(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_output(&mut self, node: &Rc<OutputNode>) {
|
||||||
|
node.on_colors_changed();
|
||||||
|
node.node_visit_children(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_float(&mut self, node: &Rc<FloatNode>) {
|
||||||
|
node.on_colors_changed();
|
||||||
|
node.node_visit_children(self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.root.clone().node_visit(&mut V);
|
||||||
|
self.damage(self.root.extents.get());
|
||||||
|
self.icons.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reset_colors(&self) {
|
||||||
|
self.theme.colors.reset();
|
||||||
|
self.colors_changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_color(&self, colored: ThemeColor, v: Color) {
|
||||||
|
colored.field(&self.theme).set(v);
|
||||||
|
self.colors_changed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
|
|
||||||
19
src/theme.rs
19
src/theme.rs
|
|
@ -392,6 +392,25 @@ macro_rules! colors {
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, Linearize)]
|
||||||
|
#[expect(non_camel_case_types)]
|
||||||
|
pub enum ThemeColor {
|
||||||
|
$(
|
||||||
|
$name,
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ThemeColor {
|
||||||
|
pub fn field(self, theme: &Theme) -> &Cell<Color> {
|
||||||
|
let colors = &theme.colors;
|
||||||
|
match self {
|
||||||
|
$(
|
||||||
|
Self::$name => &colors.$name,
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ThemeColors {
|
impl ThemeColors {
|
||||||
pub fn reset(&self) {
|
pub fn reset(&self) {
|
||||||
let default = Self::default();
|
let default = Self::default();
|
||||||
|
|
|
||||||
|
|
@ -478,6 +478,10 @@ impl OutputNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn on_colors_changed(self: &Rc<Self>) {
|
||||||
|
self.schedule_update_render_data();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_preferred_scale(self: &Rc<Self>, scale: Scale) {
|
pub fn set_preferred_scale(self: &Rc<Self>, scale: Scale) {
|
||||||
let old_scale = self.global.persistent.scale.replace(scale);
|
let old_scale = self.global.persistent.scale.replace(scale);
|
||||||
if scale == old_scale {
|
if scale == old_scale {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue