@@ -928,51 +928,93 @@ impl Workspaces {
928928 return ;
929929 } ;
930930
931- // Check which workspace is active on the new set; before removing from the
932- // old set in cause we're moving an active workspace within the same set.
933- let new_set = & mut self . sets [ & new_output] ;
934- let previous_active_handle = new_set. workspaces [ new_set. active ] . handle ;
935-
936- // Remove workspace from old set
937- let old_set = & mut self . sets [ & old_output] ;
938- let mut workspace = if new_output != old_output {
939- old_set. remove_workspace ( workspace_state, handle) . unwrap ( )
940- } else {
941- // If set is the same, just remove it here without adding empty workspace,
942- // updating `active`, etc.
943- let idx = old_set
944- . workspaces
945- . iter ( )
946- . position ( |w| w. handle == * handle)
947- . unwrap ( ) ;
948- old_set. workspaces . remove ( idx)
949- } ;
931+ match self . mode {
932+ WorkspaceMode :: OutputBound => {
933+ // Check which workspace is active on the new set; before removing from the
934+ // old set in cause we're moving an active workspace within the same set.
935+ let new_set = & mut self . sets [ & new_output] ;
936+ let previous_active_handle = new_set. workspaces [ new_set. active ] . handle ;
937+
938+ // Remove workspace from old set
939+ let old_set = & mut self . sets [ & old_output] ;
940+ let mut workspace = if new_output != old_output {
941+ old_set. remove_workspace ( workspace_state, handle) . unwrap ( )
942+ } else {
943+ // If set is the same, just remove it here without adding empty workspace,
944+ // updating `active`, etc.
945+ let idx = old_set
946+ . workspaces
947+ . iter ( )
948+ . position ( |w| w. handle == * handle)
949+ . unwrap ( ) ;
950+ old_set. workspaces . remove ( idx)
951+ } ;
950952
951- let new_set = & mut self . sets [ & new_output] ;
953+ let new_set = & mut self . sets [ & new_output] ;
952954
953- if new_output != old_output {
954- workspace_state. remove_workspace_state ( & workspace. handle , WState :: Active ) ;
955- workspace_state. move_workspace_to_group ( new_set. group , workspace. handle ) ;
956- workspace. set_output ( & new_output, true ) ;
957- workspace. refresh ( ) ;
958- }
955+ if new_output != old_output {
956+ workspace_state. remove_workspace_state ( & workspace. handle , WState :: Active ) ;
957+ workspace_state. move_workspace_to_group ( new_set. group , workspace. handle ) ;
958+ workspace. set_output ( & new_output, true ) ;
959+ workspace. refresh ( ) ;
960+ }
959961
960- // Insert workspace into new set, relative to `other_handle`
961- let idx = new_set
962- . workspaces
963- . iter ( )
964- . position ( |w| w. handle == * other_handle)
965- . unwrap ( ) ;
966- let insert_idx = if after { idx + 1 } else { idx } ;
967- new_set. workspaces . insert ( insert_idx, workspace) ;
962+ // Insert workspace into new set, relative to `other_handle`
963+ let idx = new_set
964+ . workspaces
965+ . iter ( )
966+ . position ( |w| w. handle == * other_handle)
967+ . unwrap ( ) ;
968+ let insert_idx = if after { idx + 1 } else { idx } ;
969+ new_set. workspaces . insert ( insert_idx, workspace) ;
968970
969- new_set. active = new_set
970- . workspaces
971- . iter ( )
972- . position ( |w| w. handle == previous_active_handle)
973- . unwrap ( ) ;
971+ new_set. active = new_set
972+ . workspaces
973+ . iter ( )
974+ . position ( |w| w. handle == previous_active_handle)
975+ . unwrap ( ) ;
976+
977+ new_set. update_workspace_idxs ( workspace_state) ;
978+ }
979+ WorkspaceMode :: Global => {
980+ let old_set = & mut self . sets [ & old_output] ;
981+ let old_idx = old_set
982+ . workspaces
983+ . iter ( )
984+ . position ( |w| w. handle == * handle)
985+ . unwrap ( ) ;
986+
987+ let new_set = & mut self . sets [ & new_output] ;
988+ let other_idx = new_set
989+ . workspaces
990+ . iter ( )
991+ . position ( |w| w. handle == * other_handle)
992+ . unwrap ( ) ;
974993
975- new_set. update_workspace_idxs ( workspace_state) ;
994+ // Move workspace at given index on every output
995+ for set in self . sets . values_mut ( ) {
996+ if old_idx < set. workspaces . len ( ) && other_idx < set. workspaces . len ( ) {
997+ let previous_active_handle = set. workspaces [ set. active ] . handle ;
998+
999+ if other_idx > old_idx {
1000+ let insert_idx = if after { other_idx } else { other_idx - 1 } ;
1001+ set. workspaces [ old_idx..=insert_idx] . rotate_left ( 1 ) ;
1002+ } else {
1003+ let insert_idx = if after { other_idx + 1 } else { other_idx } ;
1004+ set. workspaces [ insert_idx..=old_idx] . rotate_right ( 1 ) ;
1005+ }
1006+
1007+ set. active = set
1008+ . workspaces
1009+ . iter ( )
1010+ . position ( |w| w. handle == previous_active_handle)
1011+ . unwrap ( ) ;
1012+
1013+ set. update_workspace_idxs ( workspace_state) ;
1014+ }
1015+ }
1016+ }
1017+ }
9761018 }
9771019
9781020 pub fn update_config (
0 commit comments