diff options
author | Thomas Letan <lthms@soap.coffee> | 2022-08-24 20:26:50 +0200 |
---|---|---|
committer | Thomas Letan <lthms@soap.coffee> | 2022-08-24 20:26:50 +0200 |
commit | cf2b3fe4a40ba72c0758c4444b819822c73e1dba (patch) | |
tree | 801fbb5e8a6fe2fdd0e606628359e4e3dbf06537 | |
parent | Document the top-level module of the sway-ipc library (diff) |
Force focus on floating container
-rw-r--r-- | bin/spatial/main.ml | 22 | ||||
-rw-r--r-- | bin/spatial/ribbon.ml | 7 | ||||
-rw-r--r-- | bin/spatial/state.ml | 31 |
3 files changed, 34 insertions, 26 deletions
diff --git a/bin/spatial/main.ml b/bin/spatial/main.ml index dfec612..9f2ff56 100644 --- a/bin/spatial/main.ml +++ b/bin/spatial/main.ml @@ -10,8 +10,9 @@ let workspace_handle (ev : Event.workspace_event) state = | Some workspace -> State.set_current_workspace workspace state | None -> state in - Lwt.return (state, true) - | Init | Empty | Move | Rename | Urgent | Reload -> Lwt.return (state, false) + Lwt.return (state, true, None) + | Init | Empty | Move | Rename | Urgent | Reload -> + Lwt.return (state, false, None) let window_handle (ev : Event.window_event) state = match ev.change with @@ -20,13 +21,13 @@ let window_handle (ev : Event.window_event) state = State.register_window false 2 state.State.current_workspace state ev.container in - Lwt.return (state, true) + Lwt.return (state, true, None) | Event.Close -> let state = State.unregister_window state ev.container.id in - Lwt.return (state, true) + Lwt.return (state, true, None) | Event.Focus | Event.Title | Event.Fullscreen_mode | Event.Move | Event.Mark | Event.Urgent -> - Lwt.return (state, false) + Lwt.return (state, false, None) | Event.Floating -> ( match ev.container.node_type with | Con -> @@ -34,17 +35,17 @@ let window_handle (ev : Event.window_event) state = State.register_window false 2 state.State.current_workspace state ev.container in - Lwt.return (state, true) + Lwt.return (state, true, None) | Floating_con -> let state = State.unregister_window state ev.container.id in - Lwt.return (state, true) - | _ -> Lwt.return (state, false)) + Lwt.return (state, true, Some ev.container.id) + | _ -> Lwt.return (state, false, None)) let event_handle ev state = let open Lwt.Syntax in Lwt.try_bind (fun () -> - let* state, arrange = + let* state, arrange, force_focus = match ev with | From_sway (Event.Workspace ev) -> workspace_handle ev state | From_sway (Window ev) -> window_handle ev state @@ -52,7 +53,8 @@ let event_handle ev state = | _ -> assert false in let+ () = - if arrange then State.arrange_current_workspace state else Lwt.return () + if arrange then State.arrange_current_workspace ?force_focus state + else Lwt.return () in state) Lwt.return diff --git a/bin/spatial/ribbon.ml b/bin/spatial/ribbon.ml index 02cf889..69f2914 100644 --- a/bin/spatial/ribbon.ml +++ b/bin/spatial/ribbon.ml @@ -301,13 +301,14 @@ let focus_command ribbon = ]) (Option.to_list @@ focused_window ribbon) -let arrange_commands ~focus workspace ribbon = +let arrange_commands ?force_focus workspace ribbon = let hide_commands = hide_all_windows_commands ribbon in let show_commands = show_visible_windows_commands workspace ribbon in let focus_command = - match ribbon.visible with - | Some (f, l) when focus -> + match (force_focus, ribbon.visible) with + | None, Some (f, l) -> [ Command.With_criteria (Con_id (List.nth l f), Focus) ] + | Some w, _ -> [ Command.With_criteria (Con_id w, Focus) ] | _ -> [] in hide_commands @ show_commands @ focus_command diff --git a/bin/spatial/state.ml b/bin/spatial/state.ml index 2d1ed2c..82f20ac 100644 --- a/bin/spatial/state.ml +++ b/bin/spatial/state.ml @@ -79,20 +79,20 @@ let decr_maximum_visible_size workspace state = state.workspaces; } -let arrange_workspace_commands ~focus workspace state = +let arrange_workspace_commands ?force_focus workspace state = match Workspaces_registry.find_opt workspace state.workspaces with - | Some ribbon -> Ribbon.arrange_commands ~focus workspace ribbon + | Some ribbon -> Ribbon.arrange_commands ?force_focus workspace ribbon | None -> [] -let arrange_workspace ~focus ~socket workspace state = +let arrange_workspace ?force_focus ~socket workspace state = let open Lwt.Syntax in - let cmds = arrange_workspace_commands ~focus workspace state in + let cmds = arrange_workspace_commands ?force_focus workspace state in let* _replies = Sway_ipc.send_command ~socket (Run_command cmds) in Lwt.return () -let arrange_current_workspace state = +let arrange_current_workspace ?force_focus state = Sway_ipc.with_socket (fun socket -> - arrange_workspace ~focus:true ~socket state.current_workspace state) + arrange_workspace ?force_focus ~socket state.current_workspace state) let register_window default_full_view default_maximum_visible workspace state (tree : Node.t) = @@ -144,7 +144,8 @@ let client_handle ev state = | None -> None) state.workspaces; }, - true ) + true, + None ) | Move_right -> ( { state with @@ -155,14 +156,18 @@ let client_handle ev state = | None -> None) state.workspaces; }, - true ) - | Move_window_left -> (move_window_left state.current_workspace state, true) - | Move_window_right -> (move_window_right state.current_workspace state, true) - | Toggle_full_view -> (toggle_full_view state.current_workspace state, true) + true, + None ) + | Move_window_left -> + (move_window_left state.current_workspace state, true, None) + | Move_window_right -> + (move_window_right state.current_workspace state, true, None) + | Toggle_full_view -> + (toggle_full_view state.current_workspace state, true, None) | Incr_maximum_visible_space -> - (incr_maximum_visible_size state.current_workspace state, true) + (incr_maximum_visible_size state.current_workspace state, true, None) | Decr_maximum_visible_space -> - (decr_maximum_visible_size state.current_workspace state, true) + (decr_maximum_visible_size state.current_workspace state, true, None) let pp fmt state = Format.( |