diff --git a/src/debug.rs b/src/debug.rs index a70e15bf..f4925ed2 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -188,13 +188,28 @@ pub fn debug_ui( .default_pos([300.0, 300.0]) .show(ctx, |ui| { ui.label(format!("Global Space: {:?}", state.spaces.global_space())); - for output in state.spaces.outputs().cloned().collect::>().into_iter() { + for output in state + .spaces + .outputs() + .cloned() + .collect::>() + .into_iter() + { ui.separator(); ui.collapsing(output.name(), |ui| { ui.label(format!("Output: {:#?}", output)); - ui.label(format!("Geometry: {:?}", state.spaces.output_geometry(&output))); - ui.label(format!("Local Geometry: {:?}", state.spaces.active_space(&output).output_geometry(&output))); - ui.label(format!("Relative Geometry: {:?}", state.spaces.space_relative_output_geometry((0, 0), &output))); + ui.label(format!( + "Geometry: {:?}", + state.spaces.output_geometry(&output) + )); + ui.label(format!( + "Local Geometry: {:?}", + state.spaces.active_space(&output).output_geometry(&output) + )); + ui.label(format!( + "Relative Geometry: {:?}", + state.spaces.space_relative_output_geometry((0, 0), &output) + )); }); } }); @@ -220,52 +235,72 @@ pub fn log_ui( Some(state.egui.log_state.run( |ctx| { egui::SidePanel::right("Log") - .frame(egui::Frame { - margin: egui::Vec2::new(10.0, 10.0), - corner_radius: 5.0, - shadow: egui::epaint::Shadow { - extrusion: 0.0, - color: egui::Color32::TRANSPARENT, - }, - fill: egui::Color32::from_black_alpha(100), - stroke: egui::Stroke::none(), - }) + .frame(egui::Frame { + margin: egui::Vec2::new(10.0, 10.0), + corner_radius: 5.0, + shadow: egui::epaint::Shadow { + extrusion: 0.0, + color: egui::Color32::TRANSPARENT, + }, + fill: egui::Color32::from_black_alpha(100), + stroke: egui::Stroke::none(), + }) + .default_width(default_width) .default_width(default_width) - .show(ctx, |ui| { - egui::ScrollArea::vertical() - .always_show_scroll(true) - .stick_to_bottom() - .show(ui, |ui| { - for (i, record) in state.log.debug_buffer.lock().unwrap().iter().rev().enumerate() { - let mut message = egui::text::LayoutJob::single_section( - record.level.as_short_str().to_string(), - egui::TextFormat::simple(egui::TextStyle::Monospace, match record.level { - slog::Level::Critical => egui::Color32::RED, - slog::Level::Error => egui::Color32::LIGHT_RED, - slog::Level::Warning => egui::Color32::LIGHT_YELLOW, - slog::Level::Info => egui::Color32::LIGHT_BLUE, - slog::Level::Debug => egui::Color32::LIGHT_GREEN, - slog::Level::Trace => egui::Color32::GRAY, - }) - ); - message.append(&record.message, 6.0, egui::TextFormat::simple( - egui::TextStyle::Body, egui::Color32::WHITE, - )); - ui.vertical(|ui| { - ui.add(egui::Label::new(message)); - ui.add_space(4.0); - for (k, v) in &record.kv { - ui.horizontal(|ui| { - ui.add(egui::Label::new(egui::RichText::new(k).code()) - .sense(egui::Sense::click())) - .on_hover_cursor(egui::CursorIcon::PointingHand); - render_value(ui, v); + .default_width(default_width) + .show(ctx, |ui| { + egui::ScrollArea::vertical() + .always_show_scroll(true) + .stick_to_bottom() + .show(ui, |ui| { + for (_i, record) in state + .log + .debug_buffer + .lock() + .unwrap() + .iter() + .rev() + .enumerate() + { + let mut message = egui::text::LayoutJob::single_section( + record.level.as_short_str().to_string(), + egui::TextFormat::simple( + egui::TextStyle::Monospace, + match record.level { + slog::Level::Critical => egui::Color32::RED, + slog::Level::Error => egui::Color32::LIGHT_RED, + slog::Level::Warning => egui::Color32::LIGHT_YELLOW, + slog::Level::Info => egui::Color32::LIGHT_BLUE, + slog::Level::Debug => egui::Color32::LIGHT_GREEN, + slog::Level::Trace => egui::Color32::GRAY, + }, + ), + ); + message.append( + &record.message, + 6.0, + egui::TextFormat::simple( + egui::TextStyle::Body, + egui::Color32::WHITE, + ), + ); + ui.vertical(|ui| { + ui.add(egui::Label::new(message)); + ui.add_space(4.0); + for (k, v) in &record.kv { + ui.horizontal(|ui| { + ui.add( + egui::Label::new(egui::RichText::new(k).code()) + .sense(egui::Sense::click()), + ) + .on_hover_cursor(egui::CursorIcon::PointingHand); + render_value(ui, v); + }); + } }); } - }); - } - }) - }); + }) + }); }, area, scale, @@ -279,10 +314,18 @@ fn render_value(ui: &mut egui::Ui, value: &serde_json::Value) { use serde_json::Value::*; match value { - Null => { ui.label(egui::RichText::new("null").code()); }, - Bool(val) => { ui.label(egui::RichText::new(format!("{}", val)).code()); }, - Number(val) => { ui.label(egui::RichText::new(format!("{}", val)).code()); }, - String(val) => { ui.label(val); }, + Null => { + ui.label(egui::RichText::new("null").code()); + } + Bool(val) => { + ui.label(egui::RichText::new(format!("{}", val)).code()); + } + Number(val) => { + ui.label(egui::RichText::new(format!("{}", val)).code()); + } + String(val) => { + ui.label(val); + } Array(list) => { ui.vertical(|ui| { ui.label("["); @@ -294,7 +337,7 @@ fn render_value(ui: &mut egui::Ui, value: &serde_json::Value) { } ui.label("]"); }); - }, + } Object(map) => { ui.vertical(|ui| { for (k, val) in map { @@ -305,8 +348,6 @@ fn render_value(ui: &mut egui::Ui, value: &serde_json::Value) { }); } }); - }, + } }; } - - \ No newline at end of file diff --git a/src/input/mod.rs b/src/input/mod.rs index ed0a07d5..6f5b932d 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -207,7 +207,9 @@ impl Common { serial, time, |modifiers, handle| { - if state == KeyState::Released && userdata.get::().unwrap().filter(&handle) { + if state == KeyState::Released + && userdata.get::().unwrap().filter(&handle) + { return FilterResult::Intercept(()); } @@ -227,14 +229,21 @@ impl Common { } if modifiers.logo - && handle.raw_syms().iter().any(|sym| *sym >= keysyms::KEY_0 && *sym <= keysyms::KEY_9) + && handle + .raw_syms() + .iter() + .any(|sym| *sym >= keysyms::KEY_0 && *sym <= keysyms::KEY_9) && state == KeyState::Pressed { let current_output = active_output(seat, &self); - let key_num = handle.raw_syms() + let key_num = handle + .raw_syms() .iter() - .find(|sym| **sym >= keysyms::KEY_0 && **sym <= keysyms::KEY_9) - .unwrap() - keysyms::KEY_0; + .find(|sym| { + **sym >= keysyms::KEY_0 && **sym <= keysyms::KEY_9 + }) + .unwrap() + - keysyms::KEY_0; let workspace = match key_num { 0 => 9, x => x - 1, @@ -243,8 +252,9 @@ impl Common { userdata.get::().unwrap().add(&handle); return FilterResult::Intercept(()); } - - if modifiers.logo && modifiers.shift + + if modifiers.logo + && modifiers.shift && handle.raw_syms().contains(&keysyms::KEY_Escape) && state == KeyState::Pressed { @@ -499,9 +509,7 @@ impl Common { let device = event.device(); for seat in self.seats.clone().iter() { #[cfg(feature = "debug")] - if self.seats.iter().position(|x| x == seat).unwrap() == 0 - && self.egui.active - { + if self.seats.iter().position(|x| x == seat).unwrap() == 0 && self.egui.active { if self.egui.debug_state.wants_pointer() { self.egui.debug_state.handle_pointer_axis( event diff --git a/src/logger/mod.rs b/src/logger/mod.rs index 281cd80f..4818c7da 100644 --- a/src/logger/mod.rs +++ b/src/logger/mod.rs @@ -3,7 +3,10 @@ #[cfg(feature = "debug")] use std::{ collections::VecDeque, - sync::{Arc, Mutex, atomic::{AtomicBool, Ordering}}, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, Mutex, + }, }; use anyhow::Result; @@ -22,13 +25,13 @@ pub type LogBuffer = Arc>>; #[derive(Clone)] struct DebugDrain { buffer: LogBuffer, - dirty_flag:Arc, + dirty_flag: Arc, } pub struct LogState { _guard: slog_scope::GlobalLoggerGuard, #[cfg(feature = "debug")] - pub dirty_flag:Arc, + pub dirty_flag: Arc, #[cfg(feature = "debug")] pub debug_buffer: LogBuffer, } @@ -48,7 +51,7 @@ impl DebugDrain { ( DebugDrain { buffer: buffer.clone(), - dirty_flag: dirty_flag.clone() + dirty_flag: dirty_flag.clone(), }, buffer, dirty_flag, @@ -64,14 +67,11 @@ impl Drain for DebugDrain { fn log( &self, record: &slog::Record<'_>, - values: &slog::OwnedKVList + values: &slog::OwnedKVList, ) -> Result { - use slog::KV; + use serde_json::value::{Serializer as ValueSerializer, Value}; use serializer::SerdeSerializer; - use serde_json::value::{ - Serializer as ValueSerializer, - Value, - }; + use slog::KV; let mut serializer = SerdeSerializer::start(ValueSerializer, None)?; values.serialize(record, &mut serializer)?; @@ -116,7 +116,7 @@ pub fn init_logger() -> Result { std::sync::Mutex::new( slog_term::CompactFormat::new(decorator) .build() - .ignore_res() + .ignore_res(), ), debug_drain, ) @@ -142,4 +142,4 @@ pub fn init_logger() -> Result { #[cfg(feature = "debug")] dirty_flag, }) -} \ No newline at end of file +} diff --git a/src/logger/serializer.rs b/src/logger/serializer.rs index b442b1f9..c2c3afb3 100644 --- a/src/logger/serializer.rs +++ b/src/logger/serializer.rs @@ -117,11 +117,7 @@ where fn emit_str(&mut self, key: Key, val: &str) -> slog::Result { impl_m!(self, key, &val) } - fn emit_arguments( - &mut self, - key: Key, - val: &fmt::Arguments, - ) -> slog::Result { + fn emit_arguments(&mut self, key: Key, val: &fmt::Arguments) -> slog::Result { TL_BUF.with(|buf| { let mut buf = buf.borrow_mut(); @@ -132,4 +128,4 @@ where res }) } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index a82ca5cd..9db8f8d0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,16 +6,13 @@ use smithay::reexports::{ }; use anyhow::{Context, Result}; -use std::{ - ffi::OsString, - sync::atomic::Ordering, -}; +use std::{ffi::OsString, sync::atomic::Ordering}; pub mod backend; pub mod input; +mod logger; pub mod shell; pub mod state; -mod logger; pub mod utils; #[cfg(feature = "debug")] diff --git a/src/state.rs b/src/state.rs index c8cfcfd1..4b1a7cdd 100644 --- a/src/state.rs +++ b/src/state.rs @@ -2,8 +2,8 @@ use crate::{ backend::{kms::KmsState, winit::WinitState, x11::X11State}, - shell::{init_shell, workspaces::Workspaces, ShellStates}, logger::LogState, + shell::{init_shell, workspaces::Workspaces, ShellStates}, }; use smithay::{ reexports::{ @@ -127,7 +127,12 @@ pub fn get_dnd_icon(seat: &Seat) -> Option { } impl State { - pub fn new(mut display: Display, socket: OsString, handle: LoopHandle<'static, State>, log: LogState) -> State { + pub fn new( + mut display: Display, + socket: OsString, + handle: LoopHandle<'static, State>, + log: LogState, + ) -> State { init_shm_global(&mut display, vec![], None); init_xdg_output_manager(&mut display, None); let shell_handles = init_shell(&mut display); @@ -183,7 +188,8 @@ impl State { egui: Egui { debug_state: smithay_egui::EguiState::new(smithay_egui::EguiMode::Continuous), log_state: { - let mut state = smithay_egui::EguiState::new(smithay_egui::EguiMode::Continuous); + let mut state = + smithay_egui::EguiState::new(smithay_egui::EguiMode::Continuous); state.set_zindex(0); state }, @@ -251,9 +257,7 @@ impl Fps { return 0.0; } let secs = match (self.frames.front(), self.frames.back()) { - (Some((start, _)), Some((end, dur))) => { - end.duration_since(*start) + *dur - } + (Some((start, _)), Some((end, dur))) => end.duration_since(*start) + *dur, _ => Duration::ZERO, } .as_secs_f64();