tty: Avoid reloading ignored nodes unnecessarily
Browse files at this commit3eef19dc7dde989e27dc61f251a611d7f9d513deParent: 08fbdef3 changed files +83 -36
- src/backend/mod.rs +8 -0
- src/backend/tty.rs +68 -36
- src/niri.rs +7 -0
src/backend/mod.rsmodified+8 -0
| @@ -184,6 +184,14 @@ impl Backend { | |||
| 184 | } | 184 | } |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | + pub fn update_ignored_nodes_config(&mut self, niri: &mut Niri) { | ||
| 188 | + match self { | ||
| 189 | + Backend::Tty(tty) => tty.update_ignored_nodes_config(niri), | ||
| 190 | + Backend::Winit(_) => (), | ||
| 191 | + Backend::Headless(_) => (), | ||
| 192 | + } | ||
| 193 | + } | ||
| 194 | + | ||
| 187 | pub fn on_output_config_changed(&mut self, niri: &mut Niri) { | 195 | pub fn on_output_config_changed(&mut self, niri: &mut Niri) { |
| 188 | match self { | 196 | match self { |
| 189 | Backend::Tty(tty) => tty.on_output_config_changed(niri), | 197 | Backend::Tty(tty) => tty.on_output_config_changed(niri), |
src/backend/tty.rsmodified+68 -36
| @@ -95,6 +95,9 @@ pub struct Tty { | |||
| 95 | dmabuf_global: Option<DmabufGlobal>, | 95 | dmabuf_global: Option<DmabufGlobal>, |
| 96 | // The output config had changed, but the session is paused, so we need to update it on resume. | 96 | // The output config had changed, but the session is paused, so we need to update it on resume. |
| 97 | update_output_config_on_resume: bool, | 97 | update_output_config_on_resume: bool, |
| 98 | + // The ignored nodes have changed, but the session is paused, so we need to update it on | ||
| 99 | + // resume. | ||
| 100 | + update_ignored_nodes_on_resume: bool, | ||
| 98 | // Whether the debug tinting is enabled. | 101 | // Whether the debug tinting is enabled. |
| 99 | debug_tint: bool, | 102 | debug_tint: bool, |
| 100 | ipc_outputs: Arc<Mutex<IpcOutputMap>>, | 103 | ipc_outputs: Arc<Mutex<IpcOutputMap>>, |
| @@ -350,6 +353,7 @@ impl Tty { | |||
| 350 | devices: HashMap::new(), | 353 | devices: HashMap::new(), |
| 351 | dmabuf_global: None, | 354 | dmabuf_global: None, |
| 352 | update_output_config_on_resume: false, | 355 | update_output_config_on_resume: false, |
| 356 | + update_ignored_nodes_on_resume: false, | ||
| 353 | debug_tint: false, | 357 | debug_tint: false, |
| 354 | ipc_outputs: Arc::new(Mutex::new(HashMap::new())), | 358 | ipc_outputs: Arc::new(Mutex::new(HashMap::new())), |
| 355 | }) | 359 | }) |
| @@ -420,6 +424,17 @@ impl Tty { | |||
| 420 | warn!("error resuming libinput"); | 424 | warn!("error resuming libinput"); |
| 421 | } | 425 | } |
| 422 | 426 | ||
| 427 | + if self.update_ignored_nodes_on_resume { | ||
| 428 | + self.update_ignored_nodes_on_resume = false; | ||
| 429 | + let mut ignored_nodes = ignored_nodes_from_config(&self.config.borrow()); | ||
| 430 | + if ignored_nodes.remove(&self.primary_node) | ||
| 431 | + || ignored_nodes.remove(&self.primary_render_node) | ||
| 432 | + { | ||
| 433 | + warn!("ignoring the primary node or render node is not allowed"); | ||
| 434 | + } | ||
| 435 | + self.ignored_nodes = ignored_nodes; | ||
| 436 | + } | ||
| 437 | + | ||
| 423 | let mut device_list = self | 438 | let mut device_list = self |
| 424 | .udev_dispatcher | 439 | .udev_dispatcher |
| 425 | .as_source_ref() | 440 | .as_source_ref() |
| @@ -430,14 +445,20 @@ impl Tty { | |||
| 430 | let removed_devices = self | 445 | let removed_devices = self |
| 431 | .devices | 446 | .devices |
| 432 | .keys() | 447 | .keys() |
| 433 | - .filter(|node| !device_list.contains_key(&node.dev_id())) | 448 | + .filter(|node| { |
| 449 | + !device_list.contains_key(&node.dev_id()) | ||
| 450 | + || self.ignored_nodes.contains(node) | ||
| 451 | + }) | ||
| 434 | .copied() | 452 | .copied() |
| 435 | .collect::<Vec<_>>(); | 453 | .collect::<Vec<_>>(); |
| 436 | 454 | ||
| 437 | let remained_devices = self | 455 | let remained_devices = self |
| 438 | .devices | 456 | .devices |
| 439 | .keys() | 457 | .keys() |
| 440 | - .filter(|node| device_list.contains_key(&node.dev_id())) | 458 | + .filter(|node| { |
| 459 | + device_list.contains_key(&node.dev_id()) | ||
| 460 | + && !self.ignored_nodes.contains(node) | ||
| 461 | + }) | ||
| 441 | .copied() | 462 | .copied() |
| 442 | .collect::<Vec<_>>(); | 463 | .collect::<Vec<_>>(); |
| 443 | 464 | ||
| @@ -1901,57 +1922,68 @@ impl Tty { | |||
| 1901 | } | 1922 | } |
| 1902 | } | 1923 | } |
| 1903 | 1924 | ||
| 1904 | - pub fn on_output_config_changed(&mut self, niri: &mut Niri) { | 1925 | + pub fn update_ignored_nodes_config(&mut self, niri: &mut Niri) { |
| 1905 | - let _span = tracy_client::span!("Tty::on_output_config_changed"); | 1926 | + let _span = tracy_client::span!("Tty::update_ignored_nodes_config"); |
| 1906 | 1927 | ||
| 1907 | // If we're inactive, we can't do anything, so just set a flag for later. | 1928 | // If we're inactive, we can't do anything, so just set a flag for later. |
| 1908 | if !self.session.is_active() { | 1929 | if !self.session.is_active() { |
| 1909 | - self.update_output_config_on_resume = true; | 1930 | + self.update_ignored_nodes_on_resume = true; |
| 1910 | return; | 1931 | return; |
| 1911 | } | 1932 | } |
| 1912 | - self.update_output_config_on_resume = false; | ||
| 1913 | 1933 | ||
| 1914 | - // Update ignored nodes. | ||
| 1915 | let mut ignored_nodes = ignored_nodes_from_config(&self.config.borrow()); | 1934 | let mut ignored_nodes = ignored_nodes_from_config(&self.config.borrow()); |
| 1916 | if ignored_nodes.remove(&self.primary_node) | 1935 | if ignored_nodes.remove(&self.primary_node) |
| 1917 | || ignored_nodes.remove(&self.primary_render_node) | 1936 | || ignored_nodes.remove(&self.primary_render_node) |
| 1918 | { | 1937 | { |
| 1919 | warn!("ignoring the primary node or render node is not allowed"); | 1938 | warn!("ignoring the primary node or render node is not allowed"); |
| 1920 | } | 1939 | } |
| 1921 | - if ignored_nodes != self.ignored_nodes { | ||
| 1922 | - self.ignored_nodes = ignored_nodes; | ||
| 1923 | - | ||
| 1924 | - let mut device_list = self | ||
| 1925 | - .udev_dispatcher | ||
| 1926 | - .as_source_ref() | ||
| 1927 | - .device_list() | ||
| 1928 | - .map(|(device_id, path)| (device_id, path.to_owned())) | ||
| 1929 | - .collect::<HashMap<_, _>>(); | ||
| 1930 | - | ||
| 1931 | - let removed_devices = self | ||
| 1932 | - .devices | ||
| 1933 | - .keys() | ||
| 1934 | - .filter(|node| { | ||
| 1935 | - self.ignored_nodes.contains(node) || !device_list.contains_key(&node.dev_id()) | ||
| 1936 | - }) | ||
| 1937 | - .copied() | ||
| 1938 | - .collect::<Vec<_>>(); | ||
| 1939 | 1940 | ||
| 1940 | - for node in removed_devices { | 1941 | + if ignored_nodes == self.ignored_nodes { |
| 1941 | - device_list.remove(&node.dev_id()); | 1942 | + return; |
| 1942 | - self.device_removed(node.dev_id(), niri); | 1943 | + } |
| 1943 | - } | 1944 | + self.ignored_nodes = ignored_nodes; |
| 1944 | 1945 | ||
| 1945 | - for node in self.devices.keys() { | 1946 | + let mut device_list = self |
| 1946 | - device_list.remove(&node.dev_id()); | 1947 | + .udev_dispatcher |
| 1947 | - } | 1948 | + .as_source_ref() |
| 1949 | + .device_list() | ||
| 1950 | + .map(|(device_id, path)| (device_id, path.to_owned())) | ||
| 1951 | + .collect::<HashMap<_, _>>(); | ||
| 1948 | 1952 | ||
| 1949 | - for (device_id, path) in device_list { | 1953 | + let removed_devices = self |
| 1950 | - if let Err(err) = self.device_added(device_id, &path, niri) { | 1954 | + .devices |
| 1951 | - warn!("error adding device {path:?}: {err:?}"); | 1955 | + .keys() |
| 1952 | - } | 1956 | + .filter(|node| { |
| 1957 | + self.ignored_nodes.contains(node) || !device_list.contains_key(&node.dev_id()) | ||
| 1958 | + }) | ||
| 1959 | + .copied() | ||
| 1960 | + .collect::<Vec<_>>(); | ||
| 1961 | + | ||
| 1962 | + for node in removed_devices { | ||
| 1963 | + device_list.remove(&node.dev_id()); | ||
| 1964 | + self.device_removed(node.dev_id(), niri); | ||
| 1965 | + } | ||
| 1966 | + | ||
| 1967 | + for node in self.devices.keys() { | ||
| 1968 | + device_list.remove(&node.dev_id()); | ||
| 1969 | + } | ||
| 1970 | + | ||
| 1971 | + for (device_id, path) in device_list { | ||
| 1972 | + if let Err(err) = self.device_added(device_id, &path, niri) { | ||
| 1973 | + warn!("error adding device {path:?}: {err:?}"); | ||
| 1953 | } | 1974 | } |
| 1954 | } | 1975 | } |
| 1976 | + } | ||
| 1977 | + | ||
| 1978 | + pub fn on_output_config_changed(&mut self, niri: &mut Niri) { | ||
| 1979 | + let _span = tracy_client::span!("Tty::on_output_config_changed"); | ||
| 1980 | + | ||
| 1981 | + // If we're inactive, we can't do anything, so just set a flag for later. | ||
| 1982 | + if !self.session.is_active() { | ||
| 1983 | + self.update_output_config_on_resume = true; | ||
| 1984 | + return; | ||
| 1985 | + } | ||
| 1986 | + self.update_output_config_on_resume = false; | ||
| 1955 | 1987 | ||
| 1956 | // Figure out if we should disable laptop panels. | 1988 | // Figure out if we should disable laptop panels. |
| 1957 | let mut disable_laptop_panels = false; | 1989 | let mut disable_laptop_panels = false; |
src/niri.rsmodified+7 -0
| @@ -1476,6 +1476,9 @@ impl State { | |||
| 1476 | libinput_config_changed = true; | 1476 | libinput_config_changed = true; |
| 1477 | } | 1477 | } |
| 1478 | 1478 | ||
| 1479 | + let ignored_nodes_changed = | ||
| 1480 | + config.debug.ignored_drm_devices != old_config.debug.ignored_drm_devices; | ||
| 1481 | + | ||
| 1479 | if config.outputs != self.niri.config_file_output_config { | 1482 | if config.outputs != self.niri.config_file_output_config { |
| 1480 | output_config_changed = true; | 1483 | output_config_changed = true; |
| 1481 | self.niri | 1484 | self.niri |
| @@ -1611,6 +1614,10 @@ impl State { | |||
| 1611 | } | 1614 | } |
| 1612 | } | 1615 | } |
| 1613 | 1616 | ||
| 1617 | + if ignored_nodes_changed { | ||
| 1618 | + self.backend.update_ignored_nodes_config(&mut self.niri); | ||
| 1619 | + } | ||
| 1620 | + | ||
| 1614 | if output_config_changed { | 1621 | if output_config_changed { |
| 1615 | self.reload_output_config(); | 1622 | self.reload_output_config(); |
| 1616 | } | 1623 | } |