//! Display orientation on `Windows`: live rotation and the rotation lock.

use super::*;

impl Windows {
    pub fn set_orientation(&mut self, orientation: Orientation) {
        start_transaction();

        self.output.set_orientation(orientation);
        self.canvas = *self.output.canvas();

        let transform = orientation.surface_transform();
        with_all_windows!(self, |window| window.update_transform(transform));

        self.resize_all();
    }

    pub fn update_orientation(&mut self, orientation: Orientation) {
        self.unlocked_orientation = orientation;

        if self.orientation_locked {
            return;
        }

        self.set_orientation(orientation);
    }

    pub fn lock_orientation(&mut self, orientation: Option<Orientation>) {
        if let Some(orientation) = orientation {
            self.set_orientation(orientation);
        }

        self.orientation_locked = true;
    }

    pub fn unlock_orientation(&mut self) {
        self.orientation_locked = false;
        self.update_orientation(self.unlocked_orientation);
    }

    pub fn orientation_locked(&self) -> bool {
        self.orientation_locked
    }

}
