fmt commit

This commit is contained in:
Victoria Brekenfeld 2022-08-30 13:28:36 +02:00
parent 352c526e9e
commit 9e0a6e1b5f
25 changed files with 787 additions and 499 deletions

View file

@ -26,8 +26,8 @@ use smithay::{
Format, Fourcc, Modifier,
},
reexports::wayland_server::{
backend::GlobalId, protocol::wl_buffer::WlBuffer, Client, DataInit,
Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
backend::GlobalId, protocol::wl_buffer::WlBuffer, Client, DataInit, Dispatch,
DisplayHandle, GlobalDispatch, New, Resource,
},
wayland::{
buffer::BufferHandler,

View file

@ -1,46 +1,33 @@
// SPDX-License-Identifier: GPL-3.0-only
use smithay::{
backend::{
allocator::{dmabuf::Dmabuf, Buffer},
drm::DrmNode,
},
desktop::Window,
reexports::wayland_server::{
self, backend::GlobalId, protocol::wl_output::WlOutput, Client, Dispatch, DisplayHandle,
GlobalDispatch,
},
};
use std::{
fs::File,
io::{Seek, SeekFrom},
os::unix::io::{FromRawFd, IntoRawFd},
time::Instant,
};
use smithay::{
backend::{
allocator::{
Buffer,
dmabuf::Dmabuf,
},
drm::DrmNode,
},
desktop::Window,
reexports::{
wayland_server::{
self,
Client,
Dispatch,
GlobalDispatch,
DisplayHandle,
backend::GlobalId,
protocol::wl_output::WlOutput,
},
},
};
use cosmic_protocols::{
export_dmabuf::v1::server::{
zcosmic_export_dmabuf_manager_v1::{self, ZcosmicExportDmabufManagerV1},
zcosmic_export_dmabuf_frame_v1::{self, CancelReason, Flags, ZcosmicExportDmabufFrameV1},
},
use cosmic_protocols::export_dmabuf::v1::server::{
zcosmic_export_dmabuf_frame_v1::{self, CancelReason, Flags, ZcosmicExportDmabufFrameV1},
zcosmic_export_dmabuf_manager_v1::{self, ZcosmicExportDmabufManagerV1},
};
use crate::wayland::protocols::{
toplevel_info::{ToplevelInfoHandler, window_from_handle},
toplevel_info::{window_from_handle, ToplevelInfoHandler},
workspace::{WorkspaceHandle, WorkspaceHandler},
};
/// Export Dmabuf global state
#[derive(Debug)]
pub struct ExportDmabufState {
@ -63,9 +50,12 @@ impl ExportDmabufState {
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static,
{
ExportDmabufState {
global: display.create_global::<D, ZcosmicExportDmabufManagerV1, _>(1, ExportDmabufGlobalData {
filter: Box::new(client_filter),
}),
global: display.create_global::<D, ZcosmicExportDmabufManagerV1, _>(
1,
ExportDmabufGlobalData {
filter: Box::new(client_filter),
},
),
}
}
@ -88,18 +78,35 @@ pub struct Capture {
}
pub trait ExportDmabufHandler {
fn capture_output(&mut self, dh: &DisplayHandle, output: WlOutput, overlay_cursor: bool) -> Result<Capture, CaptureError>;
fn capture_workspace(&mut self, dh: &DisplayHandle, workspace: WorkspaceHandle, output: WlOutput, overlay_cursor: bool) -> Result<Capture, CaptureError>;
fn capture_toplevel(&mut self, dh: &DisplayHandle, toplevel: Window, overlay_cursor: bool) -> Result<Capture, CaptureError>;
fn capture_output(
&mut self,
dh: &DisplayHandle,
output: WlOutput,
overlay_cursor: bool,
) -> Result<Capture, CaptureError>;
fn capture_workspace(
&mut self,
dh: &DisplayHandle,
workspace: WorkspaceHandle,
output: WlOutput,
overlay_cursor: bool,
) -> Result<Capture, CaptureError>;
fn capture_toplevel(
&mut self,
dh: &DisplayHandle,
toplevel: Window,
overlay_cursor: bool,
) -> Result<Capture, CaptureError>;
fn start_time(&mut self) -> Instant;
}
impl<D> GlobalDispatch<ZcosmicExportDmabufManagerV1, ExportDmabufGlobalData, D> for ExportDmabufState
impl<D> GlobalDispatch<ZcosmicExportDmabufManagerV1, ExportDmabufGlobalData, D>
for ExportDmabufState
where
D: GlobalDispatch<ZcosmicExportDmabufManagerV1, ExportDmabufGlobalData>
+ Dispatch<ZcosmicExportDmabufManagerV1, ()>
+ Dispatch<ZcosmicExportDmabufFrameV1, ()>
+ ExportDmabufHandler,
+ Dispatch<ZcosmicExportDmabufManagerV1, ()>
+ Dispatch<ZcosmicExportDmabufFrameV1, ()>
+ ExportDmabufHandler,
{
fn bind(
_state: &mut D,
@ -120,11 +127,11 @@ where
impl<D> Dispatch<ZcosmicExportDmabufManagerV1, (), D> for ExportDmabufState
where
D: GlobalDispatch<ZcosmicExportDmabufManagerV1, ExportDmabufGlobalData>
+ Dispatch<ZcosmicExportDmabufManagerV1, ()>
+ Dispatch<ZcosmicExportDmabufFrameV1, ()>
+ ExportDmabufHandler
+ WorkspaceHandler
+ ToplevelInfoHandler
+ Dispatch<ZcosmicExportDmabufManagerV1, ()>
+ Dispatch<ZcosmicExportDmabufFrameV1, ()>
+ ExportDmabufHandler
+ WorkspaceHandler
+ ToplevelInfoHandler,
{
fn request(
state: &mut D,
@ -147,7 +154,7 @@ where
Ok(capture) => handle_capture(capture, frame, start_time),
Err(err) => frame.cancel(err.into()),
}
},
}
zcosmic_export_dmabuf_manager_v1::Request::CaptureWorkspace {
frame,
overlay_cursor,
@ -157,14 +164,19 @@ where
let frame = data_init.init(frame, ());
match state.workspace_state().workspace_handle(&workspace) {
Some(workspace) => {
match state.capture_workspace(dhandle, workspace, output, overlay_cursor != 0) {
match state.capture_workspace(
dhandle,
workspace,
output,
overlay_cursor != 0,
) {
Ok(capture) => handle_capture(capture, frame, start_time),
Err(err) => frame.cancel(err.into()),
}
},
}
None => frame.cancel(CancelReason::Permanent),
}
},
}
zcosmic_export_dmabuf_manager_v1::Request::CaptureToplevel {
frame,
overlay_cursor,
@ -177,36 +189,38 @@ where
Ok(capture) => handle_capture(capture, frame, start_time),
Err(err) => frame.cancel(err.into()),
}
},
}
None => frame.cancel(CancelReason::Permanent),
}
},
zcosmic_export_dmabuf_manager_v1::Request::Destroy => {},
_ => {},
}
zcosmic_export_dmabuf_manager_v1::Request::Destroy => {}
_ => {}
}
}
}
impl From<CaptureError> for CancelReason {
fn from(err: CaptureError) -> Self {
match err {
match err {
CaptureError::Temporary(err) => {
slog_scope::debug!("Temporary Capture Error: {}", err);
CancelReason::Temporary
},
}
CaptureError::Permanent(err) => {
slog_scope::warn!("Permanent Capture Error: {}", err);
CancelReason::Permanent
},
CaptureError::Resizing => {
CancelReason::Resizing
}
}
CaptureError::Resizing => CancelReason::Resizing,
}
}
}
fn handle_capture(capture: Capture, frame: ZcosmicExportDmabufFrameV1, start_time: Instant) {
let Capture { device, dmabuf, presentation_time } = capture;
let Capture {
device,
dmabuf,
presentation_time,
} = capture;
let format = dmabuf.format();
let modifier: u64 = format.modifier.into();
@ -224,7 +238,11 @@ fn handle_capture(capture: Capture, frame: ZcosmicExportDmabufFrameV1, start_tim
dmabuf.num_planes() as u32,
);
for (i, (handle, (offset, stride))) in dmabuf.handles().zip(dmabuf.offsets().zip(dmabuf.strides())).enumerate() {
for (i, (handle, (offset, stride))) in dmabuf
.handles()
.zip(dmabuf.offsets().zip(dmabuf.strides()))
.enumerate()
{
let mut file = unsafe { File::from_raw_fd(handle) };
let size = match file.seek(SeekFrom::End(0)) {
Ok(size) => size,
@ -240,31 +258,20 @@ fn handle_capture(capture: Capture, frame: ZcosmicExportDmabufFrameV1, start_tim
return;
}
let handle = file.into_raw_fd();
frame.object(
i as u32,
handle,
size as u32,
offset,
stride,
i as u32,
);
frame.object(i as u32, handle, size as u32, offset, stride, i as u32);
}
let duration = presentation_time.duration_since(start_time);
let (tv_sec, tv_nsec) = (duration.as_secs(), duration.subsec_nanos());
frame.ready(
(tv_sec >> 32) as u32,
(tv_sec & 0xFFFFFFFF) as u32,
tv_nsec,
);
frame.ready((tv_sec >> 32) as u32, (tv_sec & 0xFFFFFFFF) as u32, tv_nsec);
}
impl<D> Dispatch<ZcosmicExportDmabufFrameV1, (), D> for ExportDmabufState
where
D: GlobalDispatch<ZcosmicExportDmabufManagerV1, ExportDmabufGlobalData>
+ Dispatch<ZcosmicExportDmabufManagerV1, ()>
+ Dispatch<ZcosmicExportDmabufFrameV1, ()>
+ ExportDmabufHandler,
+ Dispatch<ZcosmicExportDmabufManagerV1, ()>
+ Dispatch<ZcosmicExportDmabufFrameV1, ()>
+ ExportDmabufHandler,
{
fn request(
_state: &mut D,
@ -276,8 +283,8 @@ where
_data_init: &mut wayland_server::DataInit<'_, D>,
) {
match request {
zcosmic_export_dmabuf_frame_v1::Request::Destroy => {},
_ => {},
zcosmic_export_dmabuf_frame_v1::Request::Destroy => {}
_ => {}
}
}
}

View file

@ -12,8 +12,7 @@ use smithay::{
wayland_server::{
backend::{ClientId, GlobalId, ObjectId},
protocol::wl_output::WlOutput,
Client, DataInit, Dispatch, DisplayHandle,
GlobalDispatch, New, Resource,
Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
},
},
utils::{Logical, Physical, Point, Size, Transform},
@ -133,8 +132,7 @@ struct OutputStateInner {
}
type OutputState = Mutex<OutputStateInner>;
impl<D> GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData, D>
for OutputConfigurationState<D>
impl<D> GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData, D> for OutputConfigurationState<D>
where
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>
@ -176,8 +174,7 @@ where
}
}
impl<D> Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData, D>
for OutputConfigurationState<D>
impl<D> Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData, D> for OutputConfigurationState<D>
where
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>
@ -279,8 +276,7 @@ where
}
}
impl<D> Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration, D>
for OutputConfigurationState<D>
impl<D> Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration, D> for OutputConfigurationState<D>
where
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>

View file

@ -1,9 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
use std::{
collections::HashMap,
sync::Mutex,
};
use std::{collections::HashMap, sync::Mutex};
use smithay::{
desktop::Window,
@ -12,11 +9,10 @@ use smithay::{
wayland_server::{
backend::{ClientId, GlobalId, ObjectId},
protocol::wl_surface::WlSurface,
Client, DataInit, Dispatch, DisplayHandle,
GlobalDispatch, New, Resource,
Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
},
},
utils::{IsAlive, Rectangle, Logical},
utils::{IsAlive, Logical, Rectangle},
wayland::{
compositor::with_states, output::Output, shell::xdg::XdgToplevelSurfaceRoleAttributes,
},
@ -68,21 +64,18 @@ pub type ToplevelHandleState = Mutex<ToplevelHandleStateInner>;
impl ToplevelHandleStateInner {
fn from_window(window: &Window) -> ToplevelHandleState {
ToplevelHandleState::new(
ToplevelHandleStateInner {
outputs: Vec::new(),
workspaces: Vec::new(),
title: String::new(),
app_id: String::new(),
states: Vec::new(),
window: window.clone(),
}
)
ToplevelHandleState::new(ToplevelHandleStateInner {
outputs: Vec::new(),
workspaces: Vec::new(),
title: String::new(),
app_id: String::new(),
states: Vec::new(),
window: window.clone(),
})
}
}
impl<D> GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData, D>
for ToplevelInfoState<D>
impl<D> GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData, D> for ToplevelInfoState<D>
where
D: GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData>
+ Dispatch<ZcosmicToplevelInfoV1, ()>
@ -256,8 +249,7 @@ where
.unwrap()
.lock()
.unwrap();
state.rectangles
.retain(|_, (surface, _)| surface.alive());
state.rectangles.retain(|_, (surface, _)| surface.alive());
if window.alive() {
std::mem::drop(state);
for instance in &self.instances {
@ -476,13 +468,7 @@ fn send_toplevel_to_client<D>(
pub fn window_from_handle(handle: ZcosmicToplevelHandleV1) -> Option<Window> {
handle
.data::<ToplevelHandleState>()
.map(|state|
state
.lock()
.unwrap()
.window
.clone()
)
.map(|state| state.lock().unwrap().window.clone())
}
macro_rules! delegate_toplevel_info {

View file

@ -2,29 +2,21 @@
use smithay::{
desktop::Window,
reexports::{
wayland_server::{
backend::{ClientId, GlobalId, ObjectId},
protocol::wl_surface::WlSurface,
Client, DataInit, Dispatch, DisplayHandle,
GlobalDispatch, New, Resource,
},
reexports::wayland_server::{
backend::{ClientId, GlobalId, ObjectId},
protocol::wl_surface::WlSurface,
Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
},
utils::{Logical, Rectangle},
wayland::{
output::Output,
seat::Seat,
},
wayland::{output::Output, seat::Seat},
};
use cosmic_protocols::toplevel_management::v1::server::{
zcosmic_toplevel_manager_v1::{self, ZcosmicToplevelManagerV1},
};
pub use cosmic_protocols::toplevel_management::v1::server::zcosmic_toplevel_manager_v1::ZcosmicToplelevelManagementCapabilitiesV1 as ManagementCapabilities;
use cosmic_protocols::toplevel_management::v1::server::zcosmic_toplevel_manager_v1::{
self, ZcosmicToplevelManagerV1,
};
use super::toplevel_info::{ToplevelInfoHandler, ToplevelState, window_from_handle};
use super::toplevel_info::{window_from_handle, ToplevelInfoHandler, ToplevelState};
pub struct ToplevelManagementState {
instances: Vec<ZcosmicToplevelManagerV1>,
@ -52,13 +44,17 @@ pub struct ToplevelManagerGlobalData {
}
impl ToplevelManagementState {
pub fn new<D, F>(dh: &DisplayHandle, capabilities: Vec<ManagementCapabilities>, client_filter: F) -> ToplevelManagementState
pub fn new<D, F>(
dh: &DisplayHandle,
capabilities: Vec<ManagementCapabilities>,
client_filter: F,
) -> ToplevelManagementState
where
D: GlobalDispatch<ZcosmicToplevelManagerV1, ToplevelManagerGlobalData>
+ Dispatch<ZcosmicToplevelManagerV1, ()>
+ ToplevelManagementHandler
+ 'static,
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static,
{
let global = dh.create_global::<D, ZcosmicToplevelManagerV1, _>(
1,
@ -73,7 +69,11 @@ impl ToplevelManagementState {
}
}
pub fn rectangle_for(&mut self, window: &Window, client: &ClientId) -> Option<(WlSurface, Rectangle<i32, Logical>)> {
pub fn rectangle_for(
&mut self,
window: &Window,
client: &ClientId,
) -> Option<(WlSurface, Rectangle<i32, Logical>)> {
if let Some(state) = window.user_data().get::<ToplevelState>() {
state.lock().unwrap().rectangles.get(client).cloned()
} else {
@ -86,12 +86,13 @@ impl ToplevelManagementState {
}
}
impl<D> GlobalDispatch<ZcosmicToplevelManagerV1, ToplevelManagerGlobalData, D> for ToplevelManagementState
impl<D> GlobalDispatch<ZcosmicToplevelManagerV1, ToplevelManagerGlobalData, D>
for ToplevelManagementState
where
D: GlobalDispatch<ZcosmicToplevelManagerV1, ToplevelManagerGlobalData>
+ Dispatch<ZcosmicToplevelManagerV1, ()>
+ ToplevelManagementHandler
+ 'static
+ 'static,
{
fn bind(
state: &mut D,
@ -120,13 +121,12 @@ where
}
}
impl<D> Dispatch<ZcosmicToplevelManagerV1, (), D> for ToplevelManagementState
where
D: GlobalDispatch<ZcosmicToplevelManagerV1, ToplevelManagerGlobalData>
+ Dispatch<ZcosmicToplevelManagerV1, ()>
+ ToplevelManagementHandler
+ 'static
+ 'static,
{
fn request(
state: &mut D,
@ -141,36 +141,43 @@ where
zcosmic_toplevel_manager_v1::Request::Activate { toplevel, seat } => {
let window = window_from_handle(toplevel).unwrap();
state.activate(dh, &window, Seat::from_resource(&seat));
},
}
zcosmic_toplevel_manager_v1::Request::Close { toplevel } => {
let window = window_from_handle(toplevel).unwrap();
state.close(dh, &window);
},
}
zcosmic_toplevel_manager_v1::Request::SetFullscreen { toplevel, output } => {
let window = window_from_handle(toplevel).unwrap();
state.fullscreen(dh, &window, output.as_ref().and_then(Output::from_resource))
},
}
zcosmic_toplevel_manager_v1::Request::UnsetFullscreen { toplevel } => {
let window = window_from_handle(toplevel).unwrap();
state.unfullscreen(dh, &window);
},
}
zcosmic_toplevel_manager_v1::Request::SetMaximized { toplevel } => {
let window = window_from_handle(toplevel).unwrap();
state.maximize(dh, &window);
},
}
zcosmic_toplevel_manager_v1::Request::UnsetMaximized { toplevel } => {
let window = window_from_handle(toplevel).unwrap();
state.unmaximize(dh, &window);
},
}
zcosmic_toplevel_manager_v1::Request::SetMinimized { toplevel } => {
let window = window_from_handle(toplevel).unwrap();
state.minimize(dh, &window);
},
}
zcosmic_toplevel_manager_v1::Request::UnsetMinimized { toplevel } => {
let window = window_from_handle(toplevel).unwrap();
state.unminimize(dh, &window);
},
zcosmic_toplevel_manager_v1::Request::SetRectangle { toplevel, surface, x, y, width, height } => {
}
zcosmic_toplevel_manager_v1::Request::SetRectangle {
toplevel,
surface,
x,
y,
width,
height,
} => {
let window = window_from_handle(toplevel).unwrap();
if let Some(toplevel_state) = window.user_data().get::<ToplevelState>() {
let mut toplevel_state = toplevel_state.lock().unwrap();
@ -178,11 +185,17 @@ where
if width == 0 && height == 0 {
toplevel_state.rectangles.remove(&client);
} else {
toplevel_state.rectangles.insert(client, (surface, Rectangle::from_loc_and_size((x, y), (width, height))));
toplevel_state.rectangles.insert(
client,
(
surface,
Rectangle::from_loc_and_size((x, y), (width, height)),
),
);
}
}
}
},
}
_ => unreachable!(),
}
}
@ -190,7 +203,11 @@ where
fn destroyed(state: &mut D, client: ClientId, resource: ObjectId, _data: &()) {
let mng_state = state.toplevel_management_state();
mng_state.instances.retain(|i| i.id() != resource);
if !mng_state.instances.iter().any(|i| i.client_id().map(|c| c == client).unwrap_or(false)) {
if !mng_state
.instances
.iter()
.any(|i| i.client_id().map(|c| c == client).unwrap_or(false))
{
for toplevel in state.toplevel_info_state_mut().toplevels.iter() {
if let Some(toplevel_state) = toplevel.user_data().get::<ToplevelState>() {
toplevel_state.lock().unwrap().rectangles.remove(&client);

View file

@ -1,15 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-only
use std::{
collections::HashSet,
sync::Mutex,
};
use std::{collections::HashSet, sync::Mutex};
use smithay::{
reexports::wayland_server::{
backend::{ClientData, ClientId, GlobalId, ObjectId},
Client, DataInit, Dispatch, DisplayHandle,
GlobalDispatch, New, Resource,
Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
},
wayland::output::Output,
};
@ -142,8 +138,7 @@ pub trait WorkspaceClientHandler {
fn workspace_state(&self) -> &WorkspaceClientState;
}
impl<D> GlobalDispatch<ZcosmicWorkspaceManagerV1, WorkspaceGlobalData, D>
for WorkspaceState<D>
impl<D> GlobalDispatch<ZcosmicWorkspaceManagerV1, WorkspaceGlobalData, D> for WorkspaceState<D>
where
D: GlobalDispatch<ZcosmicWorkspaceManagerV1, WorkspaceGlobalData>
+ Dispatch<ZcosmicWorkspaceManagerV1, ()>
@ -477,7 +472,7 @@ where
.map(|w| w.states.iter())
})
}
pub fn group_handle(
&self,
group: &ZcosmicWorkspaceGroupHandleV1,
@ -493,7 +488,11 @@ where
) -> Option<WorkspaceHandle> {
self.groups
.iter()
.find_map(|g| g.workspaces.iter().find(|w| w.instances.contains(workspace)))
.find_map(|g| {
g.workspaces
.iter()
.find(|w| w.instances.contains(workspace))
})
.map(|w| WorkspaceHandle { id: w.id })
}