Skip to content

Commit

Permalink
xdg-foreign: Fix inverted logic in set_parent_of()
Browse files Browse the repository at this point in the history
The argument is the child, not the other way around.
  • Loading branch information
YaLTeR authored and Drakulix committed Dec 16, 2024
1 parent 0f32e8d commit c2417b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/wayland/xdg_foreign/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where
handle,
ExportedState {
exported_surface: surface,
requested_parent: None,
requested_child: None,
imported_by: HashSet::new(),
},
);
Expand Down Expand Up @@ -170,20 +170,22 @@ impl<D: XdgForeignHandler> Dispatch<ZxdgImportedV2, XdgImportedUserData, D> for
_data_init: &mut DataInit<'_, D>,
) {
match request {
zxdg_imported_v2::Request::SetParentOf { surface } => {
zxdg_imported_v2::Request::SetParentOf { surface: child } => {
if let Some((_, state)) = state
.xdg_foreign_state()
.exported
.iter_mut()
.find(|(key, _)| key.as_str() == data.handle.as_str())
{
compositor::with_states(&state.exported_surface, |states| {
let parent = &state.exported_surface;

compositor::with_states(&child, |states| {
if let Some(data) = states.data_map.get::<XdgToplevelSurfaceData>() {
data.lock().unwrap().parent = Some(surface.clone());
data.lock().unwrap().parent = Some(parent.clone());
}
});

state.requested_parent = Some((surface, resource.clone()));
state.requested_child = Some((child, resource.clone()));
}
}
zxdg_imported_v2::Request::Destroy => {}
Expand All @@ -209,7 +211,7 @@ fn invalidate_all_relationships(state: &mut ExportedState) {
}

fn invalidate_relationship_for(state: &mut ExportedState, invalidate_for: Option<&ZxdgImportedV2>) {
let Some((requested_parent, requested_by)) = state.requested_parent.as_ref() else {
let Some((requested_child, requested_by)) = state.requested_child.as_ref() else {
return;
};

Expand All @@ -219,16 +221,16 @@ fn invalidate_relationship_for(state: &mut ExportedState, invalidate_for: Option
}
}

compositor::with_states(&state.exported_surface, |states| {
compositor::with_states(requested_child, |states| {
let Some(data) = states.data_map.get::<XdgToplevelSurfaceData>() else {
return;
};

let data = &mut *data.lock().unwrap();
if data.parent.as_ref() == Some(requested_parent) {
if data.parent.as_ref() == Some(&state.exported_surface) {
data.parent = None;
}
});

state.requested_parent = None;
state.requested_child = None;
}
2 changes: 1 addition & 1 deletion src/wayland/xdg_foreign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct XdgImportedUserData {
#[derive(Debug)]
struct ExportedState {
exported_surface: WlSurface,
requested_parent: Option<(WlSurface, ZxdgImportedV2)>,
requested_child: Option<(WlSurface, ZxdgImportedV2)>,
imported_by: HashSet<ZxdgImportedV2>,
}

Expand Down

0 comments on commit c2417b9

Please sign in to comment.