Initial version with working toplevel captures

This commit is contained in:
Ian Douglas Scott 2023-01-03 12:30:04 -08:00
parent 4af2d4d669
commit 8678976e8b

View file

@ -70,6 +70,20 @@ impl App {
self.max_surface_id += 1; self.max_surface_id += 1;
SurfaceId::new(self.max_surface_id) SurfaceId::new(self.max_surface_id)
} }
fn workspace_for_handle_mut(
&mut self,
handle: &zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
) -> Option<&mut Workspace> {
self.workspaces.iter_mut().find(|i| &i.handle == handle)
}
fn toplevel_for_handle_mut(
&mut self,
handle: &zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
) -> Option<&mut Toplevel> {
self.toplevels.iter_mut().find(|i| &i.handle == handle)
}
} }
impl Application for App { impl Application for App {
@ -87,6 +101,10 @@ impl Application for App {
String::from("cosmic-workspaces") String::from("cosmic-workspaces")
} }
// TODO transparent style?
// TODO: show panel and dock? Drag?
// TODO way to activate w/ keybind, button
fn update(&mut self, message: Msg) -> Command<Msg> { fn update(&mut self, message: Msg) -> Command<Msg> {
match message { match message {
Msg::WaylandEvent(evt) => match evt { Msg::WaylandEvent(evt) => match evt {
@ -144,27 +162,22 @@ impl Application for App {
} }
} }
wayland::Event::NewToplevel(handle, info) => { wayland::Event::NewToplevel(handle, info) => {
println!("New toplevel"); println!("New toplevel: {:?}", info);
self.toplevels.push(Toplevel { self.toplevels.push(Toplevel {
handle, handle,
info, info,
img: None, img: None,
}); });
} }
wayland::Event::WorkspaceCapture(workspace, image) => { wayland::Event::WorkspaceCapture(handle, image) => {
// XXX performance if let Some(workspace) = self.workspace_for_handle_mut(&handle) {
for i in &mut self.workspaces { workspace.img = Some(image.clone());
if &i.handle == &workspace {
i.img = Some(image.clone());
}
} }
} }
wayland::Event::ToplevelCapture(toplevel, image) => { wayland::Event::ToplevelCapture(handle, image) => {
println!("Toplevel capture"); if let Some(toplevel) = self.toplevel_for_handle_mut(&handle) {
for i in &mut self.toplevels { println!("Got toplevel image!");
if &i.handle == &toplevel { toplevel.img = Some(image.clone());
i.img = Some(image.clone());
}
} }
} }
} }
@ -226,13 +239,17 @@ impl Application for App {
} }
fn layer_surface<'a>(app: &'a App, surface: &'a LayerSurface) -> cosmic::Element<'a, Msg> { fn layer_surface<'a>(app: &'a App, surface: &'a LayerSurface) -> cosmic::Element<'a, Msg> {
widget::column![ widget::row![
workspaces_sidebar( workspaces_sidebar(
app.workspaces app.workspaces
.iter() .iter()
.filter(|i| &i.output_name == &surface.output_name), .filter(|i| &i.output_name == &surface.output_name),
), ),
toplevel_previews(app.toplevels.iter()) // XXX toplevel_previews(
app.toplevels
.iter()
.filter(|i| i.info.workspace == surface.active_workspace)
), // XXX
] ]
.height(iced::Length::Fill) .height(iced::Length::Fill)
.width(iced::Length::Fill) .width(iced::Length::Fill)
@ -250,7 +267,7 @@ fn workspace_sidebar_entry(workspace: &Workspace) -> cosmic::Element<Msg> {
widget::text(&workspace.name) widget::text(&workspace.name)
] ]
.height(iced::Length::Fill) .height(iced::Length::Fill)
.width(iced::Length::Fill) //.width(iced::Length::Fill)
.into() .into()
} }
@ -268,6 +285,8 @@ fn toplevel_preview<'a>(toplevel: &'a Toplevel) -> cosmic::Element<'a, Msg> {
widget::button(widget::Image::new(toplevel.img.clone().unwrap_or_else( widget::button(widget::Image::new(toplevel.img.clone().unwrap_or_else(
|| widget::image::Handle::from_pixels(0, 0, vec![0, 0, 0, 255]), || widget::image::Handle::from_pixels(0, 0, vec![0, 0, 0, 255]),
))) )))
.height(iced::Length::Fill)
//.width(iced::Length::Fill)
.into() .into()
} }