diff options
author | Thomas Letan <lthms@soap.coffee> | 2022-08-24 20:48:39 +0200 |
---|---|---|
committer | Thomas Letan <lthms@soap.coffee> | 2022-08-24 20:48:39 +0200 |
commit | 17f8e6eab02e7d3233d3e935a0d8dc5543941c5c (patch) | |
tree | fc36aff7baae5e743ee9f8eebafe9b90508de420 | |
parent | Force focus on floating container (diff) |
Use the command-line argument parsing library Clap in the spatialmsg
-rw-r--r-- | README.md | 34 | ||||
-rw-r--r-- | bin/spatialmsg/dune | 2 | ||||
-rw-r--r-- | bin/spatialmsg/main.ml | 88 |
3 files changed, 93 insertions, 31 deletions
@@ -12,36 +12,36 @@ look at `man sway-ipc`!). It is missing some features, but `spatial-sway` can already by used today. Here is an example of a configuration that works. -``` +```bash set $spatial "/usr/local/bin/spatial" set $spatialmsg "/usr/local/bin/spatialmsg" # Start the daemon when sway is started. exec $spatialmsg -# Focus the next window on the left, if the focus is on the last window -# on the left of the visible area, windows will shift right to make room -# for the next candidate on the loop, and the window on the far right -# will disappear. -bindsym $mod+t exec $spatialmsg move_left +# Focus the previous window in the ribbon, that is on the left, if the +# focus is on the last window on the left of the visible area, windows +# will shift right to make room for the next candidate on the loop, +# and the window on the far right will disappear. +bindsym $mod+t exec $spatialmsg focus prev # Same thing, for the right. -bindsym $mod+n exec $spatialmsg move_right +bindsym $mod+n exec $spatialmsg focus next # Move the focused window on the left, shift the loop if necessary. -bindsym $mod+Shift+t exec $spatialmsg move_window_left +bindsym $mod+Shift+t exec $spatialmsg move prev # Move the focused window on the right, shift the loop if necessary. -bindsym $mod+Shift+n exec $spatialmsg move_window_right +bindsym $mod+Shift+n exec $spatialmsg move next -# Toggle between a mode where only one window is visible, or a fixed -# numbers. spatial-sway will remember how may windows you want visible -# when not in full view mode. -bindsym $mod+space exec $spatialmsg toggle_full_view +# Toggle between a mode where only one window is visible (maximized +# mode), or a fixed numbers (split mode). spatial-sway will remember +# how may windows you want visible when not in full view mode. +bindsym $mod+space exec $spatialmsg maximized toggle -# Decrease the number of windows to display when not in full view mode. -bindsym $mod+g exec $spatialmsg decr_maximum_visible_size +# Decrease the number of windows to display when in split mode. +bindsym $mod+g exec $spatialmsg split decrement -# Increase the number of windows to display when not in full view mode. -bindsym $mod+h exec $spatialmsg incr_maximum_visible_size +# Increase the number of windows to display when in split mode. +bindsym $mod+h exec $spatialmsg split increment ``` diff --git a/bin/spatialmsg/dune b/bin/spatialmsg/dune index 334a1c0..3ebeb98 100644 --- a/bin/spatialmsg/dune +++ b/bin/spatialmsg/dune @@ -1,3 +1,3 @@ (executable (name main) - (libraries spatial-sway.ipc lwt lwt.unix)) + (libraries spatial-sway.ipc lwt lwt.unix clap)) diff --git a/bin/spatialmsg/main.ml b/bin/spatialmsg/main.ml index a1611c4..b6a10ee 100644 --- a/bin/spatialmsg/main.ml +++ b/bin/spatialmsg/main.ml @@ -1,3 +1,12 @@ +let select_message = function + | `Focus `Prev -> Spatial_sway_ipc.Move_left + | `Focus `Next -> Move_right + | `Move `Prev -> Move_window_left + | `Move `Next -> Move_window_right + | `Maximize `Toggle -> Toggle_full_view + | `Split `Incr -> Incr_maximum_visible_space + | `Split `Decr -> Decr_maximum_visible_space + let connect () = let open Lwt.Syntax in let socket = Lwt_unix.socket PF_UNIX SOCK_STREAM 0 in @@ -11,21 +20,74 @@ let send_command socket cmd = let* _ = Lwt_unix.write socket buffer 0 4 in Lwt.return () -let main () = +let main cmd = let open Lwt.Syntax in - let cmd = - match Sys.argv.(1) with - | "move_left" -> Spatial_sway_ipc.Move_left - | "move_right" -> Move_right - | "move_window_left" -> Move_window_left - | "move_window_right" -> Move_window_right - | "toggle_full_view" -> Toggle_full_view - | "incr_maximum_visible_size" -> Incr_maximum_visible_space - | "decr_maximum_visible_size" -> Decr_maximum_visible_space - | _ -> raise (Invalid_argument "bad command") - in let* socket = connect () in let* () = send_command socket cmd in Lwt_unix.close socket -let () = Lwt_main.run @@ main () +let () = + Clap.description + "Send messages to a running instance of spatial-sway over the IPC socket"; + + let command = + Clap.subcommand + [ + ( Clap.case "focus" ~description:"Change the focused window." + @@ fun () -> + let direction = + Clap.subcommand ~placeholder:"DIRECTION" + [ + Clap.case "prev" + ~description:"Focus the previous window in the ribbon." + (fun () -> `Prev); + Clap.case "next" + ~description:"Focus the next window in the ribbon." (fun () -> + `Next); + ] + in + `Focus direction ); + ( Clap.case "move" ~description:"Move the focused window." @@ fun () -> + let direction = + Clap.subcommand ~placeholder:"DIRECTION" + [ + Clap.case "prev" + ~description: + "Move the focused container before the previous window in \ + the ribbon." (fun () -> `Prev); + Clap.case "next" + ~description: + "Move the focused container after the previous window in \ + the ribbon." (fun () -> `Next); + ] + in + `Move direction ); + ( Clap.case "maximize" ~description:"Enable or disable maximized mode." + @@ fun () -> + let switch = + Clap.subcommand ~placeholder:"SWITCH" + [ + Clap.case "toggle" ~description:"Toggle the maximized mode" + (fun () -> `Toggle); + ] + in + `Maximize switch ); + ( Clap.case "split" ~description:"Configure the split mode." @@ fun () -> + let cmd = + Clap.subcommand ~placeholder:"COMMAND" + [ + Clap.case "increment" + ~description:"Push one more window onto the output." + (fun () -> `Incr); + Clap.case "decrement" + ~description:"Remove one window from the output." (fun () -> + `Decr); + ] + in + `Split cmd ); + ] + in + + let cmd = select_message command in + + Lwt_main.run (main cmd) |