debug: Update for egui 0.18

This commit is contained in:
Victoria Brekenfeld 2022-07-04 16:00:03 +02:00
parent 270f06182e
commit 43062c1754
8 changed files with 54 additions and 73 deletions

38
Cargo.lock generated
View file

@ -324,7 +324,7 @@ dependencies = [
"bitflags", "bitflags",
"cosmic-protocols", "cosmic-protocols",
"edid-rs", "edid-rs",
"egui 0.16.1", "egui",
"id_tree", "id_tree",
"indexmap", "indexmap",
"lazy_static", "lazy_static",
@ -556,17 +556,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ab5fa33485cd85ac354df485819a63360fefa312fe04cffe65e6f175be1522c" checksum = "2ab5fa33485cd85ac354df485819a63360fefa312fe04cffe65e6f175be1522c"
[[package]]
name = "egui"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c733356eb5f1139fdeedc370c00e9ea689c5d9120502c43925285bc7249a333"
dependencies = [
"ahash",
"epaint 0.16.0",
"nohash-hasher",
]
[[package]] [[package]]
name = "egui" name = "egui"
version = "0.18.1" version = "0.18.1"
@ -574,35 +563,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb095a8b9feb9b7ff8f00b6776dffcef059538a3f4a91238e03c900e9c9ad9a2" checksum = "eb095a8b9feb9b7ff8f00b6776dffcef059538a3f4a91238e03c900e9c9ad9a2"
dependencies = [ dependencies = [
"ahash", "ahash",
"epaint 0.18.1", "epaint",
"nohash-hasher", "nohash-hasher",
] ]
[[package]]
name = "emath"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55673de2eb96660dde25ba7b2d36a7054beead1a2bec74dcfd5eb05a1e1ba76d"
[[package]] [[package]]
name = "emath" name = "emath"
version = "0.18.0" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c223f58c7e38abe1770f367b969f1b3fbd4704b67666bcb65dbb1adb0980ba72" checksum = "c223f58c7e38abe1770f367b969f1b3fbd4704b67666bcb65dbb1adb0980ba72"
[[package]]
name = "epaint"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adfd9296f7f92902e41c0e8e5deca6d2fb29f289c86d03a01ea01bd7498316c2"
dependencies = [
"ab_glyph",
"ahash",
"atomic_refcell",
"emath 0.16.0",
"nohash-hasher",
]
[[package]] [[package]]
name = "epaint" name = "epaint"
version = "0.18.1" version = "0.18.1"
@ -612,7 +582,7 @@ dependencies = [
"ab_glyph", "ab_glyph",
"ahash", "ahash",
"atomic_refcell", "atomic_refcell",
"emath 0.18.0", "emath",
"nohash-hasher", "nohash-hasher",
"parking_lot 0.12.1", "parking_lot 0.12.1",
] ]
@ -1573,7 +1543,7 @@ version = "0.1.0"
source = "git+https://github.com/Smithay/smithay-egui.git?rev=1969c96d#1969c96d21743134bb11eadde4866245ae7c0478" source = "git+https://github.com/Smithay/smithay-egui.git?rev=1969c96d#1969c96d21743134bb11eadde4866245ae7c0478"
dependencies = [ dependencies = [
"cgmath", "cgmath",
"egui 0.18.1", "egui",
"lazy_static", "lazy_static",
"memoffset", "memoffset",
"slog", "slog",

View file

@ -15,7 +15,7 @@ slog-scope = "4.4"
slog-stdlog = "4.1" slog-stdlog = "4.1"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", optional = true } serde_json = { version = "1", optional = true }
egui = { version = "0.16", optional = true } egui = { version = "0.18.1", optional = true }
edid-rs = { version = "0.1" } edid-rs = { version = "0.1" }
lazy_static = "1.4.0" lazy_static = "1.4.0"
thiserror = "1.0.26" thiserror = "1.0.26"

View file

@ -5,7 +5,8 @@ use crate::state::Common;
use crate::{ use crate::{
debug::{debug_ui, fps_ui, log_ui, EguiFrame}, debug::{debug_ui, fps_ui, log_ui, EguiFrame},
state::Fps, state::Fps,
}; utils::prelude::*,
};
use slog::Logger; use slog::Logger;
use smithay::{ use smithay::{
@ -200,11 +201,13 @@ where
.unwrap_or(Rectangle::from_loc_and_size((0, 0), (0, 0))); .unwrap_or(Rectangle::from_loc_and_size((0, 0), (0, 0)));
let scale = output.current_scale().fractional_scale(); let scale = output.current_scale().fractional_scale();
let fps_overlay = fps_ui(_gpu, state, fps, output_geo, scale); let fps_overlay = fps_ui(_gpu, state, fps, output_geo.to_f64().to_physical(scale), scale);
custom_elements.push(fps_overlay.into()); custom_elements.push(fps_overlay.into());
let mut area = state.shell.global_space(); let area = Rectangle::<f64, smithay::utils::Logical>::from_loc_and_size(
area.loc = state.shell.space_relative_output_geometry((0, 0), output); state.shell.space_relative_output_geometry((0.0f64, 0.0f64), output),
state.shell.global_space().to_f64().size,
).to_physical(scale);
if let Some(log_ui) = log_ui(state, area, scale, output_geo.size.w as f32 * 0.6) { if let Some(log_ui) = log_ui(state, area, scale, output_geo.size.w as f32 * 0.6) {
custom_elements.push(log_ui.into()); custom_elements.push(log_ui.into());
} }
@ -264,12 +267,12 @@ where
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
{ {
let output_geo = state.shell.output_geometry(output); let output_geo = output.geometry();
let fps_overlay = fps_ui( let fps_overlay = fps_ui(
_gpu, _gpu,
state, state,
fps, fps,
Rectangle::from_loc_and_size((0, 0), output_geo.size), Rectangle::from_loc_and_size((0, 0), output_geo.size).to_f64().to_physical(scale),
scale, scale,
); );
custom_elements.push(fps_overlay.into()); custom_elements.push(fps_overlay.into());

View file

@ -36,7 +36,7 @@ pub struct StaticConfig {
pub workspace_mode: WorkspaceMode, pub workspace_mode: WorkspaceMode,
} }
#[derive(Debug, Deserialize, Clone, Copy)] #[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)]
pub enum WorkspaceMode { pub enum WorkspaceMode {
OutputBound, OutputBound,
Global, Global,

View file

@ -3,7 +3,7 @@
use crate::state::{Common, Fps}; use crate::state::{Common, Fps};
use smithay::{ use smithay::{
backend::drm::DrmNode, backend::drm::DrmNode,
utils::{Logical, Rectangle}, utils::{Physical, Rectangle},
}; };
pub use smithay_egui::EguiFrame; pub use smithay_egui::EguiFrame;
@ -11,7 +11,7 @@ pub fn fps_ui(
gpu: Option<&DrmNode>, gpu: Option<&DrmNode>,
state: &Common, state: &Common,
fps: &mut Fps, fps: &mut Fps,
area: Rectangle<i32, Logical>, area: Rectangle<f64, Physical>,
scale: f64, scale: f64,
) -> EguiFrame { ) -> EguiFrame {
use egui::widgets::plot::{Bar, BarChart, HLine, Legend, Plot}; use egui::widgets::plot::{Bar, BarChart, HLine, Legend, Plot};
@ -80,7 +80,7 @@ pub fn fps_ui(
.show(ui, |plot_ui| { .show(ui, |plot_ui| {
plot_ui.bar_chart(fps_chart); plot_ui.bar_chart(fps_chart);
plot_ui.hline( plot_ui.hline(
HLine::new(avg).highlight().color(egui::Color32::LIGHT_BLUE), HLine::new(avg).highlight(true).color(egui::Color32::LIGHT_BLUE),
); );
}); });
} }
@ -96,7 +96,7 @@ pub fn fps_ui(
pub fn debug_ui( pub fn debug_ui(
state: &mut Common, state: &mut Common,
area: Rectangle<i32, Logical>, area: Rectangle<f64, Physical>,
scale: f64, scale: f64,
) -> Option<EguiFrame> { ) -> Option<EguiFrame> {
if !state.egui.active { if !state.egui.active {
@ -105,39 +105,46 @@ pub fn debug_ui(
Some(state.egui.debug_state.run( Some(state.egui.debug_state.run(
|ctx| { |ctx| {
use crate::utils::prelude::*;
egui::Window::new("Workspaces") egui::Window::new("Workspaces")
.default_pos([0.0, 300.0]) .default_pos([0.0, 300.0])
.vscroll(true) .vscroll(true)
.collapsible(true) .collapsible(true)
.show(ctx, |ui| { .show(ctx, |ui| {
use crate::shell::{ActiveWorkspace, Mode, MAX_WORKSPACES}; use crate::{
config::WorkspaceMode as ConfigMode,
shell::{OutputBoundState, WorkspaceMode, MAX_WORKSPACES},
};
ui.set_min_width(250.0); ui.set_min_width(250.0);
// Mode // Mode
ui.label(egui::RichText::new("Mode").heading()); ui.label(egui::RichText::new("Mode").heading());
let mut mode = *state.shell.mode(); let mut mode = match &state.shell.workspace_mode {
let active = if let Mode::Global { active } = mode { WorkspaceMode::Global { .. } => ConfigMode::Global,
active WorkspaceMode::OutputBound => ConfigMode::OutputBound,
} else {
0
}; };
ui.radio_value(&mut mode, Mode::OutputBound, "Output bound"); ui.radio_value(&mut mode, ConfigMode::OutputBound, "Output bound");
ui.radio_value(&mut mode, Mode::Global { active }, "Global"); ui.radio_value(&mut mode, ConfigMode::Global, "Global");
state.shell.set_mode(mode); state.shell.set_mode(mode);
match *state.shell.mode() { let mode = match &state.shell.workspace_mode {
Mode::OutputBound => { WorkspaceMode::OutputBound => (ConfigMode::OutputBound, None),
WorkspaceMode::Global { ref active, .. } => (ConfigMode::Global, Some(*active)),
};
match mode {
(ConfigMode::OutputBound, _) => {
ui.label("Workspaces:"); ui.label("Workspaces:");
for output in state.shell.outputs().cloned().collect::<Vec<_>>() { for output in state.shell.outputs().cloned().collect::<Vec<_>>() {
ui.horizontal(|ui| { ui.horizontal(|ui| {
let active = output let active = output
.user_data() .user_data()
.get::<ActiveWorkspace>() .get::<OutputBoundState>()
.unwrap() .unwrap()
.get() .active
.unwrap(); .get();
let mut active_val = active as f64; let mut active_val = active as f64;
ui.label(output.name()); ui.label(output.name());
ui.add( ui.add(
@ -155,7 +162,7 @@ pub fn debug_ui(
}); });
} }
} }
Mode::Global { active } => { (ConfigMode::Global, Some(active)) => {
ui.horizontal(|ui| { ui.horizontal(|ui| {
let mut active_val = active as f64; let mut active_val = active as f64;
ui.label("Workspace:"); ui.label("Workspace:");
@ -173,7 +180,8 @@ pub fn debug_ui(
); );
} }
}); });
} },
_ => unreachable!(),
} }
// Spaces // Spaces
@ -219,7 +227,7 @@ pub fn debug_ui(
ui.label(format!("Output: {:#?}", output)); ui.label(format!("Output: {:#?}", output));
ui.label(format!( ui.label(format!(
"Geometry: {:?}", "Geometry: {:?}",
state.shell.output_geometry(&output) output.geometry()
)); ));
ui.label(format!( ui.label(format!(
"Local Geometry: {:?}", "Local Geometry: {:?}",
@ -231,7 +239,7 @@ pub fn debug_ui(
)); ));
ui.label(format!( ui.label(format!(
"Relative Geometry: {:?}", "Relative Geometry: {:?}",
state.shell.space_relative_output_geometry((0, 0), &output) state.shell.space_relative_output_geometry((0i32, 0i32), &output)
)); ));
}); });
} }
@ -247,7 +255,7 @@ pub fn debug_ui(
pub fn log_ui( pub fn log_ui(
state: &mut Common, state: &mut Common,
area: Rectangle<i32, Logical>, area: Rectangle<f64, Physical>,
scale: f64, scale: f64,
default_width: f32, default_width: f32,
) -> Option<EguiFrame> { ) -> Option<EguiFrame> {
@ -259,8 +267,9 @@ pub fn log_ui(
|ctx| { |ctx| {
egui::SidePanel::right("Log") egui::SidePanel::right("Log")
.frame(egui::Frame { .frame(egui::Frame {
margin: egui::Vec2::new(10.0, 10.0), inner_margin: egui::Vec2::new(10.0, 10.0).into(),
corner_radius: 5.0, outer_margin: egui::Vec2::new(0.0, 0.0).into(),
rounding: 5.0.into(),
shadow: egui::epaint::Shadow { shadow: egui::epaint::Shadow {
extrusion: 0.0, extrusion: 0.0,
color: egui::Color32::TRANSPARENT, color: egui::Color32::TRANSPARENT,
@ -286,7 +295,7 @@ pub fn log_ui(
let mut message = egui::text::LayoutJob::single_section( let mut message = egui::text::LayoutJob::single_section(
record.level.as_short_str().to_string(), record.level.as_short_str().to_string(),
egui::TextFormat::simple( egui::TextFormat::simple(
egui::TextStyle::Monospace, egui::FontId::monospace(16.0),
match record.level { match record.level {
slog::Level::Critical => egui::Color32::RED, slog::Level::Critical => egui::Color32::RED,
slog::Level::Error => egui::Color32::LIGHT_RED, slog::Level::Error => egui::Color32::LIGHT_RED,
@ -301,7 +310,7 @@ pub fn log_ui(
&record.message, &record.message,
6.0, 6.0,
egui::TextFormat::simple( egui::TextFormat::simple(
egui::TextStyle::Body, egui::FontId::default(),
egui::Color32::WHITE, egui::Color32::WHITE,
), ),
); );

View file

@ -283,7 +283,6 @@ impl State {
x => x - 1, x => x - 1,
}; };
self.common.shell.activate( self.common.shell.activate(
dh,
seat, seat,
&current_output, &current_output,
workspace as usize, workspace as usize,

View file

@ -85,7 +85,7 @@ pub enum ShellMode {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct OutputBoundState { pub struct OutputBoundState {
active: Cell<usize>, pub active: Cell<usize>,
group: Cell<WorkspaceGroupHandle>, group: Cell<WorkspaceGroupHandle>,
} }
@ -245,7 +245,7 @@ impl Shell {
} }
} }
pub fn activate(&mut self, _dh: &DisplayHandle, seat: &Seat<State>, output: &Output, idx: usize) -> Option<MotionEvent> { pub fn activate(&mut self, seat: &Seat<State>, output: &Output, idx: usize) -> Option<MotionEvent> {
if idx > MAX_WORKSPACES { if idx > MAX_WORKSPACES {
return None; return None;
} }

View file

@ -29,14 +29,14 @@ impl WorkspaceHandler for State {
&mut self.common.shell.workspace_state &mut self.common.shell.workspace_state
} }
fn commit_requests(&mut self, dh: &DisplayHandle, requests: Vec<Request>) { fn commit_requests(&mut self, _dh: &DisplayHandle, requests: Vec<Request>) {
for request in requests.into_iter() { for request in requests.into_iter() {
match request { match request {
Request::Activate(handle) => { Request::Activate(handle) => {
if let Some(idx) = self.common.shell.spaces.iter().position(|w| w.handle == handle) { if let Some(idx) = self.common.shell.spaces.iter().position(|w| w.handle == handle) {
let seat = &self.common.last_active_seat; let seat = &self.common.last_active_seat;
let output = active_output(seat, &self.common); let output = active_output(seat, &self.common);
self.common.shell.activate(dh, seat, &output, idx); self.common.shell.activate(seat, &output, idx);
} }
}, },
_ => {}, _ => {},