Add CaptureImage type
This commit is contained in:
parent
f5045286a9
commit
0c19ea7167
4 changed files with 24 additions and 23 deletions
|
|
@ -82,7 +82,7 @@ enum Msg {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Workspace {
|
struct Workspace {
|
||||||
name: String,
|
name: String,
|
||||||
img_for_output: HashMap<wl_output::WlOutput, iced::widget::image::Handle>,
|
img_for_output: HashMap<wl_output::WlOutput, wayland::CaptureImage>,
|
||||||
handle: zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
|
handle: zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
|
||||||
outputs: HashSet<wl_output::WlOutput>,
|
outputs: HashSet<wl_output::WlOutput>,
|
||||||
is_active: bool,
|
is_active: bool,
|
||||||
|
|
@ -92,7 +92,7 @@ struct Workspace {
|
||||||
struct Toplevel {
|
struct Toplevel {
|
||||||
handle: zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
handle: zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
||||||
info: ToplevelInfo,
|
info: ToplevelInfo,
|
||||||
img: Option<iced::widget::image::Handle>,
|
img: Option<wayland::CaptureImage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use cctk::wayland_client::protocol::wl_output;
|
use cctk::wayland_client::protocol::wl_output;
|
||||||
use cosmic::iced::{self, widget};
|
use cosmic::iced::{self, widget};
|
||||||
|
|
||||||
use crate::{App, DragSurface, LayerSurface, Msg, Toplevel, Workspace};
|
use crate::{wayland::CaptureImage, App, DragSurface, LayerSurface, Msg, Toplevel, Workspace};
|
||||||
|
|
||||||
pub(crate) fn layer_surface<'a>(
|
pub(crate) fn layer_surface<'a>(
|
||||||
app: &'a App,
|
app: &'a App,
|
||||||
|
|
@ -51,17 +51,7 @@ pub(crate) fn workspace_item<'a>(
|
||||||
widget::column![
|
widget::column![
|
||||||
close_button(Msg::CloseWorkspace(workspace.handle.clone())),
|
close_button(Msg::CloseWorkspace(workspace.handle.clone())),
|
||||||
cosmic::widget::button(widget::column![
|
cosmic::widget::button(widget::column![
|
||||||
widget::Image::new(
|
capture_image(workspace.img_for_output.get(output)),
|
||||||
workspace
|
|
||||||
.img_for_output
|
|
||||||
.get(output)
|
|
||||||
.cloned()
|
|
||||||
.unwrap_or_else(|| widget::image::Handle::from_pixels(
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
vec![0, 0, 0, 255]
|
|
||||||
))
|
|
||||||
),
|
|
||||||
widget::text(&workspace.name)
|
widget::text(&workspace.name)
|
||||||
])
|
])
|
||||||
.style(theme)
|
.style(theme)
|
||||||
|
|
@ -115,10 +105,8 @@ fn workspaces_sidebar<'a>(
|
||||||
fn toplevel_preview(toplevel: &Toplevel) -> cosmic::Element<Msg> {
|
fn toplevel_preview(toplevel: &Toplevel) -> cosmic::Element<Msg> {
|
||||||
widget::column![
|
widget::column![
|
||||||
close_button(Msg::CloseToplevel(toplevel.handle.clone())),
|
close_button(Msg::CloseToplevel(toplevel.handle.clone())),
|
||||||
widget::button(widget::Image::new(toplevel.img.clone().unwrap_or_else(
|
widget::button(capture_image(toplevel.img.as_ref()))
|
||||||
|| widget::image::Handle::from_pixels(1, 1, vec![0, 0, 0, 255]),
|
.on_press(Msg::ActivateToplevel(toplevel.handle.clone())),
|
||||||
)))
|
|
||||||
.on_press(Msg::ActivateToplevel(toplevel.handle.clone())),
|
|
||||||
widget::text(&toplevel.info.title)
|
widget::text(&toplevel.info.title)
|
||||||
.horizontal_alignment(iced::alignment::Horizontal::Center)
|
.horizontal_alignment(iced::alignment::Horizontal::Center)
|
||||||
]
|
]
|
||||||
|
|
@ -136,3 +124,11 @@ fn toplevel_previews<'a>(
|
||||||
.align_items(iced::Alignment::Center)
|
.align_items(iced::Alignment::Center)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn capture_image(image: Option<&CaptureImage>) -> cosmic::Element<'_, Msg> {
|
||||||
|
if let Some(image) = image {
|
||||||
|
widget::Image::new(image.img.clone()).into()
|
||||||
|
} else {
|
||||||
|
widget::Image::new(widget::image::Handle::from_pixels(1, 1, vec![0, 0, 0, 255])).into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ use cctk::{
|
||||||
use cosmic::iced::{
|
use cosmic::iced::{
|
||||||
self,
|
self,
|
||||||
futures::{executor::block_on, FutureExt, SinkExt},
|
futures::{executor::block_on, FutureExt, SinkExt},
|
||||||
widget::image,
|
|
||||||
};
|
};
|
||||||
use futures_channel::mpsc;
|
use futures_channel::mpsc;
|
||||||
use std::{
|
use std::{
|
||||||
|
|
@ -67,7 +66,7 @@ pub enum Event {
|
||||||
WorkspaceCapture(
|
WorkspaceCapture(
|
||||||
zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
|
zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1,
|
||||||
wl_output::WlOutput,
|
wl_output::WlOutput,
|
||||||
image::Handle,
|
CaptureImage,
|
||||||
),
|
),
|
||||||
NewToplevel(
|
NewToplevel(
|
||||||
zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
||||||
|
|
@ -80,11 +79,16 @@ pub enum Event {
|
||||||
CloseToplevel(zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1),
|
CloseToplevel(zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1),
|
||||||
ToplevelCapture(
|
ToplevelCapture(
|
||||||
zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
||||||
image::Handle,
|
CaptureImage,
|
||||||
),
|
),
|
||||||
Seats(Vec<wl_seat::WlSeat>),
|
Seats(Vec<wl_seat::WlSeat>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct CaptureImage {
|
||||||
|
pub img: iced::widget::image::Handle,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn subscription(conn: Connection) -> iced::Subscription<Event> {
|
pub fn subscription(conn: Connection) -> iced::Subscription<Event> {
|
||||||
iced::subscription::run_with_id("wayland-sub", async { start(conn) }.flatten_stream())
|
iced::subscription::run_with_id("wayland-sub", async { start(conn) }.flatten_stream())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use cctk::{
|
||||||
wayland_client::{Connection, QueueHandle, WEnum},
|
wayland_client::{Connection, QueueHandle, WEnum},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{AppData, Capture, CaptureSource, Event};
|
use super::{AppData, Capture, CaptureImage, CaptureSource, Event};
|
||||||
|
|
||||||
impl ScreencopyHandler for AppData {
|
impl ScreencopyHandler for AppData {
|
||||||
fn screencopy_state(&mut self) -> &mut ScreencopyState {
|
fn screencopy_state(&mut self) -> &mut ScreencopyState {
|
||||||
|
|
@ -59,7 +59,8 @@ impl ScreencopyHandler for AppData {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buffer = capture.buffer.lock().unwrap();
|
let mut buffer = capture.buffer.lock().unwrap();
|
||||||
let image = unsafe { buffer.as_mut().unwrap().to_image() };
|
let img = unsafe { buffer.as_mut().unwrap().to_image() };
|
||||||
|
let image = CaptureImage { img };
|
||||||
match &capture.source {
|
match &capture.source {
|
||||||
CaptureSource::Toplevel(toplevel) => {
|
CaptureSource::Toplevel(toplevel) => {
|
||||||
self.send_event(Event::ToplevelCapture(toplevel.clone(), image))
|
self.send_event(Event::ToplevelCapture(toplevel.clone(), image))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue