cargo fmt
This commit is contained in:
parent
43062c1754
commit
39de286d51
40 changed files with 1557 additions and 1080 deletions
|
|
@ -26,11 +26,8 @@ use smithay::{
|
|||
Format, Fourcc, Modifier,
|
||||
},
|
||||
reexports::wayland_server::{
|
||||
Client, DataInit, DisplayHandle,
|
||||
DelegateGlobalDispatch, DelegateDispatch,
|
||||
GlobalDispatch, Dispatch, Resource,
|
||||
New, backend::GlobalId,
|
||||
protocol::wl_buffer::WlBuffer,
|
||||
backend::GlobalId, protocol::wl_buffer::WlBuffer, Client, DataInit, DelegateDispatch,
|
||||
DelegateGlobalDispatch, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
|
||||
},
|
||||
wayland::{
|
||||
buffer::BufferHandler,
|
||||
|
|
@ -38,11 +35,7 @@ use smithay::{
|
|||
},
|
||||
};
|
||||
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
};
|
||||
use std::{convert::TryFrom, path::PathBuf, sync::Arc};
|
||||
|
||||
pub struct WlDrmState;
|
||||
|
||||
|
|
@ -118,18 +111,14 @@ where
|
|||
) {
|
||||
match request {
|
||||
wl_drm::Request::Authenticate { .. } => drm.authenticated(),
|
||||
wl_drm::Request::CreateBuffer { .. } => {
|
||||
drm.post_error(
|
||||
wl_drm::Error::InvalidName,
|
||||
String::from("Flink handles are unsupported, use PRIME"),
|
||||
)
|
||||
},
|
||||
wl_drm::Request::CreatePlanarBuffer { .. } => {
|
||||
drm.post_error(
|
||||
wl_drm::Error::InvalidName,
|
||||
String::from("Flink handles are unsupported, use PRIME"),
|
||||
)
|
||||
},
|
||||
wl_drm::Request::CreateBuffer { .. } => drm.post_error(
|
||||
wl_drm::Error::InvalidName,
|
||||
String::from("Flink handles are unsupported, use PRIME"),
|
||||
),
|
||||
wl_drm::Request::CreatePlanarBuffer { .. } => drm.post_error(
|
||||
wl_drm::Error::InvalidName,
|
||||
String::from("Flink handles are unsupported, use PRIME"),
|
||||
),
|
||||
wl_drm::Request::CreatePrimeBuffer {
|
||||
id,
|
||||
name,
|
||||
|
|
@ -150,7 +139,7 @@ where
|
|||
return;
|
||||
}
|
||||
format
|
||||
},
|
||||
}
|
||||
Err(_) => {
|
||||
drm.post_error(
|
||||
wl_drm::Error::InvalidFormat,
|
||||
|
|
@ -171,29 +160,30 @@ where
|
|||
let mut dma = Dmabuf::builder((width, height), format, DmabufFlags::empty());
|
||||
dma.add_plane(name, 0, offset0 as u32, stride0 as u32, Modifier::Invalid);
|
||||
match dma.build() {
|
||||
Some(dmabuf) => match state.dmabuf_imported(dh, &data.dmabuf_global, dmabuf.clone()) {
|
||||
Ok(_) => {
|
||||
// import was successful
|
||||
data_init.init(id, dmabuf);
|
||||
slog_scope::trace!("Created a new validated dma wl_buffer via wl_drm.");
|
||||
},
|
||||
Some(dmabuf) => {
|
||||
match state.dmabuf_imported(dh, &data.dmabuf_global, dmabuf.clone()) {
|
||||
Ok(_) => {
|
||||
// import was successful
|
||||
data_init.init(id, dmabuf);
|
||||
slog_scope::trace!(
|
||||
"Created a new validated dma wl_buffer via wl_drm."
|
||||
);
|
||||
}
|
||||
|
||||
Err(ImportError::InvalidFormat) => {
|
||||
drm.post_error(
|
||||
wl_drm::Error::InvalidFormat,
|
||||
"format and plane combination are not valid",
|
||||
);
|
||||
}
|
||||
Err(ImportError::InvalidFormat) => {
|
||||
drm.post_error(
|
||||
wl_drm::Error::InvalidFormat,
|
||||
"format and plane combination are not valid",
|
||||
);
|
||||
}
|
||||
|
||||
Err(ImportError::Failed) => {
|
||||
// Buffer import failed. The protocol documentation heavily implies killing the
|
||||
// client is the right thing to do here.
|
||||
drm.post_error(
|
||||
wl_drm::Error::InvalidName,
|
||||
"buffer import failed",
|
||||
);
|
||||
Err(ImportError::Failed) => {
|
||||
// Buffer import failed. The protocol documentation heavily implies killing the
|
||||
// client is the right thing to do here.
|
||||
drm.post_error(wl_drm::Error::InvalidName, "buffer import failed");
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
None => {
|
||||
// Buffer import failed. The protocol documentation heavily implies killing the
|
||||
// client is the right thing to do here.
|
||||
|
|
@ -223,7 +213,9 @@ impl WlDrmState {
|
|||
+ DmabufHandler
|
||||
+ 'static,
|
||||
{
|
||||
self.create_global_with_filter::<D, _>(display, device_path, formats, dmabuf_global, |_| true)
|
||||
self.create_global_with_filter::<D, _>(display, device_path, formats, dmabuf_global, |_| {
|
||||
true
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_global_with_filter<D, F>(
|
||||
|
|
@ -242,7 +234,13 @@ impl WlDrmState {
|
|||
+ 'static,
|
||||
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static,
|
||||
{
|
||||
let formats = Arc::new(formats.into_iter().filter(|f| f.modifier == Modifier::Invalid).map(|f| f.code).collect());
|
||||
let formats = Arc::new(
|
||||
formats
|
||||
.into_iter()
|
||||
.filter(|f| f.modifier == Modifier::Invalid)
|
||||
.map(|f| f.code)
|
||||
.collect(),
|
||||
);
|
||||
let data = DrmGlobalData {
|
||||
filter: Box::new(client_filter),
|
||||
formats,
|
||||
|
|
@ -266,4 +264,3 @@ macro_rules! delegate_wl_drm {
|
|||
};
|
||||
}
|
||||
pub(crate) use delegate_wl_drm;
|
||||
|
||||
|
|
@ -1,12 +1,5 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use std::{
|
||||
convert::{TryFrom, TryInto},
|
||||
sync::{
|
||||
Arc, Mutex,
|
||||
atomic::{AtomicBool, Ordering},
|
||||
},
|
||||
};
|
||||
use smithay::{
|
||||
reexports::{
|
||||
wayland_protocols_wlr::output_management::v1::server::{
|
||||
|
|
@ -17,16 +10,21 @@ use smithay::{
|
|||
zwlr_output_mode_v1::{self, ZwlrOutputModeV1},
|
||||
},
|
||||
wayland_server::{
|
||||
Client, DisplayHandle,
|
||||
GlobalDispatch, Dispatch,
|
||||
DelegateGlobalDispatch, DelegateDispatch,
|
||||
DataInit, New, Resource,
|
||||
backend::{ClientId, GlobalId, ObjectId},
|
||||
protocol::wl_output::WlOutput,
|
||||
Client, DataInit, DelegateDispatch, DelegateGlobalDispatch, Dispatch, DisplayHandle,
|
||||
GlobalDispatch, New, Resource,
|
||||
},
|
||||
},
|
||||
wayland::output::{Output, Mode, OutputData},
|
||||
utils::{Logical, Physical, Point, Size, Transform},
|
||||
wayland::output::{Mode, Output, OutputData},
|
||||
};
|
||||
use std::{
|
||||
convert::{TryFrom, TryInto},
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
};
|
||||
|
||||
pub struct OutputConfigurationState<D> {
|
||||
|
|
@ -105,7 +103,9 @@ pub enum OutputConfiguration {
|
|||
|
||||
impl<'a> TryFrom<&'a mut PendingOutputConfigurationInner> for OutputConfiguration {
|
||||
type Error = zwlr_output_configuration_head_v1::Error;
|
||||
fn try_from(pending: &'a mut PendingOutputConfigurationInner) -> Result<OutputConfiguration, Self::Error> {
|
||||
fn try_from(
|
||||
pending: &'a mut PendingOutputConfigurationInner,
|
||||
) -> Result<OutputConfiguration, Self::Error> {
|
||||
let mode = match pending.mode.clone() {
|
||||
Some(ModeConfiguration::Mode(wlr_mode)) => Some(ModeConfiguration::Mode(
|
||||
wlr_mode
|
||||
|
|
@ -133,7 +133,8 @@ struct OutputStateInner {
|
|||
}
|
||||
type OutputState = Mutex<OutputStateInner>;
|
||||
|
||||
impl<D> DelegateGlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData, D> for OutputConfigurationState<D>
|
||||
impl<D> DelegateGlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData, D>
|
||||
for OutputConfigurationState<D>
|
||||
where
|
||||
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
|
||||
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>
|
||||
|
|
@ -142,7 +143,7 @@ where
|
|||
+ Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration>
|
||||
+ Dispatch<ZwlrOutputConfigurationHeadV1, PendingOutputConfiguration>
|
||||
+ OutputConfigurationHandler
|
||||
+ 'static
|
||||
+ 'static,
|
||||
{
|
||||
fn bind(
|
||||
state: &mut D,
|
||||
|
|
@ -161,7 +162,7 @@ where
|
|||
heads: Vec::new(),
|
||||
active,
|
||||
};
|
||||
|
||||
|
||||
let mngr_state = state.output_configuration_state();
|
||||
for output in &mngr_state.outputs {
|
||||
send_head_to_client::<D>(dh, &mut instance, output);
|
||||
|
|
@ -175,7 +176,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<D> DelegateDispatch<ZwlrOutputManagerV1, OutputMngrInstanceData, D> for OutputConfigurationState<D>
|
||||
impl<D> DelegateDispatch<ZwlrOutputManagerV1, OutputMngrInstanceData, D>
|
||||
for OutputConfigurationState<D>
|
||||
where
|
||||
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
|
||||
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>
|
||||
|
|
@ -184,7 +186,7 @@ where
|
|||
+ Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration>
|
||||
+ Dispatch<ZwlrOutputConfigurationHeadV1, PendingOutputConfiguration>
|
||||
+ OutputConfigurationHandler
|
||||
+ 'static
|
||||
+ 'static,
|
||||
{
|
||||
fn request(
|
||||
state: &mut D,
|
||||
|
|
@ -196,25 +198,25 @@ where
|
|||
data_init: &mut DataInit<'_, D>,
|
||||
) {
|
||||
match request {
|
||||
zwlr_output_manager_v1::Request::CreateConfiguration {
|
||||
id,
|
||||
serial,
|
||||
} => {
|
||||
let conf = data_init.init(id, PendingConfiguration::new(PendingConfigurationInner {
|
||||
serial,
|
||||
used: false,
|
||||
heads: Vec::new(),
|
||||
}));
|
||||
zwlr_output_manager_v1::Request::CreateConfiguration { id, serial } => {
|
||||
let conf = data_init.init(
|
||||
id,
|
||||
PendingConfiguration::new(PendingConfigurationInner {
|
||||
serial,
|
||||
used: false,
|
||||
heads: Vec::new(),
|
||||
}),
|
||||
);
|
||||
|
||||
let state = state.output_configuration_state();
|
||||
if serial != state.serial_counter {
|
||||
conf.cancelled();
|
||||
}
|
||||
},
|
||||
}
|
||||
zwlr_output_manager_v1::Request::Stop => {
|
||||
data.active.store(false, Ordering::SeqCst);
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -228,7 +230,7 @@ where
|
|||
+ Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration>
|
||||
+ Dispatch<ZwlrOutputConfigurationHeadV1, PendingOutputConfiguration>
|
||||
+ OutputConfigurationHandler
|
||||
+ 'static
|
||||
+ 'static,
|
||||
{
|
||||
fn request(
|
||||
_state: &mut D,
|
||||
|
|
@ -244,12 +246,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
state: &mut D,
|
||||
_client: ClientId,
|
||||
resource: ObjectId,
|
||||
_data: &Output,
|
||||
) {
|
||||
fn destroyed(state: &mut D, _client: ClientId, resource: ObjectId, _data: &Output) {
|
||||
for instance in &mut state.output_configuration_state().instances {
|
||||
instance.heads.retain(|h| h.head.id() != resource);
|
||||
}
|
||||
|
|
@ -265,7 +262,7 @@ where
|
|||
+ Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration>
|
||||
+ Dispatch<ZwlrOutputConfigurationHeadV1, PendingOutputConfiguration>
|
||||
+ OutputConfigurationHandler
|
||||
+ 'static
|
||||
+ 'static,
|
||||
{
|
||||
fn request(
|
||||
_state: &mut D,
|
||||
|
|
@ -282,7 +279,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<D> DelegateDispatch<ZwlrOutputConfigurationV1, PendingConfiguration, D> for OutputConfigurationState<D>
|
||||
impl<D> DelegateDispatch<ZwlrOutputConfigurationV1, PendingConfiguration, D>
|
||||
for OutputConfigurationState<D>
|
||||
where
|
||||
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
|
||||
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>
|
||||
|
|
@ -291,7 +289,7 @@ where
|
|||
+ Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration>
|
||||
+ Dispatch<ZwlrOutputConfigurationHeadV1, PendingOutputConfiguration>
|
||||
+ OutputConfigurationHandler
|
||||
+ 'static
|
||||
+ 'static,
|
||||
{
|
||||
fn request(
|
||||
state: &mut D,
|
||||
|
|
@ -315,7 +313,7 @@ where
|
|||
|
||||
let conf_head = data_init.init(id, PendingOutputConfiguration::default());
|
||||
pending.heads.push((head, Some(conf_head)));
|
||||
},
|
||||
}
|
||||
zwlr_output_configuration_v1::Request::DisableHead { head } => {
|
||||
let mut pending = data.lock().unwrap();
|
||||
if pending.heads.iter().any(|(h, _)| *h == head) {
|
||||
|
|
@ -326,11 +324,11 @@ where
|
|||
return;
|
||||
}
|
||||
pending.heads.push((head, None));
|
||||
},
|
||||
}
|
||||
x @ zwlr_output_configuration_v1::Request::Apply
|
||||
| x @ zwlr_output_configuration_v1::Request::Test => {
|
||||
let mut pending = data.lock().unwrap();
|
||||
|
||||
|
||||
if pending.used {
|
||||
return obj.post_error(
|
||||
zwlr_output_configuration_v1::Error::AlreadyUsed,
|
||||
|
|
@ -350,16 +348,17 @@ where
|
|||
.iter_mut()
|
||||
.map(|(head, conf)| {
|
||||
let output = match {
|
||||
inner.instances
|
||||
inner
|
||||
.instances
|
||||
.iter()
|
||||
.find_map(|instance| instance.heads.iter().find(|h| h.head == *head))
|
||||
.find_map(|instance| {
|
||||
instance.heads.iter().find(|h| h.head == *head)
|
||||
})
|
||||
.map(|i| i.output.clone())
|
||||
} {
|
||||
Some(o) => o,
|
||||
None => {
|
||||
return Err(
|
||||
zwlr_output_configuration_head_v1::Error::InvalidMode,
|
||||
);
|
||||
return Err(zwlr_output_configuration_head_v1::Error::InvalidMode);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -374,8 +373,10 @@ where
|
|||
None => Ok((output, OutputConfiguration::Disabled)),
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<(Output, OutputConfiguration)>, zwlr_output_configuration_head_v1::Error>>()
|
||||
{
|
||||
.collect::<Result<
|
||||
Vec<(Output, OutputConfiguration)>,
|
||||
zwlr_output_configuration_head_v1::Error,
|
||||
>>() {
|
||||
Ok(conf) => conf,
|
||||
Err(code) => {
|
||||
return obj.post_error(code, "Incomplete configuration".to_string());
|
||||
|
|
@ -393,14 +394,15 @@ where
|
|||
} else {
|
||||
obj.failed();
|
||||
}
|
||||
},
|
||||
zwlr_output_configuration_v1::Request::Destroy => {},
|
||||
_ => {},
|
||||
}
|
||||
zwlr_output_configuration_v1::Request::Destroy => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> DelegateDispatch<ZwlrOutputConfigurationHeadV1, PendingOutputConfiguration, D> for OutputConfigurationState<D>
|
||||
impl<D> DelegateDispatch<ZwlrOutputConfigurationHeadV1, PendingOutputConfiguration, D>
|
||||
for OutputConfigurationState<D>
|
||||
where
|
||||
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
|
||||
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>
|
||||
|
|
@ -409,7 +411,7 @@ where
|
|||
+ Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration>
|
||||
+ Dispatch<ZwlrOutputConfigurationHeadV1, PendingOutputConfiguration>
|
||||
+ OutputConfigurationHandler
|
||||
+ 'static
|
||||
+ 'static,
|
||||
{
|
||||
fn request(
|
||||
_state: &mut D,
|
||||
|
|
@ -431,8 +433,12 @@ where
|
|||
return;
|
||||
}
|
||||
pending.mode = Some(ModeConfiguration::Mode(mode));
|
||||
},
|
||||
zwlr_output_configuration_head_v1::Request::SetCustomMode { width, height, refresh } => {
|
||||
}
|
||||
zwlr_output_configuration_head_v1::Request::SetCustomMode {
|
||||
width,
|
||||
height,
|
||||
refresh,
|
||||
} => {
|
||||
let mut pending = data.lock().unwrap();
|
||||
if pending.mode.is_some() {
|
||||
obj.post_error(
|
||||
|
|
@ -445,7 +451,7 @@ where
|
|||
size: Size::from((width, height)),
|
||||
refresh: if refresh == 0 { None } else { Some(refresh) },
|
||||
});
|
||||
},
|
||||
}
|
||||
zwlr_output_configuration_head_v1::Request::SetPosition { x, y } => {
|
||||
let mut pending = data.lock().unwrap();
|
||||
if pending.position.is_some() {
|
||||
|
|
@ -456,7 +462,7 @@ where
|
|||
return;
|
||||
}
|
||||
pending.position = Some(Point::from((x, y)));
|
||||
},
|
||||
}
|
||||
zwlr_output_configuration_head_v1::Request::SetScale { scale } => {
|
||||
let mut pending = data.lock().unwrap();
|
||||
if pending.scale.is_some() {
|
||||
|
|
@ -467,7 +473,7 @@ where
|
|||
return;
|
||||
}
|
||||
pending.scale = Some(scale);
|
||||
},
|
||||
}
|
||||
zwlr_output_configuration_head_v1::Request::SetTransform { transform } => {
|
||||
let mut pending = data.lock().unwrap();
|
||||
if pending.transform.is_some() {
|
||||
|
|
@ -485,36 +491,36 @@ where
|
|||
format!("Invalid transform: {:?}", err),
|
||||
);
|
||||
return;
|
||||
},
|
||||
}
|
||||
});
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> OutputConfigurationState<D>
|
||||
where
|
||||
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
|
||||
+ GlobalDispatch<WlOutput, OutputData>
|
||||
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>
|
||||
+ Dispatch<ZwlrOutputHeadV1, Output>
|
||||
+ Dispatch<ZwlrOutputModeV1, Mode>
|
||||
+ Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration>
|
||||
+ Dispatch<ZwlrOutputConfigurationHeadV1, PendingOutputConfiguration>
|
||||
+ OutputConfigurationHandler
|
||||
+ 'static,
|
||||
D: GlobalDispatch<ZwlrOutputManagerV1, OutputMngrGlobalData>
|
||||
+ GlobalDispatch<WlOutput, OutputData>
|
||||
+ Dispatch<ZwlrOutputManagerV1, OutputMngrInstanceData>
|
||||
+ Dispatch<ZwlrOutputHeadV1, Output>
|
||||
+ Dispatch<ZwlrOutputModeV1, Mode>
|
||||
+ Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration>
|
||||
+ Dispatch<ZwlrOutputConfigurationHeadV1, PendingOutputConfiguration>
|
||||
+ OutputConfigurationHandler
|
||||
+ 'static,
|
||||
{
|
||||
pub fn new<F>(
|
||||
dh: &DisplayHandle,
|
||||
client_filter: F,
|
||||
) -> OutputConfigurationState<D>
|
||||
pub fn new<F>(dh: &DisplayHandle, client_filter: F) -> OutputConfigurationState<D>
|
||||
where
|
||||
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static,
|
||||
{
|
||||
let global = dh.create_global::<D, ZwlrOutputManagerV1, _>(2, OutputMngrGlobalData {
|
||||
filter: Box::new(client_filter),
|
||||
});
|
||||
let global = dh.create_global::<D, ZwlrOutputManagerV1, _>(
|
||||
2,
|
||||
OutputMngrGlobalData {
|
||||
filter: Box::new(client_filter),
|
||||
},
|
||||
);
|
||||
|
||||
OutputConfigurationState {
|
||||
outputs: Vec::new(),
|
||||
|
|
@ -530,19 +536,23 @@ where
|
|||
pub fn global_id(&self) -> GlobalId {
|
||||
self.global.clone()
|
||||
}
|
||||
|
||||
|
||||
pub fn add_heads<'a>(&mut self, outputs: impl Iterator<Item = &'a Output>) {
|
||||
let new_outputs = outputs.filter(|o| !self.outputs.contains(o)).collect::<Vec<_>>();
|
||||
let new_outputs = outputs
|
||||
.filter(|o| !self.outputs.contains(o))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for output in new_outputs {
|
||||
output.user_data().insert_if_missing(|| OutputState::new(OutputStateInner {
|
||||
enabled: true,
|
||||
global: None,
|
||||
}));
|
||||
output.user_data().insert_if_missing(|| {
|
||||
OutputState::new(OutputStateInner {
|
||||
enabled: true,
|
||||
global: None,
|
||||
})
|
||||
});
|
||||
self.outputs.push(output.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn remove_heads<'a>(&mut self, outputs: impl Iterator<Item = &'a Output>) {
|
||||
for output in outputs {
|
||||
if self.outputs.contains(output) {
|
||||
|
|
@ -577,17 +587,19 @@ where
|
|||
pub fn update(&mut self) {
|
||||
self.instances.retain(|x| x.active.load(Ordering::SeqCst));
|
||||
self.serial_counter += 1;
|
||||
|
||||
|
||||
for output in std::mem::take(&mut self.removed_outputs).into_iter() {
|
||||
for instance in &mut self.instances {
|
||||
instance.heads.retain_mut(|head| if &head.output == &output {
|
||||
for mode in &head.modes {
|
||||
mode.finished();
|
||||
instance.heads.retain_mut(|head| {
|
||||
if &head.output == &output {
|
||||
for mode in &head.modes {
|
||||
mode.finished();
|
||||
}
|
||||
head.head.finished();
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
head.head.finished();
|
||||
false
|
||||
} else {
|
||||
true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -624,13 +636,17 @@ where
|
|||
+ Dispatch<ZwlrOutputModeV1, Mode>
|
||||
+ Dispatch<ZwlrOutputConfigurationV1, PendingConfiguration>
|
||||
+ OutputConfigurationHandler
|
||||
+ 'static
|
||||
+ 'static,
|
||||
{
|
||||
let instance = match mngr.heads.iter_mut().find(|i| i.output == *output) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
if let Ok(client) = dh.get_client(mngr.obj.id()) {
|
||||
if let Ok(head) = client.create_resource::<ZwlrOutputHeadV1, _, D>(dh, mngr.obj.version(), output.clone()) {
|
||||
if let Ok(head) = client.create_resource::<ZwlrOutputHeadV1, _, D>(
|
||||
dh,
|
||||
mngr.obj.version(),
|
||||
output.clone(),
|
||||
) {
|
||||
mngr.obj.head(&head);
|
||||
let data = OutputHeadInstance {
|
||||
head,
|
||||
|
|
@ -652,7 +668,9 @@ where
|
|||
instance.head.description(output.description());
|
||||
let physical = output.physical_properties();
|
||||
if !(physical.size.w == 0 || physical.size.h == 0) {
|
||||
instance.head.physical_size(physical.size.w, physical.size.h);
|
||||
instance
|
||||
.head
|
||||
.physical_size(physical.size.w, physical.size.h);
|
||||
}
|
||||
|
||||
let inner = output
|
||||
|
|
@ -664,26 +682,37 @@ where
|
|||
|
||||
let output_modes = output.modes();
|
||||
// remove old modes
|
||||
instance.modes.retain_mut(|m| if !output_modes.contains(m.data::<Mode>().unwrap()) {
|
||||
m.finished();
|
||||
false
|
||||
} else {
|
||||
true
|
||||
instance.modes.retain_mut(|m| {
|
||||
if !output_modes.contains(m.data::<Mode>().unwrap()) {
|
||||
m.finished();
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
// update other modes
|
||||
for output_mode in output_modes.into_iter() {
|
||||
if let Some(mode) = if let Some(wlr_mode) = instance.modes
|
||||
if let Some(mode) = if let Some(wlr_mode) = instance
|
||||
.modes
|
||||
.iter()
|
||||
.find(|mode| *mode.data::<Mode>().unwrap() == output_mode)
|
||||
{
|
||||
Some(wlr_mode)
|
||||
} else if let Ok(client) = dh.get_client(instance.head.id()) {
|
||||
// create the mode if it does not exist yet
|
||||
if let Ok(mode) = client.create_resource::<ZwlrOutputModeV1, _, D>(dh, instance.head.version(), output_mode) {
|
||||
if let Ok(mode) = client.create_resource::<ZwlrOutputModeV1, _, D>(
|
||||
dh,
|
||||
instance.head.version(),
|
||||
output_mode,
|
||||
) {
|
||||
instance.head.mode(&mode);
|
||||
mode.size(output_mode.size.w, output_mode.size.h);
|
||||
mode.refresh(output_mode.refresh);
|
||||
if output.preferred_mode().map(|p| p == output_mode).unwrap_or(false) {
|
||||
if output
|
||||
.preferred_mode()
|
||||
.map(|p| p == output_mode)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
mode.preferred();
|
||||
}
|
||||
instance.modes.push(mode);
|
||||
|
|
@ -694,7 +723,12 @@ where
|
|||
} else {
|
||||
None
|
||||
} {
|
||||
if inner.enabled && output.current_mode().map(|c| c == output_mode).unwrap_or(false) {
|
||||
if inner.enabled
|
||||
&& output
|
||||
.current_mode()
|
||||
.map(|c| c == output_mode)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
instance.head.current_mode(&*mode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,30 +5,24 @@ use std::sync::Mutex;
|
|||
use smithay::{
|
||||
desktop::Window,
|
||||
reexports::{
|
||||
wayland_server::{
|
||||
Client, DataInit,
|
||||
DisplayHandle, Resource, New,
|
||||
GlobalDispatch, Dispatch,
|
||||
DelegateGlobalDispatch, DelegateDispatch,
|
||||
backend::{ClientId, GlobalId, ObjectId},
|
||||
},
|
||||
wayland_protocols::xdg::shell::server::xdg_toplevel,
|
||||
},
|
||||
wayland::{
|
||||
compositor::with_states,
|
||||
output::Output,
|
||||
shell::xdg::XdgToplevelSurfaceRoleAttributes,
|
||||
wayland_server::{
|
||||
backend::{ClientId, GlobalId, ObjectId},
|
||||
Client, DataInit, DelegateDispatch, DelegateGlobalDispatch, Dispatch, DisplayHandle,
|
||||
GlobalDispatch, New, Resource,
|
||||
},
|
||||
},
|
||||
utils::IsAlive,
|
||||
wayland::{
|
||||
compositor::with_states, output::Output, shell::xdg::XdgToplevelSurfaceRoleAttributes,
|
||||
},
|
||||
};
|
||||
|
||||
use super::workspace::{WorkspaceHandler, WorkspaceHandle, WorkspaceState};
|
||||
use super::workspace::{WorkspaceHandle, WorkspaceHandler, WorkspaceState};
|
||||
|
||||
use cosmic_protocols::{
|
||||
toplevel_info::v1::server::{
|
||||
zcosmic_toplevel_info_v1::{self, ZcosmicToplevelInfoV1},
|
||||
zcosmic_toplevel_handle_v1::{self, ZcosmicToplevelHandleV1, State as States},
|
||||
},
|
||||
use cosmic_protocols::toplevel_info::v1::server::{
|
||||
zcosmic_toplevel_handle_v1::{self, State as States, ZcosmicToplevelHandleV1},
|
||||
zcosmic_toplevel_info_v1::{self, ZcosmicToplevelInfoV1},
|
||||
};
|
||||
|
||||
pub struct ToplevelInfoState<D> {
|
||||
|
|
@ -67,13 +61,14 @@ pub struct ToplevelHandleStateInner {
|
|||
}
|
||||
pub type ToplevelHandleState = Mutex<ToplevelHandleStateInner>;
|
||||
|
||||
impl<D> DelegateGlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData, D> for ToplevelInfoState<D>
|
||||
impl<D> DelegateGlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData, D>
|
||||
for ToplevelInfoState<D>
|
||||
where
|
||||
D: GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData>
|
||||
+ Dispatch<ZcosmicToplevelInfoV1, ()>
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState>
|
||||
+ ToplevelInfoHandler
|
||||
+ 'static
|
||||
+ 'static,
|
||||
{
|
||||
fn bind(
|
||||
state: &mut D,
|
||||
|
|
@ -100,7 +95,7 @@ where
|
|||
+ Dispatch<ZcosmicToplevelInfoV1, ()>
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState>
|
||||
+ ToplevelInfoHandler
|
||||
+ 'static
|
||||
+ 'static,
|
||||
{
|
||||
fn request(
|
||||
state: &mut D,
|
||||
|
|
@ -113,19 +108,20 @@ where
|
|||
) {
|
||||
match request {
|
||||
zcosmic_toplevel_info_v1::Request::Stop => {
|
||||
state.toplevel_info_state_mut().instances.retain(|i| i != obj);
|
||||
},
|
||||
_ => {},
|
||||
state
|
||||
.toplevel_info_state_mut()
|
||||
.instances
|
||||
.retain(|i| i != obj);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
state: &mut D,
|
||||
_client: ClientId,
|
||||
resource: ObjectId,
|
||||
_data: &(),
|
||||
) {
|
||||
state.toplevel_info_state_mut().instances.retain(|i| i.id() != resource);
|
||||
fn destroyed(state: &mut D, _client: ClientId, resource: ObjectId, _data: &()) {
|
||||
state
|
||||
.toplevel_info_state_mut()
|
||||
.instances
|
||||
.retain(|i| i.id() != resource);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +131,7 @@ where
|
|||
+ Dispatch<ZcosmicToplevelInfoV1, ()>
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState>
|
||||
+ ToplevelInfoHandler
|
||||
+ 'static
|
||||
+ 'static,
|
||||
{
|
||||
fn request(
|
||||
_state: &mut D,
|
||||
|
|
@ -147,20 +143,24 @@ where
|
|||
_data_init: &mut DataInit<'_, D>,
|
||||
) {
|
||||
match request {
|
||||
zcosmic_toplevel_handle_v1::Request::Destroy => {},
|
||||
_ => {},
|
||||
zcosmic_toplevel_handle_v1::Request::Destroy => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
state: &mut D,
|
||||
_client: ClientId,
|
||||
resource: ObjectId,
|
||||
state: &mut D,
|
||||
_client: ClientId,
|
||||
resource: ObjectId,
|
||||
_data: &ToplevelHandleState,
|
||||
) {
|
||||
for toplevel in &state.toplevel_info_state_mut().toplevels {
|
||||
if let Some(state) = toplevel.user_data().get::<ToplevelState>() {
|
||||
state.lock().unwrap().instances.retain(|i| i.id() != resource);
|
||||
state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.instances
|
||||
.retain(|i| i.id() != resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -174,16 +174,16 @@ where
|
|||
+ ToplevelInfoHandler
|
||||
+ 'static,
|
||||
{
|
||||
pub fn new<F>(
|
||||
dh: &DisplayHandle,
|
||||
client_filter: F,
|
||||
) -> ToplevelInfoState<D>
|
||||
pub fn new<F>(dh: &DisplayHandle, client_filter: F) -> ToplevelInfoState<D>
|
||||
where
|
||||
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, ZcosmicToplevelInfoV1, _>(1, ToplevelInfoGlobalData {
|
||||
filter: Box::new(client_filter),
|
||||
});
|
||||
let global = dh.create_global::<D, ZcosmicToplevelInfoV1, _>(
|
||||
1,
|
||||
ToplevelInfoGlobalData {
|
||||
filter: Box::new(client_filter),
|
||||
},
|
||||
);
|
||||
ToplevelInfoState {
|
||||
dh: dh.clone(),
|
||||
toplevels: Vec::new(),
|
||||
|
|
@ -194,7 +194,9 @@ where
|
|||
}
|
||||
|
||||
pub fn new_toplevel(&mut self, toplevel: &Window) {
|
||||
toplevel.user_data().insert_if_missing(ToplevelState::default);
|
||||
toplevel
|
||||
.user_data()
|
||||
.insert_if_missing(ToplevelState::default);
|
||||
for instance in &self.instances {
|
||||
send_toplevel_to_client::<D>(&self.dh, None, instance, toplevel);
|
||||
}
|
||||
|
|
@ -233,10 +235,19 @@ where
|
|||
}
|
||||
true
|
||||
} else {
|
||||
let state = window.user_data().get::<ToplevelState>().unwrap().lock().unwrap();
|
||||
let state = window
|
||||
.user_data()
|
||||
.get::<ToplevelState>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
for handle in &state.instances {
|
||||
// don't send events to stopped instances
|
||||
if self.instances.iter().any(|i| i.id().same_client_as(&handle.id())) {
|
||||
if self
|
||||
.instances
|
||||
.iter()
|
||||
.any(|i| i.id().same_client_as(&handle.id()))
|
||||
{
|
||||
handle.closed();
|
||||
}
|
||||
}
|
||||
|
|
@ -250,20 +261,39 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn send_toplevel_to_client<D>(dh: &DisplayHandle, workspace_state: Option<&WorkspaceState<D>>, info: &ZcosmicToplevelInfoV1, window: &Window)
|
||||
where
|
||||
fn send_toplevel_to_client<D>(
|
||||
dh: &DisplayHandle,
|
||||
workspace_state: Option<&WorkspaceState<D>>,
|
||||
info: &ZcosmicToplevelInfoV1,
|
||||
window: &Window,
|
||||
) where
|
||||
D: GlobalDispatch<ZcosmicToplevelInfoV1, ToplevelInfoGlobalData>
|
||||
+ Dispatch<ZcosmicToplevelInfoV1, ()>
|
||||
+ Dispatch<ZcosmicToplevelHandleV1, ToplevelHandleState>
|
||||
+ ToplevelInfoHandler
|
||||
+ 'static,
|
||||
{
|
||||
let mut state = window.user_data().get::<ToplevelState>().unwrap().lock().unwrap();
|
||||
let instance = match state.instances.iter().find(|i| i.id().same_client_as(&info.id())) {
|
||||
let mut state = window
|
||||
.user_data()
|
||||
.get::<ToplevelState>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
let instance = match state
|
||||
.instances
|
||||
.iter()
|
||||
.find(|i| i.id().same_client_as(&info.id()))
|
||||
{
|
||||
Some(i) => i,
|
||||
None => {
|
||||
if let Ok(client) = dh.get_client(info.id()) {
|
||||
if let Ok(toplevel_handle) = client.create_resource::<ZcosmicToplevelHandleV1, _, D>(dh, info.version(), ToplevelHandleState::default()) {
|
||||
if let Ok(toplevel_handle) = client
|
||||
.create_resource::<ZcosmicToplevelHandleV1, _, D>(
|
||||
dh,
|
||||
info.version(),
|
||||
ToplevelHandleState::default(),
|
||||
)
|
||||
{
|
||||
state.instances.push(toplevel_handle);
|
||||
state.instances.last().unwrap()
|
||||
} else {
|
||||
|
|
@ -275,7 +305,11 @@ where
|
|||
}
|
||||
};
|
||||
|
||||
let mut handle_state = instance.data::<ToplevelHandleState>().unwrap().lock().unwrap();
|
||||
let mut handle_state = instance
|
||||
.data::<ToplevelHandleState>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
let mut changed = false;
|
||||
with_states(window.toplevel().wl_surface(), |states| {
|
||||
let attributes = states
|
||||
|
|
@ -284,7 +318,7 @@ where
|
|||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
|
||||
|
||||
if handle_state.title != attributes.title.as_deref().unwrap_or(&"") {
|
||||
handle_state.title = attributes.title.clone().unwrap_or_else(String::new);
|
||||
instance.title(handle_state.title.clone());
|
||||
|
|
@ -296,21 +330,50 @@ where
|
|||
changed = true;
|
||||
}
|
||||
|
||||
if (handle_state.states.contains(&States::Maximized) != attributes.current.states.contains(xdg_toplevel::State::Maximized))
|
||||
|| (handle_state.states.contains(&States::Fullscreen) != attributes.current.states.contains(xdg_toplevel::State::Fullscreen))
|
||||
|| (handle_state.states.contains(&States::Activated) != attributes.current.states.contains(xdg_toplevel::State::Activated))
|
||||
|| (handle_state.states.contains(&States::Minimized) != state.minimized) {
|
||||
if (handle_state.states.contains(&States::Maximized)
|
||||
!= attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Maximized))
|
||||
|| (handle_state.states.contains(&States::Fullscreen)
|
||||
!= attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Fullscreen))
|
||||
|| (handle_state.states.contains(&States::Activated)
|
||||
!= attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Activated))
|
||||
|| (handle_state.states.contains(&States::Minimized) != state.minimized)
|
||||
{
|
||||
let mut states = Vec::new();
|
||||
if attributes.current.states.contains(xdg_toplevel::State::Maximized) {
|
||||
if attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Maximized)
|
||||
{
|
||||
states.push(States::Maximized);
|
||||
}
|
||||
if attributes.current.states.contains(xdg_toplevel::State::Fullscreen) {
|
||||
if attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Fullscreen)
|
||||
{
|
||||
states.push(States::Fullscreen);
|
||||
}
|
||||
if attributes.current.states.contains(xdg_toplevel::State::Activated) {
|
||||
if attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Activated)
|
||||
{
|
||||
states.push(States::Activated);
|
||||
}
|
||||
if attributes.current.states.contains(xdg_toplevel::State::Maximized) {
|
||||
if attributes
|
||||
.current
|
||||
.states
|
||||
.contains(xdg_toplevel::State::Maximized)
|
||||
{
|
||||
states.push(States::Maximized);
|
||||
}
|
||||
handle_state.states = states.clone();
|
||||
|
|
@ -329,13 +392,21 @@ where
|
|||
});
|
||||
|
||||
if let Ok(client) = dh.get_client(instance.id()) {
|
||||
for new_output in state.outputs.iter().filter(|o| !handle_state.outputs.contains(o)) {
|
||||
for new_output in state
|
||||
.outputs
|
||||
.iter()
|
||||
.filter(|o| !handle_state.outputs.contains(o))
|
||||
{
|
||||
new_output.with_client_outputs(dh, &client, |_dh, wl_output| {
|
||||
instance.output_enter(wl_output);
|
||||
});
|
||||
changed = true;
|
||||
}
|
||||
for old_output in handle_state.outputs.iter().filter(|o| !state.outputs.contains(o)) {
|
||||
for old_output in handle_state
|
||||
.outputs
|
||||
.iter()
|
||||
.filter(|o| !state.outputs.contains(o))
|
||||
{
|
||||
old_output.with_client_outputs(dh, &client, |_dh, wl_output| {
|
||||
instance.output_leave(wl_output);
|
||||
});
|
||||
|
|
@ -345,14 +416,26 @@ where
|
|||
}
|
||||
|
||||
if let Some(workspace_state) = workspace_state {
|
||||
for new_workspace in state.workspaces.iter().filter(|w| !handle_state.workspaces.contains(w)) {
|
||||
if let Some(handle) = workspace_state.raw_workspace_handle(&new_workspace, &instance.id()) {
|
||||
for new_workspace in state
|
||||
.workspaces
|
||||
.iter()
|
||||
.filter(|w| !handle_state.workspaces.contains(w))
|
||||
{
|
||||
if let Some(handle) =
|
||||
workspace_state.raw_workspace_handle(&new_workspace, &instance.id())
|
||||
{
|
||||
instance.workspace_enter(&handle);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
for old_workspace in handle_state.workspaces.iter().filter(|w| !state.workspaces.contains(w)) {
|
||||
if let Some(handle) = workspace_state.raw_workspace_handle(&old_workspace, &instance.id()) {
|
||||
for old_workspace in handle_state
|
||||
.workspaces
|
||||
.iter()
|
||||
.filter(|w| !state.workspaces.contains(w))
|
||||
{
|
||||
if let Some(handle) =
|
||||
workspace_state.raw_workspace_handle(&old_workspace, &instance.id())
|
||||
{
|
||||
instance.workspace_leave(&handle);
|
||||
changed = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,19 +4,17 @@ use std::sync::Mutex;
|
|||
|
||||
use smithay::{
|
||||
reexports::wayland_server::{
|
||||
Client, DataInit,
|
||||
DisplayHandle, Resource, New,
|
||||
GlobalDispatch, Dispatch,
|
||||
DelegateGlobalDispatch, DelegateDispatch,
|
||||
backend::{ClientId, ClientData, GlobalId, ObjectId},
|
||||
backend::{ClientData, ClientId, GlobalId, ObjectId},
|
||||
Client, DataInit, DelegateDispatch, DelegateGlobalDispatch, Dispatch, DisplayHandle,
|
||||
GlobalDispatch, New, Resource,
|
||||
},
|
||||
wayland::output::Output,
|
||||
};
|
||||
|
||||
use cosmic_protocols::workspace::v1::server::{
|
||||
zcosmic_workspace_manager_v1::{self, ZcosmicWorkspaceManagerV1},
|
||||
zcosmic_workspace_group_handle_v1::{self, ZcosmicWorkspaceGroupHandleV1},
|
||||
zcosmic_workspace_handle_v1::{self, ZcosmicWorkspaceHandleV1},
|
||||
zcosmic_workspace_manager_v1::{self, ZcosmicWorkspaceManagerV1},
|
||||
};
|
||||
|
||||
pub use cosmic_protocols::workspace::v1::server::{
|
||||
|
|
@ -32,9 +30,7 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static,
|
||||
{
|
||||
dh: DisplayHandle,
|
||||
global: GlobalId,
|
||||
|
|
@ -50,10 +46,7 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static
|
||||
;
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static;
|
||||
|
||||
crate::utils::id_gen!(next_group_id, GROUP_ID, GROUP_IDS);
|
||||
crate::utils::id_gen!(next_workspace_id, WORKSPACE_ID, WORKSPACE_IDS);
|
||||
|
|
@ -63,7 +56,7 @@ pub struct WorkspaceGroup {
|
|||
id: usize,
|
||||
instances: Vec<ZcosmicWorkspaceGroupHandleV1>,
|
||||
workspaces: Vec<Workspace>,
|
||||
|
||||
|
||||
outputs: Vec<Output>,
|
||||
capabilities: Vec<GroupCapabilities>,
|
||||
}
|
||||
|
|
@ -114,9 +107,7 @@ where
|
|||
+ Sized
|
||||
+ 'static,
|
||||
{
|
||||
type Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static;
|
||||
type Client: ClientData + WorkspaceClientHandler + 'static;
|
||||
|
||||
fn workspace_state(&self) -> &WorkspaceState<Self>;
|
||||
fn workspace_state_mut(&mut self) -> &mut WorkspaceState<Self>;
|
||||
|
|
@ -144,12 +135,12 @@ pub struct WorkspaceClientStateInner {
|
|||
}
|
||||
pub type WorkspaceClientState = Mutex<WorkspaceClientStateInner>;
|
||||
|
||||
|
||||
pub trait WorkspaceClientHandler {
|
||||
fn workspace_state(&self) -> &WorkspaceClientState;
|
||||
}
|
||||
|
||||
impl<D> DelegateGlobalDispatch<ZcosmicWorkspaceManagerV1, WorkspaceGlobalData, D> for WorkspaceState<D>
|
||||
impl<D> DelegateGlobalDispatch<ZcosmicWorkspaceManagerV1, WorkspaceGlobalData, D>
|
||||
for WorkspaceState<D>
|
||||
where
|
||||
D: GlobalDispatch<ZcosmicWorkspaceManagerV1, WorkspaceGlobalData>
|
||||
+ Dispatch<ZcosmicWorkspaceManagerV1, ()>
|
||||
|
|
@ -157,9 +148,7 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static,
|
||||
{
|
||||
fn bind(
|
||||
state: &mut D,
|
||||
|
|
@ -191,10 +180,8 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static,
|
||||
{
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static,
|
||||
{
|
||||
fn request(
|
||||
state: &mut D,
|
||||
client: &Client,
|
||||
|
|
@ -207,26 +194,29 @@ where
|
|||
match request {
|
||||
zcosmic_workspace_manager_v1::Request::Commit => {
|
||||
if state.workspace_state().instances.contains(obj) {
|
||||
let mut client_state = client.get_data::<<D as WorkspaceHandler>::Client>().unwrap().workspace_state().lock().unwrap();
|
||||
let mut client_state = client
|
||||
.get_data::<<D as WorkspaceHandler>::Client>()
|
||||
.unwrap()
|
||||
.workspace_state()
|
||||
.lock()
|
||||
.unwrap();
|
||||
state.commit_requests(dh, std::mem::take(&mut client_state.requests));
|
||||
}
|
||||
},
|
||||
}
|
||||
zcosmic_workspace_manager_v1::Request::Stop => {
|
||||
state.workspace_state_mut().instances.retain(|i| i != obj);
|
||||
// without an instance, the whole send_group_to_client machinery doesn't work
|
||||
// so there is no way for the whole clients hierachy to get any new events
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
state: &mut D,
|
||||
_client: ClientId,
|
||||
resource: ObjectId,
|
||||
_data: &(),
|
||||
) {
|
||||
state.workspace_state_mut().instances.retain(|i| i.id() != resource);
|
||||
fn destroyed(state: &mut D, _client: ClientId, resource: ObjectId, _data: &()) {
|
||||
state
|
||||
.workspace_state_mut()
|
||||
.instances
|
||||
.retain(|i| i.id() != resource);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -237,10 +227,8 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceGroupHandleV1, WorkspaceGroupData>
|
||||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static,
|
||||
{
|
||||
fn request(
|
||||
state: &mut D,
|
||||
|
|
@ -253,29 +241,35 @@ where
|
|||
) {
|
||||
match request {
|
||||
zcosmic_workspace_group_handle_v1::Request::CreateWorkspace { workspace } => {
|
||||
if let Some(id) = state.workspace_state().groups.iter().find(|g| g.instances.contains(obj)).map(|g| g.id) {
|
||||
let mut state = client.get_data::<<D as WorkspaceHandler>::Client>().unwrap().workspace_state().lock().unwrap();
|
||||
if let Some(id) = state
|
||||
.workspace_state()
|
||||
.groups
|
||||
.iter()
|
||||
.find(|g| g.instances.contains(obj))
|
||||
.map(|g| g.id)
|
||||
{
|
||||
let mut state = client
|
||||
.get_data::<<D as WorkspaceHandler>::Client>()
|
||||
.unwrap()
|
||||
.workspace_state()
|
||||
.lock()
|
||||
.unwrap();
|
||||
state.requests.push(Request::Create {
|
||||
in_group: WorkspaceGroupHandle { id },
|
||||
name: workspace,
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
zcosmic_workspace_group_handle_v1::Request::Destroy => {
|
||||
for group in &mut state.workspace_state_mut().groups {
|
||||
group.instances.retain(|i| i != obj)
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
state: &mut D,
|
||||
_client: ClientId,
|
||||
resource: ObjectId,
|
||||
_data: &WorkspaceGroupData,
|
||||
) {
|
||||
fn destroyed(state: &mut D, _client: ClientId, resource: ObjectId, _data: &WorkspaceGroupData) {
|
||||
for group in &mut state.workspace_state_mut().groups {
|
||||
group.instances.retain(|i| i.id() != resource)
|
||||
}
|
||||
|
|
@ -290,9 +284,7 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static,
|
||||
{
|
||||
fn request(
|
||||
state: &mut D,
|
||||
|
|
@ -305,30 +297,58 @@ where
|
|||
) {
|
||||
match request {
|
||||
zcosmic_workspace_handle_v1::Request::Activate => {
|
||||
if let Some(id) = state.workspace_state().groups.iter()
|
||||
if let Some(id) = state
|
||||
.workspace_state()
|
||||
.groups
|
||||
.iter()
|
||||
.find_map(|g| g.workspaces.iter().find(|w| w.instances.contains(obj)))
|
||||
.map(|w| w.id)
|
||||
{
|
||||
let mut state = client.get_data::<<D as WorkspaceHandler>::Client>().unwrap().workspace_state().lock().unwrap();
|
||||
state.requests.push(Request::Activate(WorkspaceHandle { id }));
|
||||
let mut state = client
|
||||
.get_data::<<D as WorkspaceHandler>::Client>()
|
||||
.unwrap()
|
||||
.workspace_state()
|
||||
.lock()
|
||||
.unwrap();
|
||||
state
|
||||
.requests
|
||||
.push(Request::Activate(WorkspaceHandle { id }));
|
||||
}
|
||||
}
|
||||
zcosmic_workspace_handle_v1::Request::Deactivate => {
|
||||
if let Some(id) = state.workspace_state().groups.iter()
|
||||
if let Some(id) = state
|
||||
.workspace_state()
|
||||
.groups
|
||||
.iter()
|
||||
.find_map(|g| g.workspaces.iter().find(|w| w.instances.contains(obj)))
|
||||
.map(|w| w.id)
|
||||
{
|
||||
let mut state = client.get_data::<<D as WorkspaceHandler>::Client>().unwrap().workspace_state().lock().unwrap();
|
||||
state.requests.push(Request::Deactivate(WorkspaceHandle { id }));
|
||||
let mut state = client
|
||||
.get_data::<<D as WorkspaceHandler>::Client>()
|
||||
.unwrap()
|
||||
.workspace_state()
|
||||
.lock()
|
||||
.unwrap();
|
||||
state
|
||||
.requests
|
||||
.push(Request::Deactivate(WorkspaceHandle { id }));
|
||||
}
|
||||
}
|
||||
zcosmic_workspace_handle_v1::Request::Remove => {
|
||||
if let Some(id) = state.workspace_state().groups.iter()
|
||||
if let Some(id) = state
|
||||
.workspace_state()
|
||||
.groups
|
||||
.iter()
|
||||
.find_map(|g| g.workspaces.iter().find(|w| w.instances.contains(obj)))
|
||||
.map(|w| w.id)
|
||||
{
|
||||
let mut state = client.get_data::<<D as WorkspaceHandler>::Client>().unwrap().workspace_state().lock().unwrap();
|
||||
state.requests.push(Request::Remove(WorkspaceHandle { id }));
|
||||
let mut state = client
|
||||
.get_data::<<D as WorkspaceHandler>::Client>()
|
||||
.unwrap()
|
||||
.workspace_state()
|
||||
.lock()
|
||||
.unwrap();
|
||||
state.requests.push(Request::Remove(WorkspaceHandle { id }));
|
||||
}
|
||||
}
|
||||
zcosmic_workspace_handle_v1::Request::Destroy => {
|
||||
|
|
@ -338,16 +358,11 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => {},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn destroyed(
|
||||
state: &mut D,
|
||||
_client: ClientId,
|
||||
resource: ObjectId,
|
||||
_data: &WorkspaceData,
|
||||
) {
|
||||
fn destroyed(state: &mut D, _client: ClientId, resource: ObjectId, _data: &WorkspaceData) {
|
||||
for group in &mut state.workspace_state_mut().groups {
|
||||
for workspace in &mut group.workspaces {
|
||||
workspace.instances.retain(|i| i.id() != resource)
|
||||
|
|
@ -356,7 +371,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl<D> WorkspaceState<D>
|
||||
where
|
||||
D: GlobalDispatch<ZcosmicWorkspaceManagerV1, WorkspaceGlobalData>
|
||||
|
|
@ -365,20 +379,18 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static,
|
||||
{
|
||||
pub fn new<F>(
|
||||
dh: &DisplayHandle,
|
||||
client_filter: F,
|
||||
) -> WorkspaceState<D>
|
||||
where
|
||||
pub fn new<F>(dh: &DisplayHandle, client_filter: F) -> WorkspaceState<D>
|
||||
where
|
||||
F: for<'a> Fn(&'a Client) -> bool + Send + Sync + 'static,
|
||||
{
|
||||
let global = dh.create_global::<D, ZcosmicWorkspaceManagerV1, _>(1, WorkspaceGlobalData {
|
||||
filter: Box::new(client_filter),
|
||||
});
|
||||
let global = dh.create_global::<D, ZcosmicWorkspaceManagerV1, _>(
|
||||
1,
|
||||
WorkspaceGlobalData {
|
||||
filter: Box::new(client_filter),
|
||||
},
|
||||
);
|
||||
|
||||
WorkspaceState {
|
||||
dh: dh.clone(),
|
||||
|
|
@ -388,8 +400,12 @@ where
|
|||
_marker: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn workspace_belongs_to_group(&self, group: &WorkspaceGroupHandle, workspace: &WorkspaceHandle) -> bool {
|
||||
|
||||
pub fn workspace_belongs_to_group(
|
||||
&self,
|
||||
group: &WorkspaceGroupHandle,
|
||||
workspace: &WorkspaceHandle,
|
||||
) -> bool {
|
||||
if let Some(group) = self.groups.iter().find(|g| g.id == group.id) {
|
||||
group.workspaces.iter().any(|w| w.id == workspace.id)
|
||||
} else {
|
||||
|
|
@ -397,38 +413,86 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn group_capabilities(&self, group: &WorkspaceGroupHandle) -> Option<impl Iterator<Item=&GroupCapabilities>> {
|
||||
self.groups.iter().find(|g| g.id == group.id).map(|g| g.capabilities.iter())
|
||||
pub fn group_capabilities(
|
||||
&self,
|
||||
group: &WorkspaceGroupHandle,
|
||||
) -> Option<impl Iterator<Item = &GroupCapabilities>> {
|
||||
self.groups
|
||||
.iter()
|
||||
.find(|g| g.id == group.id)
|
||||
.map(|g| g.capabilities.iter())
|
||||
}
|
||||
|
||||
pub fn group_outputs(&self, group: &WorkspaceGroupHandle) -> Option<impl Iterator<Item=&Output>> {
|
||||
self.groups.iter().find(|g| g.id == group.id).map(|g| g.outputs.iter())
|
||||
pub fn group_outputs(
|
||||
&self,
|
||||
group: &WorkspaceGroupHandle,
|
||||
) -> Option<impl Iterator<Item = &Output>> {
|
||||
self.groups
|
||||
.iter()
|
||||
.find(|g| g.id == group.id)
|
||||
.map(|g| g.outputs.iter())
|
||||
}
|
||||
|
||||
pub fn workspace_capabilities(&self, workspace: &WorkspaceHandle) -> Option<impl Iterator<Item=&WorkspaceCapabilities>> {
|
||||
self.groups.iter().find_map(|g| g.workspaces.iter().find(|w| w.id == workspace.id).map(|w| w.capabilities.iter()))
|
||||
|
||||
pub fn workspace_capabilities(
|
||||
&self,
|
||||
workspace: &WorkspaceHandle,
|
||||
) -> Option<impl Iterator<Item = &WorkspaceCapabilities>> {
|
||||
self.groups.iter().find_map(|g| {
|
||||
g.workspaces
|
||||
.iter()
|
||||
.find(|w| w.id == workspace.id)
|
||||
.map(|w| w.capabilities.iter())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn workspace_name(&self, workspace: &WorkspaceHandle) -> Option<&str> {
|
||||
self.groups.iter().find_map(|g| g.workspaces.iter().find(|w| w.id == workspace.id).map(|w| &*w.name))
|
||||
self.groups.iter().find_map(|g| {
|
||||
g.workspaces
|
||||
.iter()
|
||||
.find(|w| w.id == workspace.id)
|
||||
.map(|w| &*w.name)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn workspace_coordinates(&self, workspace: &WorkspaceHandle) -> Option<&[u32]> {
|
||||
self.groups.iter().find_map(|g| g.workspaces.iter().find(|w| w.id == workspace.id).map(|w| &*w.coordinates))
|
||||
self.groups.iter().find_map(|g| {
|
||||
g.workspaces
|
||||
.iter()
|
||||
.find(|w| w.id == workspace.id)
|
||||
.map(|w| &*w.coordinates)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn workspace_states(&self, workspace: &WorkspaceHandle) -> Option<impl Iterator<Item=&zcosmic_workspace_handle_v1::State>> {
|
||||
self.groups.iter().find_map(|g| g.workspaces.iter().find(|w| w.id == workspace.id).map(|w| w.states.iter()))
|
||||
pub fn workspace_states(
|
||||
&self,
|
||||
workspace: &WorkspaceHandle,
|
||||
) -> Option<impl Iterator<Item = &zcosmic_workspace_handle_v1::State>> {
|
||||
self.groups.iter().find_map(|g| {
|
||||
g.workspaces
|
||||
.iter()
|
||||
.find(|w| w.id == workspace.id)
|
||||
.map(|w| w.states.iter())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn raw_group_handle(&self, group: &WorkspaceGroupHandle, client: &ObjectId) -> Option<ZcosmicWorkspaceGroupHandleV1> {
|
||||
self.groups.iter()
|
||||
pub fn raw_group_handle(
|
||||
&self,
|
||||
group: &WorkspaceGroupHandle,
|
||||
client: &ObjectId,
|
||||
) -> Option<ZcosmicWorkspaceGroupHandleV1> {
|
||||
self.groups
|
||||
.iter()
|
||||
.find(|g| g.id == group.id)
|
||||
.and_then(|g| g.instances.iter().find(|i| i.id().same_client_as(client)))
|
||||
.cloned()
|
||||
}
|
||||
pub fn raw_workspace_handle(&self, workspace: &WorkspaceHandle, client: &ObjectId) -> Option<ZcosmicWorkspaceHandleV1> {
|
||||
self.groups.iter()
|
||||
pub fn raw_workspace_handle(
|
||||
&self,
|
||||
workspace: &WorkspaceHandle,
|
||||
client: &ObjectId,
|
||||
) -> Option<ZcosmicWorkspaceHandleV1> {
|
||||
self.groups
|
||||
.iter()
|
||||
.find_map(|g| g.workspaces.iter().find(|w| w.id == workspace.id))
|
||||
.and_then(|w| w.instances.iter().find(|i| i.id().same_client_as(client)))
|
||||
.cloned()
|
||||
|
|
@ -467,9 +531,7 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static,
|
||||
{
|
||||
pub fn create_workspace_group(&mut self) -> WorkspaceGroupHandle {
|
||||
let id = next_group_id();
|
||||
|
|
@ -478,9 +540,7 @@ where
|
|||
..Default::default()
|
||||
};
|
||||
self.0.groups.push(group);
|
||||
WorkspaceGroupHandle {
|
||||
id
|
||||
}
|
||||
WorkspaceGroupHandle { id }
|
||||
}
|
||||
|
||||
pub fn create_workspace(&mut self, group: &WorkspaceGroupHandle) -> Option<WorkspaceHandle> {
|
||||
|
|
@ -491,9 +551,7 @@ where
|
|||
..Default::default()
|
||||
};
|
||||
group.workspaces.push(workspace);
|
||||
Some(WorkspaceHandle {
|
||||
id
|
||||
})
|
||||
Some(WorkspaceHandle { id })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -501,10 +559,14 @@ where
|
|||
|
||||
pub fn remove_workspace_group(&mut self, group: WorkspaceGroupHandle) {
|
||||
// "The compositor must remove all workspaces belonging to a workspace group before removing the workspace group."
|
||||
for workspace in self.0.groups.iter()
|
||||
for workspace in self
|
||||
.0
|
||||
.groups
|
||||
.iter()
|
||||
.filter(|g| g.id == group.id)
|
||||
.flat_map(|g| g.workspaces.iter().map(|w| WorkspaceHandle { id: w.id }))
|
||||
.collect::<Vec<_>>().into_iter()
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
{
|
||||
self.remove_workspace(workspace);
|
||||
}
|
||||
|
|
@ -518,7 +580,7 @@ where
|
|||
GROUP_IDS.lock().unwrap().remove(&group.id);
|
||||
}
|
||||
|
||||
pub fn remove_workspace(&mut self, workspace: WorkspaceHandle) {
|
||||
pub fn remove_workspace(&mut self, workspace: WorkspaceHandle) {
|
||||
for group in &mut self.0.groups {
|
||||
if let Some(workspace) = group.workspaces.iter().find(|w| w.id == workspace.id) {
|
||||
for instance in &workspace.instances {
|
||||
|
|
@ -529,22 +591,36 @@ where
|
|||
}
|
||||
WORKSPACE_IDS.lock().unwrap().remove(&workspace.id);
|
||||
}
|
||||
|
||||
pub fn workspace_belongs_to_group(&self, group: &WorkspaceGroupHandle, workspace: &WorkspaceHandle) -> bool {
|
||||
|
||||
pub fn workspace_belongs_to_group(
|
||||
&self,
|
||||
group: &WorkspaceGroupHandle,
|
||||
workspace: &WorkspaceHandle,
|
||||
) -> bool {
|
||||
self.0.workspace_belongs_to_group(group, workspace)
|
||||
}
|
||||
|
||||
pub fn group_capabilities(&mut self, group: &WorkspaceGroupHandle) -> Option<impl Iterator<Item=&GroupCapabilities>> {
|
||||
|
||||
pub fn group_capabilities(
|
||||
&mut self,
|
||||
group: &WorkspaceGroupHandle,
|
||||
) -> Option<impl Iterator<Item = &GroupCapabilities>> {
|
||||
self.0.group_capabilities(group)
|
||||
}
|
||||
|
||||
pub fn set_group_capabilities(&mut self, group: &WorkspaceGroupHandle, capabilities: impl Iterator<Item=GroupCapabilities>) {
|
||||
pub fn set_group_capabilities(
|
||||
&mut self,
|
||||
group: &WorkspaceGroupHandle,
|
||||
capabilities: impl Iterator<Item = GroupCapabilities>,
|
||||
) {
|
||||
if let Some(group) = self.0.groups.iter_mut().find(|g| g.id == group.id) {
|
||||
group.capabilities = capabilities.collect();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn group_outputs(&self, group: &WorkspaceGroupHandle) -> Option<impl Iterator<Item=&Output>> {
|
||||
pub fn group_outputs(
|
||||
&self,
|
||||
group: &WorkspaceGroupHandle,
|
||||
) -> Option<impl Iterator<Item = &Output>> {
|
||||
self.0.group_outputs(group)
|
||||
}
|
||||
|
||||
|
|
@ -559,13 +635,23 @@ where
|
|||
group.outputs.retain(|o| o != output)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn workspace_capabilities(&self, workspace: &WorkspaceHandle) -> Option<impl Iterator<Item=&WorkspaceCapabilities>> {
|
||||
|
||||
pub fn workspace_capabilities(
|
||||
&self,
|
||||
workspace: &WorkspaceHandle,
|
||||
) -> Option<impl Iterator<Item = &WorkspaceCapabilities>> {
|
||||
self.0.workspace_capabilities(workspace)
|
||||
}
|
||||
|
||||
pub fn set_workspace_capabilities(&mut self, workspace: &WorkspaceHandle, capabilities: impl Iterator<Item=WorkspaceCapabilities>) {
|
||||
if let Some(workspace) = self.0.groups.iter_mut()
|
||||
pub fn set_workspace_capabilities(
|
||||
&mut self,
|
||||
workspace: &WorkspaceHandle,
|
||||
capabilities: impl Iterator<Item = WorkspaceCapabilities>,
|
||||
) {
|
||||
if let Some(workspace) = self
|
||||
.0
|
||||
.groups
|
||||
.iter_mut()
|
||||
.find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id))
|
||||
{
|
||||
workspace.capabilities = capabilities.collect();
|
||||
|
|
@ -577,7 +663,10 @@ where
|
|||
}
|
||||
|
||||
pub fn set_workspace_name(&mut self, workspace: &WorkspaceHandle, name: impl Into<String>) {
|
||||
if let Some(workspace) = self.0.groups.iter_mut()
|
||||
if let Some(workspace) = self
|
||||
.0
|
||||
.groups
|
||||
.iter_mut()
|
||||
.find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id))
|
||||
{
|
||||
workspace.name = name.into();
|
||||
|
|
@ -588,28 +677,56 @@ where
|
|||
self.0.workspace_coordinates(workspace)
|
||||
}
|
||||
|
||||
pub fn set_workspace_coordinates(&mut self, workspace: &WorkspaceHandle, coords: [Option<u32>; 3]) {
|
||||
if let Some(workspace) = self.0.groups.iter_mut()
|
||||
pub fn set_workspace_coordinates(
|
||||
&mut self,
|
||||
workspace: &WorkspaceHandle,
|
||||
coords: [Option<u32>; 3],
|
||||
) {
|
||||
if let Some(workspace) = self
|
||||
.0
|
||||
.groups
|
||||
.iter_mut()
|
||||
.find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id))
|
||||
{
|
||||
workspace.coordinates = coords.iter().flat_map(std::convert::identity).copied().collect();
|
||||
workspace.coordinates = coords
|
||||
.iter()
|
||||
.flat_map(std::convert::identity)
|
||||
.copied()
|
||||
.collect();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn workspace_states(&self, workspace: &WorkspaceHandle) -> Option<impl Iterator<Item=&zcosmic_workspace_handle_v1::State>> {
|
||||
pub fn workspace_states(
|
||||
&self,
|
||||
workspace: &WorkspaceHandle,
|
||||
) -> Option<impl Iterator<Item = &zcosmic_workspace_handle_v1::State>> {
|
||||
self.0.workspace_states(workspace)
|
||||
}
|
||||
|
||||
pub fn add_workspace_state(&mut self, workspace: &WorkspaceHandle, state: zcosmic_workspace_handle_v1::State) {
|
||||
if let Some(workspace) = self.0.groups.iter_mut()
|
||||
pub fn add_workspace_state(
|
||||
&mut self,
|
||||
workspace: &WorkspaceHandle,
|
||||
state: zcosmic_workspace_handle_v1::State,
|
||||
) {
|
||||
if let Some(workspace) = self
|
||||
.0
|
||||
.groups
|
||||
.iter_mut()
|
||||
.find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id))
|
||||
{
|
||||
workspace.states.push(state);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_workspace_state(&mut self, workspace: &WorkspaceHandle, state: zcosmic_workspace_handle_v1::State) {
|
||||
if let Some(workspace) = self.0.groups.iter_mut()
|
||||
pub fn remove_workspace_state(
|
||||
&mut self,
|
||||
workspace: &WorkspaceHandle,
|
||||
state: zcosmic_workspace_handle_v1::State,
|
||||
) {
|
||||
if let Some(workspace) = self
|
||||
.0
|
||||
.groups
|
||||
.iter_mut()
|
||||
.find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id))
|
||||
{
|
||||
workspace.states.retain(|s| *s != state);
|
||||
|
|
@ -625,16 +742,18 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static,
|
||||
{
|
||||
fn drop(&mut self) {
|
||||
self.0.done();
|
||||
}
|
||||
}
|
||||
|
||||
fn send_group_to_client<D>(dh: &DisplayHandle, mngr: &ZcosmicWorkspaceManagerV1, group: &mut WorkspaceGroup) -> bool
|
||||
fn send_group_to_client<D>(
|
||||
dh: &DisplayHandle,
|
||||
mngr: &ZcosmicWorkspaceManagerV1,
|
||||
group: &mut WorkspaceGroup,
|
||||
) -> bool
|
||||
where
|
||||
D: GlobalDispatch<ZcosmicWorkspaceManagerV1, WorkspaceGlobalData>
|
||||
+ Dispatch<ZcosmicWorkspaceManagerV1, ()>
|
||||
|
|
@ -642,15 +761,21 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static,
|
||||
{
|
||||
let instance = match group.instances.iter_mut().find(|i| i.id().same_client_as(&mngr.id())) {
|
||||
let instance = match group
|
||||
.instances
|
||||
.iter_mut()
|
||||
.find(|i| i.id().same_client_as(&mngr.id()))
|
||||
{
|
||||
Some(i) => i,
|
||||
None => {
|
||||
if let Ok(client) = dh.get_client(mngr.id()) {
|
||||
if let Ok(handle) = client.create_resource::<ZcosmicWorkspaceGroupHandleV1, _, D>(dh, mngr.version(), WorkspaceGroupData::default()) {
|
||||
if let Ok(handle) = client.create_resource::<ZcosmicWorkspaceGroupHandleV1, _, D>(
|
||||
dh,
|
||||
mngr.version(),
|
||||
WorkspaceGroupData::default(),
|
||||
) {
|
||||
mngr.workspace_group(&handle);
|
||||
group.instances.push(handle);
|
||||
group.instances.last_mut().unwrap()
|
||||
|
|
@ -663,16 +788,28 @@ where
|
|||
}
|
||||
};
|
||||
|
||||
let mut handle_state = instance.data::<WorkspaceGroupData>().unwrap().lock().unwrap();
|
||||
let mut handle_state = instance
|
||||
.data::<WorkspaceGroupData>()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap();
|
||||
let mut changed = false;
|
||||
if let Ok(client) = dh.get_client(instance.id()) {
|
||||
for new_output in group.outputs.iter().filter(|o| !handle_state.outputs.contains(o)) {
|
||||
for new_output in group
|
||||
.outputs
|
||||
.iter()
|
||||
.filter(|o| !handle_state.outputs.contains(o))
|
||||
{
|
||||
new_output.with_client_outputs(dh, &client, |_dh, wl_output| {
|
||||
instance.output_enter(wl_output);
|
||||
});
|
||||
changed = true;
|
||||
}
|
||||
for old_output in handle_state.outputs.iter().filter(|o| group.outputs.contains(o)) {
|
||||
for old_output in handle_state
|
||||
.outputs
|
||||
.iter()
|
||||
.filter(|o| group.outputs.contains(o))
|
||||
{
|
||||
old_output.with_client_outputs(dh, &client, |_dh, wl_output| {
|
||||
instance.output_leave(wl_output);
|
||||
});
|
||||
|
|
@ -705,7 +842,11 @@ where
|
|||
changed
|
||||
}
|
||||
|
||||
fn send_workspace_to_client<D>(dh: &DisplayHandle, group: &ZcosmicWorkspaceGroupHandleV1, workspace: &mut Workspace) -> bool
|
||||
fn send_workspace_to_client<D>(
|
||||
dh: &DisplayHandle,
|
||||
group: &ZcosmicWorkspaceGroupHandleV1,
|
||||
workspace: &mut Workspace,
|
||||
) -> bool
|
||||
where
|
||||
D: GlobalDispatch<ZcosmicWorkspaceManagerV1, WorkspaceGlobalData>
|
||||
+ Dispatch<ZcosmicWorkspaceManagerV1, ()>
|
||||
|
|
@ -713,15 +854,21 @@ where
|
|||
+ Dispatch<ZcosmicWorkspaceHandleV1, WorkspaceData>
|
||||
+ WorkspaceHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData
|
||||
+ WorkspaceClientHandler
|
||||
+ 'static,
|
||||
<D as WorkspaceHandler>::Client: ClientData + WorkspaceClientHandler + 'static,
|
||||
{
|
||||
let instance = match workspace.instances.iter_mut().find(|i| i.id().same_client_as(&group.id())) {
|
||||
let instance = match workspace
|
||||
.instances
|
||||
.iter_mut()
|
||||
.find(|i| i.id().same_client_as(&group.id()))
|
||||
{
|
||||
Some(i) => i,
|
||||
None => {
|
||||
if let Ok(client) = dh.get_client(group.id()) {
|
||||
if let Ok(handle) = client.create_resource::<ZcosmicWorkspaceHandleV1, _, D>(dh, group.version(), WorkspaceData::default()) {
|
||||
if let Ok(handle) = client.create_resource::<ZcosmicWorkspaceHandleV1, _, D>(
|
||||
dh,
|
||||
group.version(),
|
||||
WorkspaceData::default(),
|
||||
) {
|
||||
group.workspace(&handle);
|
||||
workspace.instances.push(handle);
|
||||
workspace.instances.last_mut().unwrap()
|
||||
|
|
@ -736,7 +883,7 @@ where
|
|||
|
||||
let mut handle_state = instance.data::<WorkspaceData>().unwrap().lock().unwrap();
|
||||
let mut changed = false;
|
||||
|
||||
|
||||
if handle_state.name != workspace.name {
|
||||
instance.name(workspace.name.clone());
|
||||
handle_state.name = workspace.name.clone();
|
||||
|
|
@ -773,7 +920,8 @@ where
|
|||
if handle_state.states != workspace.states {
|
||||
let states: Vec<u8> = {
|
||||
let mut states = workspace.states.clone();
|
||||
let ratio = std::mem::size_of::<zcosmic_workspace_handle_v1::State>() / std::mem::size_of::<u8>();
|
||||
let ratio = std::mem::size_of::<zcosmic_workspace_handle_v1::State>()
|
||||
/ std::mem::size_of::<u8>();
|
||||
let ptr = states.as_mut_ptr() as *mut u8;
|
||||
let len = states.len() * ratio;
|
||||
let cap = states.capacity() * ratio;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue