Implement interactive move to a new workspace above/between
Browse files at this commit1835b532d92a98808ea2e2568fa9b899c8b24b35Parent: e6d82d33 changed files +308 -104
- src/layout/mod.rs +125 -75
- src/layout/monitor.rs +171 -29
- src/niri.rs +12 -0
src/layout/mod.rsmodified+125 -75
| @@ -37,7 +37,7 @@ use std::mem; | |||
| 37 | use std::rc::Rc; | 37 | use std::rc::Rc; |
| 38 | use std::time::Duration; | 38 | use std::time::Duration; |
| 39 | 39 | ||
| 40 | -use monitor::{InsertHint, InsertPosition, MonitorAddWindowTarget}; | 40 | +use monitor::{InsertHint, InsertPosition, InsertWorkspace, MonitorAddWindowTarget}; |
| 41 | use niri_config::{ | 41 | use niri_config::{ |
| 42 | CenterFocusedColumn, Config, CornerRadius, FloatOrInt, PresetSize, Struts, | 42 | CenterFocusedColumn, Config, CornerRadius, FloatOrInt, PresetSize, Struts, |
| 43 | Workspace as WorkspaceConfig, WorkspaceReference, | 43 | Workspace as WorkspaceConfig, WorkspaceReference, |
| @@ -3031,40 +3031,51 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3031 | return; | 3031 | return; |
| 3032 | } | 3032 | } |
| 3033 | 3033 | ||
| 3034 | - // No insert hint when targeting floating. | ||
| 3035 | - if move_.is_floating { | ||
| 3036 | - self.interactive_move = Some(InteractiveMoveState::Moving(move_)); | ||
| 3037 | - return; | ||
| 3038 | - } | ||
| 3039 | - | ||
| 3040 | let _span = tracy_client::span!("Layout::update_insert_hint::update"); | 3034 | let _span = tracy_client::span!("Layout::update_insert_hint::update"); |
| 3041 | 3035 | ||
| 3042 | if let Some(mon) = self.monitor_for_output_mut(&move_.output) { | 3036 | if let Some(mon) = self.monitor_for_output_mut(&move_.output) { |
| 3043 | let zoom = mon.overview_zoom(); | 3037 | let zoom = mon.overview_zoom(); |
| 3044 | - if let Some((ws, geo)) = mon.workspace_under(move_.pointer_pos_within_output) { | 3038 | + let (insert_ws, geo) = mon.insert_position(move_.pointer_pos_within_output); |
| 3045 | - let ws_id = ws.id(); | 3039 | + match insert_ws { |
| 3046 | - let ws = mon | 3040 | + InsertWorkspace::Existing(ws_id) => { |
| 3047 | - .workspaces | 3041 | + let ws = mon |
| 3048 | - .iter_mut() | 3042 | + .workspaces |
| 3049 | - .find(|ws| ws.id() == ws_id) | 3043 | + .iter_mut() |
| 3050 | - .unwrap(); | 3044 | + .find(|ws| ws.id() == ws_id) |
| 3051 | - let pos_within_workspace = | 3045 | + .unwrap(); |
| 3052 | - (move_.pointer_pos_within_output - geo.loc).downscale(zoom); | 3046 | + let pos_within_workspace = |
| 3053 | - let position = ws.scrolling_insert_position(pos_within_workspace); | 3047 | + (move_.pointer_pos_within_output - geo.loc).downscale(zoom); |
| 3054 | - | 3048 | + let position = if move_.is_floating { |
| 3055 | - let rules = move_.tile.window().rules(); | 3049 | + InsertPosition::Floating |
| 3056 | - let border_width = move_.tile.effective_border_width().unwrap_or(0.); | 3050 | + } else { |
| 3057 | - let corner_radius = rules | 3051 | + ws.scrolling_insert_position(pos_within_workspace) |
| 3058 | - .geometry_corner_radius | 3052 | + }; |
| 3059 | - .map_or(CornerRadius::default(), |radius| { | ||
| 3060 | - radius.expanded_by(border_width as f32) | ||
| 3061 | - }); | ||
| 3062 | 3053 | ||
| 3063 | - mon.insert_hint = Some(InsertHint { | 3054 | + let rules = move_.tile.window().rules(); |
| 3064 | - workspace: ws_id, | 3055 | + let border_width = move_.tile.effective_border_width().unwrap_or(0.); |
| 3065 | - position, | 3056 | + let corner_radius = rules |
| 3066 | - corner_radius, | 3057 | + .geometry_corner_radius |
| 3067 | - }); | 3058 | + .map_or(CornerRadius::default(), |radius| { |
| 3059 | + radius.expanded_by(border_width as f32) | ||
| 3060 | + }); | ||
| 3061 | + mon.insert_hint = Some(InsertHint { | ||
| 3062 | + workspace: insert_ws, | ||
| 3063 | + position, | ||
| 3064 | + corner_radius, | ||
| 3065 | + }); | ||
| 3066 | + } | ||
| 3067 | + InsertWorkspace::NewAt(_) => { | ||
| 3068 | + let position = if move_.is_floating { | ||
| 3069 | + InsertPosition::Floating | ||
| 3070 | + } else { | ||
| 3071 | + InsertPosition::NewColumn(0) | ||
| 3072 | + }; | ||
| 3073 | + mon.insert_hint = Some(InsertHint { | ||
| 3074 | + workspace: insert_ws, | ||
| 3075 | + position, | ||
| 3076 | + corner_radius: CornerRadius::default(), | ||
| 3077 | + }); | ||
| 3078 | + } | ||
| 3068 | } | 3079 | } |
| 3069 | } | 3080 | } |
| 3070 | 3081 | ||
| @@ -4393,59 +4404,81 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4393 | active_monitor_idx, | 4404 | active_monitor_idx, |
| 4394 | .. | 4405 | .. |
| 4395 | } => { | 4406 | } => { |
| 4396 | - let (mon, ws_idx, position, offset, zoom) = if let Some(mon) = | 4407 | + let (mon, insert_ws, position, offset, zoom) = |
| 4397 | - monitors.iter_mut().find(|mon| mon.output == move_.output) | 4408 | + if let Some(mon) = monitors.iter_mut().find(|mon| mon.output == move_.output) { |
| 4398 | - { | 4409 | + let zoom = mon.overview_zoom(); |
| 4399 | - let zoom = mon.overview_zoom(); | 4410 | + |
| 4411 | + let (insert_ws, geo) = mon.insert_position(move_.pointer_pos_within_output); | ||
| 4412 | + let (position, offset) = match insert_ws { | ||
| 4413 | + InsertWorkspace::Existing(ws_id) => { | ||
| 4414 | + let ws_idx = mon | ||
| 4415 | + .workspaces | ||
| 4416 | + .iter_mut() | ||
| 4417 | + .position(|ws| ws.id() == ws_id) | ||
| 4418 | + .unwrap(); | ||
| 4400 | 4419 | ||
| 4401 | - let (ws, ws_geo) = mon | 4420 | + let position = if move_.is_floating { |
| 4402 | - .workspace_under(move_.pointer_pos_within_output) | 4421 | + InsertPosition::Floating |
| 4403 | - // If the pointer is somehow outside the move output and a workspace switch | 4422 | + } else { |
| 4404 | - // is in progress, this won't necessarily do the expected thing. | 4423 | + let pos_within_workspace = |
| 4405 | - .unwrap_or_else(|| mon.workspaces_with_render_geo().next().unwrap()); | 4424 | + (move_.pointer_pos_within_output - geo.loc).downscale(zoom); |
| 4425 | + let ws = &mut mon.workspaces[ws_idx]; | ||
| 4426 | + ws.scrolling_insert_position(pos_within_workspace) | ||
| 4427 | + }; | ||
| 4406 | 4428 | ||
| 4407 | - let ws_id = ws.id(); | 4429 | + (position, Some(geo.loc)) |
| 4408 | - let ws_idx = mon | 4430 | + } |
| 4409 | - .workspaces | 4431 | + InsertWorkspace::NewAt(_) => { |
| 4410 | - .iter_mut() | 4432 | + let position = if move_.is_floating { |
| 4411 | - .position(|ws| ws.id() == ws_id) | 4433 | + InsertPosition::Floating |
| 4412 | - .unwrap(); | 4434 | + } else { |
| 4435 | + InsertPosition::NewColumn(0) | ||
| 4436 | + }; | ||
| 4413 | 4437 | ||
| 4414 | - let position = if move_.is_floating { | 4438 | + (position, None) |
| 4415 | - InsertPosition::Floating | 4439 | + } |
| 4440 | + }; | ||
| 4441 | + | ||
| 4442 | + (mon, insert_ws, position, offset, zoom) | ||
| 4416 | } else { | 4443 | } else { |
| 4417 | - let pos_within_workspace = | 4444 | + let mon = &mut monitors[*active_monitor_idx]; |
| 4418 | - (move_.pointer_pos_within_output - ws_geo.loc).downscale(zoom); | 4445 | + let zoom = mon.overview_zoom(); |
| 4419 | - let ws = &mut mon.workspaces[ws_idx]; | 4446 | + // No point in trying to use the pointer position on the wrong output. |
| 4420 | - ws.scrolling_insert_position(pos_within_workspace) | 4447 | + let (ws, ws_geo) = mon.workspaces_with_render_geo().next().unwrap(); |
| 4421 | - }; | ||
| 4422 | 4448 | ||
| 4423 | - (mon, ws_idx, position, ws_geo.loc, zoom) | 4449 | + let position = if move_.is_floating { |
| 4424 | - } else { | 4450 | + InsertPosition::Floating |
| 4425 | - let mon = &mut monitors[*active_monitor_idx]; | 4451 | + } else { |
| 4426 | - let zoom = mon.overview_zoom(); | 4452 | + ws.scrolling_insert_position(Point::from((0., 0.))) |
| 4427 | - // No point in trying to use the pointer position on the wrong output. | 4453 | + }; |
| 4428 | - let (ws, ws_geo) = mon.workspaces_with_render_geo().next().unwrap(); | ||
| 4429 | 4454 | ||
| 4430 | - let position = if move_.is_floating { | 4455 | + let insert_ws = InsertWorkspace::Existing(ws.id()); |
| 4431 | - InsertPosition::Floating | 4456 | + (mon, insert_ws, position, Some(ws_geo.loc), zoom) |
| 4432 | - } else { | ||
| 4433 | - ws.scrolling_insert_position(Point::from((0., 0.))) | ||
| 4434 | }; | 4457 | }; |
| 4435 | 4458 | ||
| 4436 | - let ws_id = ws.id(); | 4459 | + let win_id = move_.tile.window().id().clone(); |
| 4437 | - let ws_idx = mon | 4460 | + let window_render_loc = move_.tile_render_location(zoom) + move_.tile.window_loc(); |
| 4461 | + | ||
| 4462 | + let ws_idx = match insert_ws { | ||
| 4463 | + InsertWorkspace::Existing(ws_id) => mon | ||
| 4438 | .workspaces | 4464 | .workspaces |
| 4439 | - .iter_mut() | 4465 | + .iter() |
| 4440 | .position(|ws| ws.id() == ws_id) | 4466 | .position(|ws| ws.id() == ws_id) |
| 4441 | - .unwrap(); | 4467 | + .unwrap(), |
| 4442 | - | 4468 | + InsertWorkspace::NewAt(ws_idx) => { |
| 4443 | - (mon, ws_idx, position, ws_geo.loc, zoom) | 4469 | + if self.options.empty_workspace_above_first && ws_idx == 0 { |
| 4470 | + // Reuse the top empty workspace. | ||
| 4471 | + 0 | ||
| 4472 | + } else if mon.workspaces.len() - 1 <= ws_idx { | ||
| 4473 | + // Reuse the bottom empty workspace. | ||
| 4474 | + mon.workspaces.len() - 1 | ||
| 4475 | + } else { | ||
| 4476 | + mon.add_workspace_at(ws_idx); | ||
| 4477 | + ws_idx | ||
| 4478 | + } | ||
| 4479 | + } | ||
| 4444 | }; | 4480 | }; |
| 4445 | 4481 | ||
| 4446 | - let win_id = move_.tile.window().id().clone(); | ||
| 4447 | - let window_render_loc = move_.tile_render_location(zoom) + move_.tile.window_loc(); | ||
| 4448 | - | ||
| 4449 | match position { | 4482 | match position { |
| 4450 | InsertPosition::NewColumn(column_idx) => { | 4483 | InsertPosition::NewColumn(column_idx) => { |
| 4451 | let ws_id = mon.workspaces[ws_idx].id(); | 4484 | let ws_id = mon.workspaces[ws_idx].id(); |
| @@ -4474,10 +4507,27 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4474 | let tile_render_loc = move_.tile_render_location(zoom); | 4507 | let tile_render_loc = move_.tile_render_location(zoom); |
| 4475 | 4508 | ||
| 4476 | let mut tile = move_.tile; | 4509 | let mut tile = move_.tile; |
| 4477 | - | 4510 | + tile.floating_pos = None; |
| 4478 | - let pos = (tile_render_loc - offset).downscale(zoom); | 4511 | + |
| 4479 | - let pos = mon.workspaces[ws_idx].floating_logical_to_size_frac(pos); | 4512 | + match insert_ws { |
| 4480 | - tile.floating_pos = Some(pos); | 4513 | + InsertWorkspace::Existing(_) => { |
| 4514 | + if let Some(offset) = offset { | ||
| 4515 | + let pos = (tile_render_loc - offset).downscale(zoom); | ||
| 4516 | + let pos = | ||
| 4517 | + mon.workspaces[ws_idx].floating_logical_to_size_frac(pos); | ||
| 4518 | + tile.floating_pos = Some(pos); | ||
| 4519 | + } else { | ||
| 4520 | + error!( | ||
| 4521 | + "offset unset for inserting a floating tile \ | ||
| 4522 | + to existing workspace" | ||
| 4523 | + ); | ||
| 4524 | + } | ||
| 4525 | + } | ||
| 4526 | + InsertWorkspace::NewAt(_) => { | ||
| 4527 | + // When putting a floating tile on a new workspace, we don't really | ||
| 4528 | + // have a good pre-existing position. | ||
| 4529 | + } | ||
| 4530 | + } | ||
| 4481 | 4531 | ||
| 4482 | // Set the floating size so it takes into account any window resizing that | 4532 | // Set the floating size so it takes into account any window resizing that |
| 4483 | // took place during the move. | 4533 | // took place during the move. |
src/layout/monitor.rsmodified+171 -29
| @@ -127,16 +127,22 @@ pub(super) enum InsertPosition { | |||
| 127 | Floating, | 127 | Floating, |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 131 | +pub(super) enum InsertWorkspace { | ||
| 132 | + Existing(WorkspaceId), | ||
| 133 | + NewAt(usize), | ||
| 134 | +} | ||
| 135 | + | ||
| 130 | #[derive(Debug)] | 136 | #[derive(Debug)] |
| 131 | pub(super) struct InsertHint { | 137 | pub(super) struct InsertHint { |
| 132 | - pub workspace: WorkspaceId, | 138 | + pub workspace: InsertWorkspace, |
| 133 | pub position: InsertPosition, | 139 | pub position: InsertPosition, |
| 134 | pub corner_radius: CornerRadius, | 140 | pub corner_radius: CornerRadius, |
| 135 | } | 141 | } |
| 136 | 142 | ||
| 137 | #[derive(Debug, Clone, Copy)] | 143 | #[derive(Debug, Clone, Copy)] |
| 138 | struct InsertHintRenderLoc { | 144 | struct InsertHintRenderLoc { |
| 139 | - workspace: WorkspaceId, | 145 | + workspace: InsertWorkspace, |
| 140 | location: Point<f64, Logical>, | 146 | location: Point<f64, Logical>, |
| 141 | } | 147 | } |
| 142 | 148 | ||
| @@ -167,6 +173,7 @@ niri_render_elements! { | |||
| 167 | MonitorInnerRenderElement<R> => { | 173 | MonitorInnerRenderElement<R> => { |
| 168 | Workspace = CropRenderElement<WorkspaceRenderElement<R>>, | 174 | Workspace = CropRenderElement<WorkspaceRenderElement<R>>, |
| 169 | InsertHint = CropRenderElement<InsertHintRenderElement>, | 175 | InsertHint = CropRenderElement<InsertHintRenderElement>, |
| 176 | + UncroppedInsertHint = InsertHintRenderElement, | ||
| 170 | Shadow = ShadowRenderElement, | 177 | Shadow = ShadowRenderElement, |
| 171 | } | 178 | } |
| 172 | } | 179 | } |
| @@ -231,6 +238,15 @@ impl WorkspaceSwitchGesture { | |||
| 231 | } | 238 | } |
| 232 | } | 239 | } |
| 233 | 240 | ||
| 241 | +impl InsertWorkspace { | ||
| 242 | + fn existing_id(self) -> Option<WorkspaceId> { | ||
| 243 | + match self { | ||
| 244 | + InsertWorkspace::Existing(id) => Some(id), | ||
| 245 | + InsertWorkspace::NewAt(_) => None, | ||
| 246 | + } | ||
| 247 | + } | ||
| 248 | +} | ||
| 249 | + | ||
| 234 | impl OverviewProgress { | 250 | impl OverviewProgress { |
| 235 | pub fn value(&self) -> f64 { | 251 | pub fn value(&self) -> f64 { |
| 236 | match self { | 252 | match self { |
| @@ -885,7 +901,10 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 885 | 901 | ||
| 886 | pub fn update_render_elements(&mut self, is_active: bool) { | 902 | pub fn update_render_elements(&mut self, is_active: bool) { |
| 887 | let mut insert_hint_ws_geo = None; | 903 | let mut insert_hint_ws_geo = None; |
| 888 | - let insert_hint_ws_id = self.insert_hint.as_ref().map(|hint| hint.workspace); | 904 | + let insert_hint_ws_id = self |
| 905 | + .insert_hint | ||
| 906 | + .as_ref() | ||
| 907 | + .and_then(|hint| hint.workspace.existing_id()); | ||
| 889 | 908 | ||
| 890 | for (ws, geo) in self.workspaces_with_render_geo_mut() { | 909 | for (ws, geo) in self.workspaces_with_render_geo_mut() { |
| 891 | ws.update_render_elements(is_active); | 910 | ws.update_render_elements(is_active); |
| @@ -897,38 +916,75 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 897 | 916 | ||
| 898 | self.insert_hint_render_loc = None; | 917 | self.insert_hint_render_loc = None; |
| 899 | if let Some(hint) = &self.insert_hint { | 918 | if let Some(hint) = &self.insert_hint { |
| 900 | - if let Some(ws) = self.workspaces.iter().find(|ws| ws.id() == hint.workspace) { | 919 | + match hint.workspace { |
| 901 | - if let Some(mut area) = ws.insert_hint_area(hint.position) { | 920 | + InsertWorkspace::Existing(ws_id) => { |
| 902 | - let scale = ws.scale().fractional_scale(); | 921 | + if let Some(ws) = self.workspaces.iter().find(|ws| ws.id() == ws_id) { |
| 903 | - let view_size = ws.view_size(); | 922 | + if let Some(mut area) = ws.insert_hint_area(hint.position) { |
| 904 | - | 923 | + let scale = ws.scale().fractional_scale(); |
| 905 | - // Make sure the hint is at least partially visible. | 924 | + let view_size = ws.view_size(); |
| 906 | - if matches!(hint.position, InsertPosition::NewColumn(_)) { | 925 | + |
| 907 | - let zoom = self.overview_zoom(); | 926 | + // Make sure the hint is at least partially visible. |
| 908 | - let geo = insert_hint_ws_geo.unwrap(); | 927 | + if matches!(hint.position, InsertPosition::NewColumn(_)) { |
| 909 | - let geo = geo.downscale(zoom); | 928 | + let zoom = self.overview_zoom(); |
| 910 | - | 929 | + let geo = insert_hint_ws_geo.unwrap(); |
| 911 | - area.loc.x = area.loc.x.max(-geo.loc.x - area.size.w / 2.); | 930 | + let geo = geo.downscale(zoom); |
| 912 | - area.loc.x = area.loc.x.min(geo.loc.x + geo.size.w - area.size.w / 2.); | 931 | + |
| 932 | + area.loc.x = area.loc.x.max(-geo.loc.x - area.size.w / 2.); | ||
| 933 | + area.loc.x = | ||
| 934 | + area.loc.x.min(geo.loc.x + geo.size.w - area.size.w / 2.); | ||
| 935 | + } | ||
| 936 | + | ||
| 937 | + // Round to physical pixels. | ||
| 938 | + area = area.to_physical_precise_round(scale).to_logical(scale); | ||
| 939 | + | ||
| 940 | + let view_rect = Rectangle::new(area.loc.upscale(-1.), view_size); | ||
| 941 | + self.insert_hint_element.update_render_elements( | ||
| 942 | + area.size, | ||
| 943 | + view_rect, | ||
| 944 | + hint.corner_radius, | ||
| 945 | + scale, | ||
| 946 | + ); | ||
| 947 | + self.insert_hint_render_loc = Some(InsertHintRenderLoc { | ||
| 948 | + workspace: hint.workspace, | ||
| 949 | + location: area.loc, | ||
| 950 | + }); | ||
| 951 | + } | ||
| 952 | + } else { | ||
| 953 | + error!("insert hint workspace missing from monitor"); | ||
| 913 | } | 954 | } |
| 955 | + } | ||
| 956 | + InsertWorkspace::NewAt(ws_idx) => { | ||
| 957 | + let scale = self.scale.fractional_scale(); | ||
| 958 | + let zoom = self.overview_zoom(); | ||
| 959 | + let gap = self.workspace_gap(zoom); | ||
| 960 | + | ||
| 961 | + let hint_gap = round_logical_in_physical(scale, gap * 0.1); | ||
| 962 | + let hint_height = gap - hint_gap * 2.; | ||
| 914 | 963 | ||
| 915 | - // Round to physical pixels. | 964 | + let next_ws_geo = self.workspaces_render_geo().nth(ws_idx).unwrap(); |
| 916 | - area = area.to_physical_precise_round(scale).to_logical(scale); | 965 | + let hint_loc_diff = Point::from((0., hint_height + hint_gap)); |
| 966 | + let hint_loc = next_ws_geo.loc - hint_loc_diff; | ||
| 967 | + let hint_size = Size::from((next_ws_geo.size.w, hint_height)); | ||
| 968 | + | ||
| 969 | + // FIXME: sometimes the hint ends up 1 px wider than necessary and/or 1 px | ||
| 970 | + // narrower than necessary. The values here seem correct. Might have to do with | ||
| 971 | + // how zooming out currently doesn't round to output scale properly. | ||
| 972 | + | ||
| 973 | + // Compute view rect as if we're above the next workspace (rather than below | ||
| 974 | + // the previous one). | ||
| 975 | + let view_rect = Rectangle::new(hint_loc_diff, next_ws_geo.size); | ||
| 917 | 976 | ||
| 918 | - let view_rect = Rectangle::new(area.loc.upscale(-1.), view_size); | ||
| 919 | self.insert_hint_element.update_render_elements( | 977 | self.insert_hint_element.update_render_elements( |
| 920 | - area.size, | 978 | + hint_size, |
| 921 | view_rect, | 979 | view_rect, |
| 922 | - hint.corner_radius, | 980 | + CornerRadius::default(), |
| 923 | scale, | 981 | scale, |
| 924 | ); | 982 | ); |
| 925 | self.insert_hint_render_loc = Some(InsertHintRenderLoc { | 983 | self.insert_hint_render_loc = Some(InsertHintRenderLoc { |
| 926 | workspace: hint.workspace, | 984 | workspace: hint.workspace, |
| 927 | - location: area.loc, | 985 | + location: hint_loc, |
| 928 | }); | 986 | }); |
| 929 | } | 987 | } |
| 930 | - } else { | ||
| 931 | - error!("insert hint workspace missing from monitor"); | ||
| 932 | } | 988 | } |
| 933 | } | 989 | } |
| 934 | } | 990 | } |
| @@ -1239,6 +1295,17 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1239 | .filter(move |(_ws, geo)| geo.intersection(output_geo).is_some()) | 1295 | .filter(move |(_ws, geo)| geo.intersection(output_geo).is_some()) |
| 1240 | } | 1296 | } |
| 1241 | 1297 | ||
| 1298 | + pub fn workspaces_with_render_geo_idx( | ||
| 1299 | + &self, | ||
| 1300 | + ) -> impl Iterator<Item = ((usize, &Workspace<W>), Rectangle<f64, Logical>)> { | ||
| 1301 | + let output_geo = Rectangle::from_size(self.view_size); | ||
| 1302 | + | ||
| 1303 | + let geo = self.workspaces_render_geo(); | ||
| 1304 | + zip(self.workspaces.iter().enumerate(), geo) | ||
| 1305 | + // Cull out workspaces outside the output. | ||
| 1306 | + .filter(move |(_ws, geo)| geo.intersection(output_geo).is_some()) | ||
| 1307 | + } | ||
| 1308 | + | ||
| 1242 | pub fn workspaces_with_render_geo_mut( | 1309 | pub fn workspaces_with_render_geo_mut( |
| 1243 | &mut self, | 1310 | &mut self, |
| 1244 | ) -> impl Iterator<Item = (&mut Workspace<W>, Rectangle<f64, Logical>)> { | 1311 | ) -> impl Iterator<Item = (&mut Workspace<W>, Rectangle<f64, Logical>)> { |
| @@ -1298,6 +1365,55 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1298 | ws.resize_edges_under(pos_within_output - geo.loc) | 1365 | ws.resize_edges_under(pos_within_output - geo.loc) |
| 1299 | } | 1366 | } |
| 1300 | 1367 | ||
| 1368 | + pub(super) fn insert_position( | ||
| 1369 | + &self, | ||
| 1370 | + pos_within_output: Point<f64, Logical>, | ||
| 1371 | + ) -> (InsertWorkspace, Rectangle<f64, Logical>) { | ||
| 1372 | + let mut iter = self.workspaces_with_render_geo_idx(); | ||
| 1373 | + | ||
| 1374 | + let dummy = Rectangle::default(); | ||
| 1375 | + | ||
| 1376 | + // Monitors always have at least one workspace. | ||
| 1377 | + let ((idx, ws), geo) = iter.next().unwrap(); | ||
| 1378 | + | ||
| 1379 | + // Check if above first. | ||
| 1380 | + if pos_within_output.y < geo.loc.y { | ||
| 1381 | + return (InsertWorkspace::NewAt(idx), dummy); | ||
| 1382 | + } | ||
| 1383 | + | ||
| 1384 | + let contains = move |geo: Rectangle<f64, Logical>| { | ||
| 1385 | + geo.loc.y <= pos_within_output.y && pos_within_output.y < geo.loc.y + geo.size.h | ||
| 1386 | + }; | ||
| 1387 | + | ||
| 1388 | + // Check first. | ||
| 1389 | + if contains(geo) { | ||
| 1390 | + return (InsertWorkspace::Existing(ws.id()), geo); | ||
| 1391 | + } | ||
| 1392 | + | ||
| 1393 | + let mut last_geo = geo; | ||
| 1394 | + let mut last_idx = idx; | ||
| 1395 | + for ((idx, ws), geo) in iter { | ||
| 1396 | + // Check gap above. | ||
| 1397 | + let gap_loc = Point::from((last_geo.loc.x, last_geo.loc.y + last_geo.size.h)); | ||
| 1398 | + let gap_size = Size::from((geo.size.w, geo.loc.y - gap_loc.y)); | ||
| 1399 | + let gap_geo = Rectangle::new(gap_loc, gap_size); | ||
| 1400 | + if contains(gap_geo) { | ||
| 1401 | + return (InsertWorkspace::NewAt(idx), dummy); | ||
| 1402 | + } | ||
| 1403 | + | ||
| 1404 | + // Check workspace itself. | ||
| 1405 | + if contains(geo) { | ||
| 1406 | + return (InsertWorkspace::Existing(ws.id()), geo); | ||
| 1407 | + } | ||
| 1408 | + | ||
| 1409 | + last_geo = geo; | ||
| 1410 | + last_idx = idx; | ||
| 1411 | + } | ||
| 1412 | + | ||
| 1413 | + // Anything below. | ||
| 1414 | + (InsertWorkspace::NewAt(last_idx + 1), dummy) | ||
| 1415 | + } | ||
| 1416 | + | ||
| 1301 | pub fn render_above_top_layer(&self) -> bool { | 1417 | pub fn render_above_top_layer(&self) -> bool { |
| 1302 | // Render above the top layer only if the view is stationary. | 1418 | // Render above the top layer only if the view is stationary. |
| 1303 | if self.workspace_switch.is_some() || self.overview_progress.is_some() { | 1419 | if self.workspace_switch.is_some() || self.overview_progress.is_some() { |
| @@ -1308,6 +1424,30 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1308 | ws.render_above_top_layer() | 1424 | ws.render_above_top_layer() |
| 1309 | } | 1425 | } |
| 1310 | 1426 | ||
| 1427 | + pub fn render_insert_hint_between_workspaces<R: NiriRenderer>( | ||
| 1428 | + &self, | ||
| 1429 | + renderer: &mut R, | ||
| 1430 | + ) -> impl Iterator<Item = MonitorRenderElement<R>> { | ||
| 1431 | + let mut rv = None; | ||
| 1432 | + | ||
| 1433 | + if !self.options.insert_hint.off { | ||
| 1434 | + if let Some(render_loc) = self.insert_hint_render_loc { | ||
| 1435 | + if let InsertWorkspace::NewAt(_) = render_loc.workspace { | ||
| 1436 | + let iter = self | ||
| 1437 | + .insert_hint_element | ||
| 1438 | + .render(renderer, render_loc.location) | ||
| 1439 | + .map(MonitorInnerRenderElement::UncroppedInsertHint); | ||
| 1440 | + rv = Some(iter); | ||
| 1441 | + } | ||
| 1442 | + } | ||
| 1443 | + } | ||
| 1444 | + | ||
| 1445 | + rv.into_iter().flatten().map(|elem| { | ||
| 1446 | + let elem = RescaleRenderElement::from_element(elem, Point::default(), 1.); | ||
| 1447 | + RelocateRenderElement::from_element(elem, Point::default(), Relocate::Relative) | ||
| 1448 | + }) | ||
| 1449 | + } | ||
| 1450 | + | ||
| 1311 | pub fn render_elements<'a, R: NiriRenderer>( | 1451 | pub fn render_elements<'a, R: NiriRenderer>( |
| 1312 | &'a self, | 1452 | &'a self, |
| 1313 | renderer: &'a mut R, | 1453 | renderer: &'a mut R, |
| @@ -1354,11 +1494,13 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1354 | let mut insert_hint = None; | 1494 | let mut insert_hint = None; |
| 1355 | if !self.options.insert_hint.off { | 1495 | if !self.options.insert_hint.off { |
| 1356 | if let Some(render_loc) = self.insert_hint_render_loc { | 1496 | if let Some(render_loc) = self.insert_hint_render_loc { |
| 1357 | - insert_hint = Some(( | 1497 | + if let InsertWorkspace::Existing(workspace_id) = render_loc.workspace { |
| 1358 | - render_loc.workspace, | 1498 | + insert_hint = Some(( |
| 1359 | - self.insert_hint_element | 1499 | + workspace_id, |
| 1360 | - .render(renderer, render_loc.location), | 1500 | + self.insert_hint_element |
| 1361 | - )); | 1501 | + .render(renderer, render_loc.location), |
| 1502 | + )); | ||
| 1503 | + } | ||
| 1362 | } | 1504 | } |
| 1363 | } | 1505 | } |
| 1364 | 1506 | ||
src/niri.rsmodified+12 -0
| @@ -3971,6 +3971,7 @@ impl Niri { | |||
| 3971 | mon.render_elements(renderer, target, focus_ring) | 3971 | mon.render_elements(renderer, target, focus_ring) |
| 3972 | .map(|(geo, iter)| (geo, Vec::from_iter(iter))), | 3972 | .map(|(geo, iter)| (geo, Vec::from_iter(iter))), |
| 3973 | ); | 3973 | ); |
| 3974 | + let insert_hint_elements = mon.render_insert_hint_between_workspaces(renderer); | ||
| 3974 | let int_move_elements: Vec<_> = self | 3975 | let int_move_elements: Vec<_> = self |
| 3975 | .layout | 3976 | .layout |
| 3976 | .render_interactive_move_for_output(renderer, output, target) | 3977 | .render_interactive_move_for_output(renderer, output, target) |
| @@ -4006,6 +4007,11 @@ impl Niri { | |||
| 4006 | .into_iter() | 4007 | .into_iter() |
| 4007 | .map(OutputRenderElements::from), | 4008 | .map(OutputRenderElements::from), |
| 4008 | ); | 4009 | ); |
| 4010 | + elements.extend( | ||
| 4011 | + insert_hint_elements | ||
| 4012 | + .into_iter() | ||
| 4013 | + .map(OutputRenderElements::from), | ||
| 4014 | + ); | ||
| 4009 | elements.extend( | 4015 | elements.extend( |
| 4010 | monitor_elements | 4016 | monitor_elements |
| 4011 | .into_iter() | 4017 | .into_iter() |
| @@ -4027,6 +4033,12 @@ impl Niri { | |||
| 4027 | .map(OutputRenderElements::from), | 4033 | .map(OutputRenderElements::from), |
| 4028 | ); | 4034 | ); |
| 4029 | 4035 | ||
| 4036 | + elements.extend( | ||
| 4037 | + insert_hint_elements | ||
| 4038 | + .into_iter() | ||
| 4039 | + .map(OutputRenderElements::from), | ||
| 4040 | + ); | ||
| 4041 | + | ||
| 4030 | for (ws_geo, ws_elements) in monitor_elements { | 4042 | for (ws_geo, ws_elements) in monitor_elements { |
| 4031 | // Collect all other layer-shell elements. | 4043 | // Collect all other layer-shell elements. |
| 4032 | let mut layer_elems = SplitElements::default(); | 4044 | let mut layer_elems = SplitElements::default(); |