mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-05-07 03:13:31 +02:00
fix(wm): cache monitor configs for unloaded monitors
If we have display_index_preferences that set a specific config index for a specific display device, but that device isn't loaded yet, now we store that config with the corresponding `device_id` on the monitor cache. Now when the display is connected it can load the correct config from the cache.
This commit is contained in:
@@ -1247,7 +1247,7 @@ impl StaticConfig {
|
||||
drop(workspace_matching_rules);
|
||||
|
||||
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
|
||||
let config_idx = {
|
||||
let preferred_config_idx = {
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||
let c_idx = display_index_preferences
|
||||
.iter()
|
||||
@@ -1255,7 +1255,7 @@ impl StaticConfig {
|
||||
drop(display_index_preferences);
|
||||
c_idx
|
||||
};
|
||||
let idx = config_idx.or({
|
||||
let idx = preferred_config_idx.or({
|
||||
// Monitor without preferred config idx.
|
||||
// Get index of first config that is not a preferred config of some other monitor
|
||||
// and that has not been used yet. This might return `None` as well, in that case
|
||||
@@ -1275,7 +1275,7 @@ impl StaticConfig {
|
||||
{
|
||||
// Check if this monitor config is the preferred config for this monitor and store
|
||||
// a copy of the config on the monitor cache if it is.
|
||||
if idx == config_idx {
|
||||
if idx == preferred_config_idx {
|
||||
monitor_reconciliator::insert_in_monitor_cache(
|
||||
monitor.device_id(),
|
||||
monitor_config.clone(),
|
||||
@@ -1330,6 +1330,29 @@ impl StaticConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for configs that should be tied to a specific display that isn't loaded right now
|
||||
// and cache those configs with the specific `device_id` so that when those devices are
|
||||
// connected later we can use the correct config from the cache.
|
||||
if configs_with_preference.len() > configs_used.len() {
|
||||
for i in configs_with_preference
|
||||
.iter()
|
||||
.filter(|i| !configs_used.contains(i))
|
||||
{
|
||||
let device_id = {
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||
display_index_preferences.get(i).cloned()
|
||||
};
|
||||
if let (Some(device_id), Some(monitor_config)) =
|
||||
(device_id, value.monitors.as_ref().and_then(|ms| ms.get(*i)))
|
||||
{
|
||||
monitor_reconciliator::insert_in_monitor_cache(
|
||||
&device_id,
|
||||
monitor_config.clone(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wm.enforce_workspace_rules()?;
|
||||
|
||||
if value.border == Some(true) {
|
||||
@@ -1353,7 +1376,7 @@ impl StaticConfig {
|
||||
drop(workspace_matching_rules);
|
||||
|
||||
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
|
||||
let config_idx = {
|
||||
let preferred_config_idx = {
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||
let c_idx = display_index_preferences
|
||||
.iter()
|
||||
@@ -1361,7 +1384,7 @@ impl StaticConfig {
|
||||
drop(display_index_preferences);
|
||||
c_idx
|
||||
};
|
||||
let idx = config_idx.or({
|
||||
let idx = preferred_config_idx.or({
|
||||
// Monitor without preferred config idx.
|
||||
// Get index of first config that is not a preferred config of some other monitor
|
||||
// and that has not been used yet. This might return `None` as well, in that case
|
||||
@@ -1381,7 +1404,7 @@ impl StaticConfig {
|
||||
{
|
||||
// Check if this monitor config is the preferred config for this monitor and store
|
||||
// a copy of the config on the monitor cache if it is.
|
||||
if idx == config_idx {
|
||||
if idx == preferred_config_idx {
|
||||
monitor_reconciliator::insert_in_monitor_cache(
|
||||
monitor.device_id(),
|
||||
monitor_config.clone(),
|
||||
@@ -1438,6 +1461,29 @@ impl StaticConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for configs that should be tied to a specific display that isn't loaded right now
|
||||
// and cache those configs with the specific `device_id` so that when those devices are
|
||||
// connected later we can use the correct config from the cache.
|
||||
if configs_with_preference.len() > configs_used.len() {
|
||||
for i in configs_with_preference
|
||||
.iter()
|
||||
.filter(|i| !configs_used.contains(i))
|
||||
{
|
||||
let device_id = {
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||
display_index_preferences.get(i).cloned()
|
||||
};
|
||||
if let (Some(device_id), Some(monitor_config)) =
|
||||
(device_id, value.monitors.as_ref().and_then(|ms| ms.get(*i)))
|
||||
{
|
||||
monitor_reconciliator::insert_in_monitor_cache(
|
||||
&device_id,
|
||||
monitor_config.clone(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wm.enforce_workspace_rules()?;
|
||||
|
||||
if let Some(enabled) = value.border {
|
||||
|
||||
Reference in New Issue
Block a user