theme: add title-font and bar-font settings
This commit is contained in:
parent
01f9c094ee
commit
035e2972de
14 changed files with 116 additions and 11 deletions
|
|
@ -650,6 +650,14 @@ impl ConfigClient {
|
||||||
self.send(&ClientMessage::SetFont { font });
|
self.send(&ClientMessage::SetFont { font });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_bar_font(&self, font: &str) {
|
||||||
|
self.send(&ClientMessage::SetBarFont { font });
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_title_font(&self, font: &str) {
|
||||||
|
self.send(&ClientMessage::SetTitleFont { font });
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_font(&self) -> String {
|
pub fn get_font(&self) -> String {
|
||||||
let res = self.send_with_response(&ClientMessage::GetFont);
|
let res = self.send_with_response(&ClientMessage::GetFont);
|
||||||
get_response!(res, String::new(), GetFont { font });
|
get_response!(res, String::new(), GetFont { font });
|
||||||
|
|
|
||||||
|
|
@ -768,6 +768,12 @@ pub enum ClientMessage<'a> {
|
||||||
connector: Connector,
|
connector: Connector,
|
||||||
blend_space: BlendSpace,
|
blend_space: BlendSpace,
|
||||||
},
|
},
|
||||||
|
SetBarFont {
|
||||||
|
font: &'a str,
|
||||||
|
},
|
||||||
|
SetTitleFont {
|
||||||
|
font: &'a str,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,8 @@ pub fn get_font() -> String {
|
||||||
///
|
///
|
||||||
/// Default: `monospace 8`.
|
/// Default: `monospace 8`.
|
||||||
///
|
///
|
||||||
|
/// See also [`set_bar_font`] and [`set_title_font`].
|
||||||
|
///
|
||||||
/// The font name should be specified in [pango][pango] syntax.
|
/// The font name should be specified in [pango][pango] syntax.
|
||||||
///
|
///
|
||||||
/// [pango]: https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html
|
/// [pango]: https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html
|
||||||
|
|
@ -152,7 +154,23 @@ pub fn set_font(font: &str) {
|
||||||
get!().set_font(font)
|
get!().set_font(font)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets the font to the default.
|
/// Sets the font used by the bar.
|
||||||
|
///
|
||||||
|
/// If this function is not called, the font set by [`set_font`] is used. See that
|
||||||
|
/// function for more details.
|
||||||
|
pub fn set_bar_font(font: &str) {
|
||||||
|
get!().set_bar_font(font)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the font used by window titles.
|
||||||
|
///
|
||||||
|
/// If this function is not called, the font set by [`set_font`] is used. See that
|
||||||
|
/// function for more details.
|
||||||
|
pub fn set_title_font(font: &str) {
|
||||||
|
get!().set_title_font(font)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resets the fonts to the defaults.
|
||||||
///
|
///
|
||||||
/// Currently the default is `monospace 8`.
|
/// Currently the default is `monospace 8`.
|
||||||
pub fn reset_font() {
|
pub fn reset_font() {
|
||||||
|
|
|
||||||
|
|
@ -2341,16 +2341,30 @@ impl ConfigProxyHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_reset_font(&self) {
|
fn handle_reset_font(&self) {
|
||||||
self.state
|
let theme = &self.state.theme;
|
||||||
.theme
|
theme.font.set(self.state.theme.default_font.clone());
|
||||||
.font
|
theme.bar_font.set(None);
|
||||||
.set(self.state.theme.default_font.clone());
|
theme.title_font.set(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_set_font(&self, font: &str) {
|
fn handle_set_font(&self, font: &str) {
|
||||||
self.state.theme.font.set(Arc::new(font.to_string()));
|
self.state.theme.font.set(Arc::new(font.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_set_bar_font(&self, font: &str) {
|
||||||
|
self.state
|
||||||
|
.theme
|
||||||
|
.bar_font
|
||||||
|
.set(Some(Arc::new(font.to_string())));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_set_title_font(&self, font: &str) {
|
||||||
|
self.state
|
||||||
|
.theme
|
||||||
|
.title_font
|
||||||
|
.set(Some(Arc::new(font.to_string())));
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_get_font(&self) {
|
fn handle_get_font(&self) {
|
||||||
let font = self.state.theme.font.get().to_string();
|
let font = self.state.theme.font.get().to_string();
|
||||||
self.respond(Response::GetFont { font });
|
self.respond(Response::GetFont { font });
|
||||||
|
|
@ -3143,6 +3157,8 @@ impl ConfigProxyHandler {
|
||||||
} => self
|
} => self
|
||||||
.handle_connector_set_blend_space(connector, blend_space)
|
.handle_connector_set_blend_space(connector, blend_space)
|
||||||
.wrn("connector_set_blend_space")?,
|
.wrn("connector_set_blend_space")?,
|
||||||
|
ClientMessage::SetBarFont { font } => self.handle_set_bar_font(font),
|
||||||
|
ClientMessage::SetTitleFont { font } => self.handle_set_title_font(font),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
src/theme.rs
14
src/theme.rs
|
|
@ -463,6 +463,8 @@ pub struct Theme {
|
||||||
pub colors: ThemeColors,
|
pub colors: ThemeColors,
|
||||||
pub sizes: ThemeSizes,
|
pub sizes: ThemeSizes,
|
||||||
pub font: CloneCell<Arc<String>>,
|
pub font: CloneCell<Arc<String>>,
|
||||||
|
pub bar_font: CloneCell<Option<Arc<String>>>,
|
||||||
|
pub title_font: CloneCell<Option<Arc<String>>>,
|
||||||
pub default_font: Arc<String>,
|
pub default_font: Arc<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -473,7 +475,19 @@ impl Default for Theme {
|
||||||
colors: Default::default(),
|
colors: Default::default(),
|
||||||
sizes: Default::default(),
|
sizes: Default::default(),
|
||||||
font: CloneCell::new(default_font.clone()),
|
font: CloneCell::new(default_font.clone()),
|
||||||
|
bar_font: Default::default(),
|
||||||
|
title_font: Default::default(),
|
||||||
default_font,
|
default_font,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Theme {
|
||||||
|
pub fn title_font(&self) -> Arc<String> {
|
||||||
|
self.title_font.get().unwrap_or_else(|| self.font.get())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bar_font(&self) -> Arc<String> {
|
||||||
|
self.bar_font.get().unwrap_or_else(|| self.font.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -707,7 +707,7 @@ impl ContainerNode {
|
||||||
};
|
};
|
||||||
let theme = &self.state.theme;
|
let theme = &self.state.theme;
|
||||||
let th = theme.sizes.title_height.get();
|
let th = theme.sizes.title_height.get();
|
||||||
let font = theme.font.get();
|
let font = theme.title_font();
|
||||||
let last_active = self.focus_history.last().map(|v| v.node.node_id());
|
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 have_active = self.children.iter().any(|c| c.active.get());
|
||||||
let scales = self.state.scales.lock();
|
let scales = self.state.scales.lock();
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,7 @@ impl FloatNode {
|
||||||
true => theme.colors.focused_title_text.get(),
|
true => theme.colors.focused_title_text.get(),
|
||||||
false => theme.colors.unfocused_title_text.get(),
|
false => theme.colors.unfocused_title_text.get(),
|
||||||
};
|
};
|
||||||
let font = theme.font.get();
|
let font = theme.title_font();
|
||||||
let title = self.title.borrow_mut();
|
let title = self.title.borrow_mut();
|
||||||
let ctx = match self.state.render_ctx.get() {
|
let ctx = match self.state.render_ctx.get() {
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
|
|
|
||||||
|
|
@ -514,7 +514,7 @@ impl OutputNode {
|
||||||
let Some(ctx) = self.state.render_ctx.get() else {
|
let Some(ctx) = self.state.render_ctx.get() else {
|
||||||
return on_completed.event();
|
return on_completed.event();
|
||||||
};
|
};
|
||||||
let font = self.state.theme.font.get();
|
let font = self.state.theme.bar_font();
|
||||||
let theme = &self.state.theme;
|
let theme = &self.state.theme;
|
||||||
let bh = theme.sizes.bar_height();
|
let bh = theme.sizes.bar_height();
|
||||||
let scale = self.global.persistent.scale.get();
|
let scale = self.global.persistent.scale.get();
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,8 @@ pub struct Theme {
|
||||||
pub title_height: Option<i32>,
|
pub title_height: Option<i32>,
|
||||||
pub bar_height: Option<i32>,
|
pub bar_height: Option<i32>,
|
||||||
pub font: Option<String>,
|
pub font: Option<String>,
|
||||||
|
pub title_font: Option<String>,
|
||||||
|
pub bar_font: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,9 @@ impl Parser for ThemeParser<'_> {
|
||||||
title_height,
|
title_height,
|
||||||
bar_height,
|
bar_height,
|
||||||
font,
|
font,
|
||||||
|
title_font,
|
||||||
),
|
),
|
||||||
|
(bar_font,),
|
||||||
) = ext.extract((
|
) = ext.extract((
|
||||||
(
|
(
|
||||||
opt(val("attention-requested-bg-color")),
|
opt(val("attention-requested-bg-color")),
|
||||||
|
|
@ -84,7 +86,9 @@ impl Parser for ThemeParser<'_> {
|
||||||
recover(opt(s32("title-height"))),
|
recover(opt(s32("title-height"))),
|
||||||
recover(opt(s32("bar-height"))),
|
recover(opt(s32("bar-height"))),
|
||||||
recover(opt(str("font"))),
|
recover(opt(str("font"))),
|
||||||
|
recover(opt(str("title-font"))),
|
||||||
),
|
),
|
||||||
|
(recover(opt(str("bar-font"))),),
|
||||||
))?;
|
))?;
|
||||||
macro_rules! color {
|
macro_rules! color {
|
||||||
($e:expr) => {
|
($e:expr) => {
|
||||||
|
|
@ -120,6 +124,8 @@ impl Parser for ThemeParser<'_> {
|
||||||
title_height: title_height.despan(),
|
title_height: title_height.despan(),
|
||||||
bar_height: bar_height.despan(),
|
bar_height: bar_height.despan(),
|
||||||
font: font.map(|f| f.value.to_string()),
|
font: font.map(|f| f.value.to_string()),
|
||||||
|
title_font: title_font.map(|f| f.value.to_string()),
|
||||||
|
bar_font: bar_font.map(|f| f.value.to_string()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ use {
|
||||||
set_show_float_pin_icon, set_ui_drag_enabled, set_ui_drag_threshold,
|
set_show_float_pin_icon, set_ui_drag_enabled, set_ui_drag_threshold,
|
||||||
status::{set_i3bar_separator, set_status, set_status_command, unset_status_command},
|
status::{set_i3bar_separator, set_status, set_status_command, unset_status_command},
|
||||||
switch_to_vt,
|
switch_to_vt,
|
||||||
theme::{reset_colors, reset_font, reset_sizes, set_font},
|
theme::{reset_colors, reset_font, reset_sizes, set_bar_font, set_font, set_title_font},
|
||||||
toggle_float_above_fullscreen, toggle_show_bar,
|
toggle_float_above_fullscreen, toggle_show_bar,
|
||||||
video::{
|
video::{
|
||||||
ColorSpace, Connector, DrmDevice, Eotf, connectors, drm_devices,
|
ColorSpace, Connector, DrmDevice, Eotf, connectors, drm_devices,
|
||||||
|
|
@ -894,9 +894,16 @@ impl State {
|
||||||
size!(BORDER_WIDTH, border_width);
|
size!(BORDER_WIDTH, border_width);
|
||||||
size!(TITLE_HEIGHT, title_height);
|
size!(TITLE_HEIGHT, title_height);
|
||||||
size!(BAR_HEIGHT, bar_height);
|
size!(BAR_HEIGHT, bar_height);
|
||||||
if let Some(font) = &theme.font {
|
macro_rules! font {
|
||||||
set_font(font);
|
($fun:ident, $field:ident) => {
|
||||||
|
if let Some(font) = &theme.$field {
|
||||||
|
$fun(font);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
font!(set_font, font);
|
||||||
|
font!(set_title_font, title_font);
|
||||||
|
font!(set_bar_font, bar_font);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_switch_device(self: &Rc<Self>, dev: InputDevice, actions: &Rc<SwitchActions>) {
|
fn handle_switch_device(self: &Rc<Self>, dev: InputDevice, actions: &Rc<SwitchActions>) {
|
||||||
|
|
|
||||||
|
|
@ -1915,6 +1915,14 @@
|
||||||
"font": {
|
"font": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The name of the font to use."
|
"description": "The name of the font to use."
|
||||||
|
},
|
||||||
|
"title-font": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the font to use in window titles. Defaults to `font` if not set."
|
||||||
|
},
|
||||||
|
"bar-font": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the font to use in the bar. Defaults to `font` if not set."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": []
|
"required": []
|
||||||
|
|
|
||||||
|
|
@ -4251,6 +4251,18 @@ The table has the following fields:
|
||||||
|
|
||||||
The value of this field should be a string.
|
The value of this field should be a string.
|
||||||
|
|
||||||
|
- `title-font` (optional):
|
||||||
|
|
||||||
|
The name of the font to use in window titles. Defaults to `font` if not set.
|
||||||
|
|
||||||
|
The value of this field should be a string.
|
||||||
|
|
||||||
|
- `bar-font` (optional):
|
||||||
|
|
||||||
|
The name of the font to use in the bar. Defaults to `font` if not set.
|
||||||
|
|
||||||
|
The value of this field should be a string.
|
||||||
|
|
||||||
|
|
||||||
<a name="types-TileState"></a>
|
<a name="types-TileState"></a>
|
||||||
### `TileState`
|
### `TileState`
|
||||||
|
|
|
||||||
|
|
@ -2133,6 +2133,14 @@ Theme:
|
||||||
kind: string
|
kind: string
|
||||||
required: false
|
required: false
|
||||||
description: The name of the font to use.
|
description: The name of the font to use.
|
||||||
|
title-font:
|
||||||
|
kind: string
|
||||||
|
required: false
|
||||||
|
description: The name of the font to use in window titles. Defaults to `font` if not set.
|
||||||
|
bar-font:
|
||||||
|
kind: string
|
||||||
|
required: false
|
||||||
|
description: The name of the font to use in the bar. Defaults to `font` if not set.
|
||||||
|
|
||||||
|
|
||||||
Config:
|
Config:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue