1
0
Fork 0
forked from wry/wry

static-text: add new utility

This commit is contained in:
Julian Orth 2026-03-07 12:23:01 +01:00
parent 8f57f72d14
commit 97f7b68369
10 changed files with 150 additions and 15 deletions

View file

@ -22,6 +22,7 @@ use {
}, },
}, },
libinput::consts::DeviceCapability, libinput::consts::DeviceCapability,
utils::static_text::StaticText,
video::drm::{ video::drm::{
ConnectorType, DRM_MODE_COLORIMETRY_BT2020_RGB, DRM_MODE_COLORIMETRY_DEFAULT, ConnectorType, DRM_MODE_COLORIMETRY_BT2020_RGB, DRM_MODE_COLORIMETRY_DEFAULT,
DrmConnector, DrmError, DrmVersion, HDMI_EOTF_SMPTE_ST2084, DrmConnector, DrmError, DrmVersion, HDMI_EOTF_SMPTE_ST2084,
@ -278,6 +279,20 @@ pub enum InputDeviceCapability {
Switch, 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 { impl InputDeviceCapability {
pub fn to_libinput(self) -> DeviceCapability { pub fn to_libinput(self) -> DeviceCapability {
use crate::libinput::consts::*; use crate::libinput::consts::*;
@ -299,6 +314,15 @@ pub enum InputDeviceAccelProfile {
Adaptive, Adaptive,
} }
impl StaticText for InputDeviceAccelProfile {
fn text(&self) -> &'static str {
match self {
InputDeviceAccelProfile::Flat => "Flat",
InputDeviceAccelProfile::Adaptive => "Adaptive",
}
}
}
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum InputDeviceClickMethod { pub enum InputDeviceClickMethod {
None, None,
@ -306,6 +330,16 @@ pub enum InputDeviceClickMethod {
Clickfinger, 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 { pub enum BackendEvent {
NewDrmDevice(Rc<dyn BackendDrmDevice>), NewDrmDevice(Rc<dyn BackendDrmDevice>),
NewConnector(Rc<dyn Connector>), NewConnector(Rc<dyn Connector>),

View file

@ -9,7 +9,7 @@ use {
LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER, LIBINPUT_CONFIG_CLICK_METHOD_NONE, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER, LIBINPUT_CONFIG_CLICK_METHOD_NONE,
}, },
tools::tool_client::{Handle, ToolClient, with_tool_client}, 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}, wire::{JayInputId, jay_compositor, jay_input},
}, },
clap::{Args, Subcommand, ValueEnum, ValueHint}, clap::{Args, Subcommand, ValueEnum, ValueHint},
@ -854,21 +854,11 @@ impl Input {
print!("{prefix} capabilities:"); print!("{prefix} capabilities:");
let mut first = true; let mut first = true;
for cap in &device.capabilities { for cap in &device.capabilities {
use InputDeviceCapability::*;
print!(" "); print!(" ");
if !mem::take(&mut first) { if !mem::take(&mut first) {
print!("| "); print!("| ");
} }
let name = match cap { print!("{}", cap.text());
Keyboard => "keyboard",
Pointer => "pointer",
Touch => "touch",
TabletTool => "tablet tool",
TabletPad => "tablet pad",
Gesture => "gesture",
Switch => "switch",
};
print!("{}", name);
} }
println!(); println!();
if let Some(v) = &device.accel_profile { if let Some(v) = &device.accel_profile {

View file

@ -25,6 +25,7 @@ use {
pending_serial::PendingSerial, pending_serial::PendingSerial,
pid_info::{PidInfo, get_pid_info, get_socket_creds}, pid_info::{PidInfo, get_pid_info, get_socket_creds},
pidfd_send_signal::pidfd_send_signal, pidfd_send_signal::pidfd_send_signal,
static_text::StaticText,
}, },
wire::WlRegistryId, wire::WlRegistryId,
}, },
@ -68,6 +69,28 @@ bitflags! {
CAP_GAMMA_CONTROL_MANAGER = 1 << 14, 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: ClientCaps = ClientCaps(CAP_LAYER_SHELL.0 | CAP_DRM_LEASE.0);
pub const CAPS_DEFAULT_SANDBOXED: ClientCaps = ClientCaps(CAP_DRM_LEASE.0); pub const CAPS_DEFAULT_SANDBOXED: ClientCaps = ClientCaps(CAP_DRM_LEASE.0);

View file

@ -77,6 +77,7 @@ use {
rc_eq::RcEq, rc_eq::RcEq,
refcounted::RefCounted, refcounted::RefCounted,
run_toplevel::RunToplevel, run_toplevel::RunToplevel,
static_text::StaticText,
tri::Try, tri::Try,
}, },
version::VERSION, version::VERSION,
@ -850,6 +851,19 @@ impl From<LevelFilter> 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<ConfigLogLevel> for LogLevel { impl From<ConfigLogLevel> for LogLevel {
fn from(value: ConfigLogLevel) -> Self { fn from(value: ConfigLogLevel) -> Self {
match value { match value {

View file

@ -15,7 +15,7 @@ use {
state::State, state::State,
theme::Color, theme::Color,
tree::{Node, OutputNode, Transform}, tree::{Node, OutputNode, Transform},
utils::{clonecell::UnsafeCellCloneSafe, errorfmt::ErrorFmt}, utils::{clonecell::UnsafeCellCloneSafe, errorfmt::ErrorFmt, static_text::StaticText},
video::{ video::{
Modifier, Modifier,
dmabuf::DmaBuf, dmabuf::DmaBuf,
@ -47,6 +47,12 @@ pub enum GfxApi {
Vulkan, Vulkan,
} }
impl StaticText for GfxApi {
fn text(&self) -> &'static str {
self.to_str()
}
}
impl TryFrom<ConfigGfxApi> for GfxApi { impl TryFrom<ConfigGfxApi> for GfxApi {
type Error = (); type Error = ();

View file

@ -4,6 +4,7 @@ use {
ifs::wl_surface::WlSurface, ifs::wl_surface::WlSurface,
leaks::Tracker, leaks::Tracker,
object::{Object, Version}, object::{Object, Version},
utils::static_text::StaticText,
wire::{WpContentTypeV1Id, wp_content_type_v1::*}, wire::{WpContentTypeV1Id, wp_content_type_v1::*},
}, },
jay_config::window::{ jay_config::window::{
@ -26,6 +27,16 @@ pub enum ContentType {
Game, Game,
} }
impl StaticText for ContentType {
fn text(&self) -> &'static str {
match self {
Self::Photo => "Photo",
Self::Video => "Video",
Self::Game => "Game",
}
}
}
pub trait ContentTypeExt { pub trait ContentTypeExt {
fn to_config(&self) -> ConfigContentType; fn to_config(&self) -> ConfigContentType;
} }

View file

@ -4,7 +4,7 @@ use {
crate::{ crate::{
cmm::cmm_eotf::{Eotf, bt1886_eotf_args, bt1886_inv_eotf_args}, cmm::cmm_eotf::{Eotf, bt1886_eotf_args, bt1886_inv_eotf_args},
gfx_api::AlphaMode, gfx_api::AlphaMode,
utils::clonecell::CloneCell, utils::{clonecell::CloneCell, static_text::StaticText},
}, },
jay_config::theme::BarPosition as ConfigBarPosition, jay_config::theme::BarPosition as ConfigBarPosition,
linearize::Linearize, linearize::Linearize,
@ -456,6 +456,30 @@ colors! {
highlight = (0x9d, 0x28, 0xc6, 0x7f), 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 struct ThemeSize {
pub val: Cell<i32>, pub val: Cell<i32>,
pub set: Cell<bool>, pub set: Cell<bool>,
@ -564,6 +588,17 @@ sizes! {
bar_separator_width = (0, 1000, 1), 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"; pub const DEFAULT_FONT: &str = "monospace 8";
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default, Linearize)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default, Linearize)]
@ -573,6 +608,15 @@ pub enum BarPosition {
Bottom, Bottom,
} }
impl StaticText for BarPosition {
fn text(&self) -> &'static str {
match self {
BarPosition::Top => "Top",
BarPosition::Bottom => "Bottom",
}
}
}
impl TryFrom<ConfigBarPosition> for BarPosition { impl TryFrom<ConfigBarPosition> for BarPosition {
type Error = (); type Error = ();

View file

@ -25,7 +25,7 @@ use {
keyboard::KeyboardState, keyboard::KeyboardState,
rect::Rect, rect::Rect,
renderer::Renderer, renderer::Renderer,
utils::{linkedlist::NodeRef, numcell::NumCell}, utils::{linkedlist::NodeRef, numcell::NumCell, static_text::StaticText},
}, },
jay_config::{ jay_config::{
Direction as JayDirection, video::Transform as ConfigTransform, Direction as JayDirection, video::Transform as ConfigTransform,
@ -79,6 +79,15 @@ impl Into<ConfigWorkspaceDisplayOrder> 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)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Default, Linearize)]
pub enum Transform { pub enum Transform {
#[default] #[default]

View file

@ -54,6 +54,7 @@ pub mod run_toplevel;
pub mod scroller; pub mod scroller;
pub mod smallmap; pub mod smallmap;
pub mod stack; pub mod stack;
pub mod static_text;
pub mod string_ext; pub mod string_ext;
pub mod syncqueue; pub mod syncqueue;
pub mod threshold_counter; pub mod threshold_counter;

3
src/utils/static_text.rs Normal file
View file

@ -0,0 +1,3 @@
pub trait StaticText {
fn text(&self) -> &'static str;
}