gardesk/gartray / e9f079b

Browse files

Add position arguments to gartrayctl show/toggle commands

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
e9f079bf7d936e1efdddea5034fc3f6fb5d95edd
Parents
968443b
Tree
7bd53a4

2 changed files

StatusFile+-
M gartrayctl/src/ipc.rs 1 12
M gartrayctl/src/main.rs 24 10
gartrayctl/src/ipc.rsmodified
@@ -44,7 +44,7 @@ pub struct Response {
44
 }
44
 }
45
 
45
 
46
 /// Send a command to the running daemon
46
 /// Send a command to the running daemon
47
-pub fn send_command(command: &str) -> Result<()> {
47
+pub fn send_command(cmd: Command) -> Result<()> {
48
     let path = socket_path();
48
     let path = socket_path();
49
 
49
 
50
     if !path.exists() {
50
     if !path.exists() {
@@ -54,17 +54,6 @@ pub fn send_command(command: &str) -> Result<()> {
54
     let mut stream = UnixStream::connect(&path)
54
     let mut stream = UnixStream::connect(&path)
55
         .with_context(|| "Failed to connect to gartray daemon")?;
55
         .with_context(|| "Failed to connect to gartray daemon")?;
56
 
56
 
57
-    // CLI commands use default position (0,0) which the daemon interprets as "use default position"
58
-    let cmd = match command {
59
-        "show" => Command::Show { x: 0, y: 0 },
60
-        "hide" => Command::Hide,
61
-        "toggle" => Command::Toggle { x: 0, y: 0 },
62
-        "reload" => Command::Reload,
63
-        "status" => Command::Status,
64
-        "quit" => Command::Quit,
65
-        _ => anyhow::bail!("Unknown command: {}", command),
66
-    };
67
-
68
     let cmd_json = serde_json::to_string(&cmd)?;
57
     let cmd_json = serde_json::to_string(&cmd)?;
69
     writeln!(stream, "{}", cmd_json)?;
58
     writeln!(stream, "{}", cmd_json)?;
70
     stream.flush()?;
59
     stream.flush()?;
gartrayctl/src/main.rsmodified
@@ -17,11 +17,25 @@ struct Cli {
17
 #[derive(Subcommand)]
17
 #[derive(Subcommand)]
18
 enum Commands {
18
 enum Commands {
19
     /// Show the quick settings panel
19
     /// Show the quick settings panel
20
-    Show,
20
+    Show {
21
+        /// X position for panel
22
+        #[arg(default_value = "0")]
23
+        x: i32,
24
+        /// Y position for panel
25
+        #[arg(default_value = "0")]
26
+        y: i32,
27
+    },
21
     /// Hide the quick settings panel
28
     /// Hide the quick settings panel
22
     Hide,
29
     Hide,
23
     /// Toggle quick settings panel visibility
30
     /// Toggle quick settings panel visibility
24
-    Toggle,
31
+    Toggle {
32
+        /// X position for panel
33
+        #[arg(default_value = "0")]
34
+        x: i32,
35
+        /// Y position for panel
36
+        #[arg(default_value = "0")]
37
+        y: i32,
38
+    },
25
     /// Reload configuration
39
     /// Reload configuration
26
     Reload,
40
     Reload,
27
     /// Get daemon status
41
     /// Get daemon status
@@ -33,14 +47,14 @@ enum Commands {
33
 fn main() -> Result<()> {
47
 fn main() -> Result<()> {
34
     let cli = Cli::parse();
48
     let cli = Cli::parse();
35
 
49
 
36
-    let command = match cli.command {
50
+    let cmd = match cli.command {
37
-        Commands::Show => "show",
51
+        Commands::Show { x, y } => ipc::Command::Show { x, y },
38
-        Commands::Hide => "hide",
52
+        Commands::Hide => ipc::Command::Hide,
39
-        Commands::Toggle => "toggle",
53
+        Commands::Toggle { x, y } => ipc::Command::Toggle { x, y },
40
-        Commands::Reload => "reload",
54
+        Commands::Reload => ipc::Command::Reload,
41
-        Commands::Status => "status",
55
+        Commands::Status => ipc::Command::Status,
42
-        Commands::Quit => "quit",
56
+        Commands::Quit => ipc::Command::Quit,
43
     };
57
     };
44
 
58
 
45
-    ipc::send_command(command)
59
+    ipc::send_command(cmd)
46
 }
60
 }