forge
Explore
Log in

Don't you dare go Hollow

Implement by-id window addressing in IPC and CLI, fix move-column-to-workspace

Browse files at this commit

dcb29efce58ce0e122806b7f352a9f682e2fcbd8Ivan MolodetskikhParent: cb5d97f
This is a JSON-breaking change for the IPC actions that changed from
unit variants to struct variants. Unfortunately, I couldn't find a way
with serde to both preserve a single variant, and make it serialize to
the old value when the new field is None. I don't think anyone is using
these actions from JSON at the moment, so this breaking change is fine.
niri-config/src/lib.rsmodified+45 -8
@@ -1073,8 +1073,16 @@ pub enum Action {
1073 Screenshot,1073 Screenshot,
1074 ScreenshotScreen,1074 ScreenshotScreen,
1075 ScreenshotWindow,1075 ScreenshotWindow,
1076+ #[knuffel(skip)]
1077+ ScreenshotWindowById(u64),
1076 CloseWindow,1078 CloseWindow,
1079+ #[knuffel(skip)]
1080+ CloseWindowById(u64),
1077 FullscreenWindow,1081 FullscreenWindow,
1082+ #[knuffel(skip)]
1083+ FullscreenWindowById(u64),
1084+ #[knuffel(skip)]
1085+ FocusWindow(u64),
1078 FocusColumnLeft,1086 FocusColumnLeft,
1079 FocusColumnRight,1087 FocusColumnRight,
1080 FocusColumnFirst,1088 FocusColumnFirst,
@@ -1115,6 +1123,11 @@ pub enum Action {
1115 MoveWindowToWorkspaceDown,1123 MoveWindowToWorkspaceDown,
1116 MoveWindowToWorkspaceUp,1124 MoveWindowToWorkspaceUp,
1117 MoveWindowToWorkspace(#[knuffel(argument)] WorkspaceReference),1125 MoveWindowToWorkspace(#[knuffel(argument)] WorkspaceReference),
1126+ #[knuffel(skip)]
1127+ MoveWindowToWorkspaceById {
1128+ window_id: u64,
1129+ reference: WorkspaceReference,
1130+ },
1118 MoveColumnToWorkspaceDown,1131 MoveColumnToWorkspaceDown,
1119 MoveColumnToWorkspaceUp,1132 MoveColumnToWorkspaceUp,
1120 MoveColumnToWorkspace(#[knuffel(argument)] WorkspaceReference),1133 MoveColumnToWorkspace(#[knuffel(argument)] WorkspaceReference),
@@ -1133,7 +1146,14 @@ pub enum Action {
1133 MoveColumnToMonitorDown,1146 MoveColumnToMonitorDown,
1134 MoveColumnToMonitorUp,1147 MoveColumnToMonitorUp,
1135 SetWindowHeight(#[knuffel(argument, str)] SizeChange),1148 SetWindowHeight(#[knuffel(argument, str)] SizeChange),
1149+ #[knuffel(skip)]
1150+ SetWindowHeightById {
1151+ id: u64,
1152+ change: SizeChange,
1153+ },
1136 ResetWindowHeight,1154 ResetWindowHeight,
1155+ #[knuffel(skip)]
1156+ ResetWindowHeightById(u64),
1137 SwitchPresetColumnWidth,1157 SwitchPresetColumnWidth,
1138 MaximizeColumn,1158 MaximizeColumn,
1139 SetColumnWidth(#[knuffel(argument, str)] SizeChange),1159 SetColumnWidth(#[knuffel(argument, str)] SizeChange),
@@ -1154,9 +1174,13 @@ impl From<niri_ipc::Action> for Action {
1154 niri_ipc::Action::DoScreenTransition { delay_ms } => Self::DoScreenTransition(delay_ms),1174 niri_ipc::Action::DoScreenTransition { delay_ms } => Self::DoScreenTransition(delay_ms),
1155 niri_ipc::Action::Screenshot => Self::Screenshot,1175 niri_ipc::Action::Screenshot => Self::Screenshot,
1156 niri_ipc::Action::ScreenshotScreen => Self::ScreenshotScreen,1176 niri_ipc::Action::ScreenshotScreen => Self::ScreenshotScreen,
1157- niri_ipc::Action::ScreenshotWindow => Self::ScreenshotWindow,1177+ niri_ipc::Action::ScreenshotWindow { id: None } => Self::ScreenshotWindow,
1158- niri_ipc::Action::CloseWindow => Self::CloseWindow,1178+ niri_ipc::Action::ScreenshotWindow { id: Some(id) } => Self::ScreenshotWindowById(id),
1159- niri_ipc::Action::FullscreenWindow => Self::FullscreenWindow,1179+ niri_ipc::Action::CloseWindow { id: None } => Self::CloseWindow,
1180+ niri_ipc::Action::CloseWindow { id: Some(id) } => Self::CloseWindowById(id),
1181+ niri_ipc::Action::FullscreenWindow { id: None } => Self::FullscreenWindow,
1182+ niri_ipc::Action::FullscreenWindow { id: Some(id) } => Self::FullscreenWindowById(id),
1183+ niri_ipc::Action::FocusWindow { id } => Self::FocusWindow(id),
1160 niri_ipc::Action::FocusColumnLeft => Self::FocusColumnLeft,1184 niri_ipc::Action::FocusColumnLeft => Self::FocusColumnLeft,
1161 niri_ipc::Action::FocusColumnRight => Self::FocusColumnRight,1185 niri_ipc::Action::FocusColumnRight => Self::FocusColumnRight,
1162 niri_ipc::Action::FocusColumnFirst => Self::FocusColumnFirst,1186 niri_ipc::Action::FocusColumnFirst => Self::FocusColumnFirst,
@@ -1202,9 +1226,17 @@ impl From<niri_ipc::Action> for Action {
1202 niri_ipc::Action::FocusWorkspacePrevious => Self::FocusWorkspacePrevious,1226 niri_ipc::Action::FocusWorkspacePrevious => Self::FocusWorkspacePrevious,
1203 niri_ipc::Action::MoveWindowToWorkspaceDown => Self::MoveWindowToWorkspaceDown,1227 niri_ipc::Action::MoveWindowToWorkspaceDown => Self::MoveWindowToWorkspaceDown,
1204 niri_ipc::Action::MoveWindowToWorkspaceUp => Self::MoveWindowToWorkspaceUp,1228 niri_ipc::Action::MoveWindowToWorkspaceUp => Self::MoveWindowToWorkspaceUp,
1205- niri_ipc::Action::MoveWindowToWorkspace { reference } => {1229+ niri_ipc::Action::MoveWindowToWorkspace {
1206- Self::MoveWindowToWorkspace(WorkspaceReference::from(reference))1230+ window_id: None,
1207- }1231+ reference,
1232+ } => Self::MoveWindowToWorkspace(WorkspaceReference::from(reference)),
1233+ niri_ipc::Action::MoveWindowToWorkspace {
1234+ window_id: Some(window_id),
1235+ reference,
1236+ } => Self::MoveWindowToWorkspaceById {
1237+ window_id,
1238+ reference: WorkspaceReference::from(reference),
1239+ },
1208 niri_ipc::Action::MoveColumnToWorkspaceDown => Self::MoveColumnToWorkspaceDown,1240 niri_ipc::Action::MoveColumnToWorkspaceDown => Self::MoveColumnToWorkspaceDown,
1209 niri_ipc::Action::MoveColumnToWorkspaceUp => Self::MoveColumnToWorkspaceUp,1241 niri_ipc::Action::MoveColumnToWorkspaceUp => Self::MoveColumnToWorkspaceUp,
1210 niri_ipc::Action::MoveColumnToWorkspace { reference } => {1242 niri_ipc::Action::MoveColumnToWorkspace { reference } => {
@@ -1224,8 +1256,13 @@ impl From<niri_ipc::Action> for Action {
1224 niri_ipc::Action::MoveColumnToMonitorRight => Self::MoveColumnToMonitorRight,1256 niri_ipc::Action::MoveColumnToMonitorRight => Self::MoveColumnToMonitorRight,
1225 niri_ipc::Action::MoveColumnToMonitorDown => Self::MoveColumnToMonitorDown,1257 niri_ipc::Action::MoveColumnToMonitorDown => Self::MoveColumnToMonitorDown,
1226 niri_ipc::Action::MoveColumnToMonitorUp => Self::MoveColumnToMonitorUp,1258 niri_ipc::Action::MoveColumnToMonitorUp => Self::MoveColumnToMonitorUp,
1227- niri_ipc::Action::SetWindowHeight { change } => Self::SetWindowHeight(change),1259+ niri_ipc::Action::SetWindowHeight { id: None, change } => Self::SetWindowHeight(change),
1228- niri_ipc::Action::ResetWindowHeight => Self::ResetWindowHeight,1260+ niri_ipc::Action::SetWindowHeight {
1261+ id: Some(id),
1262+ change,
1263+ } => Self::SetWindowHeightById { id, change },
1264+ niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight,
1265+ niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id),
1229 niri_ipc::Action::SwitchPresetColumnWidth => Self::SwitchPresetColumnWidth,1266 niri_ipc::Action::SwitchPresetColumnWidth => Self::SwitchPresetColumnWidth,
1230 niri_ipc::Action::MaximizeColumn => Self::MaximizeColumn,1267 niri_ipc::Action::MaximizeColumn => Self::MaximizeColumn,
1231 niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change),1268 niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change),
niri-ipc/src/lib.rsmodified+70 -10
@@ -138,12 +138,42 @@ pub enum Action {
138 Screenshot,138 Screenshot,
139 /// Screenshot the focused screen.139 /// Screenshot the focused screen.
140 ScreenshotScreen,140 ScreenshotScreen,
141- /// Screenshot the focused window.141+ /// Screenshot a window.
142- ScreenshotWindow,142+ #[cfg_attr(feature = "clap", clap(about = "Screenshot the focused window"))]
143- /// Close the focused window.143+ ScreenshotWindow {
144- CloseWindow,144+ /// Id of the window to screenshot.
145- /// Toggle fullscreen on the focused window.145+ ///
146- FullscreenWindow,146+ /// If `None`, uses the focused window.
147+ #[cfg_attr(feature = "clap", arg(long))]
148+ id: Option<u64>,
149+ },
150+ /// Close a window.
151+ #[cfg_attr(feature = "clap", clap(about = "Close the focused window"))]
152+ CloseWindow {
153+ /// Id of the window to close.
154+ ///
155+ /// If `None`, uses the focused window.
156+ #[cfg_attr(feature = "clap", arg(long))]
157+ id: Option<u64>,
158+ },
159+ /// Toggle fullscreen on a window.
160+ #[cfg_attr(
161+ feature = "clap",
162+ clap(about = "Toggle fullscreen on the focused window")
163+ )]
164+ FullscreenWindow {
165+ /// Id of the window to toggle fullscreen of.
166+ ///
167+ /// If `None`, uses the focused window.
168+ #[cfg_attr(feature = "clap", arg(long))]
169+ id: Option<u64>,
170+ },
171+ /// Focus a window by id.
172+ FocusWindow {
173+ /// Id of the window to focus.
174+ #[cfg_attr(feature = "clap", arg(long))]
175+ id: u64,
176+ },
147 /// Focus the column to the left.177 /// Focus the column to the left.
148 FocusColumnLeft,178 FocusColumnLeft,
149 /// Focus the column to the right.179 /// Focus the column to the right.
@@ -226,8 +256,18 @@ pub enum Action {
226 MoveWindowToWorkspaceDown,256 MoveWindowToWorkspaceDown,
227 /// Move the focused window to the workspace above.257 /// Move the focused window to the workspace above.
228 MoveWindowToWorkspaceUp,258 MoveWindowToWorkspaceUp,
229- /// Move the focused window to a workspace by reference (index or name).259+ /// Move a window to a workspace.
260+ #[cfg_attr(
261+ feature = "clap",
262+ clap(about = "Move the focused window to a workspace by reference (index or name)")
263+ )]
230 MoveWindowToWorkspace {264 MoveWindowToWorkspace {
265+ /// Id of the window to move.
266+ ///
267+ /// If `None`, uses the focused window.
268+ #[cfg_attr(feature = "clap", arg(long))]
269+ window_id: Option<u64>,
270+
231 /// Reference (index or name) of the workspace to move the window to.271 /// Reference (index or name) of the workspace to move the window to.
232 #[cfg_attr(feature = "clap", arg())]272 #[cfg_attr(feature = "clap", arg())]
233 reference: WorkspaceReferenceArg,273 reference: WorkspaceReferenceArg,
@@ -270,14 +310,34 @@ pub enum Action {
270 MoveColumnToMonitorDown,310 MoveColumnToMonitorDown,
271 /// Move the focused column to the monitor above.311 /// Move the focused column to the monitor above.
272 MoveColumnToMonitorUp,312 MoveColumnToMonitorUp,
273- /// Change the height of the focused window.313+ /// Change the height of a window.
314+ #[cfg_attr(
315+ feature = "clap",
316+ clap(about = "Change the height of the focused window")
317+ )]
274 SetWindowHeight {318 SetWindowHeight {
319+ /// Id of the window whose height to set.
320+ ///
321+ /// If `None`, uses the focused window.
322+ #[cfg_attr(feature = "clap", arg(long))]
323+ id: Option<u64>,
324+
275 /// How to change the height.325 /// How to change the height.
276 #[cfg_attr(feature = "clap", arg())]326 #[cfg_attr(feature = "clap", arg())]
277 change: SizeChange,327 change: SizeChange,
278 },328 },
279- /// Reset the height of the focused window back to automatic.329+ /// Reset the height of a window back to automatic.
280- ResetWindowHeight,330+ #[cfg_attr(
331+ feature = "clap",
332+ clap(about = "Reset the height of the focused window back to automatic")
333+ )]
334+ ResetWindowHeight {
335+ /// Id of the window whose height to reset.
336+ ///
337+ /// If `None`, uses the focused window.
338+ #[cfg_attr(feature = "clap", arg(long))]
339+ id: Option<u64>,
340+ },
281 /// Switch between preset column widths.341 /// Switch between preset column widths.
282 SwitchPresetColumnWidth,342 SwitchPresetColumnWidth,
283 /// Toggle the maximized state of the focused column.343 /// Toggle the maximized state of the focused column.
src/handlers/xdg_shell.rsmodified+1 -3
@@ -119,10 +119,8 @@ impl XdgShellHandler for State {
119 self.niri.layout.toggle_full_width();119 self.niri.layout.toggle_full_width();
120 }120 }
121 if intersection.intersects(ResizeEdge::TOP_BOTTOM) {121 if intersection.intersects(ResizeEdge::TOP_BOTTOM) {
122- // FIXME: don't activate once we can pass specific windows to actions.
123- self.niri.layout.activate_window(&window);
124 self.niri.layer_shell_on_demand_focus = None;122 self.niri.layer_shell_on_demand_focus = None;
125- self.niri.layout.reset_window_height();123+ self.niri.layout.reset_window_height(Some(&window));
126 }124 }
127 // FIXME: granular.125 // FIXME: granular.
128 self.niri.queue_redraw_all();126 self.niri.queue_redraw_all();
src/input/mod.rsmodified+144 -14
@@ -525,11 +525,29 @@ impl State {
525 });525 });
526 }526 }
527 }527 }
528+ Action::ScreenshotWindowById(id) => {
529+ let mut windows = self.niri.layout.windows();
530+ let window = windows.find(|(_, m)| m.id().get() == id);
531+ if let Some((Some(monitor), mapped)) = window {
532+ let output = &monitor.output;
533+ self.backend.with_primary_renderer(|renderer| {
534+ if let Err(err) = self.niri.screenshot_window(renderer, output, mapped) {
535+ warn!("error taking screenshot: {err:?}");
536+ }
537+ });
538+ }
539+ }
528 Action::CloseWindow => {540 Action::CloseWindow => {
529 if let Some(mapped) = self.niri.layout.focus() {541 if let Some(mapped) = self.niri.layout.focus() {
530 mapped.toplevel().send_close();542 mapped.toplevel().send_close();
531 }543 }
532 }544 }
545+ Action::CloseWindowById(id) => {
546+ let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);
547+ if let Some((_, mapped)) = window {
548+ mapped.toplevel().send_close();
549+ }
550+ }
533 Action::FullscreenWindow => {551 Action::FullscreenWindow => {
534 let focus = self.niri.layout.focus().map(|m| m.window.clone());552 let focus = self.niri.layout.focus().map(|m| m.window.clone());
535 if let Some(window) = focus {553 if let Some(window) = focus {
@@ -538,6 +556,37 @@ impl State {
538 self.niri.queue_redraw_all();556 self.niri.queue_redraw_all();
539 }557 }
540 }558 }
559+ Action::FullscreenWindowById(id) => {
560+ let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);
561+ let window = window.map(|(_, m)| m.window.clone());
562+ if let Some(window) = window {
563+ self.niri.layout.toggle_fullscreen(&window);
564+ // FIXME: granular
565+ self.niri.queue_redraw_all();
566+ }
567+ }
568+ Action::FocusWindow(id) => {
569+ let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);
570+ let window = window.map(|(_, m)| m.window.clone());
571+ if let Some(window) = window {
572+ let active_output = self.niri.layout.active_output().cloned();
573+
574+ self.niri.layout.activate_window(&window);
575+
576+ let new_active = self.niri.layout.active_output().cloned();
577+ #[allow(clippy::collapsible_if)]
578+ if new_active != active_output {
579+ if !self.maybe_warp_cursor_to_focus_centered() {
580+ self.move_cursor_to_output(&new_active.unwrap());
581+ }
582+ } else {
583+ self.maybe_warp_cursor_to_focus();
584+ }
585+
586+ // FIXME: granular
587+ self.niri.queue_redraw_all();
588+ }
589+ }
541 Action::SwitchLayout(action) => {590 Action::SwitchLayout(action) => {
542 let keyboard = &self.niri.seat.get_keyboard().unwrap();591 let keyboard = &self.niri.seat.get_keyboard().unwrap();
543 keyboard.with_xkb_state(self, |mut state| match action {592 keyboard.with_xkb_state(self, |mut state| match action {
@@ -804,15 +853,25 @@ impl State {
804 self.niri.queue_redraw_all();853 self.niri.queue_redraw_all();
805 }854 }
806 Action::MoveWindowToWorkspace(reference) => {855 Action::MoveWindowToWorkspace(reference) => {
807- if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)856+ if let Some((mut output, index)) =
857+ self.niri.find_output_and_workspace_index(reference)
808 {858 {
859+ // The source output is always the active output, so if the target output is
860+ // also the active output, we don't need to use move_to_output().
861+ if let Some(active) = self.niri.layout.active_output() {
862+ if output.as_ref() == Some(active) {
863+ output = None;
864+ }
865+ }
866+
809 if let Some(output) = output {867 if let Some(output) = output {
810- self.niri.layout.move_to_workspace_on_output(&output, index);868+ self.niri.layout.move_to_output(None, &output, Some(index));
869+
811 if !self.maybe_warp_cursor_to_focus_centered() {870 if !self.maybe_warp_cursor_to_focus_centered() {
812 self.move_cursor_to_output(&output);871 self.move_cursor_to_output(&output);
813 }872 }
814 } else {873 } else {
815- self.niri.layout.move_to_workspace(index);874+ self.niri.layout.move_to_workspace(None, index);
816 self.maybe_warp_cursor_to_focus();875 self.maybe_warp_cursor_to_focus();
817 }876 }
818 877
@@ -820,6 +879,51 @@ impl State {
820 self.niri.queue_redraw_all();879 self.niri.queue_redraw_all();
821 }880 }
822 }881 }
882+ Action::MoveWindowToWorkspaceById {
883+ window_id: id,
884+ reference,
885+ } => {
886+ let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);
887+ let window = window.map(|(_, m)| m.window.clone());
888+ if let Some(window) = window {
889+ if let Some((output, index)) =
890+ self.niri.find_output_and_workspace_index(reference)
891+ {
892+ let target_was_active = self
893+ .niri
894+ .layout
895+ .active_output()
896+ .map_or(false, |active| output.as_ref() == Some(active));
897+
898+ if let Some(output) = output {
899+ self.niri
900+ .layout
901+ .move_to_output(Some(&window), &output, Some(index));
902+
903+ // If the active output changed (window was moved and focused).
904+ #[allow(clippy::collapsible_if)]
905+ if !target_was_active
906+ && self.niri.layout.active_output() == Some(&output)
907+ {
908+ if !self.maybe_warp_cursor_to_focus_centered() {
909+ self.move_cursor_to_output(&output);
910+ }
911+ }
912+ } else {
913+ self.niri.layout.move_to_workspace(Some(&window), index);
914+
915+ // If we focused the target window.
916+ let new_active_win = self.niri.layout.active_window();
917+ if new_active_win.map_or(false, |(win, _)| win.window == window) {
918+ self.maybe_warp_cursor_to_focus();
919+ }
920+ }
921+
922+ // FIXME: granular
923+ self.niri.queue_redraw_all();
924+ }
925+ }
926+ }
823 Action::MoveColumnToWorkspaceDown => {927 Action::MoveColumnToWorkspaceDown => {
824 self.niri.layout.move_column_to_workspace_down();928 self.niri.layout.move_column_to_workspace_down();
825 self.maybe_warp_cursor_to_focus();929 self.maybe_warp_cursor_to_focus();
@@ -833,8 +937,15 @@ impl State {
833 self.niri.queue_redraw_all();937 self.niri.queue_redraw_all();
834 }938 }
835 Action::MoveColumnToWorkspace(reference) => {939 Action::MoveColumnToWorkspace(reference) => {
836- if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)940+ if let Some((mut output, index)) =
941+ self.niri.find_output_and_workspace_index(reference)
837 {942 {
943+ if let Some(active) = self.niri.layout.active_output() {
944+ if output.as_ref() == Some(active) {
945+ output = None;
946+ }
947+ }
948+
838 if let Some(output) = output {949 if let Some(output) = output {
839 self.niri950 self.niri
840 .layout951 .layout
@@ -864,8 +975,15 @@ impl State {
864 self.niri.queue_redraw_all();975 self.niri.queue_redraw_all();
865 }976 }
866 Action::FocusWorkspace(reference) => {977 Action::FocusWorkspace(reference) => {
867- if let Some((output, index)) = self.niri.find_output_and_workspace_index(reference)978+ if let Some((mut output, index)) =
979+ self.niri.find_output_and_workspace_index(reference)
868 {980 {
981+ if let Some(active) = self.niri.layout.active_output() {
982+ if output.as_ref() == Some(active) {
983+ output = None;
984+ }
985+ }
986+
869 if let Some(output) = output {987 if let Some(output) = output {
870 self.niri.layout.focus_output(&output);988 self.niri.layout.focus_output(&output);
871 self.niri.layout.switch_workspace(index);989 self.niri.layout.switch_workspace(index);
@@ -959,7 +1077,7 @@ impl State {
959 }1077 }
960 Action::MoveWindowToMonitorLeft => {1078 Action::MoveWindowToMonitorLeft => {
961 if let Some(output) = self.niri.output_left() {1079 if let Some(output) = self.niri.output_left() {
962- self.niri.layout.move_to_output(&output);1080+ self.niri.layout.move_to_output(None, &output, None);
963 self.niri.layout.focus_output(&output);1081 self.niri.layout.focus_output(&output);
964 if !self.maybe_warp_cursor_to_focus_centered() {1082 if !self.maybe_warp_cursor_to_focus_centered() {
965 self.move_cursor_to_output(&output);1083 self.move_cursor_to_output(&output);
@@ -968,7 +1086,7 @@ impl State {
968 }1086 }
969 Action::MoveWindowToMonitorRight => {1087 Action::MoveWindowToMonitorRight => {
970 if let Some(output) = self.niri.output_right() {1088 if let Some(output) = self.niri.output_right() {
971- self.niri.layout.move_to_output(&output);1089+ self.niri.layout.move_to_output(None, &output, None);
972 self.niri.layout.focus_output(&output);1090 self.niri.layout.focus_output(&output);
973 if !self.maybe_warp_cursor_to_focus_centered() {1091 if !self.maybe_warp_cursor_to_focus_centered() {
974 self.move_cursor_to_output(&output);1092 self.move_cursor_to_output(&output);
@@ -977,7 +1095,7 @@ impl State {
977 }1095 }
978 Action::MoveWindowToMonitorDown => {1096 Action::MoveWindowToMonitorDown => {
979 if let Some(output) = self.niri.output_down() {1097 if let Some(output) = self.niri.output_down() {
980- self.niri.layout.move_to_output(&output);1098+ self.niri.layout.move_to_output(None, &output, None);
981 self.niri.layout.focus_output(&output);1099 self.niri.layout.focus_output(&output);
982 if !self.maybe_warp_cursor_to_focus_centered() {1100 if !self.maybe_warp_cursor_to_focus_centered() {
983 self.move_cursor_to_output(&output);1101 self.move_cursor_to_output(&output);
@@ -986,7 +1104,7 @@ impl State {
986 }1104 }
987 Action::MoveWindowToMonitorUp => {1105 Action::MoveWindowToMonitorUp => {
988 if let Some(output) = self.niri.output_up() {1106 if let Some(output) = self.niri.output_up() {
989- self.niri.layout.move_to_output(&output);1107+ self.niri.layout.move_to_output(None, &output, None);
990 self.niri.layout.focus_output(&output);1108 self.niri.layout.focus_output(&output);
991 if !self.maybe_warp_cursor_to_focus_centered() {1109 if !self.maybe_warp_cursor_to_focus_centered() {
992 self.move_cursor_to_output(&output);1110 self.move_cursor_to_output(&output);
@@ -1033,10 +1151,24 @@ impl State {
1033 self.niri.layout.set_column_width(change);1151 self.niri.layout.set_column_width(change);
1034 }1152 }
1035 Action::SetWindowHeight(change) => {1153 Action::SetWindowHeight(change) => {
1036- self.niri.layout.set_window_height(change);1154+ self.niri.layout.set_window_height(None, change);
1155+ }
1156+ Action::SetWindowHeightById { id, change } => {
1157+ let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);
1158+ let window = window.map(|(_, m)| m.window.clone());
1159+ if let Some(window) = window {
1160+ self.niri.layout.set_window_height(Some(&window), change);
1161+ }
1037 }1162 }
1038 Action::ResetWindowHeight => {1163 Action::ResetWindowHeight => {
1039- self.niri.layout.reset_window_height();1164+ self.niri.layout.reset_window_height(None);
1165+ }
1166+ Action::ResetWindowHeightById(id) => {
1167+ let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);
1168+ let window = window.map(|(_, m)| m.window.clone());
1169+ if let Some(window) = window {
1170+ self.niri.layout.reset_window_height(Some(&window));
1171+ }
1040 }1172 }
1041 Action::ShowHotkeyOverlay => {1173 Action::ShowHotkeyOverlay => {
1042 if self.niri.hotkey_overlay.show() {1174 if self.niri.hotkey_overlay.show() {
@@ -1366,10 +1498,8 @@ impl State {
1366 self.niri.layout.toggle_full_width();1498 self.niri.layout.toggle_full_width();
1367 }1499 }
1368 if intersection.intersects(ResizeEdge::TOP_BOTTOM) {1500 if intersection.intersects(ResizeEdge::TOP_BOTTOM) {
1369- // FIXME: don't activate once we can pass specific windows
1370- // to actions.
1371 self.niri.layout.activate_window(&window);1501 self.niri.layout.activate_window(&window);
1372- self.niri.layout.reset_window_height();1502+ self.niri.layout.reset_window_height(Some(&window));
1373 }1503 }
1374 // FIXME: granular.1504 // FIXME: granular.
1375 self.niri.queue_redraw_all();1505 self.niri.queue_redraw_all();
src/layout/mod.rsmodified+260 -52
@@ -1092,6 +1092,20 @@ impl<W: LayoutElement> Layout<W> {
1092 Some(&mon.workspaces[mon.active_workspace_idx])1092 Some(&mon.workspaces[mon.active_workspace_idx])
1093 }1093 }
1094 1094
1095+ pub fn active_workspace_mut(&mut self) -> Option<&mut Workspace<W>> {
1096+ let MonitorSet::Normal {
1097+ monitors,
1098+ active_monitor_idx,
1099+ ..
1100+ } = &mut self.monitor_set
1101+ else {
1102+ return None;
1103+ };
1104+
1105+ let mon = &mut monitors[*active_monitor_idx];
1106+ Some(&mut mon.workspaces[mon.active_workspace_idx])
1107+ }
1108+
1095 pub fn active_window(&self) -> Option<(&W, &Output)> {1109 pub fn active_window(&self) -> Option<(&W, &Output)> {
1096 let MonitorSet::Normal {1110 let MonitorSet::Normal {
1097 monitors,1111 monitors,
@@ -1502,17 +1516,11 @@ impl<W: LayoutElement> Layout<W> {
1502 monitor.move_to_workspace_down();1516 monitor.move_to_workspace_down();
1503 }1517 }
1504 1518
1505- pub fn move_to_workspace(&mut self, idx: usize) {1519+ pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) {
1506 let Some(monitor) = self.active_monitor() else {1520 let Some(monitor) = self.active_monitor() else {
1507 return;1521 return;
1508 };1522 };
1509- monitor.move_to_workspace(idx);1523+ monitor.move_to_workspace(window, idx);
1510- }
1511-
1512- pub fn move_to_workspace_on_output(&mut self, output: &Output, idx: usize) {
1513- self.move_to_output(output);
1514- self.focus_output(output);
1515- self.move_to_workspace(idx);
1516 }1524 }
1517 1525
1518 pub fn move_column_to_workspace_up(&mut self) {1526 pub fn move_column_to_workspace_up(&mut self) {
@@ -1537,7 +1545,7 @@ impl<W: LayoutElement> Layout<W> {
1537 }1545 }
1538 1546
1539 pub fn move_column_to_workspace_on_output(&mut self, output: &Output, idx: usize) {1547 pub fn move_column_to_workspace_on_output(&mut self, output: &Output, idx: usize) {
1540- self.move_to_output(output);1548+ self.move_column_to_output(output);
1541 self.focus_output(output);1549 self.focus_output(output);
1542 self.move_column_to_workspace(idx);1550 self.move_column_to_workspace(idx);
1543 }1551 }
@@ -1943,18 +1951,38 @@ impl<W: LayoutElement> Layout<W> {
1943 monitor.set_column_width(change);1951 monitor.set_column_width(change);
1944 }1952 }
1945 1953
1946- pub fn set_window_height(&mut self, change: SizeChange) {1954+ pub fn set_window_height(&mut self, window: Option<&W::Id>, change: SizeChange) {
1947- let Some(monitor) = self.active_monitor() else {1955+ let workspace = if let Some(window) = window {
1956+ Some(
1957+ self.workspaces_mut()
1958+ .find(|ws| ws.has_window(window))
1959+ .unwrap(),
1960+ )
1961+ } else {
1962+ self.active_workspace_mut()
1963+ };
1964+
1965+ let Some(workspace) = workspace else {
1948 return;1966 return;
1949 };1967 };
1950- monitor.set_window_height(change);1968+ workspace.set_window_height(window, change);
1951 }1969 }
1952 1970
1953- pub fn reset_window_height(&mut self) {1971+ pub fn reset_window_height(&mut self, window: Option<&W::Id>) {
1954- let Some(monitor) = self.active_monitor() else {1972+ let workspace = if let Some(window) = window {
1973+ Some(
1974+ self.workspaces_mut()
1975+ .find(|ws| ws.has_window(window))
1976+ .unwrap(),
1977+ )
1978+ } else {
1979+ self.active_workspace_mut()
1980+ };
1981+
1982+ let Some(workspace) = workspace else {
1955 return;1983 return;
1956 };1984 };
1957- monitor.reset_window_height();1985+ workspace.reset_window_height(window);
1958 }1986 }
1959 1987
1960 pub fn focus_output(&mut self, output: &Output) {1988 pub fn focus_output(&mut self, output: &Output) {
@@ -1973,7 +2001,12 @@ impl<W: LayoutElement> Layout<W> {
1973 }2001 }
1974 }2002 }
1975 2003
1976- pub fn move_to_output(&mut self, output: &Output) {2004+ pub fn move_to_output(
2005+ &mut self,
2006+ window: Option<&W::Id>,
2007+ output: &Output,
2008+ target_ws_idx: Option<usize>,
2009+ ) {
1977 if let MonitorSet::Normal {2010 if let MonitorSet::Normal {
1978 monitors,2011 monitors,
1979 active_monitor_idx,2012 active_monitor_idx,
@@ -1985,25 +2018,71 @@ impl<W: LayoutElement> Layout<W> {
1985 .position(|mon| &mon.output == output)2018 .position(|mon| &mon.output == output)
1986 .unwrap();2019 .unwrap();
1987 2020
1988- let current = &mut monitors[*active_monitor_idx];2021+ let (mon_idx, ws_idx, col_idx, tile_idx) = if let Some(window) = window {
1989- let ws = current.active_workspace();2022+ monitors
1990- if !ws.has_windows() {2023+ .iter()
2024+ .enumerate()
2025+ .find_map(|(mon_idx, mon)| {
2026+ mon.workspaces.iter().enumerate().find_map(|(ws_idx, ws)| {
2027+ ws.columns.iter().enumerate().find_map(|(col_idx, col)| {
2028+ col.tiles
2029+ .iter()
2030+ .position(|tile| tile.window().id() == window)
2031+ .map(|tile_idx| (mon_idx, ws_idx, col_idx, tile_idx))
2032+ })
2033+ })
2034+ })
2035+ .unwrap()
2036+ } else {
2037+ let mon_idx = *active_monitor_idx;
2038+ let mon = &monitors[mon_idx];
2039+ let ws_idx = mon.active_workspace_idx;
2040+ let ws = &mon.workspaces[ws_idx];
2041+
2042+ if ws.columns.is_empty() {
2043+ return;
2044+ }
2045+
2046+ let col_idx = ws.active_column_idx;
2047+ let tile_idx = ws.columns[col_idx].active_tile_idx;
2048+ (mon_idx, ws_idx, col_idx, tile_idx)
2049+ };
2050+
2051+ let workspace_idx = target_ws_idx.unwrap_or(monitors[new_idx].active_workspace_idx);
2052+ if mon_idx == new_idx && ws_idx == workspace_idx {
1991 return;2053 return;
1992 }2054 }
1993- let column = &ws.columns[ws.active_column_idx];2055+
2056+ let mon = &mut monitors[mon_idx];
2057+ let ws = &mut mon.workspaces[ws_idx];
2058+ let column = &ws.columns[col_idx];
1994 let width = column.width;2059 let width = column.width;
1995 let is_full_width = column.is_full_width;2060 let is_full_width = column.is_full_width;
2061+ let activate = mon_idx == *active_monitor_idx
2062+ && ws_idx == mon.active_workspace_idx
2063+ && col_idx == ws.active_column_idx
2064+ && tile_idx == column.active_tile_idx;
2065+
1996 let window = ws2066 let window = ws
1997- .remove_tile_by_idx(2067+ .remove_tile_by_idx(col_idx, tile_idx, Transaction::new(), None)
1998- ws.active_column_idx,
1999- column.active_tile_idx,
2000- Transaction::new(),
2001- None,
2002- )
2003 .into_window();2068 .into_window();
2004 2069
2005- let workspace_idx = monitors[new_idx].active_workspace_idx;2070+ self.add_window_by_idx(
2006- self.add_window_by_idx(new_idx, workspace_idx, window, true, width, is_full_width);2071+ new_idx,
2072+ workspace_idx,
2073+ window,
2074+ activate,
2075+ width,
2076+ is_full_width,
2077+ );
2078+
2079+ let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else {
2080+ unreachable!()
2081+ };
2082+ let mon = &mut monitors[mon_idx];
2083+ if mon.workspace_switch.is_none() {
2084+ monitors[mon_idx].clean_up_workspaces();
2085+ }
2007 }2086 }
2008 }2087 }
2009 2088
@@ -2543,6 +2622,41 @@ impl<W: LayoutElement> Layout<W> {
2543 let iter_no_outputs = iter_no_outputs.into_iter().flatten();2622 let iter_no_outputs = iter_no_outputs.into_iter().flatten();
2544 iter_normal.chain(iter_no_outputs)2623 iter_normal.chain(iter_no_outputs)
2545 }2624 }
2625+
2626+ pub fn workspaces_mut(&mut self) -> impl Iterator<Item = &mut Workspace<W>> + '_ {
2627+ let iter_normal;
2628+ let iter_no_outputs;
2629+
2630+ match &mut self.monitor_set {
2631+ MonitorSet::Normal { monitors, .. } => {
2632+ let it = monitors
2633+ .iter_mut()
2634+ .flat_map(|mon| mon.workspaces.iter_mut());
2635+
2636+ iter_normal = Some(it);
2637+ iter_no_outputs = None;
2638+ }
2639+ MonitorSet::NoOutputs { workspaces } => {
2640+ let it = workspaces.iter_mut();
2641+
2642+ iter_normal = None;
2643+ iter_no_outputs = Some(it);
2644+ }
2645+ }
2646+
2647+ let iter_normal = iter_normal.into_iter().flatten();
2648+ let iter_no_outputs = iter_no_outputs.into_iter().flatten();
2649+ iter_normal.chain(iter_no_outputs)
2650+ }
2651+
2652+ pub fn windows(&self) -> impl Iterator<Item = (Option<&Monitor<W>>, &W)> {
2653+ self.workspaces()
2654+ .flat_map(|(mon, _, ws)| ws.windows().map(move |win| (mon, win)))
2655+ }
2656+
2657+ pub fn has_window(&self, window: &W::Id) -> bool {
2658+ self.windows().any(|(_, win)| win.id() == window)
2659+ }
2546 }2660 }
2547 2661
2548 impl<W: LayoutElement> Default for MonitorSet<W> {2662 impl<W: LayoutElement> Default for MonitorSet<W> {
@@ -2892,19 +3006,39 @@ mod tests {
2892 FocusWorkspacePrevious,3006 FocusWorkspacePrevious,
2893 MoveWindowToWorkspaceDown,3007 MoveWindowToWorkspaceDown,
2894 MoveWindowToWorkspaceUp,3008 MoveWindowToWorkspaceUp,
2895- MoveWindowToWorkspace(#[proptest(strategy = "0..=4usize")] usize),3009+ MoveWindowToWorkspace {
3010+ #[proptest(strategy = "proptest::option::of(1..=5usize)")]
3011+ window_id: Option<usize>,
3012+ #[proptest(strategy = "0..=4usize")]
3013+ workspace_idx: usize,
3014+ },
2896 MoveColumnToWorkspaceDown,3015 MoveColumnToWorkspaceDown,
2897 MoveColumnToWorkspaceUp,3016 MoveColumnToWorkspaceUp,
2898 MoveColumnToWorkspace(#[proptest(strategy = "0..=4usize")] usize),3017 MoveColumnToWorkspace(#[proptest(strategy = "0..=4usize")] usize),
2899 MoveWorkspaceDown,3018 MoveWorkspaceDown,
2900 MoveWorkspaceUp,3019 MoveWorkspaceUp,
2901- MoveWindowToOutput(#[proptest(strategy = "1..=5u8")] u8),3020+ MoveWindowToOutput {
3021+ #[proptest(strategy = "proptest::option::of(1..=5usize)")]
3022+ window_id: Option<usize>,
3023+ #[proptest(strategy = "1..=5u8")]
3024+ output_id: u8,
3025+ #[proptest(strategy = "proptest::option::of(0..=4usize)")]
3026+ target_ws_idx: Option<usize>,
3027+ },
2902 MoveColumnToOutput(#[proptest(strategy = "1..=5u8")] u8),3028 MoveColumnToOutput(#[proptest(strategy = "1..=5u8")] u8),
2903 SwitchPresetColumnWidth,3029 SwitchPresetColumnWidth,
2904 MaximizeColumn,3030 MaximizeColumn,
2905 SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),3031 SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),
2906- SetWindowHeight(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),3032+ SetWindowHeight {
2907- ResetWindowHeight,3033+ #[proptest(strategy = "proptest::option::of(1..=5usize)")]
3034+ id: Option<usize>,
3035+ #[proptest(strategy = "arbitrary_size_change()")]
3036+ change: SizeChange,
3037+ },
3038+ ResetWindowHeight {
3039+ #[proptest(strategy = "proptest::option::of(1..=5usize)")]
3040+ id: Option<usize>,
3041+ },
2908 Communicate(#[proptest(strategy = "1..=5usize")] usize),3042 Communicate(#[proptest(strategy = "1..=5usize")] usize),
2909 MoveWorkspaceToOutput(#[proptest(strategy = "1..=5u8")] u8),3043 MoveWorkspaceToOutput(#[proptest(strategy = "1..=5u8")] u8),
2910 ViewOffsetGestureBegin {3044 ViewOffsetGestureBegin {
@@ -3279,17 +3413,34 @@ mod tests {
3279 Op::FocusWorkspacePrevious => layout.switch_workspace_previous(),3413 Op::FocusWorkspacePrevious => layout.switch_workspace_previous(),
3280 Op::MoveWindowToWorkspaceDown => layout.move_to_workspace_down(),3414 Op::MoveWindowToWorkspaceDown => layout.move_to_workspace_down(),
3281 Op::MoveWindowToWorkspaceUp => layout.move_to_workspace_up(),3415 Op::MoveWindowToWorkspaceUp => layout.move_to_workspace_up(),
3282- Op::MoveWindowToWorkspace(idx) => layout.move_to_workspace(idx),3416+ Op::MoveWindowToWorkspace {
3417+ window_id,
3418+ workspace_idx,
3419+ } => {
3420+ let window_id = window_id.filter(|id| {
3421+ layout
3422+ .active_monitor()
3423+ .map_or(false, |mon| mon.has_window(id))
3424+ });
3425+ layout.move_to_workspace(window_id.as_ref(), workspace_idx);
3426+ }
3283 Op::MoveColumnToWorkspaceDown => layout.move_column_to_workspace_down(),3427 Op::MoveColumnToWorkspaceDown => layout.move_column_to_workspace_down(),
3284 Op::MoveColumnToWorkspaceUp => layout.move_column_to_workspace_up(),3428 Op::MoveColumnToWorkspaceUp => layout.move_column_to_workspace_up(),
3285 Op::MoveColumnToWorkspace(idx) => layout.move_column_to_workspace(idx),3429 Op::MoveColumnToWorkspace(idx) => layout.move_column_to_workspace(idx),
3286- Op::MoveWindowToOutput(id) => {3430+ Op::MoveWindowToOutput {
3431+ window_id,
3432+ output_id: id,
3433+ target_ws_idx,
3434+ } => {
3287 let name = format!("output{id}");3435 let name = format!("output{id}");
3288 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {3436 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
3289 return;3437 return;
3290 };3438 };
3439+ let mon = layout.monitor_for_output(&output).unwrap();
3291 3440
3292- layout.move_to_output(&output);3441+ let window_id = window_id.filter(|id| layout.has_window(id));
3442+ let target_ws_idx = target_ws_idx.filter(|idx| mon.workspaces.len() > *idx);
3443+ layout.move_to_output(window_id.as_ref(), &output, target_ws_idx);
3293 }3444 }
3294 Op::MoveColumnToOutput(id) => {3445 Op::MoveColumnToOutput(id) => {
3295 let name = format!("output{id}");3446 let name = format!("output{id}");
@@ -3304,8 +3455,14 @@ mod tests {
3304 Op::SwitchPresetColumnWidth => layout.toggle_width(),3455 Op::SwitchPresetColumnWidth => layout.toggle_width(),
3305 Op::MaximizeColumn => layout.toggle_full_width(),3456 Op::MaximizeColumn => layout.toggle_full_width(),
3306 Op::SetColumnWidth(change) => layout.set_column_width(change),3457 Op::SetColumnWidth(change) => layout.set_column_width(change),
3307- Op::SetWindowHeight(change) => layout.set_window_height(change),3458+ Op::SetWindowHeight { id, change } => {
3308- Op::ResetWindowHeight => layout.reset_window_height(),3459+ let id = id.filter(|id| layout.has_window(id));
3460+ layout.set_window_height(id.as_ref(), change);
3461+ }
3462+ Op::ResetWindowHeight { id } => {
3463+ let id = id.filter(|id| layout.has_window(id));
3464+ layout.reset_window_height(id.as_ref());
3465+ }
3309 Op::Communicate(id) => {3466 Op::Communicate(id) => {
3310 let mut update = false;3467 let mut update = false;
3311 match &mut layout.monitor_set {3468 match &mut layout.monitor_set {
@@ -3502,8 +3659,14 @@ mod tests {
3502 Op::FocusWorkspace(2),3659 Op::FocusWorkspace(2),
3503 Op::MoveWindowToWorkspaceDown,3660 Op::MoveWindowToWorkspaceDown,
3504 Op::MoveWindowToWorkspaceUp,3661 Op::MoveWindowToWorkspaceUp,
3505- Op::MoveWindowToWorkspace(1),3662+ Op::MoveWindowToWorkspace {
3506- Op::MoveWindowToWorkspace(2),3663+ window_id: None,
3664+ workspace_idx: 1,
3665+ },
3666+ Op::MoveWindowToWorkspace {
3667+ window_id: None,
3668+ workspace_idx: 2,
3669+ },
3507 Op::MoveColumnToWorkspaceDown,3670 Op::MoveColumnToWorkspaceDown,
3508 Op::MoveColumnToWorkspaceUp,3671 Op::MoveColumnToWorkspaceUp,
3509 Op::MoveColumnToWorkspace(1),3672 Op::MoveColumnToWorkspace(1),
@@ -3575,7 +3738,11 @@ mod tests {
3575 bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),3738 bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
3576 min_max_size: Default::default(),3739 min_max_size: Default::default(),
3577 },3740 },
3578- Op::MoveWindowToOutput(2),3741+ Op::MoveWindowToOutput {
3742+ window_id: None,
3743+ output_id: 2,
3744+ target_ws_idx: None,
3745+ },
3579 Op::FocusOutput(1),3746 Op::FocusOutput(1),
3580 Op::Communicate(1),3747 Op::Communicate(1),
3581 Op::Communicate(2),3748 Op::Communicate(2),
@@ -3684,9 +3851,18 @@ mod tests {
3684 Op::FocusWorkspace(3),3851 Op::FocusWorkspace(3),
3685 Op::MoveWindowToWorkspaceDown,3852 Op::MoveWindowToWorkspaceDown,
3686 Op::MoveWindowToWorkspaceUp,3853 Op::MoveWindowToWorkspaceUp,
3687- Op::MoveWindowToWorkspace(1),3854+ Op::MoveWindowToWorkspace {
3688- Op::MoveWindowToWorkspace(2),3855+ window_id: None,
3689- Op::MoveWindowToWorkspace(3),3856+ workspace_idx: 1,
3857+ },
3858+ Op::MoveWindowToWorkspace {
3859+ window_id: None,
3860+ workspace_idx: 2,
3861+ },
3862+ Op::MoveWindowToWorkspace {
3863+ window_id: None,
3864+ workspace_idx: 3,
3865+ },
3690 Op::MoveColumnToWorkspaceDown,3866 Op::MoveColumnToWorkspaceDown,
3691 Op::MoveColumnToWorkspaceUp,3867 Op::MoveColumnToWorkspaceUp,
3692 Op::MoveColumnToWorkspace(1),3868 Op::MoveColumnToWorkspace(1),
@@ -3798,7 +3974,18 @@ mod tests {
3798 bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),3974 bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
3799 min_max_size: Default::default(),3975 min_max_size: Default::default(),
3800 },3976 },
3801- Op::MoveWindowToWorkspace(2),3977+ Op::AddOutput(2),
3978+ Op::FocusOutput(2),
3979+ Op::AddWindow {
3980+ id: 1,
3981+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
3982+ min_max_size: Default::default(),
3983+ },
3984+ Op::RemoveOutput(1),
3985+ Op::MoveWindowToWorkspace {
3986+ window_id: Some(0),
3987+ workspace_idx: 2,
3988+ },
3802 ];3989 ];
3803 3990
3804 let mut layout = Layout::default();3991 let mut layout = Layout::default();
@@ -3810,7 +3997,7 @@ mod tests {
3810 unreachable!()3997 unreachable!()
3811 };3998 };
3812 3999
3813- assert!(monitors[0].workspaces[0].has_windows());4000+ assert!(monitors[0].workspaces[1].has_windows());
3814 }4001 }
3815 4002
3816 #[test]4003 #[test]
@@ -3847,7 +4034,10 @@ mod tests {
3847 bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),4034 bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
3848 min_max_size: Default::default(),4035 min_max_size: Default::default(),
3849 },4036 },
3850- Op::SetWindowHeight(SizeChange::AdjustProportion(-1e129)),4037+ Op::SetWindowHeight {
4038+ id: None,
4039+ change: SizeChange::AdjustProportion(-1e129),
4040+ },
3851 ];4041 ];
3852 4042
3853 let mut options = Options::default();4043 let mut options = Options::default();
@@ -4311,9 +4501,15 @@ mod tests {
4311 min_max_size: Default::default(),4501 min_max_size: Default::default(),
4312 },4502 },
4313 Op::ConsumeOrExpelWindowLeft,4503 Op::ConsumeOrExpelWindowLeft,
4314- Op::SetWindowHeight(SizeChange::SetFixed(100)),4504+ Op::SetWindowHeight {
4505+ id: None,
4506+ change: SizeChange::SetFixed(100),
4507+ },
4315 Op::FocusWindowUp,4508 Op::FocusWindowUp,
4316- Op::SetWindowHeight(SizeChange::SetFixed(200)),4509+ Op::SetWindowHeight {
4510+ id: None,
4511+ change: SizeChange::SetFixed(200),
4512+ },
4317 ];4513 ];
4318 4514
4319 check_ops(&ops);4515 check_ops(&ops);
@@ -4340,10 +4536,16 @@ mod tests {
4340 min_max_size: Default::default(),4536 min_max_size: Default::default(),
4341 },4537 },
4342 Op::ConsumeOrExpelWindowLeft,4538 Op::ConsumeOrExpelWindowLeft,
4343- Op::SetWindowHeight(SizeChange::SetFixed(100)),4539+ Op::SetWindowHeight {
4540+ id: None,
4541+ change: SizeChange::SetFixed(100),
4542+ },
4344 Op::Communicate(2),4543 Op::Communicate(2),
4345 Op::FocusWindowUp,4544 Op::FocusWindowUp,
4346- Op::SetWindowHeight(SizeChange::SetFixed(200)),4545+ Op::SetWindowHeight {
4546+ id: None,
4547+ change: SizeChange::SetFixed(200),
4548+ },
4347 Op::Communicate(1),4549 Op::Communicate(1),
4348 Op::CloseWindow(0),4550 Op::CloseWindow(0),
4349 Op::CloseWindow(1),4551 Op::CloseWindow(1),
@@ -4373,10 +4575,16 @@ mod tests {
4373 min_max_size: Default::default(),4575 min_max_size: Default::default(),
4374 },4576 },
4375 Op::ConsumeOrExpelWindowLeft,4577 Op::ConsumeOrExpelWindowLeft,
4376- Op::SetWindowHeight(SizeChange::SetFixed(100)),4578+ Op::SetWindowHeight {
4579+ id: None,
4580+ change: SizeChange::SetFixed(100),
4581+ },
4377 Op::Communicate(2),4582 Op::Communicate(2),
4378 Op::FocusWindowUp,4583 Op::FocusWindowUp,
4379- Op::SetWindowHeight(SizeChange::SetFixed(200)),4584+ Op::SetWindowHeight {
4585+ id: None,
4586+ change: SizeChange::SetFixed(200),
4587+ },
4380 Op::Communicate(1),4588 Op::Communicate(1),
4381 Op::CloseWindow(0),4589 Op::CloseWindow(0),
4382 Op::FullscreenWindow(1),4590 Op::FullscreenWindow(1),
src/layout/monitor.rsmodified+44 -31
@@ -133,6 +133,14 @@ impl<W: LayoutElement> Monitor<W> {
133 &mut self.workspaces[self.active_workspace_idx]133 &mut self.workspaces[self.active_workspace_idx]
134 }134 }
135 135
136+ pub fn windows(&self) -> impl Iterator<Item = &W> {
137+ self.workspaces.iter().flat_map(|ws| ws.windows())
138+ }
139+
140+ pub fn has_window(&self, window: &W::Id) -> bool {
141+ self.windows().any(|win| win.id() == window)
142+ }
143+
136 fn activate_workspace(&mut self, idx: usize) {144 fn activate_workspace(&mut self, idx: usize) {
137 if self.active_workspace_idx == idx {145 if self.active_workspace_idx == idx {
138 return;146 return;
@@ -489,8 +497,32 @@ impl<W: LayoutElement> Monitor<W> {
489 self.add_window(new_idx, window, true, width, is_full_width);497 self.add_window(new_idx, window, true, width, is_full_width);
490 }498 }
491 499
492- pub fn move_to_workspace(&mut self, idx: usize) {500+ pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) {
493- let source_workspace_idx = self.active_workspace_idx;501+ let (source_workspace_idx, col_idx, tile_idx) = if let Some(window) = window {
502+ self.workspaces
503+ .iter()
504+ .enumerate()
505+ .find_map(|(ws_idx, ws)| {
506+ ws.columns.iter().enumerate().find_map(|(col_idx, col)| {
507+ col.tiles
508+ .iter()
509+ .position(|tile| tile.window().id() == window)
510+ .map(|tile_idx| (ws_idx, col_idx, tile_idx))
511+ })
512+ })
513+ .unwrap()
514+ } else {
515+ let ws_idx = self.active_workspace_idx;
516+
517+ let ws = &self.workspaces[ws_idx];
518+ if ws.columns.is_empty() {
519+ return;
520+ }
521+
522+ let col_idx = ws.active_column_idx;
523+ let tile_idx = ws.columns[col_idx].active_tile_idx;
524+ (ws_idx, col_idx, tile_idx)
525+ };
494 526
495 let new_idx = min(idx, self.workspaces.len() - 1);527 let new_idx = min(idx, self.workspaces.len() - 1);
496 if new_idx == source_workspace_idx {528 if new_idx == source_workspace_idx {
@@ -498,28 +530,22 @@ impl<W: LayoutElement> Monitor<W> {
498 }530 }
499 531
500 let workspace = &mut self.workspaces[source_workspace_idx];532 let workspace = &mut self.workspaces[source_workspace_idx];
501- if workspace.columns.is_empty() {533+ let column = &workspace.columns[col_idx];
502- return;
503- }
504-
505- let column = &workspace.columns[workspace.active_column_idx];
506 let width = column.width;534 let width = column.width;
507 let is_full_width = column.is_full_width;535 let is_full_width = column.is_full_width;
536+ let activate = source_workspace_idx == self.active_workspace_idx
537+ && col_idx == workspace.active_column_idx
538+ && tile_idx == column.active_tile_idx;
539+
508 let window = workspace540 let window = workspace
509- .remove_tile_by_idx(541+ .remove_tile_by_idx(col_idx, tile_idx, Transaction::new(), None)
510- workspace.active_column_idx,
511- column.active_tile_idx,
512- Transaction::new(),
513- None,
514- )
515 .into_window();542 .into_window();
516 543
517- self.add_window(new_idx, window, true, width, is_full_width);544+ self.add_window(new_idx, window, activate, width, is_full_width);
518-
519- // Don't animate this action.
520- self.workspace_switch = None;
521 545
522- self.clean_up_workspaces();546+ if self.workspace_switch.is_none() {
547+ self.clean_up_workspaces();
548+ }
523 }549 }
524 550
525 pub fn move_column_to_workspace_up(&mut self) {551 pub fn move_column_to_workspace_up(&mut self) {
@@ -571,11 +597,6 @@ impl<W: LayoutElement> Monitor<W> {
571 597
572 let column = workspace.remove_column_by_idx(workspace.active_column_idx);598 let column = workspace.remove_column_by_idx(workspace.active_column_idx);
573 self.add_column(new_idx, column, true);599 self.add_column(new_idx, column, true);
574-
575- // Don't animate this action.
576- self.workspace_switch = None;
577-
578- self.clean_up_workspaces();
579 }600 }
580 601
581 pub fn switch_workspace_up(&mut self) {602 pub fn switch_workspace_up(&mut self) {
@@ -727,14 +748,6 @@ impl<W: LayoutElement> Monitor<W> {
727 self.active_workspace().set_column_width(change);748 self.active_workspace().set_column_width(change);
728 }749 }
729 750
730- pub fn set_window_height(&mut self, change: SizeChange) {
731- self.active_workspace().set_window_height(change);
732- }
733-
734- pub fn reset_window_height(&mut self) {
735- self.active_workspace().reset_window_height();
736- }
737-
738 pub fn move_workspace_down(&mut self) {751 pub fn move_workspace_down(&mut self) {
739 let new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1);752 let new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1);
740 if new_idx == self.active_workspace_idx {753 if new_idx == self.active_workspace_idx {
src/layout/workspace.rsmodified+32 -6
@@ -2303,24 +2303,50 @@ impl<W: LayoutElement> Workspace<W> {
2303 cancel_resize_for_column(&mut self.interactive_resize, col);2303 cancel_resize_for_column(&mut self.interactive_resize, col);
2304 }2304 }
2305 2305
2306- pub fn set_window_height(&mut self, change: SizeChange) {2306+ pub fn set_window_height(&mut self, window: Option<&W::Id>, change: SizeChange) {
2307 if self.columns.is_empty() {2307 if self.columns.is_empty() {
2308 return;2308 return;
2309 }2309 }
2310 2310
2311- let col = &mut self.columns[self.active_column_idx];2311+ let (col, tile_idx) = if let Some(window) = window {
2312- col.set_window_height(change, None, true);2312+ self.columns
2313+ .iter_mut()
2314+ .find_map(|col| {
2315+ col.tiles
2316+ .iter()
2317+ .position(|tile| tile.window().id() == window)
2318+ .map(|tile_idx| (col, Some(tile_idx)))
2319+ })
2320+ .unwrap()
2321+ } else {
2322+ (&mut self.columns[self.active_column_idx], None)
2323+ };
2324+
2325+ col.set_window_height(change, tile_idx, true);
2313 2326
2314 cancel_resize_for_column(&mut self.interactive_resize, col);2327 cancel_resize_for_column(&mut self.interactive_resize, col);
2315 }2328 }
2316 2329
2317- pub fn reset_window_height(&mut self) {2330+ pub fn reset_window_height(&mut self, window: Option<&W::Id>) {
2318 if self.columns.is_empty() {2331 if self.columns.is_empty() {
2319 return;2332 return;
2320 }2333 }
2321 2334
2322- let col = &mut self.columns[self.active_column_idx];2335+ let (col, tile_idx) = if let Some(window) = window {
2323- col.reset_window_height(None, true);2336+ self.columns
2337+ .iter_mut()
2338+ .find_map(|col| {
2339+ col.tiles
2340+ .iter()
2341+ .position(|tile| tile.window().id() == window)
2342+ .map(|tile_idx| (col, Some(tile_idx)))
2343+ })
2344+ .unwrap()
2345+ } else {
2346+ (&mut self.columns[self.active_column_idx], None)
2347+ };
2348+
2349+ col.reset_window_height(tile_idx, true);
2324 2350
2325 cancel_resize_for_column(&mut self.interactive_resize, col);2351 cancel_resize_for_column(&mut self.interactive_resize, col);
2326 }2352 }
src/niri.rsmodified+2 -9
@@ -2447,15 +2447,8 @@ impl Niri {
2447 }2447 }
2448 };2448 };
2449 2449
2450- // FIXME: when we do fixes for no connected outputs, this will need fixing too.2450+ let target_output = target_workspace.current_output();
2451- let active_workspace = self.layout.active_workspace()?;2451+ Some((target_output.cloned(), target_workspace_index))
2452-
2453- if target_workspace.current_output() == active_workspace.current_output() {
2454- return Some((None, target_workspace_index));
2455- }
2456- let target_output = target_workspace.current_output()?;
2457-
2458- Some((Some(target_output.clone()), target_workspace_index))
2459 }2452 }
2460 2453
2461 pub fn output_down(&self) -> Option<Output> {2454 pub fn output_down(&self) -> Option<Output> {