-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP client-toolkit/screencopy: improvements to API
- Loading branch information
Showing
3 changed files
with
197 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use cosmic_protocols::{ | ||
image_source::v1::client::zcosmic_image_source_v1, | ||
toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1, | ||
workspace::v1::client::zcosmic_workspace_handle_v1::ZcosmicWorkspaceHandleV1, | ||
}; | ||
use std::{error::Error, fmt}; | ||
use wayland_client::{protocol::wl_output, Dispatch, QueueHandle}; | ||
|
||
use super::Capturer; | ||
use crate::GlobalData; | ||
|
||
// TODO enum for supported sources | ||
|
||
#[derive(Debug)] | ||
pub struct CaptureSourceError; | ||
|
||
impl fmt::Display for CaptureSourceError { | ||
// TODO | ||
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { | ||
todo!() | ||
} | ||
} | ||
|
||
impl Error for CaptureSourceError {} | ||
|
||
#[derive(Clone, Debug, Hash, PartialEq, Eq)] | ||
pub enum CaptureSource { | ||
Output(wl_output::WlOutput), | ||
// TODO: when adding ext protocol | ||
// Toplevel(ExtForeignToplevelHandleV1), | ||
CosmicToplevel(ZcosmicToplevelHandleV1), | ||
CosmicWorkspace(ZcosmicWorkspaceHandleV1), | ||
} | ||
|
||
impl CaptureSource { | ||
pub(crate) fn create_source<D>( | ||
&self, | ||
capturer: &Capturer, | ||
qh: &QueueHandle<D>, | ||
) -> Result<WlCaptureSource, CaptureSourceError> | ||
where | ||
D: 'static, | ||
D: Dispatch<zcosmic_image_source_v1::ZcosmicImageSourceV1, GlobalData>, | ||
{ | ||
match self { | ||
CaptureSource::Output(output) => { | ||
if let Some(manager) = &capturer.0.output_source_manager { | ||
return Ok(WlCaptureSource( | ||
manager.create_source(output, qh, GlobalData), | ||
)); | ||
} | ||
} | ||
CaptureSource::CosmicToplevel(toplevel) => { | ||
if let Some(manager) = &capturer.0.toplevel_source_manager { | ||
return Ok(WlCaptureSource( | ||
manager.create_source(toplevel, qh, GlobalData), | ||
)); | ||
} | ||
} | ||
CaptureSource::CosmicWorkspace(workspace) => { | ||
if let Some(manager) = &capturer.0.workspace_source_manager { | ||
return Ok(WlCaptureSource( | ||
manager.create_source(workspace, qh, GlobalData), | ||
)); | ||
} | ||
} | ||
} | ||
Err(CaptureSourceError) | ||
} | ||
} | ||
|
||
// TODO name? | ||
pub(crate) struct WlCaptureSource(pub(crate) zcosmic_image_source_v1::ZcosmicImageSourceV1); | ||
|
||
impl Drop for WlCaptureSource { | ||
fn drop(&mut self) { | ||
self.0.destroy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters