From 97f7b68369afca11c0709f7883207f9259eaea4a Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sat, 7 Mar 2026 12:23:01 +0100 Subject: [PATCH] static-text: add new utility --- src/backend.rs | 34 ++++++++++++++++++++++++++ src/cli/input.rs | 14 ++--------- src/client.rs | 23 ++++++++++++++++++ src/compositor.rs | 14 +++++++++++ src/gfx_api.rs | 8 +++++- src/ifs/wp_content_type_v1.rs | 11 +++++++++ src/theme.rs | 46 ++++++++++++++++++++++++++++++++++- src/tree.rs | 11 ++++++++- src/utils.rs | 1 + src/utils/static_text.rs | 3 +++ 10 files changed, 150 insertions(+), 15 deletions(-) create mode 100644 src/utils/static_text.rs diff --git a/src/backend.rs b/src/backend.rs index 0cad389e..20a82669 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -22,6 +22,7 @@ use { }, }, libinput::consts::DeviceCapability, + utils::static_text::StaticText, video::drm::{ ConnectorType, DRM_MODE_COLORIMETRY_BT2020_RGB, DRM_MODE_COLORIMETRY_DEFAULT, DrmConnector, DrmError, DrmVersion, HDMI_EOTF_SMPTE_ST2084, @@ -278,6 +279,20 @@ pub enum InputDeviceCapability { Switch, } +impl StaticText for InputDeviceCapability { + fn text(&self) -> &'static str { + match self { + InputDeviceCapability::Keyboard => "keyboard", + InputDeviceCapability::Pointer => "pointer", + InputDeviceCapability::Touch => "touch", + InputDeviceCapability::TabletTool => "tablet tool", + InputDeviceCapability::TabletPad => "tablet pad", + InputDeviceCapability::Gesture => "gesture", + InputDeviceCapability::Switch => "switch", + } + } +} + impl InputDeviceCapability { pub fn to_libinput(self) -> DeviceCapability { use crate::libinput::consts::*; @@ -299,6 +314,15 @@ pub enum InputDeviceAccelProfile { Adaptive, } +impl StaticText for InputDeviceAccelProfile { + fn text(&self) -> &'static str { + match self { + InputDeviceAccelProfile::Flat => "Flat", + InputDeviceAccelProfile::Adaptive => "Adaptive", + } + } +} + #[derive(Debug, Copy, Clone)] pub enum InputDeviceClickMethod { None, @@ -306,6 +330,16 @@ pub enum InputDeviceClickMethod { Clickfinger, } +impl StaticText for InputDeviceClickMethod { + fn text(&self) -> &'static str { + match self { + InputDeviceClickMethod::None => "none", + InputDeviceClickMethod::ButtonAreas => "button-areas", + InputDeviceClickMethod::Clickfinger => "clickfinger", + } + } +} + pub enum BackendEvent { NewDrmDevice(Rc), NewConnector(Rc), diff --git a/src/cli/input.rs b/src/cli/input.rs index 887293a8..2df25758 100644 --- a/src/cli/input.rs +++ b/src/cli/input.rs @@ -9,7 +9,7 @@ use { LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER, LIBINPUT_CONFIG_CLICK_METHOD_NONE, }, tools::tool_client::{Handle, ToolClient, with_tool_client}, - utils::{errorfmt::ErrorFmt, string_ext::StringExt}, + utils::{errorfmt::ErrorFmt, static_text::StaticText, string_ext::StringExt}, wire::{JayInputId, jay_compositor, jay_input}, }, clap::{Args, Subcommand, ValueEnum, ValueHint}, @@ -854,21 +854,11 @@ impl Input { print!("{prefix} capabilities:"); let mut first = true; for cap in &device.capabilities { - use InputDeviceCapability::*; print!(" "); if !mem::take(&mut first) { print!("| "); } - let name = match cap { - Keyboard => "keyboard", - Pointer => "pointer", - Touch => "touch", - TabletTool => "tablet tool", - TabletPad => "tablet pad", - Gesture => "gesture", - Switch => "switch", - }; - print!("{}", name); + print!("{}", cap.text()); } println!(); if let Some(v) = &device.accel_profile { diff --git a/src/client.rs b/src/client.rs index 0dc2634b..a1fa33cb 100644 --- a/src/client.rs +++ b/src/client.rs @@ -25,6 +25,7 @@ use { pending_serial::PendingSerial, pid_info::{PidInfo, get_pid_info, get_socket_creds}, pidfd_send_signal::pidfd_send_signal, + static_text::StaticText, }, wire::WlRegistryId, }, @@ -68,6 +69,28 @@ bitflags! { CAP_GAMMA_CONTROL_MANAGER = 1 << 14, } +impl StaticText for ClientCapsEnum { + fn text(&self) -> &'static str { + match self { + ClientCapsEnum::CAP_DATA_CONTROL_MANAGER => "data-control", + ClientCapsEnum::CAP_VIRTUAL_KEYBOARD_MANAGER => "virtual-keyboard", + ClientCapsEnum::CAP_FOREIGN_TOPLEVEL_LIST => "foreign-toplevel-list", + ClientCapsEnum::CAP_IDLE_NOTIFIER => "idle-notifier", + ClientCapsEnum::CAP_SESSION_LOCK_MANAGER => "session-lock", + ClientCapsEnum::CAP_JAY_COMPOSITOR => "jay-compositor", + ClientCapsEnum::CAP_LAYER_SHELL => "layer-shell", + ClientCapsEnum::CAP_SCREENCOPY_MANAGER => "screencopy", + ClientCapsEnum::CAP_SEAT_MANAGER => "seat-manager", + ClientCapsEnum::CAP_DRM_LEASE => "drm-lease", + ClientCapsEnum::CAP_INPUT_METHOD => "input-method", + ClientCapsEnum::CAP_WORKSPACE => "workspace-manager", + ClientCapsEnum::CAP_FOREIGN_TOPLEVEL_MANAGER => "foreign-toplevel-manager", + ClientCapsEnum::CAP_HEAD_MANAGER => "head-manager", + ClientCapsEnum::CAP_GAMMA_CONTROL_MANAGER => "gamma-control-manager", + } + } +} + pub const CAPS_DEFAULT: ClientCaps = ClientCaps(CAP_LAYER_SHELL.0 | CAP_DRM_LEASE.0); pub const CAPS_DEFAULT_SANDBOXED: ClientCaps = ClientCaps(CAP_DRM_LEASE.0); diff --git a/src/compositor.rs b/src/compositor.rs index aba6f1f9..3f74088c 100644 --- a/src/compositor.rs +++ b/src/compositor.rs @@ -77,6 +77,7 @@ use { rc_eq::RcEq, refcounted::RefCounted, run_toplevel::RunToplevel, + static_text::StaticText, tri::Try, }, version::VERSION, @@ -850,6 +851,19 @@ impl From for LogLevel { } } +impl StaticText for LogLevel { + fn text(&self) -> &'static str { + match self { + LogLevel::Off => "Off", + LogLevel::Error => "Error", + LogLevel::Warn => "Warn", + LogLevel::Info => "Info", + LogLevel::Debug => "Debug", + LogLevel::Trace => "Trace", + } + } +} + impl From for LogLevel { fn from(value: ConfigLogLevel) -> Self { match value { diff --git a/src/gfx_api.rs b/src/gfx_api.rs index f178b753..2900f5a8 100644 --- a/src/gfx_api.rs +++ b/src/gfx_api.rs @@ -15,7 +15,7 @@ use { state::State, theme::Color, tree::{Node, OutputNode, Transform}, - utils::{clonecell::UnsafeCellCloneSafe, errorfmt::ErrorFmt}, + utils::{clonecell::UnsafeCellCloneSafe, errorfmt::ErrorFmt, static_text::StaticText}, video::{ Modifier, dmabuf::DmaBuf, @@ -47,6 +47,12 @@ pub enum GfxApi { Vulkan, } +impl StaticText for GfxApi { + fn text(&self) -> &'static str { + self.to_str() + } +} + impl TryFrom for GfxApi { type Error = (); diff --git a/src/ifs/wp_content_type_v1.rs b/src/ifs/wp_content_type_v1.rs index 16f3727d..2118fbb2 100644 --- a/src/ifs/wp_content_type_v1.rs +++ b/src/ifs/wp_content_type_v1.rs @@ -4,6 +4,7 @@ use { ifs::wl_surface::WlSurface, leaks::Tracker, object::{Object, Version}, + utils::static_text::StaticText, wire::{WpContentTypeV1Id, wp_content_type_v1::*}, }, jay_config::window::{ @@ -26,6 +27,16 @@ pub enum ContentType { Game, } +impl StaticText for ContentType { + fn text(&self) -> &'static str { + match self { + Self::Photo => "Photo", + Self::Video => "Video", + Self::Game => "Game", + } + } +} + pub trait ContentTypeExt { fn to_config(&self) -> ConfigContentType; } diff --git a/src/theme.rs b/src/theme.rs index 84a43997..ad54c0de 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -4,7 +4,7 @@ use { crate::{ cmm::cmm_eotf::{Eotf, bt1886_eotf_args, bt1886_inv_eotf_args}, gfx_api::AlphaMode, - utils::clonecell::CloneCell, + utils::{clonecell::CloneCell, static_text::StaticText}, }, jay_config::theme::BarPosition as ConfigBarPosition, linearize::Linearize, @@ -456,6 +456,30 @@ colors! { highlight = (0x9d, 0x28, 0xc6, 0x7f), } +impl StaticText for ThemeColor { + fn text(&self) -> &'static str { + match self { + ThemeColor::background => "Background", + ThemeColor::unfocused_title_background => "Title Background (unfocused)", + ThemeColor::focused_title_background => "Title Background (focused)", + ThemeColor::captured_unfocused_title_background => { + "Title Background (unfocused, captured)" + } + ThemeColor::captured_focused_title_background => "Title Background (focused, captured)", + ThemeColor::focused_inactive_title_background => "Title Background (focused, inactive)", + ThemeColor::unfocused_title_text => "Title Text (unfocused)", + ThemeColor::focused_title_text => "Title Text (focused)", + ThemeColor::focused_inactive_title_text => "Title Text (focused, inactive)", + ThemeColor::separator => "Separator", + ThemeColor::border => "Border", + ThemeColor::bar_background => "Bar Background", + ThemeColor::bar_text => "Bar Text", + ThemeColor::attention_requested_background => "Attention Requested", + ThemeColor::highlight => "Highlight", + } + } +} + pub struct ThemeSize { pub val: Cell, pub set: Cell, @@ -564,6 +588,17 @@ sizes! { bar_separator_width = (0, 1000, 1), } +impl StaticText for ThemeSized { + fn text(&self) -> &'static str { + match self { + ThemeSized::title_height => "Title Height", + ThemeSized::bar_height => "Bar Height", + ThemeSized::border_width => "Border Width", + ThemeSized::bar_separator_width => "Bar Separator Width", + } + } +} + pub const DEFAULT_FONT: &str = "monospace 8"; #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default, Linearize)] @@ -573,6 +608,15 @@ pub enum BarPosition { Bottom, } +impl StaticText for BarPosition { + fn text(&self) -> &'static str { + match self { + BarPosition::Top => "Top", + BarPosition::Bottom => "Bottom", + } + } +} + impl TryFrom for BarPosition { type Error = (); diff --git a/src/tree.rs b/src/tree.rs index 50a9624b..6495f1b7 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -25,7 +25,7 @@ use { keyboard::KeyboardState, rect::Rect, renderer::Renderer, - utils::{linkedlist::NodeRef, numcell::NumCell}, + utils::{linkedlist::NodeRef, numcell::NumCell, static_text::StaticText}, }, jay_config::{ Direction as JayDirection, video::Transform as ConfigTransform, @@ -79,6 +79,15 @@ impl Into for WorkspaceDisplayOrder { } } +impl StaticText for WorkspaceDisplayOrder { + fn text(&self) -> &'static str { + match self { + WorkspaceDisplayOrder::Manual => "Manual", + WorkspaceDisplayOrder::Sorted => "Sorted", + } + } +} + #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default, Linearize)] pub enum Transform { #[default] diff --git a/src/utils.rs b/src/utils.rs index 8b0ac860..7c956c82 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -54,6 +54,7 @@ pub mod run_toplevel; pub mod scroller; pub mod smallmap; pub mod stack; +pub mod static_text; pub mod string_ext; pub mod syncqueue; pub mod threshold_counter; diff --git a/src/utils/static_text.rs b/src/utils/static_text.rs new file mode 100644 index 00000000..eb8d03c1 --- /dev/null +++ b/src/utils/static_text.rs @@ -0,0 +1,3 @@ +pub trait StaticText { + fn text(&self) -> &'static str; +}