From d8892f3ff24c3c9622dd80601706b69e79cdb6f6 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Thu, 31 Aug 2023 14:24:51 -0700 Subject: [PATCH] feat(config): add monitor index prefs to static This commit adds an "monitor_index_preferences" key to the static config schema, which was missed during the initial rollout of the static configuration files. To help with testing, these indexes have also been exposed on the State struct. resolve #522 --- komorebi/src/main.rs | 7 ++++++- komorebi/src/process_command.rs | 3 ++- komorebi/src/static_config.rs | 19 ++++++++++++++----- komorebi/src/window_manager.rs | 3 +++ schema.json | 10 ++++++++++ 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 58573071f..e00cca34d 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -1,5 +1,10 @@ #![warn(clippy::all, clippy::nursery, clippy::pedantic)] -#![allow(clippy::missing_errors_doc, clippy::redundant_pub_crate)] +#![allow( + clippy::missing_errors_doc, + clippy::redundant_pub_crate, + clippy::significant_drop_tightening, + clippy::significant_drop_in_scrutinee +)] use std::collections::HashMap; use std::fs::File; diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 2ca7df944..52083d2b1 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1341,7 +1341,8 @@ pub fn read_commands_tcp( break; } Ok(size) => { - let Ok(message) = SocketMessage::from_str(&String::from_utf8_lossy(&buf[..size])) else { + let Ok(message) = SocketMessage::from_str(&String::from_utf8_lossy(&buf[..size])) + else { tracing::warn!("client sent an invalid message, disconnecting: {addr}"); let mut connections = TCP_CONNECTIONS.lock(); connections.remove(addr); diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 05c04d3db..db0bb6449 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -22,6 +22,7 @@ use crate::FLOAT_IDENTIFIERS; use crate::HIDING_BEHAVIOUR; use crate::LAYERED_WHITELIST; use crate::MANAGE_IDENTIFIERS; +use crate::MONITOR_INDEX_PREFERENCES; use crate::OBJECT_NAME_CHANGE_ON_LAUNCH; use crate::TRAY_AND_MULTI_WINDOW_IDENTIFIERS; use crate::WORKSPACE_RULES; @@ -70,9 +71,9 @@ pub struct Rgb { impl From for Rgb { fn from(value: u32) -> Self { Self { - r: value & 0xff, - g: value >> 8 & 0xff, - b: value >> 16 & 0xff + r: value & 0xff, + g: value >> 8 & 0xff, + b: value >> 16 & 0xff, } } } @@ -297,9 +298,13 @@ pub struct StaticConfig { /// Identify applications that send EVENT_OBJECT_NAMECHANGE on launch (very rare) #[serde(skip_serializing_if = "Option::is_none")] pub object_name_change_applications: Option>, + /// Set monitor index preferences + #[serde(skip_serializing_if = "Option::is_none")] + pub monitor_index_preferences: Option>, } impl From<&WindowManager> for StaticConfig { + #[allow(clippy::too_many_lines)] fn from(value: &WindowManager) -> Self { let default_invisible_borders = Rect { left: 7, @@ -411,15 +416,19 @@ impl From<&WindowManager> for StaticConfig { tray_and_multi_window_applications: None, layered_applications: None, object_name_change_applications: None, + monitor_index_preferences: Option::from(MONITOR_INDEX_PREFERENCES.lock().clone()), } - - } } impl StaticConfig { #[allow(clippy::cognitive_complexity, clippy::too_many_lines)] fn apply_globals(&self) -> Result<()> { + if let Some(monitor_index_preferences) = &self.monitor_index_preferences { + let mut preferences = MONITOR_INDEX_PREFERENCES.lock(); + *preferences = monitor_index_preferences.clone(); + } + if let Some(behaviour) = self.window_hiding_behaviour { let mut window_hiding_behaviour = HIDING_BEHAVIOUR.lock(); *window_hiding_behaviour = behaviour; diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 4dea31162..3ac0eb1bc 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -50,6 +50,7 @@ use crate::FLOAT_IDENTIFIERS; use crate::HOME_DIR; use crate::LAYERED_WHITELIST; use crate::MANAGE_IDENTIFIERS; +use crate::MONITOR_INDEX_PREFERENCES; use crate::NO_TITLEBAR; use crate::OBJECT_NAME_CHANGE_ON_LAUNCH; use crate::REMOVE_TITLEBARS; @@ -98,6 +99,7 @@ pub struct State { pub tray_and_multi_window_identifiers: Vec, pub border_overflow_identifiers: Vec, pub name_change_on_launch_identifiers: Vec, + pub monitor_index_preferences: HashMap, } impl AsRef for WindowManager { @@ -126,6 +128,7 @@ impl From<&WindowManager> for State { tray_and_multi_window_identifiers: TRAY_AND_MULTI_WINDOW_IDENTIFIERS.lock().clone(), border_overflow_identifiers: BORDER_OVERFLOW_IDENTIFIERS.lock().clone(), name_change_on_launch_identifiers: OBJECT_NAME_CHANGE_ON_LAUNCH.lock().clone(), + monitor_index_preferences: MONITOR_INDEX_PREFERENCES.lock().clone(), } } } diff --git a/schema.json b/schema.json index 8ba451ca5..7f54f131d 100644 --- a/schema.json +++ b/schema.json @@ -154,6 +154,16 @@ "$ref": "#/definitions/IdWithIdentifier" } }, + "monitor_index_preferences": { + "description": "Set monitor index preferences", + "type": [ + "object", + "null" + ], + "additionalProperties": { + "$ref": "#/definitions/Rect" + } + }, "monitors": { "description": "Monitor and workspace configurations", "type": [