-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #223 from mahkoh/jorth/damage-tracking
Implement damage tracking
- Loading branch information
Showing
68 changed files
with
1,533 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# Unreleased | ||
|
||
- Add fine-grained damage tracking. | ||
|
||
# 1.4.0 (2024-07-07) | ||
|
||
- Add window management mode. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use { | ||
crate::{theme::Color, utils::errorfmt::ErrorFmt}, | ||
std::ops::Range, | ||
}; | ||
|
||
pub fn parse_color(string: &str) -> Color { | ||
let hex = match string.strip_prefix("#") { | ||
Some(s) => s, | ||
_ => fatal!("Color must start with #"), | ||
}; | ||
let d = |range: Range<usize>| match u8::from_str_radix(&hex[range.clone()], 16) { | ||
Ok(n) => n, | ||
Err(e) => { | ||
fatal!( | ||
"Could not parse color component {}: {}", | ||
&hex[range], | ||
ErrorFmt(e) | ||
) | ||
} | ||
}; | ||
let s = |range: Range<usize>| { | ||
let v = d(range); | ||
(v << 4) | v | ||
}; | ||
let (r, g, b, a) = match hex.len() { | ||
3 => (s(0..1), s(1..2), s(2..3), u8::MAX), | ||
4 => (s(0..1), s(1..2), s(2..3), s(3..4)), | ||
6 => (d(0..2), d(2..4), d(4..6), u8::MAX), | ||
8 => (d(0..2), d(2..4), d(4..6), d(6..8)), | ||
_ => fatal!( | ||
"Unexpected length of color string (should be 3, 4, 6, or 8): {}", | ||
hex.len() | ||
), | ||
}; | ||
jay_config::theme::Color::new_straight(r, g, b, a).into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use { | ||
crate::{ | ||
cli::{color::parse_color, duration::parse_duration, GlobalArgs}, | ||
tools::tool_client::{with_tool_client, ToolClient}, | ||
wire::jay_damage_tracking::{SetVisualizerColor, SetVisualizerDecay, SetVisualizerEnabled}, | ||
}, | ||
clap::{Args, Subcommand}, | ||
std::rc::Rc, | ||
}; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct DamageTrackingArgs { | ||
#[clap(subcommand)] | ||
pub command: DamageTrackingCmd, | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum DamageTrackingCmd { | ||
/// Visualize damage. | ||
Show, | ||
/// Hide damage. | ||
Hide, | ||
/// Set the color used for damage visualization. | ||
SetColor(ColorArgs), | ||
/// Set the amount of time damage is shown. | ||
SetDecay(DecayArgs), | ||
} | ||
|
||
#[derive(Args, Debug)] | ||
pub struct ColorArgs { | ||
/// The color to visualize damage. | ||
/// | ||
/// Should be specified in one of the following formats: | ||
/// | ||
/// * `#rgb` | ||
/// * `#rgba` | ||
/// * `#rrggbb` | ||
/// * `#rrggbbaa` | ||
pub color: String, | ||
} | ||
|
||
#[derive(Args, Debug)] | ||
pub struct DecayArgs { | ||
/// The interval of inactivity after which to disable the screens. | ||
/// | ||
/// Minutes, seconds, and milliseconds can be specified in any of the following formats: | ||
/// | ||
/// * 1m | ||
/// * 1m5s | ||
/// * 1m 5s | ||
/// * 1min 5sec | ||
/// * 1 minute 5 seconds. | ||
pub duration: Vec<String>, | ||
} | ||
|
||
pub fn main(global: GlobalArgs, damage_tracking_args: DamageTrackingArgs) { | ||
with_tool_client(global.log_level.into(), |tc| async move { | ||
let damage_tracking = Rc::new(DamageTracking { tc: tc.clone() }); | ||
damage_tracking.run(damage_tracking_args).await; | ||
}); | ||
} | ||
|
||
struct DamageTracking { | ||
tc: Rc<ToolClient>, | ||
} | ||
|
||
impl DamageTracking { | ||
async fn run(&self, args: DamageTrackingArgs) { | ||
let tc = &self.tc; | ||
let Some(dt) = tc.jay_damage_tracking().await else { | ||
fatal!("Compositor does not support damage tracking"); | ||
}; | ||
match args.command { | ||
DamageTrackingCmd::Show => { | ||
tc.send(SetVisualizerEnabled { | ||
self_id: dt, | ||
enabled: 1, | ||
}); | ||
} | ||
DamageTrackingCmd::Hide => { | ||
tc.send(SetVisualizerEnabled { | ||
self_id: dt, | ||
enabled: 0, | ||
}); | ||
} | ||
DamageTrackingCmd::SetColor(c) => { | ||
let color = parse_color(&c.color); | ||
tc.send(SetVisualizerColor { | ||
self_id: dt, | ||
r: color.r, | ||
g: color.g, | ||
b: color.b, | ||
a: color.a, | ||
}); | ||
} | ||
DamageTrackingCmd::SetDecay(c) => { | ||
let duration = parse_duration(&c.duration); | ||
tc.send(SetVisualizerDecay { | ||
self_id: dt, | ||
millis: duration.as_millis() as _, | ||
}); | ||
} | ||
} | ||
tc.round_trip().await; | ||
} | ||
} |
Oops, something went wrong.