forge
Explore
Log in

Don't you dare go Hollow

layout: Refactor window opening targets

Browse files at this commit

daaee43be387d75c62c7ba63d33b0b8f9ae192c8Ivan MolodetskikhParent: 0d71cb9
niri-visual-tests/src/cases/layout.rsmodified+10 -3
@@ -3,7 +3,7 @@ use std::time::Duration;
33
44 use niri::animation::Clock;
55 use niri::layout::scrolling::ColumnWidth;
6-use niri::layout::{ActivateWindow, LayoutElement as _, Options};
6+use niri::layout::{ActivateWindow, AddWindowTarget, LayoutElement as _, Options};
77 use niri::render_helpers::RenderTarget;
88 use niri_config::{Color, FloatOrInt, OutputName};
99 use smithay::backend::renderer::element::RenderElement;
@@ -170,6 +170,7 @@ impl Layout {
170170
171171 self.layout.add_window(
172172 window.clone(),
173+ AddWindowTarget::Auto,
173174 width,
174175 false,
175176 false,
@@ -194,8 +195,14 @@ impl Layout {
194195 );
195196 window.communicate();
196197
197- self.layout
198- .add_window_right_of(right_of.id(), window.clone(), width, false, false);
198+ self.layout.add_window(
199+ window.clone(),
200+ AddWindowTarget::NextTo(right_of.id()),
201+ width,
202+ false,
203+ false,
204+ ActivateWindow::default(),
205+ );
199206 self.windows.push(window);
200207 }
201208
src/handlers/compositor.rsmodified+22 -42
@@ -19,7 +19,7 @@ use smithay::{delegate_compositor, delegate_shm};
1919
2020 use super::xdg_shell::add_mapped_toplevel_pre_commit_hook;
2121 use crate::handlers::XDG_ACTIVATION_TOKEN_TIMEOUT;
22-use crate::layout::ActivateWindow;
22+use crate::layout::{ActivateWindow, AddWindowTarget};
2323 use crate::niri::{ClientState, State};
2424 use crate::utils::send_scale_transform;
2525 use crate::utils::transaction::Transaction;
@@ -96,7 +96,7 @@ impl CompositorHandler for State {
9696
9797 let toplevel = window.toplevel().expect("no X11 support");
9898
99- let (rules, width, is_full_width, output, workspace_name) =
99+ let (rules, width, is_full_width, output, workspace_id) =
100100 if let InitialConfigureState::Configured {
101101 rules,
102102 width,
@@ -110,10 +110,12 @@ impl CompositorHandler for State {
110110 output.filter(|o| self.niri.layout.monitor_for_output(o).is_some());
111111
112112 // Check that the workspace still exists.
113- let workspace_name = workspace_name
114- .filter(|n| self.niri.layout.find_workspace_by_name(n).is_some());
113+ let workspace_id = workspace_name
114+ .as_deref()
115+ .and_then(|n| self.niri.layout.find_workspace_by_name(n))
116+ .map(|(_, ws)| ws.id());
115117
116- (rules, width, is_full_width, output, workspace_name)
118+ (rules, width, is_full_width, output, workspace_id)
117119 } else {
118120 error!("window map must happen after initial configure");
119121 (ResolvedWindowRules::empty(), None, false, None, None)
@@ -160,46 +162,24 @@ impl CompositorHandler for State {
160162 }
161163 };
162164
163- let output = if let Some(p) = parent {
164- // Open dialogs immediately to the right of their parent window.
165- //
166- // FIXME: do we want to use activate here? How do we want things to behave
167- // exactly?
168- self.niri.layout.add_window_right_of(
169- &p,
170- mapped,
171- width,
172- is_full_width,
173- is_floating,
174- )
175- } else if let Some(workspace_name) = &workspace_name {
176- self.niri.layout.add_window_to_named_workspace(
177- workspace_name,
178- mapped,
179- width,
180- is_full_width,
181- is_floating,
182- activate,
183- )
165+ let target = if let Some(p) = &parent {
166+ // Open dialogs next to their parent window.
167+ AddWindowTarget::NextTo(p)
168+ } else if let Some(id) = workspace_id {
169+ AddWindowTarget::Workspace(id)
184170 } else if let Some(output) = &output {
185- self.niri.layout.add_window_on_output(
186- output,
187- mapped,
188- width,
189- is_full_width,
190- is_floating,
191- activate,
192- );
193- Some(output)
171+ AddWindowTarget::Output(output)
194172 } else {
195- self.niri.layout.add_window(
196- mapped,
197- width,
198- is_full_width,
199- is_floating,
200- activate,
201- )
173+ AddWindowTarget::Auto
202174 };
175+ let output = self.niri.layout.add_window(
176+ mapped,
177+ target,
178+ width,
179+ is_full_width,
180+ is_floating,
181+ activate,
182+ );
203183
204184 if let Some(output) = output.cloned() {
205185 self.niri.layout.start_open_animation_for_window(&window);
src/handlers/xdg_shell.rsmodified+1 -1
@@ -859,7 +859,7 @@ impl State {
859859 });
860860 }
861861
862- width = ws.resolve_default_width(rules.default_width);
862+ width = ws.resolve_default_width(rules.default_width, is_floating);
863863
864864 let configure_width = if is_full_width {
865865 Some(ColumnWidth::Proportion(1.))
src/layout/floating.rsmodified+1 -4
@@ -428,10 +428,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
428428 self.bring_up_descendants_of(idx);
429429 }
430430
431- pub fn add_tile_above(&mut self, above: &W::Id, mut tile: Tile<W>) {
432- // Activate the new window if above was active.
433- let activate = Some(above) == self.active_window_id.as_ref();
434-
431+ pub fn add_tile_above(&mut self, above: &W::Id, mut tile: Tile<W>, activate: bool) {
435432 let idx = self.idx_of(above).unwrap();
436433
437434 let above_pos = self.data[idx].logical_pos;
src/layout/mod.rsmodified+229 -239
@@ -35,6 +35,7 @@ use std::mem;
3535 use std::rc::Rc;
3636 use std::time::Duration;
3737
38+use monitor::MonitorAddWindowTarget;
3839 use niri_config::{
3940 CenterFocusedColumn, Config, CornerRadius, FloatOrInt, PresetSize, Struts,
4041 Workspace as WorkspaceConfig,
@@ -48,7 +49,7 @@ use smithay::output::{self, Output};
4849 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
4950 use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};
5051 use tile::{Tile, TileRenderElement};
51-use workspace::WorkspaceId;
52+use workspace::{WorkspaceAddWindowTarget, WorkspaceId};
5253
5354 pub use self::monitor::MonitorRenderElement;
5455 use self::monitor::{Monitor, WorkspaceSwitch};
@@ -424,6 +425,20 @@ pub enum ActivateWindow {
424425 No,
425426 }
426427
428+/// Where to put a newly added window.
429+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
430+pub enum AddWindowTarget<'a, W: LayoutElement> {
431+ /// No particular preference.
432+ #[default]
433+ Auto,
434+ /// On this output.
435+ Output(&'a Output),
436+ /// On this workspace.
437+ Workspace(WorkspaceId),
438+ /// Next to this existing window.
439+ NextTo(&'a W::Id),
440+}
441+
427442 impl<W: LayoutElement> InteractiveMoveState<W> {
428443 fn moving(&self) -> Option<&InteractiveMoveData<W>> {
429444 match self {
@@ -797,71 +812,6 @@ impl<W: LayoutElement> Layout<W> {
797812 }
798813 }
799814
800- /// Adds a new window to the layout on a specific workspace.
801- pub fn add_window_to_named_workspace(
802- &mut self,
803- workspace_name: &str,
804- window: W,
805- width: Option<ColumnWidth>,
806- is_full_width: bool,
807- is_floating: bool,
808- activate: ActivateWindow,
809- ) -> Option<&Output> {
810- let width = self.resolve_default_width(&window, width);
811-
812- match &mut self.monitor_set {
813- MonitorSet::Normal {
814- monitors,
815- active_monitor_idx,
816- ..
817- } => {
818- let (mon_idx, mon, ws_idx) = monitors
819- .iter_mut()
820- .enumerate()
821- .find_map(|(mon_idx, mon)| {
822- mon.find_named_workspace_index(workspace_name)
823- .map(move |ws_idx| (mon_idx, mon, ws_idx))
824- })
825- .unwrap();
826-
827- if activate == ActivateWindow::Yes {
828- *active_monitor_idx = mon_idx;
829- }
830-
831- let activate = activate.map_smart(|| {
832- // Don't steal focus from an active fullscreen window.
833- let ws = &mon.workspaces[ws_idx];
834- if mon_idx == *active_monitor_idx && ws.is_active_fullscreen() {
835- return false;
836- }
837-
838- // Don't activate if on a different workspace.
839- if mon.active_workspace_idx != ws_idx {
840- return false;
841- }
842-
843- true
844- });
845-
846- mon.add_window(ws_idx, window, activate, width, is_full_width, is_floating);
847- Some(&mon.output)
848- }
849- MonitorSet::NoOutputs { workspaces } => {
850- let ws = workspaces
851- .iter_mut()
852- .find(|ws| {
853- ws.name
854- .as_ref()
855- .map_or(false, |name| name.eq_ignore_ascii_case(workspace_name))
856- })
857- .unwrap();
858- let activate = activate.map_smart(|| true);
859- ws.add_window(window, activate, width, is_full_width, is_floating);
860- None
861- }
862- }
863- }
864-
865815 pub fn add_column_by_idx(
866816 &mut self,
867817 monitor_idx: usize,
@@ -891,12 +841,13 @@ impl<W: LayoutElement> Layout<W> {
891841 pub fn add_window(
892842 &mut self,
893843 window: W,
844+ target: AddWindowTarget<W>,
894845 width: Option<ColumnWidth>,
895846 is_full_width: bool,
896847 is_floating: bool,
897848 activate: ActivateWindow,
898849 ) -> Option<&Output> {
899- let width = self.resolve_default_width(&window, width);
850+ let resolved_width = self.resolve_default_width(&window, width, is_floating);
900851
901852 match &mut self.monitor_set {
902853 MonitorSet::Normal {
@@ -904,142 +855,136 @@ impl<W: LayoutElement> Layout<W> {
904855 active_monitor_idx,
905856 ..
906857 } => {
907- let mon = &mut monitors[*active_monitor_idx];
858+ let (mon_idx, target) = match target {
859+ AddWindowTarget::Auto => (*active_monitor_idx, MonitorAddWindowTarget::Auto),
860+ AddWindowTarget::Output(output) => {
861+ let mon_idx = monitors
862+ .iter()
863+ .position(|mon| mon.output == *output)
864+ .unwrap();
908865
909- let activate = activate.map_smart(|| {
910- // Don't steal focus from an active fullscreen window.
911- let ws = &mon.workspaces[mon.active_workspace_idx];
912- !ws.is_active_fullscreen()
913- });
866+ (mon_idx, MonitorAddWindowTarget::Auto)
867+ }
868+ AddWindowTarget::Workspace(ws_id) => {
869+ let mon_idx = monitors
870+ .iter()
871+ .position(|mon| mon.workspaces.iter().any(|ws| ws.id() == ws_id))
872+ .unwrap();
873+
874+ (
875+ mon_idx,
876+ MonitorAddWindowTarget::Workspace {
877+ id: ws_id,
878+ column_idx: None,
879+ },
880+ )
881+ }
882+ AddWindowTarget::NextTo(next_to) => {
883+ if let Some(output) = self
884+ .interactive_move
885+ .as_ref()
886+ .and_then(|move_| {
887+ if let InteractiveMoveState::Moving(move_) = move_ {
888+ Some(move_)
889+ } else {
890+ None
891+ }
892+ })
893+ .filter(|move_| next_to == move_.tile.window().id())
894+ .map(|move_| move_.output.clone())
895+ {
896+ // The next_to window is being interactively moved.
897+ let mon_idx = monitors
898+ .iter()
899+ .position(|mon| mon.output == output)
900+ .unwrap_or(*active_monitor_idx);
901+
902+ (mon_idx, MonitorAddWindowTarget::Auto)
903+ } else {
904+ let mon_idx = monitors
905+ .iter()
906+ .position(|mon| {
907+ mon.workspaces.iter().any(|ws| ws.has_window(next_to))
908+ })
909+ .unwrap();
910+ (mon_idx, MonitorAddWindowTarget::NextTo(next_to))
911+ }
912+ }
913+ };
914+ let mon = &mut monitors[mon_idx];
914915
915916 mon.add_window(
916- mon.active_workspace_idx,
917917 window,
918+ target,
918919 activate,
919- width,
920+ resolved_width,
920921 is_full_width,
921922 is_floating,
922923 );
923- Some(&mon.output)
924- }
925- MonitorSet::NoOutputs { workspaces } => {
926- let ws = if let Some(ws) = workspaces.get_mut(0) {
927- ws
928- } else {
929- workspaces.push(Workspace::new_no_outputs(
930- self.clock.clone(),
931- self.options.clone(),
932- ));
933- &mut workspaces[0]
934- };
935- let activate = activate.map_smart(|| true);
936- ws.add_window(window, activate, width, is_full_width, is_floating);
937- None
938- }
939- }
940- }
941924
942- /// Adds a new window to the layout immediately to the right of another window.
943- ///
944- /// If that another window was active, activates the new window.
945- ///
946- /// Returns an output that the window was added to, if there were any outputs.
947- pub fn add_window_right_of(
948- &mut self,
949- right_of: &W::Id,
950- window: W,
951- width: Option<ColumnWidth>,
952- is_full_width: bool,
953- is_floating: bool,
954- ) -> Option<&Output> {
955- if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
956- if right_of == move_.tile.window().id() {
957- let output = move_.output.clone();
958- let activate = ActivateWindow::default();
959- if self.monitor_for_output(&output).is_some() {
960- self.add_window_on_output(
961- &output,
962- window,
963- width,
964- is_full_width,
965- is_floating,
966- activate,
967- );
968- return Some(&self.monitor_for_output(&output).unwrap().output);
969- } else {
970- return self.add_window(window, width, is_full_width, is_floating, activate);
925+ if activate.map_smart(|| false) {
926+ *active_monitor_idx = mon_idx;
971927 }
972- }
973- }
974-
975- let width = self.resolve_default_width(&window, width);
976-
977- match &mut self.monitor_set {
978- MonitorSet::Normal { monitors, .. } => {
979- let mon = monitors
980- .iter_mut()
981- .find(|mon| mon.workspaces.iter().any(|ws| ws.has_window(right_of)))
982- .unwrap();
983928
984- mon.add_window_right_of(right_of, window, width, is_full_width, is_floating);
985929 Some(&mon.output)
986930 }
987931 MonitorSet::NoOutputs { workspaces } => {
988- let ws = workspaces
989- .iter_mut()
990- .find(|ws| ws.has_window(right_of))
991- .unwrap();
992- ws.add_window_right_of(right_of, window, width, is_full_width, is_floating);
993- None
994- }
995- }
996- }
997-
998- /// Adds a new window to the layout on a specific output.
999- pub fn add_window_on_output(
1000- &mut self,
1001- output: &Output,
1002- window: W,
1003- width: Option<ColumnWidth>,
1004- is_full_width: bool,
1005- is_floating: bool,
1006- activate: ActivateWindow,
1007- ) {
1008- let width = self.resolve_default_width(&window, width);
932+ let (ws_idx, target) = match target {
933+ AddWindowTarget::Auto => {
934+ if workspaces.is_empty() {
935+ workspaces.push(Workspace::new_no_outputs(
936+ self.clock.clone(),
937+ self.options.clone(),
938+ ));
939+ }
1009940
1010- let MonitorSet::Normal {
1011- monitors,
1012- active_monitor_idx,
1013- ..
1014- } = &mut self.monitor_set
1015- else {
1016- panic!()
1017- };
941+ (0, WorkspaceAddWindowTarget::Auto)
942+ }
943+ AddWindowTarget::Output(_) => panic!(),
944+ AddWindowTarget::Workspace(ws_id) => {
945+ let ws_idx = workspaces.iter().position(|ws| ws.id() == ws_id).unwrap();
946+ (ws_idx, WorkspaceAddWindowTarget::Auto)
947+ }
948+ AddWindowTarget::NextTo(next_to) => {
949+ if self
950+ .interactive_move
951+ .as_ref()
952+ .and_then(|move_| {
953+ if let InteractiveMoveState::Moving(move_) = move_ {
954+ Some(move_)
955+ } else {
956+ None
957+ }
958+ })
959+ .filter(|move_| next_to == move_.tile.window().id())
960+ .is_some()
961+ {
962+ // The next_to window is being interactively moved.
963+ (0, WorkspaceAddWindowTarget::Auto)
964+ } else {
965+ let ws_idx = workspaces
966+ .iter()
967+ .position(|ws| ws.has_window(next_to))
968+ .unwrap();
969+ (ws_idx, WorkspaceAddWindowTarget::NextTo(next_to))
970+ }
971+ }
972+ };
973+ let ws = &mut workspaces[ws_idx];
1018974
1019- let (mon_idx, mon) = monitors
1020- .iter_mut()
1021- .enumerate()
1022- .find(|(_, mon)| mon.output == *output)
1023- .unwrap();
975+ let tile = ws.make_tile(window);
976+ ws.add_tile(
977+ tile,
978+ target,
979+ activate,
980+ resolved_width,
981+ is_full_width,
982+ is_floating,
983+ );
1024984
1025- if activate == ActivateWindow::Yes {
1026- *active_monitor_idx = mon_idx;
985+ None
986+ }
1027987 }
1028-
1029- let activate = activate.map_smart(|| {
1030- // Don't steal focus from an active fullscreen window.
1031- let ws = &mon.workspaces[mon.active_workspace_idx];
1032- mon_idx != *active_monitor_idx || !ws.is_active_fullscreen()
1033- });
1034-
1035- mon.add_window(
1036- mon.active_workspace_idx,
1037- window,
1038- activate,
1039- width,
1040- is_full_width,
1041- is_floating,
1042- );
1043988 }
1044989
1045990 pub fn remove_window(
@@ -2801,12 +2746,18 @@ impl<W: LayoutElement> Layout<W> {
28012746 if mon_idx == new_idx && ws_idx == workspace_idx {
28022747 return;
28032748 }
2749+ let ws_id = monitors[new_idx].workspaces[workspace_idx].id();
28042750
28052751 let mon = &mut monitors[mon_idx];
28062752 let activate = window.map_or(true, |win| {
28072753 mon_idx == *active_monitor_idx
28082754 && mon.active_window().map(|win| win.id()) == Some(win)
28092755 });
2756+ let activate = if activate {
2757+ ActivateWindow::Yes
2758+ } else {
2759+ ActivateWindow::No
2760+ };
28102761
28112762 let ws = &mut mon.workspaces[ws_idx];
28122763 let transaction = Transaction::new();
@@ -2821,19 +2772,18 @@ impl<W: LayoutElement> Layout<W> {
28212772 removed.tile.stop_move_animations();
28222773
28232774 let mon = &mut monitors[new_idx];
2824- if removed.is_floating {
2825- mon.add_floating_tile(workspace_idx, removed.tile, activate);
2826- } else {
2827- mon.add_tile(
2828- workspace_idx,
2829- None,
2830- removed.tile,
2831- activate,
2832- removed.width,
2833- removed.is_full_width,
2834- );
2835- }
2836- if activate {
2775+ mon.add_tile(
2776+ removed.tile,
2777+ MonitorAddWindowTarget::Workspace {
2778+ id: ws_id,
2779+ column_idx: None,
2780+ },
2781+ activate,
2782+ removed.width,
2783+ removed.is_full_width,
2784+ removed.is_floating,
2785+ );
2786+ if activate.map_smart(|| false) {
28372787 *active_monitor_idx = new_idx;
28382788 }
28392789
@@ -3443,13 +3393,17 @@ impl<W: LayoutElement> Layout<W> {
34433393
34443394 match position {
34453395 InsertPosition::NewColumn(column_idx) => {
3396+ let ws_id = mon.workspaces[ws_idx].id();
34463397 mon.add_tile(
3447- ws_idx,
3448- Some(column_idx),
34493398 move_.tile,
3450- true,
3399+ MonitorAddWindowTarget::Workspace {
3400+ id: ws_id,
3401+ column_idx: Some(column_idx),
3402+ },
3403+ ActivateWindow::Yes,
34513404 move_.width,
34523405 move_.is_full_width,
3406+ false,
34533407 );
34543408 }
34553409 InsertPosition::InColumn(column_idx, tile_idx) => {
@@ -3474,7 +3428,18 @@ impl<W: LayoutElement> Layout<W> {
34743428 tile.floating_window_size = Some(size);
34753429 }
34763430
3477- mon.add_floating_tile(ws_idx, tile, true);
3431+ let ws_id = mon.workspaces[ws_idx].id();
3432+ mon.add_tile(
3433+ tile,
3434+ MonitorAddWindowTarget::Workspace {
3435+ id: ws_id,
3436+ column_idx: None,
3437+ },
3438+ ActivateWindow::Yes,
3439+ move_.width,
3440+ move_.is_full_width,
3441+ true,
3442+ );
34783443 }
34793444 }
34803445
@@ -3490,18 +3455,23 @@ impl<W: LayoutElement> Layout<W> {
34903455 tile.animate_move_from(window_render_loc - new_window_render_loc);
34913456 }
34923457 MonitorSet::NoOutputs { workspaces, .. } => {
3493- let ws = if let Some(ws) = workspaces.get_mut(0) {
3494- ws
3495- } else {
3458+ if workspaces.is_empty() {
34963459 workspaces.push(Workspace::new_no_outputs(
34973460 self.clock.clone(),
34983461 self.options.clone(),
34993462 ));
3500- &mut workspaces[0]
3501- };
3463+ }
3464+ let ws = &mut workspaces[0];
35023465
35033466 // No point in trying to use the pointer position without outputs.
3504- ws.add_tile(None, move_.tile, true, move_.width, move_.is_full_width);
3467+ ws.add_tile(
3468+ move_.tile,
3469+ WorkspaceAddWindowTarget::Auto,
3470+ ActivateWindow::Yes,
3471+ move_.width,
3472+ move_.is_full_width,
3473+ move_.is_floating,
3474+ );
35053475 }
35063476 }
35073477 }
@@ -3894,8 +3864,19 @@ impl<W: LayoutElement> Layout<W> {
38943864 self.windows().any(|(_, win)| win.id() == window)
38953865 }
38963866
3897- fn resolve_default_width(&self, window: &W, width: Option<ColumnWidth>) -> ColumnWidth {
3867+ fn resolve_default_width(
3868+ &self,
3869+ window: &W,
3870+ width: Option<ColumnWidth>,
3871+ is_floating: bool,
3872+ ) -> ColumnWidth {
38983873 let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w)));
3874+ if is_floating {
3875+ return width;
3876+ }
3877+
3878+ // Add border width to account for the issue that the scrolling layout currently doesn't
3879+ // take borders into account for fixed sizes.
38993880 if let ColumnWidth::Fixed(w) = &mut width {
39003881 let rules = window.rules();
39013882 let border_config = rules.border.resolve_against(self.options.border);
@@ -3903,6 +3884,7 @@ impl<W: LayoutElement> Layout<W> {
39033884 *w += border_config.width.0 * 2.;
39043885 }
39053886 }
3887+
39063888 width
39073889 }
39083890 }
@@ -4242,10 +4224,10 @@ mod tests {
42424224 AddWindow {
42434225 params: TestWindowParams,
42444226 },
4245- AddWindowRightOf {
4227+ AddWindowNextTo {
42464228 params: TestWindowParams,
42474229 #[proptest(strategy = "1..=5usize")]
4248- right_of_id: usize,
4230+ next_to_id: usize,
42494231 },
42504232 AddWindowToNamedWorkspace {
42514233 params: TestWindowParams,
@@ -4548,25 +4530,26 @@ mod tests {
45484530 let win = TestWindow::new(params);
45494531 layout.add_window(
45504532 win,
4533+ AddWindowTarget::Auto,
45514534 None,
45524535 false,
45534536 params.is_floating,
45544537 ActivateWindow::default(),
45554538 );
45564539 }
4557- Op::AddWindowRightOf {
4540+ Op::AddWindowNextTo {
45584541 mut params,
4559- right_of_id,
4542+ next_to_id,
45604543 } => {
4561- let mut found_right_of = false;
4544+ let mut found_next_to = false;
45624545
45634546 if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move {
45644547 let win_id = move_.tile.window().0.id;
45654548 if win_id == params.id {
45664549 return;
45674550 }
4568- if win_id == right_of_id {
4569- found_right_of = true;
4551+ if win_id == next_to_id {
4552+ found_next_to = true;
45704553 }
45714554 }
45724555
@@ -4579,8 +4562,8 @@ mod tests {
45794562 return;
45804563 }
45814564
4582- if win.0.id == right_of_id {
4583- found_right_of = true;
4565+ if win.0.id == next_to_id {
4566+ found_next_to = true;
45844567 }
45854568 }
45864569 }
@@ -4593,15 +4576,15 @@ mod tests {
45934576 return;
45944577 }
45954578
4596- if win.0.id == right_of_id {
4597- found_right_of = true;
4579+ if win.0.id == next_to_id {
4580+ found_next_to = true;
45984581 }
45994582 }
46004583 }
46014584 }
46024585 }
46034586
4604- if !found_right_of {
4587+ if !found_next_to {
46054588 return;
46064589 }
46074590
@@ -4612,14 +4595,21 @@ mod tests {
46124595 }
46134596
46144597 let win = TestWindow::new(params);
4615- layout.add_window_right_of(&right_of_id, win, None, false, params.is_floating);
4598+ layout.add_window(
4599+ win,
4600+ AddWindowTarget::NextTo(&next_to_id),
4601+ None,
4602+ false,
4603+ params.is_floating,
4604+ ActivateWindow::default(),
4605+ );
46164606 }
46174607 Op::AddWindowToNamedWorkspace {
46184608 mut params,
46194609 ws_name,
46204610 } => {
46214611 let ws_name = format!("ws{ws_name}");
4622- let mut found_workspace = false;
4612+ let mut ws_id = None;
46234613
46244614 if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move {
46254615 if move_.tile.window().0.id == params.id {
@@ -4642,7 +4632,7 @@ mod tests {
46424632 .as_ref()
46434633 .map_or(false, |name| name.eq_ignore_ascii_case(&ws_name))
46444634 {
4645- found_workspace = true;
4635+ ws_id = Some(ws.id());
46464636 }
46474637 }
46484638 }
@@ -4660,15 +4650,15 @@ mod tests {
46604650 .as_ref()
46614651 .map_or(false, |name| name.eq_ignore_ascii_case(&ws_name))
46624652 {
4663- found_workspace = true;
4653+ ws_id = Some(ws.id());
46644654 }
46654655 }
46664656 }
46674657 }
46684658
4669- if !found_workspace {
4659+ let Some(ws_id) = ws_id else {
46704660 return;
4671- }
4661+ };
46724662
46734663 if let Some(parent_id) = params.parent_id {
46744664 if parent_id_causes_loop(layout, params.id, parent_id) {
@@ -4677,9 +4667,9 @@ mod tests {
46774667 }
46784668
46794669 let win = TestWindow::new(params);
4680- layout.add_window_to_named_workspace(
4681- &ws_name,
4670+ layout.add_window(
46824671 win,
4672+ AddWindowTarget::Workspace(ws_id),
46834673 None,
46844674 false,
46854675 params.is_floating,
@@ -5116,9 +5106,9 @@ mod tests {
51165106 Op::AddWindow {
51175107 params: TestWindowParams::new(1),
51185108 },
5119- Op::AddWindowRightOf {
5109+ Op::AddWindowNextTo {
51205110 params: TestWindowParams::new(2),
5121- right_of_id: 1,
5111+ next_to_id: 1,
51225112 },
51235113 Op::AddWindowToNamedWorkspace {
51245114 params: TestWindowParams::new(3),
@@ -5265,13 +5255,13 @@ mod tests {
52655255 Op::AddWindow {
52665256 params: TestWindowParams::new(2),
52675257 },
5268- Op::AddWindowRightOf {
5258+ Op::AddWindowNextTo {
52695259 params: TestWindowParams::new(6),
5270- right_of_id: 0,
5260+ next_to_id: 0,
52715261 },
5272- Op::AddWindowRightOf {
5262+ Op::AddWindowNextTo {
52735263 params: TestWindowParams::new(7),
5274- right_of_id: 1,
5264+ next_to_id: 1,
52755265 },
52765266 Op::AddWindowToNamedWorkspace {
52775267 params: TestWindowParams::new(5),
@@ -5663,9 +5653,9 @@ mod tests {
56635653 Op::AddWindow {
56645654 params: TestWindowParams::new(2),
56655655 },
5666- Op::AddWindowRightOf {
5656+ Op::AddWindowNextTo {
56675657 params: TestWindowParams::new(3),
5668- right_of_id: 1,
5658+ next_to_id: 1,
56695659 },
56705660 ];
56715661
@@ -5699,9 +5689,9 @@ mod tests {
56995689 Op::AddWindow {
57005690 params: TestWindowParams::new(2),
57015691 },
5702- Op::AddWindowRightOf {
5692+ Op::AddWindowNextTo {
57035693 params: TestWindowParams::new(3),
5704- right_of_id: 1,
5694+ next_to_id: 1,
57055695 },
57065696 ];
57075697
src/layout/monitor.rsmodified+95 -109
@@ -11,8 +11,10 @@ use smithay::utils::{Logical, Point, Rectangle};
1111
1212 use super::scrolling::{Column, ColumnWidth};
1313 use super::tile::Tile;
14-use super::workspace::{OutputId, Workspace, WorkspaceId, WorkspaceRenderElement};
15-use super::{LayoutElement, Options};
14+use super::workspace::{
15+ OutputId, Workspace, WorkspaceAddWindowTarget, WorkspaceId, WorkspaceRenderElement,
16+};
17+use super::{ActivateWindow, LayoutElement, Options};
1618 use crate::animation::{Animation, Clock};
1719 use crate::input::swipe_tracker::SwipeTracker;
1820 use crate::render_helpers::renderer::NiriRenderer;
@@ -66,6 +68,23 @@ pub struct WorkspaceSwitchGesture {
6668 is_touchpad: bool,
6769 }
6870
71+/// Where to put a newly added window.
72+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
73+pub enum MonitorAddWindowTarget<'a, W: LayoutElement> {
74+ /// No particular preference.
75+ #[default]
76+ Auto,
77+ /// On this workspace.
78+ Workspace {
79+ /// Id of the target workspace.
80+ id: WorkspaceId,
81+ /// Override where the window will open as a new column.
82+ column_idx: Option<usize>,
83+ },
84+ /// Next to this existing window.
85+ NextTo(&'a W::Id),
86+}
87+
6988 pub type MonitorRenderElement<R> =
7089 RelocateRenderElement<CropRenderElement<WorkspaceRenderElement<R>>>;
7190
@@ -220,56 +239,18 @@ impl<W: LayoutElement> Monitor<W> {
220239
221240 pub fn add_window(
222241 &mut self,
223- mut workspace_idx: usize,
224- window: W,
225- activate: bool,
226- width: ColumnWidth,
227- is_full_width: bool,
228- is_floating: bool,
229- ) {
230- let workspace = &mut self.workspaces[workspace_idx];
231-
232- workspace.add_window(window, activate, width, is_full_width, is_floating);
233-
234- // After adding a new window, workspace becomes this output's own.
235- workspace.original_output = OutputId::new(&self.output);
236-
237- if workspace_idx == self.workspaces.len() - 1 {
238- self.add_workspace_bottom();
239- }
240-
241- if self.options.empty_workspace_above_first && workspace_idx == 0 {
242- self.add_workspace_top();
243- workspace_idx += 1;
244- }
245-
246- if activate {
247- self.activate_workspace(workspace_idx);
248- }
249- }
250-
251- pub fn add_window_right_of(
252- &mut self,
253- right_of: &W::Id,
254242 window: W,
243+ target: MonitorAddWindowTarget<W>,
244+ activate: ActivateWindow,
255245 width: ColumnWidth,
256246 is_full_width: bool,
257247 is_floating: bool,
258248 ) {
259- let workspace_idx = self
260- .workspaces
261- .iter_mut()
262- .position(|ws| ws.has_window(right_of))
263- .unwrap();
264- let workspace = &mut self.workspaces[workspace_idx];
249+ // Currently, everything a workspace sets on a Tile is the same across all workspaces of a
250+ // monitor. So we can use any workspace, not necessarily the exact target workspace.
251+ let tile = self.workspaces[0].make_tile(window);
265252
266- workspace.add_window_right_of(right_of, window, width, is_full_width, is_floating);
267-
268- // After adding a new window, workspace becomes this output's own.
269- workspace.original_output = OutputId::new(&self.output);
270-
271- // Since we're adding window right of something, the workspace isn't empty, and therefore
272- // cannot be the last one, so we never need to insert a new empty workspace.
253+ self.add_tile(tile, target, activate, width, is_full_width, is_floating);
273254 }
274255
275256 pub fn add_column(&mut self, mut workspace_idx: usize, column: Column<W>, activate: bool) {
@@ -295,39 +276,39 @@ impl<W: LayoutElement> Monitor<W> {
295276
296277 pub fn add_tile(
297278 &mut self,
298- mut workspace_idx: usize,
299- column_idx: Option<usize>,
300279 tile: Tile<W>,
301- activate: bool,
280+ target: MonitorAddWindowTarget<W>,
281+ activate: ActivateWindow,
302282 width: ColumnWidth,
303283 is_full_width: bool,
284+ is_floating: bool,
304285 ) {
305- let workspace = &mut self.workspaces[workspace_idx];
306-
307- workspace.add_tile(column_idx, tile, activate, width, is_full_width);
308-
309- // After adding a new window, workspace becomes this output's own.
310- workspace.original_output = OutputId::new(&self.output);
311-
312- if workspace_idx == self.workspaces.len() - 1 {
313- // Insert a new empty workspace.
314- self.add_workspace_bottom();
315- }
316-
317- if self.options.empty_workspace_above_first && workspace_idx == 0 {
318- self.add_workspace_top();
319- workspace_idx += 1;
320- }
321-
322- if activate {
323- self.activate_workspace(workspace_idx);
324- }
325- }
286+ let (mut workspace_idx, target) = match target {
287+ MonitorAddWindowTarget::Auto => {
288+ (self.active_workspace_idx, WorkspaceAddWindowTarget::Auto)
289+ }
290+ MonitorAddWindowTarget::Workspace { id, column_idx } => {
291+ let idx = self.workspaces.iter().position(|ws| ws.id() == id).unwrap();
292+ let target = if let Some(column_idx) = column_idx {
293+ WorkspaceAddWindowTarget::NewColumnAt(column_idx)
294+ } else {
295+ WorkspaceAddWindowTarget::Auto
296+ };
297+ (idx, target)
298+ }
299+ MonitorAddWindowTarget::NextTo(win_id) => {
300+ let idx = self
301+ .workspaces
302+ .iter_mut()
303+ .position(|ws| ws.has_window(win_id))
304+ .unwrap();
305+ (idx, WorkspaceAddWindowTarget::NextTo(win_id))
306+ }
307+ };
326308
327- pub fn add_floating_tile(&mut self, mut workspace_idx: usize, tile: Tile<W>, activate: bool) {
328309 let workspace = &mut self.workspaces[workspace_idx];
329310
330- workspace.add_floating_tile(tile, activate);
311+ workspace.add_tile(tile, target, activate, width, is_full_width, is_floating);
331312
332313 // After adding a new window, workspace becomes this output's own.
333314 workspace.original_output = OutputId::new(&self.output);
@@ -342,7 +323,7 @@ impl<W: LayoutElement> Monitor<W> {
342323 workspace_idx += 1;
343324 }
344325
345- if activate {
326+ if activate.map_smart(|| false) {
346327 self.activate_workspace(workspace_idx);
347328 }
348329 }
@@ -518,24 +499,24 @@ impl<W: LayoutElement> Monitor<W> {
518499 if new_idx == source_workspace_idx {
519500 return;
520501 }
502+ let new_id = self.workspaces[new_idx].id();
521503
522504 let workspace = &mut self.workspaces[source_workspace_idx];
523505 let Some(removed) = workspace.remove_active_tile(Transaction::new()) else {
524506 return;
525507 };
526508
527- if removed.is_floating {
528- self.add_floating_tile(new_idx, removed.tile, true);
529- } else {
530- self.add_tile(
531- new_idx,
532- None,
533- removed.tile,
534- true,
535- removed.width,
536- removed.is_full_width,
537- );
538- }
509+ self.add_tile(
510+ removed.tile,
511+ MonitorAddWindowTarget::Workspace {
512+ id: new_id,
513+ column_idx: None,
514+ },
515+ ActivateWindow::Yes,
516+ removed.width,
517+ removed.is_full_width,
518+ removed.is_floating,
519+ );
539520 }
540521
541522 pub fn move_to_workspace_down(&mut self) {
@@ -545,24 +526,24 @@ impl<W: LayoutElement> Monitor<W> {
545526 if new_idx == source_workspace_idx {
546527 return;
547528 }
529+ let new_id = self.workspaces[new_idx].id();
548530
549531 let workspace = &mut self.workspaces[source_workspace_idx];
550532 let Some(removed) = workspace.remove_active_tile(Transaction::new()) else {
551533 return;
552534 };
553535
554- if removed.is_floating {
555- self.add_floating_tile(new_idx, removed.tile, true);
556- } else {
557- self.add_tile(
558- new_idx,
559- None,
560- removed.tile,
561- true,
562- removed.width,
563- removed.is_full_width,
564- );
565- }
536+ self.add_tile(
537+ removed.tile,
538+ MonitorAddWindowTarget::Workspace {
539+ id: new_id,
540+ column_idx: None,
541+ },
542+ ActivateWindow::Yes,
543+ removed.width,
544+ removed.is_full_width,
545+ removed.is_floating,
546+ );
566547 }
567548
568549 pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) {
@@ -579,10 +560,16 @@ impl<W: LayoutElement> Monitor<W> {
579560 if new_idx == source_workspace_idx {
580561 return;
581562 }
563+ let new_id = self.workspaces[new_idx].id();
582564
583565 let activate = window.map_or(true, |win| {
584566 self.active_window().map(|win| win.id()) == Some(win)
585567 });
568+ let activate = if activate {
569+ ActivateWindow::Yes
570+ } else {
571+ ActivateWindow::No
572+ };
586573
587574 let workspace = &mut self.workspaces[source_workspace_idx];
588575 let transaction = Transaction::new();
@@ -594,18 +581,17 @@ impl<W: LayoutElement> Monitor<W> {
594581 return;
595582 };
596583
597- if removed.is_floating {
598- self.add_floating_tile(new_idx, removed.tile, activate);
599- } else {
600- self.add_tile(
601- new_idx,
602- None,
603- removed.tile,
604- activate,
605- removed.width,
606- removed.is_full_width,
607- );
608- }
584+ self.add_tile(
585+ removed.tile,
586+ MonitorAddWindowTarget::Workspace {
587+ id: new_id,
588+ column_idx: None,
589+ },
590+ activate,
591+ removed.width,
592+ removed.is_full_width,
593+ removed.is_floating,
594+ );
609595
610596 if self.workspace_switch.is_none() {
611597 self.clean_up_workspaces();
src/layout/scrolling.rsmodified+1 -3
@@ -783,6 +783,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
783783 &mut self,
784784 right_of: &W::Id,
785785 tile: Tile<W>,
786+ activate: bool,
786787 width: ColumnWidth,
787788 is_full_width: bool,
788789 ) {
@@ -793,9 +794,6 @@ impl<W: LayoutElement> ScrollingSpace<W> {
793794 .unwrap();
794795 let col_idx = right_of_idx + 1;
795796
796- // Activate the new window if right_of was active.
797- let activate = self.active_column_idx == right_of_idx;
798-
799797 self.add_tile(Some(col_idx), tile, activate, width, is_full_width, None);
800798 }
801799
src/layout/workspace.rsmodified+131 -98
@@ -18,7 +18,7 @@ use super::scrolling::{
1818 Column, ColumnWidth, InsertHint, InsertPosition, ScrollingSpace, ScrollingSpaceRenderElement,
1919 };
2020 use super::tile::{Tile, TileRenderSnapshot};
21-use super::{InteractiveResizeData, LayoutElement, Options, RemovedTile, SizeFrac};
21+use super::{ActivateWindow, InteractiveResizeData, LayoutElement, Options, RemovedTile, SizeFrac};
2222 use crate::animation::Clock;
2323 use crate::niri_render_elements;
2424 use crate::render_helpers::renderer::NiriRenderer;
@@ -157,6 +157,18 @@ enum FloatingActive {
157157 Yes,
158158 }
159159
160+/// Where to put a newly added window.
161+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
162+pub enum WorkspaceAddWindowTarget<'a, W: LayoutElement> {
163+ /// No particular preference.
164+ #[default]
165+ Auto,
166+ /// As a new column at this index.
167+ NewColumnAt(usize),
168+ /// Next to this existing window.
169+ NextTo(&'a W::Id),
170+}
171+
160172 impl OutputId {
161173 pub fn new(output: &Output) -> Self {
162174 let output_name = output.user_data().get::<OutputName>().unwrap();
@@ -488,55 +500,138 @@ impl<W: LayoutElement> Workspace<W> {
488500 self.view_size
489501 }
490502
491- pub fn add_window(
492- &mut self,
493- window: W,
494- activate: bool,
495- width: ColumnWidth,
496- is_full_width: bool,
497- is_floating: bool,
498- ) {
499- let mut tile = Tile::new(
503+ pub fn make_tile(&self, window: W) -> Tile<W> {
504+ Tile::new(
500505 window,
501506 self.view_size,
502507 self.scale.fractional_scale(),
503508 self.clock.clone(),
504509 self.options.clone(),
505- );
506- tile.unfullscreen_to_floating = is_floating;
507-
508- // If the tile is pending fullscreen, open it in the scrolling layout where it can go
509- // fullscreen.
510- if is_floating && !tile.window().is_pending_fullscreen() {
511- self.add_floating_tile(tile, activate);
512- } else {
513- self.add_tile(None, tile, activate, width, is_full_width);
514- }
510+ )
515511 }
516512
517513 pub fn add_tile(
518514 &mut self,
519- col_idx: Option<usize>,
520- tile: Tile<W>,
521- activate: bool,
515+ mut tile: Tile<W>,
516+ target: WorkspaceAddWindowTarget<W>,
517+ activate: ActivateWindow,
522518 width: ColumnWidth,
523519 is_full_width: bool,
520+ is_floating: bool,
524521 ) {
525522 self.enter_output_for_window(tile.window());
526- self.scrolling
527- .add_tile(col_idx, tile, activate, width, is_full_width, None);
523+ tile.unfullscreen_to_floating = is_floating;
528524
529- if activate {
530- self.floating_is_active = FloatingActive::No;
531- }
532- }
525+ match target {
526+ WorkspaceAddWindowTarget::Auto => {
527+ // Don't steal focus from an active fullscreen window.
528+ let activate = activate.map_smart(|| !self.is_active_fullscreen());
533529
534- pub fn add_floating_tile(&mut self, tile: Tile<W>, activate: bool) {
535- self.enter_output_for_window(tile.window());
536- self.floating.add_tile(tile, activate);
530+ // If the tile is pending fullscreen, open it in the scrolling layout where it can
531+ // go fullscreen.
532+ if is_floating && !tile.window().is_pending_fullscreen() {
533+ self.floating.add_tile(tile, activate);
537534
538- if activate || self.scrolling.is_empty() {
539- self.floating_is_active = FloatingActive::Yes;
535+ if activate || self.scrolling.is_empty() {
536+ self.floating_is_active = FloatingActive::Yes;
537+ }
538+ } else {
539+ self.scrolling
540+ .add_tile(None, tile, activate, width, is_full_width, None);
541+
542+ if activate {
543+ self.floating_is_active = FloatingActive::No;
544+ }
545+ }
546+ }
547+ WorkspaceAddWindowTarget::NewColumnAt(col_idx) => {
548+ let activate = activate.map_smart(|| false);
549+ self.scrolling
550+ .add_tile(Some(col_idx), tile, activate, width, is_full_width, None);
551+
552+ if activate {
553+ self.floating_is_active = FloatingActive::No;
554+ }
555+ }
556+ WorkspaceAddWindowTarget::NextTo(next_to) => {
557+ let activate = activate.map_smart(|| self.active_window().unwrap().id() == next_to);
558+
559+ let floating_has_window = self.floating.has_window(next_to);
560+ if is_floating || floating_has_window {
561+ if floating_has_window {
562+ self.floating.add_tile_above(next_to, tile, activate);
563+ } else {
564+ // FIXME: use static pos
565+ let (next_to_tile, render_pos) = self
566+ .scrolling
567+ .tiles_with_render_positions()
568+ .find(|(tile, _)| tile.window().id() == next_to)
569+ .unwrap();
570+
571+ // Position the new tile in the center above the next_to tile. Think a
572+ // dialog opening on top of a window.
573+ let tile_size = tile.tile_size();
574+ let pos = render_pos
575+ + (next_to_tile.tile_size().to_point() - tile_size.to_point())
576+ .downscale(2.);
577+ let pos = self.floating.clamp_within_working_area(pos, tile_size);
578+ let pos = self.floating.logical_to_size_frac(pos);
579+ tile.floating_pos = Some(pos);
580+
581+ self.floating.add_tile(tile, activate);
582+
583+ if activate {
584+ self.floating_is_active = FloatingActive::Yes;
585+ }
586+ }
587+ } else {
588+ self.scrolling
589+ .add_tile_right_of(next_to, tile, activate, width, is_full_width);
590+ }
591+
592+ // if is_floating && !tile.window().is_pending_fullscreen() {
593+ // if floating_has_window {
594+ // self.floating.add_tile_above(next_to, tile, activate);
595+ // } else {
596+ // // FIXME: use static pos
597+ // let (next_to_tile, render_pos) = self
598+ // .scrolling
599+ // .tiles_with_render_positions()
600+ // .find(|(tile, _)| tile.window().id() == next_to)
601+ // .unwrap();
602+ //
603+ // // Position the new tile in the center above the next_to tile. Think a
604+ // // dialog opening on top of a window.
605+ // let tile_size = tile.tile_size();
606+ // let pos = render_pos
607+ // + (next_to_tile.tile_size().to_point() - tile_size.to_point())
608+ // .downscale(2.);
609+ // let pos = self.floating.clamp_within_working_area(pos, tile_size);
610+ // let pos = self.floating.logical_to_size_frac(pos);
611+ // tile.floating_pos = Some(pos);
612+ //
613+ // self.floating.add_tile(tile, activate);
614+ // }
615+ //
616+ // if activate || self.scrolling.is_empty() {
617+ // self.floating_is_active = FloatingActive::Yes;
618+ // }
619+ // } else if floating_has_window {
620+ // self.scrolling
621+ // .add_tile(None, tile, activate, width, is_full_width, None);
622+ //
623+ // if activate {
624+ // self.floating_is_active = FloatingActive::No;
625+ // }
626+ // } else {
627+ // self.scrolling
628+ // .add_tile_right_of(next_to, tile, activate, width, is_full_width);
629+ //
630+ // if activate {
631+ // self.floating_is_active = FloatingActive::No;
632+ // }
633+ // }
634+ }
540635 }
541636 }
542637
@@ -556,70 +651,6 @@ impl<W: LayoutElement> Workspace<W> {
556651 }
557652 }
558653
559- pub fn add_window_right_of(
560- &mut self,
561- right_of: &W::Id,
562- window: W,
563- width: ColumnWidth,
564- is_full_width: bool,
565- // TODO: smarter enum, so you can override is_floating = false for floating right_of.
566- is_floating: bool,
567- ) {
568- let mut tile = Tile::new(
569- window,
570- self.view_size,
571- self.scale.fractional_scale(),
572- self.clock.clone(),
573- self.options.clone(),
574- );
575- tile.unfullscreen_to_floating = is_floating;
576- self.add_tile_right_of(right_of, tile, width, is_full_width, is_floating);
577- }
578-
579- pub fn add_tile_right_of(
580- &mut self,
581- right_of: &W::Id,
582- mut tile: Tile<W>,
583- width: ColumnWidth,
584- is_full_width: bool,
585- is_floating: bool,
586- ) {
587- self.enter_output_for_window(tile.window());
588-
589- // TODO: open-fullscreen into scrolling.
590- let floating_has_window = self.floating.has_window(right_of);
591- if is_floating || floating_has_window {
592- if floating_has_window {
593- self.floating.add_tile_above(right_of, tile);
594- } else {
595- let activate = self.scrolling.active_window().unwrap().id() == right_of;
596- // FIXME: use static pos
597- let (right_of_tile, render_pos) = self
598- .scrolling
599- .tiles_with_render_positions()
600- .find(|(tile, _)| tile.window().id() == right_of)
601- .unwrap();
602-
603- // Position the new tile in the center above the right_of tile. Think a dialog
604- // opening on top of a window.
605- let tile_size = tile.tile_size();
606- let pos = render_pos
607- + (right_of_tile.tile_size().to_point() - tile_size.to_point()).downscale(2.);
608- let pos = self.floating.clamp_within_working_area(pos, tile_size);
609- let pos = self.floating.logical_to_size_frac(pos);
610- tile.floating_pos = Some(pos);
611-
612- self.floating.add_tile(tile, activate);
613- if activate {
614- self.floating_is_active = FloatingActive::Yes;
615- }
616- }
617- } else {
618- self.scrolling
619- .add_tile_right_of(right_of, tile, width, is_full_width);
620- }
621- }
622-
623654 pub fn add_column(&mut self, column: Column<W>, activate: bool) {
624655 for (tile, _) in column.tiles() {
625656 self.enter_output_for_window(tile.window());
@@ -702,10 +733,12 @@ impl<W: LayoutElement> Workspace<W> {
702733 pub fn resolve_default_width(
703734 &self,
704735 default_width: Option<Option<ColumnWidth>>,
736+ is_floating: bool,
705737 ) -> Option<ColumnWidth> {
706738 match default_width {
707739 Some(Some(width)) => Some(width),
708740 Some(None) => None,
741+ None if is_floating => None,
709742 None => self.options.default_column_width,
710743 }
711744 }