diff --git a/examples/sctk_subsurface_gst/Cargo.toml b/examples/sctk_subsurface_gst/Cargo.toml index 4b8095ce..0c9724b5 100644 --- a/examples/sctk_subsurface_gst/Cargo.toml +++ b/examples/sctk_subsurface_gst/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "828b1eb" } iced = { path = "../..", default-features = false, features = [ "wayland", + "winit", "debug", "a11y", ] } diff --git a/examples/sctk_subsurface_gst/src/main.rs b/examples/sctk_subsurface_gst/src/main.rs index 09119117..d384457f 100644 --- a/examples/sctk_subsurface_gst/src/main.rs +++ b/examples/sctk_subsurface_gst/src/main.rs @@ -1,28 +1,32 @@ // Shows a subsurface with a 1x1 px red buffer, stretch to window size use iced::{ - wayland::InitialSurface, widget::text, window, Application, Command, - Element, Length, Subscription, Theme, + platform_specific::shell::subsurface_widget::{self, SubsurfaceBuffer}, + widget::text, + window, Element, Length, Subscription, Task, }; -use iced_sctk::subsurface_widget::SubsurfaceBuffer; use std::{env, path::Path}; mod pipewire; -fn main() { +fn main() -> iced::Result { let args = env::args(); if args.len() != 2 { eprintln!("usage: sctk_subsurface_gst [h264 mp4 path]"); - return; + return Ok(()); } let path = args.skip(1).next().unwrap(); if !Path::new(&path).exists() { eprintln!("File `{path}` not found."); - return; + return Ok(()); } - let mut settings = iced::Settings::with_flags(path); - settings.initial_surface = InitialSurface::XdgWindow(Default::default()); - SubsurfaceApp::run(settings).unwrap(); + iced::daemon( + SubsurfaceApp::title, + SubsurfaceApp::update, + SubsurfaceApp::view, + ) + .subscription(SubsurfaceApp::subscription) + .run_with(|| SubsurfaceApp::new(path)) } #[derive(Debug, Clone, Default)] @@ -36,19 +40,14 @@ pub enum Message { Pipewire(pipewire::Event), } -impl Application for SubsurfaceApp { - type Executor = iced::executor::Default; - type Message = Message; - type Flags = String; - type Theme = Theme; - - fn new(flags: String) -> (SubsurfaceApp, Command) { +impl SubsurfaceApp { + fn new(flags: String) -> (SubsurfaceApp, Task) { ( SubsurfaceApp { path: flags, ..SubsurfaceApp::default() }, - Command::none(), + Task::none(), ) } @@ -56,7 +55,7 @@ impl Application for SubsurfaceApp { String::from("SubsurfaceApp") } - fn update(&mut self, message: Self::Message) -> Command { + fn update(&mut self, message: Message) -> Task { match message { Message::Pipewire(evt) => match evt { pipewire::Event::Frame(subsurface_buffer) => { @@ -64,12 +63,12 @@ impl Application for SubsurfaceApp { } }, } - Command::none() + Task::none() } - fn view(&self, _id: window::Id) -> Element { + fn view(&self, _id: window::Id) -> Element { if let Some(buffer) = &self.buffer { - iced_sctk::subsurface_widget::Subsurface::new(1, 1, buffer) + subsurface_widget::Subsurface::new(buffer.clone()) .width(Length::Fill) .height(Length::Fill) .into() @@ -78,7 +77,7 @@ impl Application for SubsurfaceApp { } } - fn subscription(&self) -> Subscription { + fn subscription(&self) -> Subscription { pipewire::subscription(&self.path).map(Message::Pipewire) } } diff --git a/examples/sctk_subsurface_gst/src/pipewire.rs b/examples/sctk_subsurface_gst/src/pipewire.rs index 9933ee09..70537b85 100644 --- a/examples/sctk_subsurface_gst/src/pipewire.rs +++ b/examples/sctk_subsurface_gst/src/pipewire.rs @@ -2,7 +2,7 @@ use drm_fourcc::{DrmFourcc, DrmModifier}; use gst::glib::{self, translate::IntoGlib}; use gst::prelude::*; use iced::futures::{executor::block_on, SinkExt}; -use iced_sctk::subsurface_widget::{ +use iced::platform_specific::shell::subsurface_widget::{ BufferSource, Dmabuf, Plane, SubsurfaceBuffer, }; use std::{ffi::c_void, os::unix::io::BorrowedFd, sync::Arc, thread}; @@ -53,10 +53,13 @@ pub enum Event { pub fn subscription(path: &str) -> iced::Subscription { let path = path.to_string(); - iced::subscription::channel("pw", 16, |sender| async { - thread::spawn(move || pipewire_thread(&path, sender)); - std::future::pending().await - }) + iced::Subscription::run_with_id( + "pw", + iced::stream::channel(16, |sender| async { + thread::spawn(move || pipewire_thread(&path, sender)); + std::future::pending().await + }), + ) } fn pipewire_thread(