mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 13:51:19 +01:00
feat(cli): implement save/load resize dimensions cmds
This commit is contained in:
1 parent
8f36549fae
commit
563c3b8446
3 files changed
+99
-18
No files matched your search
@@ -289,10 +289,10 @@ pub enum SocketMessage {
|
||||
TogglePause,
|
||||
Retile,
|
||||
RetileWithResizeDimensions,
|
||||
// QuickSave,
|
||||
// QuickLoad,
|
||||
// Save(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
|
||||
// Load(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
|
||||
QuickSave,
|
||||
QuickLoad,
|
||||
Save(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
|
||||
Load(#[serde_as(as = "ResolvedPathBuf")] PathBuf),
|
||||
CycleFocusMonitor(CycleDirection),
|
||||
CycleFocusWorkspace(CycleDirection),
|
||||
CycleFocusEmptyWorkspace(CycleDirection),
|
||||
|
||||
@@ -35,9 +35,12 @@ use crate::window_manager::WindowManager;
|
||||
use crate::workspace::WorkspaceLayer;
|
||||
use crate::workspace::WorkspaceWindowLocation;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use parking_lot::Mutex;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::BufRead;
|
||||
use std::io::BufReader;
|
||||
use std::num::NonZeroUsize;
|
||||
@@ -1539,6 +1542,58 @@ impl WindowManager {
|
||||
|
||||
reply.write_all(config.as_bytes())?;
|
||||
}
|
||||
SocketMessage::QuickSave => {
|
||||
let workspace = self.focused_workspace()?;
|
||||
let resize = &workspace.resize_dimensions;
|
||||
|
||||
let quicksave_json = std::env::temp_dir().join("komorebi.quicksave.json");
|
||||
|
||||
let file = OpenOptions::new()
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
.open(quicksave_json)?;
|
||||
|
||||
serde_json::to_writer_pretty(&file, &resize)?;
|
||||
}
|
||||
SocketMessage::QuickLoad => {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let quicksave_json = std::env::temp_dir().join("komorebi.quicksave.json");
|
||||
|
||||
let file = File::open(&quicksave_json).wrap_err(format!(
|
||||
"no quicksave found at {}",
|
||||
quicksave_json.display()
|
||||
))?;
|
||||
|
||||
let resize: Vec<Option<Rect>> = serde_json::from_reader(file)?;
|
||||
|
||||
workspace.resize_dimensions = resize;
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
SocketMessage::Save(ref path) => {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
let resize = &workspace.resize_dimensions;
|
||||
|
||||
let file = OpenOptions::new()
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
.open(path)?;
|
||||
|
||||
serde_json::to_writer_pretty(&file, &resize)?;
|
||||
}
|
||||
SocketMessage::Load(ref path) => {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let file =
|
||||
File::open(path).wrap_err(format!("no file found at {}", path.display()))?;
|
||||
|
||||
let resize: Vec<Option<Rect>> = serde_json::from_reader(file)?;
|
||||
|
||||
workspace.resize_dimensions = resize;
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
}
|
||||
|
||||
notify_subscribers(
|
||||
|
||||
+40
-14
@@ -560,6 +560,20 @@ struct Stop {
|
||||
ignore_restore: bool,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct SaveResize {
|
||||
/// File to which the resize layout dimensions should be saved
|
||||
#[clap(value_parser = replace_env_in_path)]
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct LoadResize {
|
||||
/// File from which the resize layout dimensions should be loaded
|
||||
#[clap(value_parser = replace_env_in_path)]
|
||||
path: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct EagerFocus {
|
||||
/// Case-sensitive exe identifier
|
||||
@@ -640,20 +654,20 @@ enum SubCommand {
|
||||
// UnsubscribePipe(UnsubscribePipe),
|
||||
/// Tail komorebi.exe's process logs (cancel with Ctrl-C)
|
||||
Log,
|
||||
// /// Quicksave the current resize layout dimensions
|
||||
// #[clap(alias = "quick-save")]
|
||||
// QuickSaveResize,
|
||||
// /// Load the last quicksaved resize layout dimensions
|
||||
// #[clap(alias = "quick-load")]
|
||||
// QuickLoadResize,
|
||||
// /// Save the current resize layout dimensions to a file
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// #[clap(alias = "save")]
|
||||
// SaveResize(SaveResize),
|
||||
// /// Load the resize layout dimensions from a file
|
||||
// #[clap(arg_required_else_help = true)]
|
||||
// #[clap(alias = "load")]
|
||||
// LoadResize(LoadResize),
|
||||
/// Quicksave the current resize layout dimensions
|
||||
#[clap(alias = "quick-save")]
|
||||
QuickSaveResize,
|
||||
/// Load the last quicksaved resize layout dimensions
|
||||
#[clap(alias = "quick-load")]
|
||||
QuickLoadResize,
|
||||
/// Save the current resize layout dimensions to a file
|
||||
#[clap(arg_required_else_help = true)]
|
||||
#[clap(alias = "save")]
|
||||
SaveResize(SaveResize),
|
||||
/// Load the resize layout dimensions from a file
|
||||
#[clap(arg_required_else_help = true)]
|
||||
#[clap(alias = "load")]
|
||||
LoadResize(LoadResize),
|
||||
/// Change focus to the window in the specified direction
|
||||
#[clap(arg_required_else_help = true)]
|
||||
Focus(Focus),
|
||||
@@ -1776,6 +1790,18 @@ fn main() -> eyre::Result<()> {
|
||||
SubCommand::GenerateStaticConfig => {
|
||||
print_query(&SocketMessage::GenerateStaticConfig);
|
||||
}
|
||||
SubCommand::QuickSaveResize => {
|
||||
send_message(&SocketMessage::QuickSave)?;
|
||||
}
|
||||
SubCommand::QuickLoadResize => {
|
||||
send_message(&SocketMessage::QuickLoad)?;
|
||||
}
|
||||
SubCommand::SaveResize(arg) => {
|
||||
send_message(&SocketMessage::Save(arg.path))?;
|
||||
}
|
||||
SubCommand::LoadResize(arg) => {
|
||||
send_message(&SocketMessage::Load(arg.path))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user