pub fn toggle_window_visibility(
        &self,
        window: xlib::Window,
        visible: bool,
        preferred_stategy: Option<WindowHidingStrategy>,
    ) {
        let hiding_strategy = preferred_stategy.unwrap_or(self.window_hiding_strategy);
        let maybe_change_mask = |mask| {
            if let WindowHidingStrategy::Unmap = hiding_strategy {
                let mut attrs: xlib::XSetWindowAttributes = unsafe { std::mem::zeroed() };
                attrs.event_mask = mask;
                self.change_window_attributes(self.root, xlib::CWEventMask, attrs);
            }
        };
        // We don't want to receive this potential map or unmap event.
        maybe_change_mask(ROOT_EVENT_MASK & !(xlib::SubstructureNotifyMask));

        if visible {
            // NOTE: The window does not need to be moved here in case of non-unmap strategy,
            // if it's beeing made visible it's going to be naturally tiled or placed floating where it should.
            if hiding_strategy == WindowHidingStrategy::Unmap {
                unsafe { (self.xlib.XMapWindow)(self.display, window) };
            }

            // Set WM_STATE to normal state.
            self.set_wm_states(window, &[NORMAL_STATE]);
            // Regrab the mouse clicks but ignore `dock` windows as some don't handle click events put on them
            if self.focus_behaviour.is_clickto() && self.get_window_type(window) != WindowType::Dock
            {
                self.grab_mouse_clicks(window, false);
            }
        } else {
            // Ungrab the mouse clicks.
            self.ungrab_buttons(window);

            match hiding_strategy {
                WindowHidingStrategy::Unmap => {
                    unsafe { (self.xlib.XUnmapWindow)(self.display, window) };
                }
                WindowHidingStrategy::MoveMinimize | WindowHidingStrategy::MoveOnly => {
                    // Move the window out of view, so it can still be captured if necessary
                    let Ok(window_geometry) = self.get_window_geometry(window) else {
                        tracing::error!("Error querying window geometry for window {}", window);
                        return;
                    };

                    let (x, y) = (
                        window_geometry
                            .w
                            .unwrap_or_else(|| self.get_screens_area_dimensions().0)
                            * -2,
                        window_geometry
                            .h
                            .unwrap_or_else(|| self.get_screens_area_dimensions().1)
                            * -2,
                    );

                    let mut window_changes: xlib::XWindowChanges = unsafe { std::mem::zeroed() };
                    window_changes.x = x;
                    window_changes.y = y;
                    self.set_window_config(
                        window,
                        window_changes,
                        u32::from(xlib::CWX | xlib::CWY),
                    );
                    self.move_resize_window(window, x, y, 0, 0);
                }
            }

            // make sure to always change the window state, so we don't forget
            // to grab mouse button events when we show the window again.
            let new_state = if hiding_strategy == WindowHidingStrategy::Unmap
                || hiding_strategy == WindowHidingStrategy::MoveMinimize
            {
                ICONIC_STATE
            } else {
                WITHDRAWN_STATE
            };
            self.set_wm_states(window, &[new_state]);
        }

        maybe_change_mask(ROOT_EVENT_MASK);
    }
Show or hide a window, depending on its current visibility.
Depending on the configured `window_hiding_strategy`, this will toggle window visibility by moving
the window out of / in to view, or map / unmap it in the display server.

see `<https://github.com/leftwm/leftwm/issues/1100>` and `<https://github.com/leftwm/leftwm/pull/1274>` for details
display-servers/xlib-display-server/src/xwrap/window.rs