tty: Extract should_disable_laptop_panels()
Browse files at this commita19326fd129c3aa03da7ea32cbc1602fee93284cParent: 6ca21e71 changed file +21 -15
- src/backend/tty.rs +21 -15
src/backend/tty.rsmodified+21 -15
| @@ -1998,6 +1998,26 @@ impl Tty { | ||
| 1998 | 1998 | } |
| 1999 | 1999 | } |
| 2000 | 2000 | |
| 2001 | + fn should_disable_laptop_panels(&self, is_lid_closed: bool) -> bool { | |
| 2002 | + if !is_lid_closed { | |
| 2003 | + return false; | |
| 2004 | + } | |
| 2005 | + | |
| 2006 | + let config = self.config.borrow(); | |
| 2007 | + if !config.debug.keep_laptop_panel_on_when_lid_is_closed { | |
| 2008 | + // Check if any external monitor is connected. | |
| 2009 | + for device in self.devices.values() { | |
| 2010 | + for (connector, _crtc) in device.drm_scanner.crtcs() { | |
| 2011 | + if !is_laptop_panel(&format_connector_name(connector)) { | |
| 2012 | + return true; | |
| 2013 | + } | |
| 2014 | + } | |
| 2015 | + } | |
| 2016 | + } | |
| 2017 | + | |
| 2018 | + false | |
| 2019 | + } | |
| 2020 | + | |
| 2001 | 2021 | pub fn on_output_config_changed(&mut self, niri: &mut Niri) { |
| 2002 | 2022 | let _span = tracy_client::span!("Tty::on_output_config_changed"); |
| 2003 | 2023 | |
| @@ -2009,21 +2029,7 @@ impl Tty { | ||
| 2009 | 2029 | self.update_output_config_on_resume = false; |
| 2010 | 2030 | |
| 2011 | 2031 | // Figure out if we should disable laptop panels. |
| 2012 | - let mut disable_laptop_panels = false; | |
| 2013 | - if niri.is_lid_closed { | |
| 2014 | - let config = self.config.borrow(); | |
| 2015 | - if !config.debug.keep_laptop_panel_on_when_lid_is_closed { | |
| 2016 | - // Check if any external monitor is connected. | |
| 2017 | - 'outer: for device in self.devices.values() { | |
| 2018 | - for (connector, _crtc) in device.drm_scanner.crtcs() { | |
| 2019 | - if !is_laptop_panel(&format_connector_name(connector)) { | |
| 2020 | - disable_laptop_panels = true; | |
| 2021 | - break 'outer; | |
| 2022 | - } | |
| 2023 | - } | |
| 2024 | - } | |
| 2025 | - } | |
| 2026 | - } | |
| 2032 | + let disable_laptop_panels = self.should_disable_laptop_panels(niri.is_lid_closed); | |
| 2027 | 2033 | let should_disable = |connector: &str| disable_laptop_panels && is_laptop_panel(connector); |
| 2028 | 2034 | |
| 2029 | 2035 | let mut to_disconnect = vec![]; |