mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-28 03:12:46 +01:00
style(windows): format with the project's rustfmt settings (tools/format-all --apply --tree windows)
Pure formatting by the same nightly rustfmt invocation the nix fmt check uses (tools/format-all, edition 2024, the tree's rustfmt.toml). No code change. Applied last on the candidate because it touches many files other agents were editing. Verified: tools/format-all --check --tree windows passes afterwards; light gates (fast-check) after all three.
This commit is contained in:
1 parent
c670ab35c8
commit
e70a0e4921
19 files changed
+266
-110
No files matched your search
@@ -42,5 +42,5 @@ pub use id::MonitorId;
|
||||
pub use id::WindowId;
|
||||
pub use info::MonitorInfo;
|
||||
pub use info::WindowInfo;
|
||||
pub use registry::Registry;
|
||||
pub use komorebi_layouts::Rect;
|
||||
pub use registry::Registry;
|
||||
@@ -1,20 +1,20 @@
|
||||
use crate::config::types::*;
|
||||
use crate::statics::AUTO_SELECT_FILL_COLOUR;
|
||||
use crate::statics::AUTO_SELECT_TEXT_COLOUR;
|
||||
use crate::statics::DEFAULT_PADDING;
|
||||
use crate::platform::platform;
|
||||
use crate::render::Grouping;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::render::RenderExt;
|
||||
use crate::statics::AUTO_SELECT_FILL_COLOUR;
|
||||
use crate::statics::AUTO_SELECT_TEXT_COLOUR;
|
||||
use crate::statics::DEFAULT_PADDING;
|
||||
use crate::widgets::widget::WidgetConfig;
|
||||
use eframe::egui::Color32;
|
||||
use eframe::egui::Context;
|
||||
use eframe::egui::FontId;
|
||||
use eframe::egui::TextBuffer;
|
||||
use eframe::egui::TextStyle;
|
||||
use komorebi_protocol::pathext::PathExt;
|
||||
use komorebi_layouts::Rect;
|
||||
use komorebi_protocol::message::SocketMessage;
|
||||
use komorebi_protocol::pathext::PathExt;
|
||||
use komorebi_themes::colour::Colour;
|
||||
use komorebi_themes::colour::Rgb;
|
||||
use serde::Deserialize;
|
||||
@@ -535,7 +535,9 @@ impl KomobarConfig {
|
||||
);
|
||||
|
||||
if value.mouse.is_some() && !cfg!(target_os = "windows") {
|
||||
tracing::warn!("the `mouse` options are not supported on this platform and are ignored");
|
||||
tracing::warn!(
|
||||
"the `mouse` options are not supported on this platform and are ignored"
|
||||
);
|
||||
}
|
||||
|
||||
if value.frame.is_none() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::config::DisplayFormat;
|
||||
use crate::platform::platform;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::platform::platform;
|
||||
use crate::widgets::komorebi_config::KomorebiLayout;
|
||||
use crate::widgets::komorebi_config::KomorebiLayoutConfig;
|
||||
use eframe::egui::Context;
|
||||
@@ -61,38 +61,44 @@ impl KomorebiLayoutExt for KomorebiLayout {
|
||||
match self {
|
||||
KomorebiLayout::Default(option) => {
|
||||
if let Some(ws_idx) = workspace_idx
|
||||
&& platform().send_komorebi_message(&SocketMessage::WorkspaceLayout(
|
||||
monitor_idx,
|
||||
ws_idx,
|
||||
*option,
|
||||
))
|
||||
.is_err()
|
||||
&& platform()
|
||||
.send_komorebi_message(&SocketMessage::WorkspaceLayout(
|
||||
monitor_idx,
|
||||
ws_idx,
|
||||
*option,
|
||||
))
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!("could not send message to komorebi: WorkspaceLayout");
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Monocle => {
|
||||
if platform().send_komorebi_batch(vec![
|
||||
SocketMessage::FocusMonitorAtCursor,
|
||||
SocketMessage::ToggleMonocle,
|
||||
])
|
||||
.is_err()
|
||||
if platform()
|
||||
.send_komorebi_batch(vec![
|
||||
SocketMessage::FocusMonitorAtCursor,
|
||||
SocketMessage::ToggleMonocle,
|
||||
])
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!("could not send message to komorebi: ToggleMonocle");
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Floating => {
|
||||
if platform().send_komorebi_batch(vec![
|
||||
SocketMessage::FocusMonitorAtCursor,
|
||||
SocketMessage::ToggleTiling,
|
||||
])
|
||||
.is_err()
|
||||
if platform()
|
||||
.send_komorebi_batch(vec![
|
||||
SocketMessage::FocusMonitorAtCursor,
|
||||
SocketMessage::ToggleTiling,
|
||||
])
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!("could not send message to komorebi: ToggleTiling");
|
||||
}
|
||||
}
|
||||
KomorebiLayout::Paused => {
|
||||
if platform().send_komorebi_message(&SocketMessage::TogglePause).is_err() {
|
||||
if platform()
|
||||
.send_komorebi_message(&SocketMessage::TogglePause)
|
||||
.is_err()
|
||||
{
|
||||
tracing::error!("could not send message to komorebi: TogglePause");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use crate::alignment::Alignment;
|
||||
use crate::config::LabelPrefix;
|
||||
use crate::platform::SystemTool;
|
||||
use crate::platform::platform;
|
||||
use crate::render::RenderConfig;
|
||||
use crate::selected_frame::SelectableFrame;
|
||||
use crate::widgets::widget::BarWidget;
|
||||
@@ -11,8 +13,6 @@ use eframe::egui::Ui;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use crate::platform::SystemTool;
|
||||
use crate::platform::platform;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
use sysinfo::Disks;
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
//! A container can be locked ([`Lockable`]): a locked container keeps its index in the workspace
|
||||
//! while others are inserted, removed or swapped around it.
|
||||
|
||||
use color_eyre::eyre;
|
||||
use komorebi_collections::Lockable;
|
||||
use komorebi_collections::ring::Ring;
|
||||
use nanoid::nanoid;
|
||||
use color_eyre::eyre;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::VecDeque;
|
||||
@@ -319,7 +319,10 @@ mod tests {
|
||||
}
|
||||
|
||||
fn hide_stacked(&self, spot: u8) -> eyre::Result<()> {
|
||||
LOG.with(|log| log.borrow_mut().push(format!("hide-stacked {} at {spot}", self.0)));
|
||||
LOG.with(|log| {
|
||||
log.borrow_mut()
|
||||
.push(format!("hide-stacked {} at {spot}", self.0))
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -435,7 +438,11 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
log(),
|
||||
["restore-stacked 1", "hide-stacked 2 at 7", "hide-stacked 3 at 7"]
|
||||
[
|
||||
"restore-stacked 1",
|
||||
"hide-stacked 2 at 7",
|
||||
"hide-stacked 3 at 7"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ pub use container::Container;
|
||||
pub use container::ContainerWindow;
|
||||
pub use container::WorkspaceWindow;
|
||||
pub use globals::WorkspaceGlobals;
|
||||
pub use monitor::*;
|
||||
pub use workspace::*;
|
||||
pub use komorebi_collections::Lockable;
|
||||
pub use komorebi_collections::ring;
|
||||
pub use monitor::*;
|
||||
pub use workspace::*;
|
||||
@@ -392,7 +392,8 @@ fn pointer_on_the_second_monitor() -> Host {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_pointer_picks_the_monitor_for_the_empty_close_last_cycle_and_number_commands_on_all_platforms() {
|
||||
fn the_pointer_picks_the_monitor_for_the_empty_close_last_cycle_and_number_commands_on_all_platforms()
|
||||
{
|
||||
// commands.py: close-workspace, cycle-empty-workspace, focus-last-workspace, focus-workspace,
|
||||
// focus-workspaces; the monitor under the pointer is focused first when its workspace is empty
|
||||
for command in 0..5 {
|
||||
@@ -400,7 +401,9 @@ fn the_pointer_picks_the_monitor_for_the_empty_close_last_cycle_and_number_comma
|
||||
match command {
|
||||
0 => komorebi_core::close_workspace(&mut host).unwrap(),
|
||||
1 => komorebi_core::focus_last_workspace(&mut host).unwrap(),
|
||||
2 => komorebi_core::cycle_focus_empty_workspace(&mut host, CycleDirection::Next).unwrap(),
|
||||
2 => {
|
||||
komorebi_core::cycle_focus_empty_workspace(&mut host, CycleDirection::Next).unwrap()
|
||||
}
|
||||
3 => komorebi_core::focus_workspace_number(&mut host, 1).unwrap(),
|
||||
_ => komorebi_core::focus_workspace_numbers(&mut host, 1).unwrap(),
|
||||
}
|
||||
|
||||
@@ -141,7 +141,8 @@ impl serde_with::schemars_1::JsonSchemaAs<PathBuf> for ResolvedPathBuf {
|
||||
#[cfg(target_os = "windows")]
|
||||
let description = "A file system path. Environment variables like %VAR%, $Env:VAR, or $VAR are automatically resolved.";
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let description = "A file system path. Environment variables like $VAR are automatically resolved.";
|
||||
let description =
|
||||
"A file system path. Environment variables like $VAR are automatically resolved.";
|
||||
|
||||
schemars::json_schema!({
|
||||
"type": "string",
|
||||
|
||||
@@ -18,7 +18,9 @@ use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
|
||||
fn resolve<'a>(root: &'a Value, r: &str) -> &'a Value {
|
||||
let path = r.strip_prefix("#/").unwrap_or_else(|| panic!("unsupported $ref {r}"));
|
||||
let path = r
|
||||
.strip_prefix("#/")
|
||||
.unwrap_or_else(|| panic!("unsupported $ref {r}"));
|
||||
let mut cur = root;
|
||||
for seg in path.split('/') {
|
||||
cur = cur.get(seg).unwrap_or_else(|| panic!("dangling $ref {r}"));
|
||||
@@ -34,12 +36,20 @@ thread_local! {
|
||||
/// The smallest value the schema accepts; deterministic (branch MODE.0, lowest bound).
|
||||
pub fn minimal(s: &Value, root: &Value, depth: usize) -> Value {
|
||||
assert!(depth < 40, "schema recursion too deep");
|
||||
let Some(o) = s.as_object() else { return Value::Null };
|
||||
let Some(o) = s.as_object() else {
|
||||
return Value::Null;
|
||||
};
|
||||
if let Some(r) = o.get("$ref").and_then(Value::as_str) {
|
||||
let mut base = minimal(resolve(root, r), root, depth + 1);
|
||||
// siblings of $ref (schemars adds `properties` for an internally tagged variant)
|
||||
if let (Value::Object(m), Some(p)) = (&mut base, o.get("properties").and_then(Value::as_object)) {
|
||||
let req: Vec<&str> = o.get("required").and_then(Value::as_array).map(|r| r.iter().filter_map(Value::as_str).collect()).unwrap_or_default();
|
||||
if let (Value::Object(m), Some(p)) =
|
||||
(&mut base, o.get("properties").and_then(Value::as_object))
|
||||
{
|
||||
let req: Vec<&str> = o
|
||||
.get("required")
|
||||
.and_then(Value::as_array)
|
||||
.map(|r| r.iter().filter_map(Value::as_str).collect())
|
||||
.unwrap_or_default();
|
||||
for (k, v) in p {
|
||||
if req.contains(&k.as_str()) {
|
||||
m.insert(k.clone(), minimal(v, root, depth + 1));
|
||||
@@ -59,7 +69,10 @@ pub fn minimal(s: &Value, root: &Value, depth: usize) -> Value {
|
||||
if let Some(b) = o.get(k).and_then(Value::as_array) {
|
||||
// prefer a branch that is not the bare null type; keep source order otherwise
|
||||
let (k, nulls) = MODE.get();
|
||||
let non_null: Vec<&Value> = b.iter().filter(|x| x.get("type") != Some(&json!("null"))).collect();
|
||||
let non_null: Vec<&Value> = b
|
||||
.iter()
|
||||
.filter(|x| x.get("type") != Some(&json!("null")))
|
||||
.collect();
|
||||
let null = b.iter().find(|x| x.get("type") == Some(&json!("null")));
|
||||
let pick = match (nulls, null) {
|
||||
(true, Some(n)) => n,
|
||||
@@ -104,11 +117,19 @@ pub fn minimal(s: &Value, root: &Value, depth: usize) -> Value {
|
||||
"null" => Value::Null,
|
||||
"boolean" => json!(false),
|
||||
"integer" | "number" => {
|
||||
let mut v = o.get("minimum").and_then(Value::as_f64).unwrap_or(0.0).max(0.0);
|
||||
let mut v = o
|
||||
.get("minimum")
|
||||
.and_then(Value::as_f64)
|
||||
.unwrap_or(0.0)
|
||||
.max(0.0);
|
||||
if let Some(x) = o.get("exclusiveMinimum").and_then(Value::as_f64) {
|
||||
v = v.max(x + 1.0);
|
||||
}
|
||||
if ty == "integer" { json!(v as i64) } else { json!(v) }
|
||||
if ty == "integer" {
|
||||
json!(v as i64)
|
||||
} else {
|
||||
json!(v)
|
||||
}
|
||||
}
|
||||
"string" => json!("x"),
|
||||
"array" => {
|
||||
@@ -116,7 +137,10 @@ pub fn minimal(s: &Value, root: &Value, depth: usize) -> Value {
|
||||
return Value::Array(p.iter().map(|x| minimal(x, root, depth + 1)).collect());
|
||||
}
|
||||
let n = o.get("minItems").and_then(Value::as_u64).unwrap_or(0) as usize;
|
||||
let item = o.get("items").map(|i| minimal(i, root, depth + 1)).unwrap_or(Value::Null);
|
||||
let item = o
|
||||
.get("items")
|
||||
.map(|i| minimal(i, root, depth + 1))
|
||||
.unwrap_or(Value::Null);
|
||||
Value::Array(vec![item; n])
|
||||
}
|
||||
"object" => {
|
||||
@@ -151,27 +175,50 @@ where
|
||||
std::env::set_var("GOLDEN_VAR", "golden-value");
|
||||
}
|
||||
let schema = serde_json::to_value(schemars::schema_for!(T)).unwrap();
|
||||
std::fs::write(outdir.join("schema.json"), serde_json::to_string_pretty(&schema).unwrap() + "\n").unwrap();
|
||||
std::fs::write(
|
||||
outdir.join("schema.json"),
|
||||
serde_json::to_string_pretty(&schema).unwrap() + "\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branches = schema["oneOf"].as_array().expect("top-level oneOf");
|
||||
let mut out: BTreeMap<String, Value> = BTreeMap::new();
|
||||
let mut inst_by_name: BTreeMap<String, Value> = BTreeMap::new();
|
||||
for b in branches {
|
||||
let name = b["properties"]["type"]["const"].as_str().expect("type const").to_owned();
|
||||
let name = b["properties"]["type"]["const"]
|
||||
.as_str()
|
||||
.expect("type const")
|
||||
.to_owned();
|
||||
let mut inst = Map::new();
|
||||
inst.insert("type".into(), json!(name));
|
||||
if let Some(c) = b["properties"].get("content") {
|
||||
inst.insert("content".into(), minimal(c, &schema, 0));
|
||||
}
|
||||
assert!(inst_by_name.insert(name, Value::Object(inst)).is_none(), "duplicate variant");
|
||||
assert!(
|
||||
inst_by_name.insert(name, Value::Object(inst)).is_none(),
|
||||
"duplicate variant"
|
||||
);
|
||||
}
|
||||
// more instances: other oneOf/enum branches (@1, @2, @3, only if different), null options (@nulls)
|
||||
let base: Vec<(String, Value)> = inst_by_name.iter().map(|(k, v)| (k.clone(), v.clone())).collect();
|
||||
let base: Vec<(String, Value)> = inst_by_name
|
||||
.iter()
|
||||
.map(|(k, v)| (k.clone(), v.clone()))
|
||||
.collect();
|
||||
for b in branches {
|
||||
let name = b["properties"]["type"]["const"].as_str().unwrap().to_owned();
|
||||
let Some(c) = b["properties"].get("content") else { continue };
|
||||
let name = b["properties"]["type"]["const"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_owned();
|
||||
let Some(c) = b["properties"].get("content") else {
|
||||
continue;
|
||||
};
|
||||
let mut seen = vec![inst_by_name[&name]["content"].clone()];
|
||||
for (suffix, mode) in [("@1", (1, false)), ("@2", (2, false)), ("@3", (3, false)), ("@nulls", (0, true))] {
|
||||
for (suffix, mode) in [
|
||||
("@1", (1, false)),
|
||||
("@2", (2, false)),
|
||||
("@3", (3, false)),
|
||||
("@nulls", (0, true)),
|
||||
] {
|
||||
MODE.set(mode);
|
||||
let v = minimal(c, &schema, 0);
|
||||
MODE.set((0, false));
|
||||
@@ -182,16 +229,22 @@ where
|
||||
if serde_json::from_value::<T>(inst.clone()).is_ok() {
|
||||
inst_by_name.insert(format!("{name}{suffix}"), inst);
|
||||
} else {
|
||||
println!(" skipped alternative instance {name}{suffix} (not accepted by the type)");
|
||||
println!(
|
||||
" skipped alternative instance {name}{suffix} (not accepted by the type)"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = base;
|
||||
for (name, content) in [
|
||||
("Load@~", "~/k.json"), ("Load@dollar", "$HOME/k.json"), ("Load@braces", "${GOLDEN_VAR}/k.json"),
|
||||
("Load@percent", "%USERPROFILE%/k.json"), ("Load@psenv", "$Env:USERPROFILE/k.json"),
|
||||
("Save@~", "~/k.json"), ("ReplaceConfiguration@dollar", "$HOME/k.json"),
|
||||
("Load@~", "~/k.json"),
|
||||
("Load@dollar", "$HOME/k.json"),
|
||||
("Load@braces", "${GOLDEN_VAR}/k.json"),
|
||||
("Load@percent", "%USERPROFILE%/k.json"),
|
||||
("Load@psenv", "$Env:USERPROFILE/k.json"),
|
||||
("Save@~", "~/k.json"),
|
||||
("ReplaceConfiguration@dollar", "$HOME/k.json"),
|
||||
("ReloadStaticConfiguration@percent", "%USERPROFILE%/k.json"),
|
||||
] {
|
||||
let t = name.split('@').next().unwrap();
|
||||
@@ -215,7 +268,11 @@ where
|
||||
let s = serde_json::to_string(&t).unwrap();
|
||||
wire = json!(s.clone());
|
||||
let back: T = serde_json::from_str(&s).expect("reserialised text must parse");
|
||||
assert_eq!(serde_json::to_value(&back).unwrap(), g, "{name}: unstable round trip");
|
||||
assert_eq!(
|
||||
serde_json::to_value(&back).unwrap(),
|
||||
g,
|
||||
"{name}: unstable round trip"
|
||||
);
|
||||
let eq = &g == inst;
|
||||
(g, true, eq)
|
||||
}
|
||||
@@ -228,7 +285,11 @@ where
|
||||
json!({ "instance": inst, "wire": wire, "golden": golden, "deserialised": de, "roundtrip_equal": eq, "payload_stubbed": stubbed.contains(&name.as_str()) }),
|
||||
);
|
||||
}
|
||||
std::fs::write(outdir.join("variants.json"), serde_json::to_string_pretty(&out).unwrap() + "\n").unwrap();
|
||||
std::fs::write(
|
||||
outdir.join("variants.json"),
|
||||
serde_json::to_string_pretty(&out).unwrap() + "\n",
|
||||
)
|
||||
.unwrap();
|
||||
let names: Vec<&String> = out.keys().collect();
|
||||
std::fs::write(
|
||||
outdir.join("variants.txt"),
|
||||
@@ -244,7 +305,10 @@ where
|
||||
);
|
||||
for (n, v) in &out {
|
||||
if v["deserialised"] == json!(false) || v["roundtrip_equal"] == json!(false) {
|
||||
println!(" note {n}: deserialised={} equal={} golden={}", v["deserialised"], v["roundtrip_equal"], v["golden"]);
|
||||
println!(
|
||||
" note {n}: deserialised={} equal={} golden={}",
|
||||
v["deserialised"], v["roundtrip_equal"], v["golden"]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,18 +28,33 @@ use serde_json::Value;
|
||||
const PLATFORMS: [(&str, usize); 3] = [("windows", 1), ("kde", 2), ("macos", 3)];
|
||||
|
||||
fn golden(platform: &str) -> Value {
|
||||
let p = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/golden").join(platform).join("variants.json");
|
||||
let p = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("tests/golden")
|
||||
.join(platform)
|
||||
.join("variants.json");
|
||||
serde_json::from_str(&std::fs::read_to_string(p).unwrap()).unwrap()
|
||||
}
|
||||
|
||||
fn schema_variants(platform: &str) -> BTreeSet<String> {
|
||||
let p = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/golden").join(platform).join("schema-variants.txt");
|
||||
std::fs::read_to_string(p).unwrap().lines().map(str::to_owned).collect()
|
||||
let p = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("tests/golden")
|
||||
.join(platform)
|
||||
.join("schema-variants.txt");
|
||||
std::fs::read_to_string(p)
|
||||
.unwrap()
|
||||
.lines()
|
||||
.map(str::to_owned)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn table() -> Vec<Vec<String>> {
|
||||
let p = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/golden/variants-table.tsv");
|
||||
std::fs::read_to_string(p).unwrap().lines().skip(1).map(|l| l.split('\t').map(str::to_owned).collect()).collect()
|
||||
std::fs::read_to_string(p)
|
||||
.unwrap()
|
||||
.lines()
|
||||
.skip(1)
|
||||
.map(|l| l.split('\t').map(str::to_owned).collect())
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -63,24 +78,32 @@ fn golden_variants_match_the_support_table() {
|
||||
let rows = table();
|
||||
assert_eq!(rows.len(), 197);
|
||||
for (platform, col) in PLATFORMS {
|
||||
let from_table: BTreeSet<String> = rows.iter().filter(|r| r[col] != "-").map(|r| r[0].clone()).collect();
|
||||
let from_table: BTreeSet<String> = rows
|
||||
.iter()
|
||||
.filter(|r| r[col] != "-")
|
||||
.map(|r| r[0].clone())
|
||||
.collect();
|
||||
assert_eq!(from_table, schema_variants(platform), "{platform}");
|
||||
// every golden instance is of a variant of the platform (or one of its serde aliases)
|
||||
let g = golden(platform);
|
||||
for (name, v) in g.as_object().unwrap() {
|
||||
let ty = v["golden"]["type"].as_str().unwrap();
|
||||
assert!(from_table.contains(ty), "{platform}: {name} serialises as {ty}, which the table does not list");
|
||||
assert!(
|
||||
from_table.contains(ty),
|
||||
"{platform}: {name} serialises as {ty}, which the table does not list"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
use komorebi_protocol::message::SocketMessage;
|
||||
use komorebi_protocol::platforms::Platform;
|
||||
|
||||
/// Path-expansion instances depend on the compile target (HOME, %VAR%, ~): only with STRICT_PATHS=1
|
||||
fn is_path_extra(name: &str) -> bool {
|
||||
["@~", "@dollar", "@braces", "@percent", "@psenv"].iter().any(|s| name.ends_with(s))
|
||||
["@~", "@dollar", "@braces", "@percent", "@psenv"]
|
||||
.iter()
|
||||
.any(|s| name.ends_with(s))
|
||||
}
|
||||
|
||||
fn pin_environment() {
|
||||
@@ -127,11 +150,14 @@ fn the_unified_enum_accepts_every_golden_instance_with_the_same_wire_text() {
|
||||
|
||||
/// The variants of the unified schema, from the generator, one instance each
|
||||
fn unified() -> (Value, Value) {
|
||||
let dir = std::env::temp_dir().join(format!("komorebi-protocol-unified-{}", std::process::id()));
|
||||
let dir =
|
||||
std::env::temp_dir().join(format!("komorebi-protocol-unified-{}", std::process::id()));
|
||||
pin_environment();
|
||||
golden_gen::run::<SocketMessage>("unified", &dir, &[], &["ApplyState"]);
|
||||
let schema = serde_json::from_str(&std::fs::read_to_string(dir.join("schema.json")).unwrap()).unwrap();
|
||||
let variants = serde_json::from_str(&std::fs::read_to_string(dir.join("variants.json")).unwrap()).unwrap();
|
||||
let schema =
|
||||
serde_json::from_str(&std::fs::read_to_string(dir.join("schema.json")).unwrap()).unwrap();
|
||||
let variants =
|
||||
serde_json::from_str(&std::fs::read_to_string(dir.join("variants.json")).unwrap()).unwrap();
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
(schema, variants)
|
||||
}
|
||||
@@ -143,12 +169,23 @@ fn the_unified_schema_has_every_variant_of_every_platform_and_all_of_them_round_
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|b| b["properties"]["type"]["const"].as_str().unwrap().to_owned())
|
||||
.map(|b| {
|
||||
b["properties"]["type"]["const"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_owned()
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(in_schema.len(), 197);
|
||||
for (platform, _) in PLATFORMS {
|
||||
let missing: Vec<_> = schema_variants(platform).difference(&in_schema).cloned().collect();
|
||||
assert!(missing.is_empty(), "{platform}: {missing:?} are not in the unified schema");
|
||||
let missing: Vec<_> = schema_variants(platform)
|
||||
.difference(&in_schema)
|
||||
.cloned()
|
||||
.collect();
|
||||
assert!(
|
||||
missing.is_empty(),
|
||||
"{platform}: {missing:?} are not in the unified schema"
|
||||
);
|
||||
}
|
||||
for (name, v) in variants.as_object().unwrap() {
|
||||
assert_eq!(v["deserialised"], Value::Bool(true), "{name}");
|
||||
@@ -163,7 +200,12 @@ fn platforms_says_what_each_platform_handled_and_nothing_else() {
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|b| b["properties"]["type"]["const"].as_str().unwrap().to_owned())
|
||||
.map(|b| {
|
||||
b["properties"]["type"]["const"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_owned()
|
||||
})
|
||||
.collect();
|
||||
for (platform, _) in PLATFORMS {
|
||||
let handled = schema_variants(platform);
|
||||
@@ -173,7 +215,8 @@ fn platforms_says_what_each_platform_handled_and_nothing_else() {
|
||||
_ => Platform::MacOs,
|
||||
};
|
||||
for name in &all {
|
||||
let message: SocketMessage = serde_json::from_value(variants[name]["instance"].clone()).unwrap();
|
||||
let message: SocketMessage =
|
||||
serde_json::from_value(variants[name]["instance"].clone()).unwrap();
|
||||
assert_eq!(
|
||||
message.platforms().contains(which),
|
||||
handled.contains(name),
|
||||
@@ -196,7 +239,8 @@ enum Stand {
|
||||
fn generator_runs_on_a_stand_in_enum() {
|
||||
let dir = std::env::temp_dir().join(format!("komorebi-protocol-golden-{}", std::process::id()));
|
||||
golden_gen::run::<Stand>("stand-in", &dir, &[], &[]);
|
||||
let v: Value = serde_json::from_str(&std::fs::read_to_string(dir.join("variants.json")).unwrap()).unwrap();
|
||||
let v: Value =
|
||||
serde_json::from_str(&std::fs::read_to_string(dir.join("variants.json")).unwrap()).unwrap();
|
||||
for k in ["Unit", "Number", "Pair", "Maybe"] {
|
||||
assert_eq!(v[k]["deserialised"], Value::Bool(true), "{k}");
|
||||
}
|
||||
|
||||
@@ -60,16 +60,11 @@ use windows::Win32::UI::WindowsAndMessaging::DefWindowProcW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DestroyWindow;
|
||||
use windows::Win32::UI::WindowsAndMessaging::DispatchMessageW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GWL_STYLE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetMessageW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetWindowLongPtrW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetWindowRect;
|
||||
use windows::Win32::UI::WindowsAndMessaging::HWND_TOP;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SWP_FRAMECHANGED;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SWP_NOOWNERZORDER;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SetWindowLongPtrW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_POPUP;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_VISIBLE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::GetMessageW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::HMENU;
|
||||
use windows::Win32::UI::WindowsAndMessaging::HWND_TOP;
|
||||
use windows::Win32::UI::WindowsAndMessaging::IDC_ARROW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::LoadCursorW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::MINMAXINFO;
|
||||
@@ -78,8 +73,11 @@ use windows::Win32::UI::WindowsAndMessaging::PostMessageW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::PostQuitMessage;
|
||||
use windows::Win32::UI::WindowsAndMessaging::RegisterClassW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SW_SHOW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SWP_FRAMECHANGED;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SWP_NOMOVE;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SWP_NOOWNERZORDER;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SWP_NOZORDER;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SetWindowLongPtrW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SetWindowPos;
|
||||
use windows::Win32::UI::WindowsAndMessaging::SetWindowTextW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::ShowWindow;
|
||||
@@ -94,7 +92,9 @@ use windows::Win32::UI::WindowsAndMessaging::WM_PAINT;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WNDCLASSW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_MAXIMIZEBOX;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_OVERLAPPEDWINDOW;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_POPUP;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_THICKFRAME;
|
||||
use windows::Win32::UI::WindowsAndMessaging::WS_VISIBLE;
|
||||
use windows::core::PCWSTR;
|
||||
|
||||
/// Posted to the window when a command is waiting in [`COMMANDS`].
|
||||
|
||||
@@ -311,21 +311,30 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
-> eframe::AppCreator<'static> {
|
||||
Box::new(move |cc| {
|
||||
let ctx_repainter = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || loop {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
ctx_repainter.request_repaint();
|
||||
std::thread::spawn(move || {
|
||||
loop {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
ctx_repainter.request_repaint();
|
||||
}
|
||||
});
|
||||
|
||||
let ctx_komorebi = cc.egui_ctx.clone();
|
||||
std::thread::spawn(move || {
|
||||
let subscriber_name = format!("komorebi-bar-{}", random_word::get(random_word::Lang::En));
|
||||
let subscriber_name =
|
||||
format!("komorebi-bar-{}", random_word::get(random_word::Lang::En));
|
||||
|
||||
let listener = komorebi_client::subscribe_with_options(&subscriber_name, SubscribeOptions {
|
||||
filter_state_changes: true,
|
||||
})
|
||||
.expect("could not subscribe to komorebi notifications");
|
||||
let listener = komorebi_client::subscribe_with_options(
|
||||
&subscriber_name,
|
||||
SubscribeOptions {
|
||||
filter_state_changes: true,
|
||||
},
|
||||
)
|
||||
.expect("could not subscribe to komorebi notifications");
|
||||
|
||||
tracing::info!("subscribed to komorebi notifications: \"{}\"", subscriber_name);
|
||||
tracing::info!(
|
||||
"subscribed to komorebi notifications: \"{}\"",
|
||||
subscriber_name
|
||||
);
|
||||
|
||||
for client in listener.incoming() {
|
||||
match client {
|
||||
@@ -345,7 +354,7 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
while komorebi_client::send_message(
|
||||
&SocketMessage::AddSubscriberSocket(subscriber_name.clone()),
|
||||
)
|
||||
.is_err()
|
||||
.is_err()
|
||||
{
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
@@ -353,7 +362,9 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
tracing::info!("reconnected to komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Reconnect) {
|
||||
tracing::error!("could not send komorebi reconnect event to gui thread: {error}")
|
||||
tracing::error!(
|
||||
"could not send komorebi reconnect event to gui thread: {error}"
|
||||
)
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
@@ -368,14 +379,20 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
Ok(notification) => {
|
||||
tracing::debug!("received notification from komorebi");
|
||||
|
||||
if let Err(error) = tx_gui.send(KomorebiEvent::Notification(Box::new(notification))) {
|
||||
tracing::error!("could not send komorebi notification update to gui thread: {error}")
|
||||
if let Err(error) = tx_gui.send(
|
||||
KomorebiEvent::Notification(Box::new(notification)),
|
||||
) {
|
||||
tracing::error!(
|
||||
"could not send komorebi notification update to gui thread: {error}"
|
||||
)
|
||||
}
|
||||
|
||||
ctx_komorebi.request_repaint();
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::error!("could not deserialize komorebi notification: {error}");
|
||||
tracing::error!(
|
||||
"could not deserialize komorebi notification: {error}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -401,7 +418,14 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
native_options,
|
||||
// a creator for each attempt: the first is never run when its renderer fails to start, so the
|
||||
// second gets what it would have had (the channels are shared, the configuration is a copy)
|
||||
|_renderer| app_creator(tx_gui.clone(), rx_gui.clone(), rx_config.clone(), config.clone()),
|
||||
|_renderer| {
|
||||
app_creator(
|
||||
tx_gui.clone(),
|
||||
rx_gui.clone(),
|
||||
rx_config.clone(),
|
||||
config.clone(),
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -431,13 +455,19 @@ fn run_with_fallback(
|
||||
creator: impl Fn(eframe::Renderer) -> eframe::AppCreator<'static>,
|
||||
) -> color_eyre::Result<()> {
|
||||
tracing::info!("renderer: glow");
|
||||
match eframe::run_native("komorebi-bar", options(eframe::Renderer::Glow), creator(eframe::Renderer::Glow)) {
|
||||
match eframe::run_native(
|
||||
"komorebi-bar",
|
||||
options(eframe::Renderer::Glow),
|
||||
creator(eframe::Renderer::Glow),
|
||||
) {
|
||||
Err(error) if is_context_failure(&error) => {
|
||||
tracing::warn!("renderer: glow failed ({error}); trying wgpu");
|
||||
eframe::run_native("komorebi-bar", options(eframe::Renderer::Wgpu), creator(eframe::Renderer::Wgpu))
|
||||
.map_err(|wgpu| {
|
||||
color_eyre::eyre::Error::msg(format!("glow: {error}; wgpu: {wgpu}"))
|
||||
})
|
||||
eframe::run_native(
|
||||
"komorebi-bar",
|
||||
options(eframe::Renderer::Wgpu),
|
||||
creator(eframe::Renderer::Wgpu),
|
||||
)
|
||||
.map_err(|wgpu| color_eyre::eyre::Error::msg(format!("glow: {error}; wgpu: {wgpu}")))
|
||||
}
|
||||
result => result.map_err(|error| color_eyre::eyre::Error::msg(error.to_string())),
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ use crate::windows::widgets::ImageIcon;
|
||||
use egui_phosphor::regular::CALENDAR_DOTS;
|
||||
use komorebi_bar_core::platform::BarPlatform;
|
||||
use komorebi_bar_core::platform::SystemTool;
|
||||
use std::borrow::Cow;
|
||||
use komorebi_client::SocketMessage;
|
||||
use std::borrow::Cow;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::windows::config::LabelPrefix;
|
||||
pub use komorebi_bar_core::widgets::platform_config::KeyboardConfig;
|
||||
use crate::windows::render::RenderConfig;
|
||||
use crate::windows::widgets::widget::BarWidget;
|
||||
use color_eyre::eyre;
|
||||
@@ -10,6 +9,7 @@ use eframe::egui::TextFormat;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::WidgetText;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
pub use komorebi_bar_core::widgets::platform_config::KeyboardConfig;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::windows::MAX_LABEL_WIDTH;
|
||||
use crate::windows::bar::Alignment;
|
||||
use crate::windows::config::MediaDisplayFormat;
|
||||
pub use komorebi_bar_core::widgets::platform_config::MediaConfig;
|
||||
use crate::windows::render::RenderConfig;
|
||||
use crate::windows::selected_frame::SelectableFrame;
|
||||
use crate::windows::ui::CustomUi;
|
||||
@@ -13,6 +12,7 @@ use eframe::egui::TextFormat;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::Vec2;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
pub use komorebi_bar_core::widgets::platform_config::MediaConfig;
|
||||
use std::sync::atomic::Ordering;
|
||||
use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager;
|
||||
use windows::Media::Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
pub use komorebi_bar_core::widgets::applications;
|
||||
pub use komorebi_bar_core::widgets::battery;
|
||||
pub use komorebi_bar_core::widgets::cpu;
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
use crate::windows::bar::Alignment;
|
||||
pub use komorebi_bar_core::widgets::network_config::DefaultInterfaceConfig;
|
||||
pub use komorebi_bar_core::widgets::network_config::InterfaceDisplayType;
|
||||
pub use komorebi_bar_core::widgets::network_config::NetworkConfig;
|
||||
pub use komorebi_bar_core::widgets::network_config::NetworkSelectConfig;
|
||||
use crate::windows::config::LabelPrefix;
|
||||
use crate::windows::render::RenderConfig;
|
||||
use crate::windows::selected_frame::SelectableFrame;
|
||||
@@ -14,6 +10,10 @@ use eframe::egui::Label;
|
||||
use eframe::egui::TextFormat;
|
||||
use eframe::egui::Ui;
|
||||
use eframe::egui::text::LayoutJob;
|
||||
pub use komorebi_bar_core::widgets::network_config::DefaultInterfaceConfig;
|
||||
pub use komorebi_bar_core::widgets::network_config::InterfaceDisplayType;
|
||||
pub use komorebi_bar_core::widgets::network_config::NetworkConfig;
|
||||
pub use komorebi_bar_core::widgets::network_config::NetworkSelectConfig;
|
||||
use num_derive::FromPrimitive;
|
||||
use std::fmt;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
pub use komorebi::AnimationsConfig;
|
||||
pub use komorebi::AppSpecificConfigurationPath;
|
||||
pub use komorebi::AspectRatio;
|
||||
|
||||
@@ -252,7 +252,8 @@ impl eframe::App for KomorebiGui {
|
||||
ui.collapsing("Window Rules", |ui| {
|
||||
let window = Window::from(self.debug_hwnd);
|
||||
|
||||
let label = if let (Some(title), Some(exe)) = (window.title(), window.exe()) {
|
||||
let label = if let (Some(title), Some(exe)) = (window.title(), window.exe())
|
||||
{
|
||||
format!("{title} ({exe})")
|
||||
} else {
|
||||
String::from("Select a Window")
|
||||
|
||||
Reference in new issue
Block a user