cosmic-workspaces/src/main.rs

661 lines
22 KiB
Rust
Raw Normal View History

2023-02-09 14:29:34 -08:00
#![allow(clippy::single_match)]
2022-12-30 14:07:39 -08:00
use cctk::{
2022-12-30 15:21:05 -08:00
cosmic_protocols::{
toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
2023-01-04 15:17:57 -08:00
toplevel_management::v1::client::zcosmic_toplevel_manager_v1,
2023-01-04 14:41:44 -08:00
workspace::v1::client::{zcosmic_workspace_handle_v1, zcosmic_workspace_manager_v1},
2022-12-30 15:21:05 -08:00
},
2023-03-27 10:37:30 -07:00
sctk::shell::wlr_layer::{Anchor, KeyboardInteractivity, Layer},
2022-12-30 15:21:05 -08:00
toplevel_info::ToplevelInfo,
2023-01-04 15:41:19 -08:00
wayland_client::{
2023-07-10 13:55:32 -07:00
protocol::{wl_data_device_manager::DndAction, wl_output, wl_seat},
2023-02-09 14:29:34 -08:00
Connection, WEnum,
2023-01-04 15:41:19 -08:00
},
2022-12-30 14:07:39 -08:00
};
2023-01-17 12:36:05 -08:00
use cosmic::{
iced::{
self,
event::wayland::{Event as WaylandEvent, OutputEvent},
keyboard::KeyCode,
2023-07-10 13:55:32 -07:00
wayland::{
actions::data_device::{DataFromMimeType, DndIcon},
data_device::start_drag,
},
2023-02-09 14:29:34 -08:00
widget, Application, Command, Subscription,
2023-01-17 12:36:05 -08:00
},
iced_runtime::{
2023-01-17 12:36:05 -08:00
command::platform_specific::wayland::layer_surface::{
IcedOutput, SctkLayerSurfaceSettings,
},
window::Id as SurfaceId,
},
2023-01-26 15:47:23 -08:00
iced_sctk::{
commands::layer_surface::{destroy_layer_surface, get_layer_surface},
settings::InitialSurface,
},
2022-12-30 14:07:39 -08:00
};
2023-02-09 14:29:34 -08:00
use std::{collections::HashMap, mem};
2022-12-30 14:07:39 -08:00
mod toggle_dbus;
2022-12-30 14:07:39 -08:00
mod wayland;
2023-07-10 13:55:32 -07:00
static WORKSPACE_MIME: &str = "text/x.cosmic-workspace-id";
struct WorkspaceDndId(String);
impl DataFromMimeType for WorkspaceDndId {
fn from_mime_type(&self, mime_type: &str) -> Option<Vec<u8>> {
if mime_type == WORKSPACE_MIME {
Some(self.0.as_bytes().to_vec())
} else {
None
}
}
}
2022-12-30 15:21:05 -08:00
#[derive(Clone, Debug)]
2022-12-30 14:07:39 -08:00
enum Msg {
WaylandEvent(WaylandEvent),
Wayland(wayland::Event),
Close,
2023-04-04 16:20:40 -07:00
Closed(SurfaceId),
2022-12-30 15:21:05 -08:00
ActivateWorkspace(zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1),
2023-01-18 10:58:22 -08:00
CloseWorkspace(zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1),
2023-01-04 15:17:57 -08:00
ActivateToplevel(zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1),
2023-01-18 10:58:22 -08:00
CloseToplevel(zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1),
DBus(toggle_dbus::Event),
2023-07-10 13:55:32 -07:00
StartDrag(DragSurface),
SourceFinished,
2022-12-30 14:07:39 -08:00
}
#[derive(Debug)]
struct Workspace {
name: String,
2023-03-22 10:03:18 -07:00
img_for_output: HashMap<String, iced::widget::image::Handle>,
2022-12-30 14:07:39 -08:00
handle: zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
2023-03-22 10:03:18 -07:00
output_names: Vec<String>,
2023-01-05 18:30:50 -08:00
is_active: bool,
2022-12-30 14:07:39 -08:00
}
2022-12-30 15:21:05 -08:00
#[derive(Debug)]
struct Toplevel {
handle: zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
info: ToplevelInfo,
2023-03-22 10:03:18 -07:00
output_name: Option<String>,
2022-12-30 15:21:05 -08:00
img: Option<iced::widget::image::Handle>,
}
#[derive(Clone)]
struct Output {
// Output, on the `iced_sctk` Wayland connection
handle: wl_output::WlOutput,
name: String,
width: i32,
height: i32,
}
2022-12-30 14:07:39 -08:00
struct LayerSurface {
// Output, on the `iced_sctk` Wayland connection
2022-12-30 14:07:39 -08:00
output: wl_output::WlOutput,
output_name: String,
2022-12-30 15:35:36 -08:00
// for transitions, would need windows in more than one workspace? But don't capture all of
// them all the time every frame.
2022-12-30 14:07:39 -08:00
}
2023-07-10 13:55:32 -07:00
#[derive(Clone, Debug)]
enum DragSurface {
Workspace { name: String, output_name: String },
}
2022-12-30 14:07:39 -08:00
#[derive(Default)]
struct App {
max_surface_id: u128,
2022-12-30 14:07:39 -08:00
layer_surfaces: HashMap<SurfaceId, LayerSurface>,
outputs: Vec<Output>,
2022-12-30 14:07:39 -08:00
workspaces: Vec<Workspace>,
2022-12-30 15:21:05 -08:00
toplevels: Vec<Toplevel>,
2023-01-04 15:17:57 -08:00
conn: Option<Connection>,
workspace_manager: Option<zcosmic_workspace_manager_v1::ZcosmicWorkspaceManagerV1>,
toplevel_manager: Option<zcosmic_toplevel_manager_v1::ZcosmicToplevelManagerV1>,
2023-01-04 15:41:19 -08:00
seats: Vec<wl_seat::WlSeat>,
visible: bool,
wayland_cmd_sender: Option<calloop::channel::Sender<wayland::Cmd>>,
2023-07-10 13:55:32 -07:00
drag_surface: Option<(SurfaceId, DragSurface)>,
2022-12-30 14:07:39 -08:00
}
impl App {
fn next_surface_id(&mut self) -> SurfaceId {
self.max_surface_id += 1;
SurfaceId(self.max_surface_id)
2022-12-30 14:07:39 -08:00
}
2023-01-05 18:30:50 -08:00
fn workspace_for_handle(
&self,
handle: &zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
) -> Option<&Workspace> {
self.workspaces.iter().find(|i| &i.handle == handle)
}
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)
}
fn create_surface(
&mut self,
output: wl_output::WlOutput,
output_name: String,
width: i32,
height: i32,
) -> Command<Msg> {
let id = self.next_surface_id();
self.layer_surfaces.insert(
2023-02-09 14:29:34 -08:00
id,
LayerSurface {
output: output.clone(),
output_name,
},
);
get_layer_surface(SctkLayerSurfaceSettings {
id,
keyboard_interactivity: KeyboardInteractivity::Exclusive,
namespace: "cosmic-workspace-overview".into(),
layer: Layer::Overlay,
2023-03-27 10:37:30 -07:00
size: Some((None, None)),
output: IcedOutput::Output(output),
2023-03-27 10:37:30 -07:00
anchor: Anchor::all(),
..Default::default()
})
}
fn destroy_surface(&mut self, output: &wl_output::WlOutput) -> Command<Msg> {
if let Some((id, _)) = self
.layer_surfaces
.iter()
.find(|(_id, surface)| &surface.output == output)
{
let id = *id;
self.layer_surfaces.remove(&id).unwrap();
destroy_layer_surface(id)
} else {
Command::none()
}
}
fn toggle(&mut self) -> Command<Msg> {
if self.visible {
self.hide()
} else {
self.show()
}
}
fn show(&mut self) -> Command<Msg> {
if !self.visible {
self.visible = true;
let outputs = self.outputs.clone();
let cmd = Command::batch(
outputs
.into_iter()
.map(|output| {
self.create_surface(output.handle, output.name, output.width, output.height)
})
.collect::<Vec<_>>(),
);
self.update_capture_filter();
cmd
} else {
Command::none()
}
}
// Close all shell surfaces
fn hide(&mut self) -> Command<Msg> {
self.visible = false;
self.update_capture_filter();
Command::batch(
mem::take(&mut self.layer_surfaces)
.into_keys()
.map(destroy_layer_surface)
.collect::<Vec<_>>(),
)
}
fn update_capture_filter(&self) {
if let Some(sender) = self.wayland_cmd_sender.as_ref() {
let mut capture_filter = wayland::CaptureFilter::default();
if self.visible {
// XXX handle on wrong connection
capture_filter.workspaces_on_outputs =
self.outputs.iter().map(|x| x.name.clone()).collect();
capture_filter.toplevels_on_workspaces = self
.workspaces
.iter()
.filter(|x| x.is_active)
.map(|x| x.handle.clone())
.collect();
}
let _ = sender.send(wayland::Cmd::CaptureFilter(capture_filter));
}
}
2022-12-30 14:07:39 -08:00
}
impl Application for App {
type Message = Msg;
type Theme = cosmic::Theme;
type Executor = iced::executor::Default;
type Flags = ();
fn new(_flags: ()) -> (Self, Command<Msg>) {
(Self::default(), Command::none())
}
fn title(&self) -> String {
String::from("cosmic-workspaces")
}
// TODO transparent style?
// TODO: show panel and dock? Drag?
2022-12-30 14:07:39 -08:00
fn update(&mut self, message: Msg) -> Command<Msg> {
match message {
Msg::WaylandEvent(evt) => match evt {
WaylandEvent::Output(evt, output) => match evt {
OutputEvent::Created(Some(info)) => {
if let (Some((width, height)), Some(name)) = (info.logical_size, info.name)
{
self.outputs.push(Output {
handle: output.clone(),
name: name.clone(),
width,
height,
2022-12-30 14:07:39 -08:00
});
if self.visible {
return self.create_surface(output.clone(), name, width, height);
}
2022-12-30 14:07:39 -08:00
}
}
2023-01-20 14:02:52 -08:00
OutputEvent::Created(None) => {} // XXX?
OutputEvent::InfoUpdate(info) => {
2023-02-09 14:29:34 -08:00
if let Some(output) = self.outputs.iter_mut().find(|x| x.handle == output) {
2023-01-20 14:02:52 -08:00
if let Some((width, height)) = info.logical_size {
output.width = width;
output.height = height;
}
if let Some(name) = info.name {
output.name = name;
}
2023-01-20 14:02:52 -08:00
// XXX re-create surface?
}
}
2022-12-30 14:07:39 -08:00
OutputEvent::Removed => {
2023-02-09 14:29:34 -08:00
if let Some(idx) = self.outputs.iter().position(|x| x.handle == output) {
self.outputs.remove(idx);
}
if self.visible {
return self.destroy_surface(&output);
2022-12-30 14:07:39 -08:00
}
}
},
_ => {}
},
Msg::Wayland(evt) => {
match evt {
2023-01-04 15:17:57 -08:00
wayland::Event::Connection(conn) => {
self.conn = Some(conn);
}
wayland::Event::CmdSender(sender) => {
self.wayland_cmd_sender = Some(sender);
}
2023-01-04 15:17:57 -08:00
wayland::Event::ToplevelManager(manager) => {
self.toplevel_manager = Some(manager);
}
wayland::Event::WorkspaceManager(manager) => {
self.workspace_manager = Some(manager);
2023-01-04 14:41:44 -08:00
}
2022-12-30 14:07:39 -08:00
wayland::Event::Workspaces(workspaces) => {
2023-01-04 14:41:44 -08:00
let old_workspaces = mem::take(&mut self.workspaces);
2022-12-30 14:07:39 -08:00
self.workspaces = Vec::new();
2023-03-22 10:03:18 -07:00
for (output_names, workspace) in workspaces {
2023-01-04 14:41:44 -08:00
let is_active = workspace.state.contains(&WEnum::Value(
zcosmic_workspace_handle_v1::State::Active,
));
// XXX efficiency
2023-03-22 10:03:18 -07:00
let img_for_output = old_workspaces
2023-01-04 14:41:44 -08:00
.iter()
2023-02-09 14:29:34 -08:00
.find(|i| i.handle == workspace.handle)
2023-03-22 10:03:18 -07:00
.map(|i| i.img_for_output.clone())
.unwrap_or_default();
2023-01-04 14:41:44 -08:00
2022-12-30 14:07:39 -08:00
self.workspaces.push(Workspace {
name: workspace.name,
handle: workspace.handle,
2023-03-22 10:03:18 -07:00
output_names,
img_for_output,
2023-01-05 18:30:50 -08:00
is_active,
2022-12-30 14:07:39 -08:00
});
}
self.update_capture_filter();
2022-12-30 14:07:39 -08:00
}
2023-03-22 10:03:18 -07:00
wayland::Event::NewToplevel(handle, output_name, info) => {
2023-02-09 14:29:34 -08:00
println!("New toplevel: {info:?}");
2022-12-30 15:21:05 -08:00
self.toplevels.push(Toplevel {
handle,
2023-03-22 10:03:18 -07:00
output_name,
2022-12-30 15:21:05 -08:00
info,
img: None,
});
}
2023-03-22 10:03:18 -07:00
wayland::Event::UpdateToplevel(handle, output_name, info) => {
2023-02-10 13:41:08 -08:00
if let Some(toplevel) =
self.toplevels.iter_mut().find(|x| x.handle == handle)
{
2023-03-22 10:03:18 -07:00
toplevel.output_name = output_name;
2023-02-10 13:41:08 -08:00
toplevel.info = info;
}
}
2023-01-18 11:01:47 -08:00
wayland::Event::CloseToplevel(handle) => {
if let Some(idx) = self.toplevels.iter().position(|x| x.handle == handle) {
self.toplevels.remove(idx);
}
}
2023-03-22 10:03:18 -07:00
wayland::Event::WorkspaceCapture(handle, output_name, image) => {
if let Some(workspace) = self.workspace_for_handle_mut(&handle) {
2023-03-22 10:03:18 -07:00
workspace.img_for_output.insert(output_name, image);
2022-12-30 14:07:39 -08:00
}
}
wayland::Event::ToplevelCapture(handle, image) => {
if let Some(toplevel) = self.toplevel_for_handle_mut(&handle) {
2023-02-10 13:41:08 -08:00
//println!("Got toplevel image!");
2023-02-09 14:29:34 -08:00
toplevel.img = Some(image);
2022-12-30 15:21:05 -08:00
}
}
2023-01-04 15:41:19 -08:00
wayland::Event::Seats(seats) => {
self.seats = seats;
}
2022-12-30 14:07:39 -08:00
}
}
Msg::Close => {
2023-01-26 16:01:43 -08:00
return self.hide();
2022-12-30 14:07:39 -08:00
}
Msg::Closed(_) => {}
2022-12-30 15:35:36 -08:00
Msg::ActivateWorkspace(workspace_handle) => {
2023-01-04 15:17:57 -08:00
let workspace_manager = self.workspace_manager.as_ref().unwrap();
2023-01-04 14:41:44 -08:00
workspace_handle.activate();
workspace_manager.commit();
2023-02-09 14:29:34 -08:00
let _ = self.conn.as_ref().unwrap().flush();
2023-01-04 15:17:57 -08:00
}
Msg::ActivateToplevel(toplevel_handle) => {
if let Some(toplevel_manager) = self.toplevel_manager.as_ref() {
2023-01-04 15:41:19 -08:00
if !self.seats.is_empty() {
for seat in &self.seats {
2023-02-09 14:29:34 -08:00
toplevel_manager.activate(&toplevel_handle, seat);
2023-01-04 15:41:19 -08:00
}
2023-02-09 14:29:34 -08:00
let _ = self.conn.as_ref().unwrap().flush();
2023-01-26 16:01:43 -08:00
return self.hide();
2023-01-04 15:41:19 -08:00
}
2023-01-04 15:17:57 -08:00
}
2022-12-30 15:21:05 -08:00
}
2023-02-09 14:29:34 -08:00
Msg::CloseWorkspace(_workspace_handle) => {}
2023-01-18 10:58:22 -08:00
Msg::CloseToplevel(toplevel_handle) => {
// TODO confirmation?
if let Some(toplevel_manager) = self.toplevel_manager.as_ref() {
toplevel_manager.close(&toplevel_handle);
}
}
Msg::DBus(toggle_dbus::Event::Toggle) => {
return self.toggle();
}
2023-07-10 13:55:32 -07:00
Msg::StartDrag(drag_surface) => {
match &drag_surface {
DragSurface::Workspace {
output_name,
name: _,
} => {
let id = self.next_surface_id();
if let Some((parent_id, _)) = self
.layer_surfaces
.iter()
.find(|(_, x)| &x.output_name == output_name)
{
println!("\n\n\nSTART DRAG");
self.drag_surface = Some((id, drag_surface));
return start_drag(
vec![WORKSPACE_MIME.to_string()],
DndAction::Move,
*parent_id,
Some(DndIcon::Custom(id)), // TODO store
Box::new(WorkspaceDndId(String::new())),
);
}
}
}
}
Msg::SourceFinished => {
println!("finish");
}
2022-12-30 14:07:39 -08:00
}
Command::none()
}
fn subscription(&self) -> Subscription<Msg> {
let events = iced::subscription::events_with(|evt, _| {
if let iced::Event::PlatformSpecific(iced::event::PlatformSpecific::Wayland(evt)) = evt
{
Some(Msg::WaylandEvent(evt))
} else if let iced::Event::Keyboard(iced::keyboard::Event::KeyReleased {
key_code: KeyCode::Escape,
modifiers: _,
}) = evt
{
Some(Msg::Close)
} else {
None
}
});
iced::Subscription::batch(vec![
events,
toggle_dbus::subscription().map(Msg::DBus),
wayland::subscription().map(Msg::Wayland),
])
2022-12-30 14:07:39 -08:00
}
2023-04-04 16:20:40 -07:00
fn view(&self, id: SurfaceId) -> cosmic::Element<Msg> {
2022-12-30 14:07:39 -08:00
use iced::widget::*;
2023-04-04 16:20:40 -07:00
if let Some(surface) = self.layer_surfaces.get(&id) {
return layer_surface(self, surface);
}
2023-07-10 13:55:32 -07:00
if let Some((drag_id, drag_surface)) = &self.drag_surface {
if drag_id == &id {
println!("DRAG VIEW");
match drag_surface {
DragSurface::Workspace { output_name, name } => {
if let Some(workspace) = self.workspaces.iter().find(|x| &x.name == name) {
return workspace_item2(workspace, &output_name);
}
}
}
}
}
println!("NO VIEW");
2022-12-30 14:07:39 -08:00
text("workspaces").into()
2023-07-10 13:55:32 -07:00
//
// workspace_sidebar_entry(&self.workspaces[0], "eDP-1").into()
//text("FOO BAR BAZ FOO BAR BAZ").into()
2022-12-30 14:07:39 -08:00
}
2023-04-04 16:20:40 -07:00
fn close_requested(&self, id: SurfaceId) -> Msg {
2022-12-30 14:07:39 -08:00
Msg::Closed(id)
}
}
fn layer_surface<'a>(app: &'a App, surface: &'a LayerSurface) -> cosmic::Element<'a, Msg> {
widget::row![
2022-12-30 15:21:05 -08:00
workspaces_sidebar(
app.workspaces
.iter()
2023-03-22 10:03:18 -07:00
.filter(|i| i.output_names.contains(&surface.output_name)),
&surface.output_name
2022-12-30 15:21:05 -08:00
),
2023-01-05 18:30:50 -08:00
toplevel_previews(app.toplevels.iter().filter(|i| {
2023-03-22 10:03:18 -07:00
if i.output_name.as_ref() != Some(&surface.output_name) {
return false;
}
2023-01-05 18:30:50 -08:00
if let Some(workspace) = &i.info.workspace {
2023-03-22 10:03:18 -07:00
app.workspace_for_handle(workspace)
.map_or(false, |x| x.is_active)
2023-01-05 18:30:50 -08:00
} else {
false
}
2023-03-22 10:03:18 -07:00
}))
2022-12-30 15:21:05 -08:00
]
2023-02-10 14:28:44 -08:00
.spacing(12)
2022-12-30 15:21:05 -08:00
.height(iced::Length::Fill)
.width(iced::Length::Fill)
.into()
2022-12-30 14:07:39 -08:00
}
2023-01-18 10:58:22 -08:00
fn close_button(on_press: Msg) -> cosmic::Element<'static, Msg> {
2023-01-06 19:21:49 -08:00
iced::widget::button(cosmic::widget::icon("window-close-symbolic", 16))
.style(cosmic::theme::Button::Destructive)
2023-01-18 10:58:22 -08:00
.on_press(on_press)
2023-01-06 19:21:49 -08:00
.into()
}
2023-07-10 13:55:32 -07:00
fn workspace_item<'a>(workspace: &'a Workspace, output_name: &'a str) -> cosmic::Element<'a, Msg> {
2023-01-06 19:06:09 -08:00
// TODO style
let theme = if workspace.is_active {
cosmic::theme::Button::Primary
} else {
cosmic::theme::Button::Secondary
};
2022-12-30 15:21:05 -08:00
widget::column![
2023-01-18 10:58:22 -08:00
close_button(Msg::CloseWorkspace(workspace.handle.clone())),
2023-02-10 14:28:44 -08:00
widget::button(widget::column![
widget::Image::new(
workspace
2023-03-22 10:03:18 -07:00
.img_for_output
.get(output_name)
.cloned()
2023-02-10 14:28:44 -08:00
.unwrap_or_else(|| widget::image::Handle::from_pixels(
1,
1,
vec![0, 0, 0, 255]
))
),
widget::text(&workspace.name)
])
2023-01-06 19:06:09 -08:00
.style(theme)
2022-12-30 15:21:05 -08:00
.on_press(Msg::ActivateWorkspace(workspace.handle.clone())),
2022-12-30 14:07:39 -08:00
]
.height(iced::Length::Fill)
2022-12-30 14:07:39 -08:00
.into()
}
2023-07-10 13:55:32 -07:00
fn workspace_item2<'a>(workspace: &'a Workspace, output_name: &'a str) -> cosmic::Element<'a, Msg> {
println!("{:?}", workspace);
println!("{:?}", output_name);
/*
widget::column![
widget::Image::new(
workspace
.img_for_output
.get(output_name)
.cloned()
.unwrap_or_else(|| widget::image::Handle::from_pixels(
1,
1,
vec![0, 0, 0, 255]
))
),
widget::text(&workspace.name)
]
.into()
*/
//widget::text(&workspace.name).into()
widget::Image::new(workspace.img_for_output.get(output_name).cloned().unwrap()).into()
//widget::text(&format!("WORKSPACE: {}", workspace.name)).into()
//widget::text("ABC").into()
}
fn workspace_sidebar_entry<'a>(
workspace: &'a Workspace,
output_name: &'a str,
) -> cosmic::Element<'a, Msg> {
widget::dnd_source(workspace_item(workspace, output_name))
2023-07-20 14:48:36 -07:00
.on_drag(|_| {
Msg::StartDrag(DragSurface::Workspace {
name: workspace.name.to_string(),
output_name: output_name.to_string(),
})
})
2023-07-10 13:55:32 -07:00
.on_finished(Msg::SourceFinished)
.on_cancelled(Msg::SourceFinished)
.into()
}
2022-12-30 14:07:39 -08:00
fn workspaces_sidebar<'a>(
workspaces: impl Iterator<Item = &'a Workspace>,
2023-03-22 10:03:18 -07:00
output_name: &'a str,
2022-12-30 14:07:39 -08:00
) -> cosmic::Element<'a, Msg> {
2023-03-22 10:03:18 -07:00
widget::column(
workspaces
.map(|w| workspace_sidebar_entry(w, output_name))
.collect(),
)
.width(iced::Length::Fill)
.height(iced::Length::Fill)
.into()
2023-01-03 12:38:02 -08:00
2022-12-30 14:07:39 -08:00
// New workspace
}
2023-02-09 14:29:34 -08:00
fn toplevel_preview(toplevel: &Toplevel) -> cosmic::Element<Msg> {
2023-01-05 18:41:48 -08:00
widget::column![
2023-01-18 10:58:22 -08:00
close_button(Msg::CloseToplevel(toplevel.handle.clone())),
2023-01-05 18:41:48 -08:00
widget::button(widget::Image::new(toplevel.img.clone().unwrap_or_else(
|| widget::image::Handle::from_pixels(1, 1, vec![0, 0, 0, 255]),
2023-01-05 18:41:48 -08:00
)))
.on_press(Msg::ActivateToplevel(toplevel.handle.clone())),
widget::text(&toplevel.info.title)
2023-02-10 14:28:44 -08:00
.horizontal_alignment(iced::alignment::Horizontal::Center)
2023-01-05 18:41:48 -08:00
]
.width(iced::Length::Fill)
2022-12-30 15:21:05 -08:00
.into()
2022-12-30 14:07:39 -08:00
}
2022-12-30 15:21:05 -08:00
fn toplevel_previews<'a>(
toplevels: impl Iterator<Item = &'a Toplevel>,
) -> cosmic::Element<'a, Msg> {
2023-01-03 12:38:02 -08:00
widget::row(toplevels.map(toplevel_preview).collect())
.width(iced::Length::FillPortion(4))
.height(iced::Length::Fill)
2023-02-10 14:28:44 -08:00
.spacing(16)
.align_items(iced::Alignment::Center)
2023-01-03 12:38:02 -08:00
.into()
2022-12-30 14:07:39 -08:00
}
pub fn main() -> iced::Result {
2023-04-13 14:30:47 -07:00
env_logger::init();
2022-12-30 14:07:39 -08:00
App::run(iced::Settings {
antialiasing: true,
exit_on_close_request: false,
2023-03-22 11:53:03 -07:00
initial_surface: InitialSurface::None,
2022-12-30 14:07:39 -08:00
..iced::Settings::default()
})
}