pub fn setup_managed_window(
        &mut self,
        h: WindowHandle<X11rbWindowHandle>,
        floating: bool,
        follow_mouse: bool,
    ) -> Result<Option<DisplayEvent<X11rbWindowHandle>>> {
        let WindowHandle(X11rbWindowHandle(handle)) = h;
        self.subscribe_to_window_events(handle)?;
        self.managed_windows.push(handle);

        // Make sure the window is mapped.
        xproto::map_window(&self.conn, handle)?;

        // Let Xlib know we are managing this window.
        self.append_property_u32(
            self.root,
            self.atoms.NetClientList,
            xproto::AtomEnum::WINDOW.into(),
            &[handle],
        )?;

        // Make sure there is at least an empty list of _NET_WM_STATE.
        let states = self.get_window_states_atoms(handle)?;
        self.set_window_states_atoms(handle, &states)?;

        // Set WM_STATE to normal state to allow window sharing.
        self.set_wm_state(handle, WMStateWindowState::Normal)?;

        let r#type = self.get_window_type(handle)?;
        if r#type == WindowType::Dock || r#type == WindowType::Desktop {
            if let Some(dock_area) = self.get_window_strut_array(handle)? {
                let dems = self.get_screens_area_dimensions()?;
                let Some(screen) = self
                    .get_screens()?
                    .iter()
                    .find(|s| s.contains_dock_area(dock_area, dems))
                    .cloned()
                else {
                    return Ok(None);
                };

                if let Some(xyhw) = dock_area.as_xyhw(dems.0, dems.1, &screen) {
                    let mut change = WindowChange::new(h);
                    change.strut = Some(xyhw.into());
                    change.r#type = Some(r#type);
                    return Ok(Some(DisplayEvent::WindowChange(change)));
                }
            } else {
                let geo = self.get_window_geometry(handle)?;
                let mut xyhw = Xyhw::default();
                geo.update(&mut xyhw);
                let mut change = WindowChange::new(h);
                change.strut = Some(xyhw.into());
                change.r#type = Some(r#type);
                return Ok(Some(DisplayEvent::WindowChange(change)));
            }
        } else {
            let color = if floating {
                self.colors.floating
            } else {
                self.colors.normal
            };
            self.set_window_border_color(handle, color)?;

            if follow_mouse {
                self.move_cursor_to_window(handle)?;
            }
            if self.focus_behaviour.is_clickto() {
                self.grab_mouse_clicks(handle, false)?;
            }
        }
        Ok(None)
    }
Sets up a window that we want to manage.
display-servers/x11rb-display-server/src/xwrap/window.rs