1
0
Fork 0
forked from wry/wry

tree: allow floats to be pinned

This commit is contained in:
Julian Orth 2025-04-24 14:21:25 +02:00
parent 3e6640f0ca
commit 65a66c2e26
28 changed files with 528 additions and 36 deletions

View file

@ -14,6 +14,7 @@ use {
parsers::{
color_management::ColorManagement,
config::{ConfigParser, ConfigParserError},
float::Float,
},
},
toml::{self},
@ -58,6 +59,8 @@ pub enum SimpleCommand {
EnableWindowManagement(bool),
SetFloatAboveFullscreen(bool),
ToggleFloatAboveFullscreen,
SetFloatPinned(bool),
ToggleFloatPinned,
}
#[derive(Debug, Clone)]
@ -367,6 +370,7 @@ pub struct Config {
pub ui_drag: UiDrag,
pub xwayland: Option<Xwayland>,
pub color_management: Option<ColorManagement>,
pub float: Option<Float>,
}
#[derive(Debug, Error)]

View file

@ -16,6 +16,7 @@ mod drm_device;
mod drm_device_match;
mod env;
pub mod exec;
pub mod float;
mod format;
mod gfx_api;
mod idle;

View file

@ -116,6 +116,9 @@ impl ActionParser<'_> {
"enable-float-above-fullscreen" => SetFloatAboveFullscreen(true),
"disable-float-above-fullscreen" => SetFloatAboveFullscreen(false),
"toggle-float-above-fullscreen" => ToggleFloatAboveFullscreen,
"pin-float" => SetFloatPinned(true),
"unpin-float" => SetFloatPinned(false),
"toggle-float-pinned" => ToggleFloatPinned,
_ => {
return Err(
ActionParserError::UnknownSimpleAction(string.to_string()).spanned(span)

View file

@ -12,6 +12,7 @@ use {
drm_device::DrmDevicesParser,
drm_device_match::DrmDeviceMatchParser,
env::EnvParser,
float::FloatParser,
gfx_api::GfxApiParser,
idle::IdleParser,
input::InputsParser,
@ -118,7 +119,7 @@ impl Parser for ConfigParser<'_> {
ui_drag_val,
xwayland_val,
),
(color_management_val,),
(color_management_val, float_val),
) = ext.extract((
(
opt(val("keymap")),
@ -156,7 +157,7 @@ impl Parser for ConfigParser<'_> {
opt(val("ui-drag")),
opt(val("xwayland")),
),
(opt(val("color-management")),),
(opt(val("color-management")), opt(val("float"))),
))?;
let mut keymap = None;
if let Some(value) = keymap_val {
@ -381,6 +382,15 @@ impl Parser for ConfigParser<'_> {
}
}
}
let mut float = None;
if let Some(value) = float_val {
match value.parse(&mut FloatParser(self.0)) {
Ok(v) => float = Some(v),
Err(e) => {
log::warn!("Could not parse the float settings: {}", self.0.error(e));
}
}
}
Ok(Config {
keymap,
repeat_rate,
@ -412,6 +422,7 @@ impl Parser for ConfigParser<'_> {
ui_drag,
xwayland,
color_management,
float,
})
}
}

View file

@ -0,0 +1,48 @@
use {
crate::{
config::{
context::Context,
extractor::{Extractor, ExtractorError, bol, opt, recover},
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
},
toml::{
toml_span::{DespanExt, Span, Spanned},
toml_value::Value,
},
},
indexmap::IndexMap,
thiserror::Error,
};
#[derive(Debug, Error)]
pub enum FloatParserError {
#[error(transparent)]
Expected(#[from] UnexpectedDataType),
#[error(transparent)]
Extract(#[from] ExtractorError),
}
pub struct FloatParser<'a>(pub &'a Context<'a>);
#[derive(Debug, Clone)]
pub struct Float {
pub show_pin_icon: Option<bool>,
}
impl Parser for FloatParser<'_> {
type Value = Float;
type Error = FloatParserError;
const EXPECTED: &'static [DataType] = &[DataType::Table];
fn parse_table(
&mut self,
span: Span,
table: &IndexMap<Spanned<String>, Spanned<Value>>,
) -> ParseResult<Self> {
let mut ext = Extractor::new(self.0, span, table);
let (show_pin_icon,) = ext.extract((recover(opt(bol("show-pin-icon"))),))?;
Ok(Float {
show_pin_icon: show_pin_icon.despan(),
})
}
}

View file

@ -25,7 +25,8 @@ use {
logging::set_log_level,
on_devices_enumerated, on_idle, quit, reload, set_color_management_enabled,
set_default_workspace_capture, set_explicit_sync_enabled, set_float_above_fullscreen,
set_idle, set_idle_grace_period, set_ui_drag_enabled, set_ui_drag_threshold,
set_idle, set_idle_grace_period, 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},
switch_to_vt,
theme::{reset_colors, reset_font, reset_sizes, set_font},
@ -101,6 +102,8 @@ impl Action {
B::new(move || set_float_above_fullscreen(bool))
}
SimpleCommand::ToggleFloatAboveFullscreen => B::new(toggle_float_above_fullscreen),
SimpleCommand::SetFloatPinned(pinned) => B::new(move || s.set_float_pinned(pinned)),
SimpleCommand::ToggleFloatPinned => B::new(move || s.toggle_float_pinned()),
},
Action::Multi { actions } => {
let actions: Vec<_> = actions.into_iter().map(|a| a.into_fn(state)).collect();
@ -1096,6 +1099,11 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
set_color_management_enabled(enabled);
}
}
if let Some(float) = config.float {
if let Some(show) = float.show_pin_icon {
set_show_float_pin_icon(show);
}
}
}
fn create_command(exec: &Exec) -> Command {