mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-17 06:11:21 +01:00
feat(cli): implement display index preference cmd
This commit implements the komorebic display-index-preference command for updating display index preferences, however the monitor reconciliator module has not been reimplemented completely yet so these values will not have any effect.
This commit is contained in:
1 parent
61369df025
commit
c66db5a0bd
5 files changed
+60
-39
No files matched your search
@@ -279,7 +279,7 @@ pub enum SocketMessage {
|
||||
ToggleWorkspaceFloatOverride,
|
||||
// Monitor and Workspace Commands
|
||||
// MonitorIndexPreference(usize, i32, i32, i32, i32),
|
||||
// DisplayIndexPreference(usize, String),
|
||||
DisplayIndexPreference(usize, String),
|
||||
EnsureWorkspaces(usize, usize),
|
||||
EnsureNamedWorkspaces(usize, Vec<String>),
|
||||
NewWorkspace,
|
||||
|
||||
@@ -29,6 +29,7 @@ use objc2_core_foundation::CGPoint;
|
||||
use objc2_core_foundation::CGRect;
|
||||
use objc2_core_foundation::CGSize;
|
||||
use parking_lot::Mutex;
|
||||
use parking_lot::RwLock;
|
||||
use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
@@ -94,6 +95,8 @@ lazy_static! {
|
||||
static ref FLOATING_WINDOW_TOGGLE_ASPECT_RATIO: Arc<Mutex<AspectRatio>> = Arc::new(Mutex::new(
|
||||
AspectRatio::Predefined(PredefinedAspectRatio::Widescreen)
|
||||
));
|
||||
static ref DISPLAY_INDEX_PREFERENCES: Arc<RwLock<HashMap<usize, String>>> =
|
||||
Arc::new(RwLock::new(HashMap::new()));
|
||||
static ref WINDOW_RESTORE_POSITIONS: Arc<Mutex<HashMap<u32, CGRect>>> =
|
||||
Arc::new(Mutex::new(HashMap::new()));
|
||||
pub static ref UPDATE_MONITOR_WORK_AREAS: Arc<AtomicBool> = Arc::new(AtomicBool::new(false));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::DATA_DIR;
|
||||
use crate::DISPLAY_INDEX_PREFERENCES;
|
||||
use crate::FLOATING_APPLICATIONS;
|
||||
use crate::IGNORE_IDENTIFIERS;
|
||||
use crate::MANAGE_IDENTIFIERS;
|
||||
@@ -1624,8 +1625,11 @@ impl WindowManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
SocketMessage::DisplayIndexPreference(index_preference, ref display) => {
|
||||
let mut display_index_preferences = DISPLAY_INDEX_PREFERENCES.write();
|
||||
display_index_preferences.insert(index_preference, display.clone());
|
||||
}
|
||||
}
|
||||
|
||||
notify_subscribers(
|
||||
Notification {
|
||||
event: NotificationEvent::Socket(message.clone()),
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::CoreFoundationRunLoop;
|
||||
use crate::DATA_DIR;
|
||||
use crate::DEFAULT_CONTAINER_PADDING;
|
||||
use crate::DEFAULT_WORKSPACE_PADDING;
|
||||
use crate::DISPLAY_INDEX_PREFERENCES;
|
||||
use crate::FLOATING_APPLICATIONS;
|
||||
use crate::FLOATING_WINDOW_TOGGLE_ASPECT_RATIO;
|
||||
use crate::IGNORE_IDENTIFIERS;
|
||||
@@ -480,9 +481,9 @@ pub struct StaticConfig {
|
||||
// /// Set monitor index preferences
|
||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
||||
// pub monitor_index_preferences: Option<HashMap<usize, Rect>>,
|
||||
// /// Set display index preferences
|
||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
||||
// pub display_index_preferences: Option<HashMap<usize, String>>,
|
||||
/// Set display index preferences
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub display_index_preferences: Option<HashMap<usize, String>>,
|
||||
// /// Stackbar configuration options
|
||||
// #[serde(skip_serializing_if = "Option::is_none")]
|
||||
// pub stackbar: Option<StackbarConfig>,
|
||||
@@ -772,7 +773,7 @@ impl From<&WindowManager> for StaticConfig {
|
||||
object_name_change_applications: None,
|
||||
object_name_change_title_ignore_list: None,
|
||||
// monitor_index_preferences: Option::from(MONITOR_INDEX_PREFERENCES.lock().clone()),
|
||||
// display_index_preferences: Option::from(DISPLAY_INDEX_PREFERENCES.read().clone()),
|
||||
display_index_preferences: Option::from(DISPLAY_INDEX_PREFERENCES.read().clone()),
|
||||
// stackbar: None,
|
||||
// animation: None,
|
||||
// theme: None,
|
||||
@@ -800,10 +801,10 @@ impl StaticConfig {
|
||||
// preferences.clone_from(monitor_index_preferences);
|
||||
// }
|
||||
//
|
||||
// if let Some(display_index_preferences) = &self.display_index_preferences {
|
||||
// let mut preferences = DISPLAY_INDEX_PREFERENCES.write();
|
||||
// preferences.clone_from(display_index_preferences);
|
||||
// }
|
||||
if let Some(display_index_preferences) = &self.display_index_preferences {
|
||||
let mut preferences = DISPLAY_INDEX_PREFERENCES.write();
|
||||
preferences.clone_from(display_index_preferences);
|
||||
}
|
||||
|
||||
// if let Some(behaviour) = self.window_hiding_behaviour {
|
||||
// let mut window_hiding_behaviour = HIDING_BEHAVIOUR.lock();
|
||||
@@ -1197,9 +1198,8 @@ impl StaticConfig {
|
||||
let mut value = Self::read(path)?;
|
||||
let mut wm = wm.lock();
|
||||
|
||||
// let configs_with_preference: Vec<_> =
|
||||
// DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect();
|
||||
let configs_with_preference = [];
|
||||
let configs_with_preference: Vec<_> =
|
||||
DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect();
|
||||
let mut configs_used = Vec::new();
|
||||
|
||||
let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock();
|
||||
@@ -1210,16 +1210,17 @@ impl StaticConfig {
|
||||
|
||||
let offset = wm.work_area_offset;
|
||||
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
|
||||
let preferred_config_idx = None;
|
||||
// let preferred_config_idx = {
|
||||
// let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read();
|
||||
// let c_idx = display_index_preferences.iter().find_map(|(c_idx, id)| {
|
||||
// (monitor.serial_number_id.as_ref().is_some_and(|sn| sn == id)
|
||||
// || monitor.device_id.eq(id))
|
||||
// .then_some(*c_idx)
|
||||
// });
|
||||
// c_idx
|
||||
// };
|
||||
let preferred_config_idx = {
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read();
|
||||
|
||||
display_index_preferences.iter().find_map(|(c_idx, id)| {
|
||||
if monitor.serial_number_id.eq(id) {
|
||||
Some(*c_idx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let idx = preferred_config_idx.or({
|
||||
// Monitor without preferred config idx.
|
||||
@@ -1374,9 +1375,8 @@ impl StaticConfig {
|
||||
|
||||
value.apply_globals()?;
|
||||
|
||||
// let configs_with_preference: Vec<_> =
|
||||
// DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect();
|
||||
let configs_with_preference = [];
|
||||
let configs_with_preference: Vec<_> =
|
||||
DISPLAY_INDEX_PREFERENCES.read().keys().copied().collect();
|
||||
let mut configs_used = Vec::new();
|
||||
|
||||
let mut workspace_matching_rules = WORKSPACE_MATCHING_RULES.lock();
|
||||
@@ -1385,17 +1385,17 @@ impl StaticConfig {
|
||||
|
||||
let offset = wm.work_area_offset;
|
||||
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
|
||||
// let preferred_config_idx = {
|
||||
// let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read();
|
||||
// let c_idx = display_index_preferences.iter().find_map(|(c_idx, id)| {
|
||||
// (monitor.serial_number_id.as_ref().is_some_and(|sn| sn == id)
|
||||
// || monitor.device_id.eq(id))
|
||||
// .then_some(*c_idx)
|
||||
// });
|
||||
// c_idx
|
||||
// };
|
||||
let preferred_config_idx = {
|
||||
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read();
|
||||
|
||||
let preferred_config_idx = None;
|
||||
display_index_preferences.iter().find_map(|(c_idx, id)| {
|
||||
if monitor.serial_number_id.eq(id) {
|
||||
Some(*c_idx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
let idx = preferred_config_idx.or({
|
||||
// Monitor without preferred config idx.
|
||||
|
||||
+17
-3
@@ -525,6 +525,14 @@ pub struct NamedWorkspaceLayoutRule {
|
||||
layout: DefaultLayout,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct DisplayIndexPreference {
|
||||
/// Preferred monitor index (zero-indexed)
|
||||
index_preference: usize,
|
||||
/// Display name as identified in komorebic state
|
||||
display: String,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct EnsureWorkspaces {
|
||||
/// Monitor index (zero-indexed)
|
||||
@@ -851,9 +859,9 @@ enum SubCommand {
|
||||
// /// Set the monitor index preference for a monitor identified using its size
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// MonitorIndexPreference(MonitorIndexPreference),
|
||||
// /// Set the display index preference for a monitor identified using its display name
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// DisplayIndexPreference(DisplayIndexPreference),
|
||||
/// Set the display index preference for a monitor identified using its display name
|
||||
#[clap(arg_required_else_help = true)]
|
||||
DisplayIndexPreference(DisplayIndexPreference),
|
||||
/// Create at least this many workspaces for the specified monitor
|
||||
#[clap(arg_required_else_help = true)]
|
||||
EnsureWorkspaces(EnsureWorkspaces),
|
||||
@@ -1802,6 +1810,12 @@ fn main() -> eyre::Result<()> {
|
||||
SubCommand::LoadResize(arg) => {
|
||||
send_message(&SocketMessage::Load(arg.path))?;
|
||||
}
|
||||
SubCommand::DisplayIndexPreference(arg) => {
|
||||
send_message(&SocketMessage::DisplayIndexPreference(
|
||||
arg.index_preference,
|
||||
arg.display,
|
||||
))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user