mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-05-16 16:57:02 +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);
|
drop(workspace_matching_rules);
|
||||||
|
|
||||||
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
|
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 display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||||
let c_idx = display_index_preferences
|
let c_idx = display_index_preferences
|
||||||
.iter()
|
.iter()
|
||||||
@@ -1255,7 +1255,7 @@ impl StaticConfig {
|
|||||||
drop(display_index_preferences);
|
drop(display_index_preferences);
|
||||||
c_idx
|
c_idx
|
||||||
};
|
};
|
||||||
let idx = config_idx.or({
|
let idx = preferred_config_idx.or({
|
||||||
// Monitor without preferred config idx.
|
// Monitor without preferred config idx.
|
||||||
// Get index of first config that is not a preferred config of some other monitor
|
// 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
|
// 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
|
// 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.
|
// 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_reconciliator::insert_in_monitor_cache(
|
||||||
monitor.device_id(),
|
monitor.device_id(),
|
||||||
monitor_config.clone(),
|
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()?;
|
wm.enforce_workspace_rules()?;
|
||||||
|
|
||||||
if value.border == Some(true) {
|
if value.border == Some(true) {
|
||||||
@@ -1353,7 +1376,7 @@ impl StaticConfig {
|
|||||||
drop(workspace_matching_rules);
|
drop(workspace_matching_rules);
|
||||||
|
|
||||||
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
|
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 display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
|
||||||
let c_idx = display_index_preferences
|
let c_idx = display_index_preferences
|
||||||
.iter()
|
.iter()
|
||||||
@@ -1361,7 +1384,7 @@ impl StaticConfig {
|
|||||||
drop(display_index_preferences);
|
drop(display_index_preferences);
|
||||||
c_idx
|
c_idx
|
||||||
};
|
};
|
||||||
let idx = config_idx.or({
|
let idx = preferred_config_idx.or({
|
||||||
// Monitor without preferred config idx.
|
// Monitor without preferred config idx.
|
||||||
// Get index of first config that is not a preferred config of some other monitor
|
// 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
|
// 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
|
// 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.
|
// 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_reconciliator::insert_in_monitor_cache(
|
||||||
monitor.device_id(),
|
monitor.device_id(),
|
||||||
monitor_config.clone(),
|
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()?;
|
wm.enforce_workspace_rules()?;
|
||||||
|
|
||||||
if let Some(enabled) = value.border {
|
if let Some(enabled) = value.border {
|
||||||
|
|||||||
Reference in New Issue
Block a user