output_configuration: Use unwrap in calls to Resource::data
Having if conditions for these is unnecessary when they should never be reached. (This is commonly unwrapped in `smithay`.) Some of these else conditions fail to call `data_init.init` with a new id, so they'd result in a crash later anyway.
This commit is contained in:
parent
fdfc5cbeb4
commit
16a1214207
2 changed files with 69 additions and 85 deletions
|
|
@ -99,10 +99,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zcosmic_output_manager_v1::Request::GetConfiguration { extended, config } => {
|
zcosmic_output_manager_v1::Request::GetConfiguration { extended, config } => {
|
||||||
if let Some(pending) = config.data::<PendingConfiguration>() {
|
let pending = config.data::<PendingConfiguration>().unwrap();
|
||||||
let obj = data_init.init(extended, config.downgrade());
|
let obj = data_init.init(extended, config.downgrade());
|
||||||
pending.lock().unwrap().extension_obj = Some(obj);
|
pending.lock().unwrap().extension_obj = Some(obj);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
zcosmic_output_manager_v1::Request::GetConfigurationHead {
|
zcosmic_output_manager_v1::Request::GetConfigurationHead {
|
||||||
extended,
|
extended,
|
||||||
|
|
@ -178,56 +177,49 @@ where
|
||||||
mirroring,
|
mirroring,
|
||||||
} => {
|
} => {
|
||||||
if let Ok(obj) = obj.upgrade() {
|
if let Ok(obj) = obj.upgrade() {
|
||||||
if let Some(data) = obj.data::<PendingConfiguration>() {
|
let data = obj.data::<PendingConfiguration>().unwrap();
|
||||||
if let Some(output) =
|
if let Some(output) = mirroring.data::<WeakOutput>().unwrap().upgrade() {
|
||||||
mirroring.data::<WeakOutput>().and_then(|x| x.upgrade())
|
let mut pending = data.lock().unwrap();
|
||||||
{
|
if pending.heads.iter().any(|(h, _)| *h == head) {
|
||||||
let mut pending = data.lock().unwrap();
|
obj.post_error(
|
||||||
if pending.heads.iter().any(|(h, _)| *h == head) {
|
zwlr_output_configuration_v1::Error::AlreadyConfiguredHead,
|
||||||
obj.post_error(
|
format!("{:?} was already configured", head),
|
||||||
zwlr_output_configuration_v1::Error::AlreadyConfiguredHead,
|
|
||||||
format!("{:?} was already configured", head),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if pending.heads.iter().any(|(h, c)| {
|
|
||||||
match c.as_ref() {
|
|
||||||
Some(c) => {
|
|
||||||
if let Some(conf) = c.data::<PendingOutputConfiguration>() {
|
|
||||||
match conf.lock().unwrap().mirroring.as_ref() {
|
|
||||||
Some(mirrored) => {
|
|
||||||
head.data::<WeakOutput>().is_some_and(|o| o == mirrored) // we are already a mirror target -> invalid
|
|
||||||
|| *h == mirroring // our target already mirrors -> invalid
|
|
||||||
}
|
|
||||||
None => false,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*h == mirroring // unknown state for our mirror target -> invalid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => *h == mirroring, // disabled state for our mirror target -> invalid
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
extension_obj.post_error(
|
|
||||||
zcosmic_output_configuration_v1::Error::MirroredHeadBusy,
|
|
||||||
format!("{:?} can't mirror, it is either a mirror target itself or {:?} is not enabled/already mirroring", head, mirroring),
|
|
||||||
);
|
);
|
||||||
}
|
return;
|
||||||
|
|
||||||
let output_conf = PendingOutputConfiguration::default();
|
|
||||||
output_conf.lock().unwrap().mirroring = Some(output.clone());
|
|
||||||
let conf_head = data_init.init(id, output_conf);
|
|
||||||
pending.heads.push((head, Some(conf_head)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if pending.heads.iter().any(|(h, c)| {
|
||||||
|
match c.as_ref() {
|
||||||
|
Some(c) => {
|
||||||
|
let conf = c.data::<PendingOutputConfiguration>().unwrap();
|
||||||
|
match conf.lock().unwrap().mirroring.as_ref() {
|
||||||
|
Some(mirrored) => {
|
||||||
|
head.data::<WeakOutput>().unwrap() == mirrored // we are already a mirror target -> invalid
|
||||||
|
|| *h == mirroring // our target already mirrors -> invalid
|
||||||
|
}
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => *h == mirroring, // disabled state for our mirror target -> invalid
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
extension_obj.post_error(
|
||||||
|
zcosmic_output_configuration_v1::Error::MirroredHeadBusy,
|
||||||
|
format!("{:?} can't mirror, it is either a mirror target itself or {:?} is not enabled/already mirroring", head, mirroring),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let output_conf = PendingOutputConfiguration::default();
|
||||||
|
output_conf.lock().unwrap().mirroring = Some(output.clone());
|
||||||
|
let conf_head = data_init.init(id, output_conf);
|
||||||
|
pending.heads.push((head, Some(conf_head)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zcosmic_output_configuration_v1::Request::Release => {
|
zcosmic_output_configuration_v1::Request::Release => {
|
||||||
if let Ok(obj) = obj.upgrade() {
|
if let Ok(obj) = obj.upgrade() {
|
||||||
if let Some(data) = obj.data::<PendingConfiguration>() {
|
let data = obj.data::<PendingConfiguration>().unwrap();
|
||||||
data.lock().unwrap().extension_obj.take();
|
data.lock().unwrap().extension_obj.take();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
@ -259,40 +251,38 @@ where
|
||||||
match request {
|
match request {
|
||||||
zcosmic_output_configuration_head_v1::Request::SetScale1000 { scale_1000 } => {
|
zcosmic_output_configuration_head_v1::Request::SetScale1000 { scale_1000 } => {
|
||||||
if let Ok(obj) = obj.upgrade() {
|
if let Ok(obj) = obj.upgrade() {
|
||||||
if let Some(data) = obj.data::<PendingOutputConfiguration>() {
|
let data = obj.data::<PendingOutputConfiguration>().unwrap();
|
||||||
let mut pending = data.lock().unwrap();
|
let mut pending = data.lock().unwrap();
|
||||||
if pending.scale.is_some() {
|
if pending.scale.is_some() {
|
||||||
obj.post_error(
|
obj.post_error(
|
||||||
zwlr_output_configuration_head_v1::Error::AlreadySet,
|
zwlr_output_configuration_head_v1::Error::AlreadySet,
|
||||||
format!("{:?} already had a scale configured", obj),
|
format!("{:?} already had a scale configured", obj),
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
pending.scale = Some((scale_1000 as f64) / 1000.0);
|
|
||||||
}
|
}
|
||||||
|
pending.scale = Some((scale_1000 as f64) / 1000.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zcosmic_output_configuration_head_v1::Request::SetAdaptiveSyncExt { state } => {
|
zcosmic_output_configuration_head_v1::Request::SetAdaptiveSyncExt { state } => {
|
||||||
if let Ok(obj) = obj.upgrade() {
|
if let Ok(obj) = obj.upgrade() {
|
||||||
if let Some(data) = obj.data::<PendingOutputConfiguration>() {
|
let data = obj.data::<PendingOutputConfiguration>().unwrap();
|
||||||
let mut pending = data.lock().unwrap();
|
let mut pending = data.lock().unwrap();
|
||||||
if pending.adaptive_sync.is_some() {
|
if pending.adaptive_sync.is_some() {
|
||||||
obj.post_error(
|
obj.post_error(
|
||||||
zwlr_output_configuration_head_v1::Error::AlreadySet,
|
zwlr_output_configuration_head_v1::Error::AlreadySet,
|
||||||
format!("{:?} already had an adaptive_sync state configured", obj),
|
format!("{:?} already had an adaptive_sync state configured", obj),
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
pending.adaptive_sync = match state.into_result() {
|
|
||||||
Ok(zcosmic_output_head_v1::AdaptiveSyncStateExt::Always) => {
|
|
||||||
Some(AdaptiveSync::Force)
|
|
||||||
}
|
|
||||||
Ok(zcosmic_output_head_v1::AdaptiveSyncStateExt::Automatic) => {
|
|
||||||
Some(AdaptiveSync::Enabled)
|
|
||||||
}
|
|
||||||
_ => Some(AdaptiveSync::Disabled),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
pending.adaptive_sync = match state.into_result() {
|
||||||
|
Ok(zcosmic_output_head_v1::AdaptiveSyncStateExt::Always) => {
|
||||||
|
Some(AdaptiveSync::Force)
|
||||||
|
}
|
||||||
|
Ok(zcosmic_output_head_v1::AdaptiveSyncStateExt::Automatic) => {
|
||||||
|
Some(AdaptiveSync::Enabled)
|
||||||
|
}
|
||||||
|
_ => Some(AdaptiveSync::Disabled),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
||||||
|
|
@ -233,16 +233,10 @@ where
|
||||||
|
|
||||||
if pending.heads.iter().any(|(_, c)| match c {
|
if pending.heads.iter().any(|(_, c)| match c {
|
||||||
Some(conf) => {
|
Some(conf) => {
|
||||||
if let Some(output_conf) = conf.data::<PendingOutputConfiguration>() {
|
let output_conf = conf.data::<PendingOutputConfiguration>().unwrap();
|
||||||
if let Some(output) = head.data::<WeakOutput>() {
|
let output = head.data::<WeakOutput>().unwrap();
|
||||||
let pending_conf = output_conf.lock().unwrap();
|
let pending_conf = output_conf.lock().unwrap();
|
||||||
pending_conf.mirroring.as_ref().is_some_and(|o| o == output)
|
pending_conf.mirroring.as_ref().is_some_and(|o| o == output)
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => false,
|
None => false,
|
||||||
}) {
|
}) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue