Skip to content

Commit db13eea

Browse files
committed
shell: Allow active workspace to be None
1 parent 23570ea commit db13eea

File tree

13 files changed

+230
-167
lines changed

13 files changed

+230
-167
lines changed

src/backend/kms/surface/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,11 @@ impl SurfaceThreadState {
943943
let has_active_fullscreen = {
944944
let shell = self.shell.read().unwrap();
945945
let output = self.mirroring.as_ref().unwrap_or(&self.output);
946-
shell.workspaces.active(output).1.get_fullscreen().is_some()
946+
if let Some((_, workspace)) = shell.workspaces.active(output) {
947+
workspace.get_fullscreen().is_some()
948+
} else {
949+
false
950+
}
947951
};
948952

949953
if self.vrr_mode == AdaptiveSync::Enabled {
@@ -1457,7 +1461,9 @@ fn render_node_for_output(
14571461
return *target_node;
14581462
}
14591463

1460-
let workspace = shell.active_space(output);
1464+
let Some(workspace) = shell.active_space(output) else {
1465+
return *target_node;
1466+
};
14611467
let nodes = workspace
14621468
.get_fullscreen()
14631469
.map(|w| vec![w.clone()])

src/backend/render/mod.rs

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,42 @@ where
516516
WorkspaceRenderElement<R>: RenderElement<R>,
517517
{
518518
let shell_guard = shell.read().unwrap();
519+
#[cfg(feature = "debug")]
520+
let mut debug_elements = {
521+
let output_geo = output.geometry();
522+
let seats = shell_guard.seats.iter().cloned().collect::<Vec<_>>();
523+
let scale = output.current_scale().fractional_scale();
524+
525+
if let Some((state, timings)) = _fps {
526+
let debug_active = shell_guard.debug_active;
527+
vec![fps_ui(
528+
_gpu,
529+
debug_active,
530+
&seats,
531+
renderer.glow_renderer_mut(),
532+
state,
533+
timings,
534+
Rectangle::from_loc_and_size(
535+
(0, 0),
536+
(output_geo.size.w.min(400), output_geo.size.h.min(800)),
537+
),
538+
scale,
539+
)
540+
.map_err(FromGlesError::from_gles_error)
541+
.map_err(RenderError::Rendering)?
542+
.into()]
543+
} else {
544+
Vec::new()
545+
}
546+
};
547+
548+
let Some((previous_workspace, workspace)) = shell_guard.workspaces.active(output) else {
549+
#[cfg(not(feature = "debug"))]
550+
return Ok(Vec::new());
551+
#[cfg(feature = "debug")]
552+
return Ok(debug_elements);
553+
};
519554

520-
let (previous_workspace, workspace) = shell_guard.workspaces.active(output);
521555
let (previous_idx, idx) = shell_guard.workspaces.active_num(&output);
522556
let previous_workspace = previous_workspace
523557
.zip(previous_idx)
@@ -532,7 +566,8 @@ where
532566
ElementFilter::All
533567
};
534568

535-
workspace_elements(
569+
#[allow(unused_mut)]
570+
let workspace_elements = workspace_elements(
536571
_gpu,
537572
renderer,
538573
shell,
@@ -542,8 +577,15 @@ where
542577
workspace,
543578
cursor_mode,
544579
element_filter,
545-
_fps,
546-
)
580+
)?;
581+
582+
#[cfg(feature = "debug")]
583+
{
584+
debug_elements.extend(workspace_elements);
585+
Ok(debug_elements)
586+
}
587+
#[cfg(not(feature = "debug"))]
588+
Ok(workspace_elements)
547589
}
548590

549591
#[profiling::function]
@@ -557,7 +599,6 @@ pub fn workspace_elements<R>(
557599
current: (WorkspaceHandle, usize),
558600
cursor_mode: CursorMode,
559601
element_filter: ElementFilter,
560-
_fps: Option<(&EguiState, &Timings)>,
561602
) -> Result<Vec<CosmicElement<R>>, RenderError<<R as Renderer>::Error>>
562603
where
563604
R: Renderer + ImportAll + ImportMem + AsGlowRenderer,
@@ -588,31 +629,6 @@ where
588629
element_filter == ElementFilter::ExcludeWorkspaceOverview,
589630
));
590631

591-
#[cfg(feature = "debug")]
592-
{
593-
let output_geo = output.geometry();
594-
595-
if let Some((state, timings)) = _fps {
596-
let debug_active = shell.read().unwrap().debug_active;
597-
let fps_overlay = fps_ui(
598-
_gpu,
599-
debug_active,
600-
&seats,
601-
renderer.glow_renderer_mut(),
602-
state,
603-
timings,
604-
Rectangle::from_loc_and_size(
605-
(0, 0),
606-
(output_geo.size.w.min(400), output_geo.size.h.min(800)),
607-
),
608-
scale,
609-
)
610-
.map_err(FromGlesError::from_gles_error)
611-
.map_err(RenderError::Rendering)?;
612-
elements.push(fps_overlay.into());
613-
}
614-
}
615-
616632
let shell = shell.read().unwrap();
617633

618634
let overview = shell.overview_mode();
@@ -933,7 +949,10 @@ where
933949
Target: Clone,
934950
{
935951
let shell_ref = shell.read().unwrap();
936-
let (previous_workspace, workspace) = shell_ref.workspaces.active(output);
952+
let (previous_workspace, workspace) = shell_ref
953+
.workspaces
954+
.active(output)
955+
.ok_or(RenderError::OutputNoMode(OutputNoMode))?;
937956
let (previous_idx, idx) = shell_ref.workspaces.active_num(output);
938957
let previous_workspace = previous_workspace
939958
.zip(previous_idx)
@@ -1099,7 +1118,6 @@ where
10991118
current,
11001119
cursor_mode,
11011120
element_filter,
1102-
None,
11031121
)?;
11041122

11051123
if let Some(additional_damage) = additional_damage {

src/input/actions.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ impl State {
408408
let new_target = shell
409409
.workspaces
410410
.active(&next_output)
411+
.unwrap()
411412
.1
412413
.focus_stack
413414
.get(&seat)
@@ -495,6 +496,7 @@ impl State {
495496
let new_target = shell
496497
.workspaces
497498
.active(&next_output)
499+
.unwrap()
498500
.1
499501
.focus_stack
500502
.get(&seat)
@@ -554,6 +556,7 @@ impl State {
554556
let new_target = shell
555557
.workspaces
556558
.active(&prev_output)
559+
.unwrap()
557560
.1
558561
.focus_stack
559562
.get(&seat)
@@ -765,7 +768,7 @@ impl State {
765768
.next()
766769
.cloned();
767770

768-
(shell.active_space(&active_output).handle, output)
771+
(shell.active_space(&active_output).unwrap().handle, output)
769772
};
770773
if let Some(next_output) = next_output {
771774
self.common
@@ -785,7 +788,7 @@ impl State {
785788
.next()
786789
.cloned();
787790

788-
(shell.active_space(&active_output).handle, output)
791+
(shell.active_space(&active_output).unwrap().handle, output)
789792
};
790793
if let Some(prev_output) = prev_output {
791794
self.common
@@ -799,7 +802,7 @@ impl State {
799802
let shell = self.common.shell.read().unwrap();
800803

801804
(
802-
shell.active_space(&active_output).handle,
805+
shell.active_space(&active_output).unwrap().handle,
803806
shell.next_output(&active_output, direction).cloned(),
804807
)
805808
};
@@ -865,7 +868,7 @@ impl State {
865868
_ => {
866869
let current_output = seat.active_output();
867870
let mut shell = self.common.shell.write().unwrap();
868-
let workspace = shell.active_space(&current_output);
871+
let workspace = shell.active_space(&current_output).unwrap();
869872
if let Some(focused_window) = workspace.focus_stack.get(seat).last() {
870873
if workspace.is_tiled(focused_window) {
871874
shell.set_overview_mode(
@@ -884,7 +887,7 @@ impl State {
884887
};
885888
let mut shell = self.common.shell.write().unwrap();
886889

887-
let workspace = shell.active_space_mut(&focused_output);
890+
let workspace = shell.active_space_mut(&focused_output).unwrap();
888891
if workspace.get_fullscreen().is_some() {
889892
return; // TODO, is this what we want? Maybe disengage fullscreen instead?
890893
}
@@ -909,7 +912,7 @@ impl State {
909912
return;
910913
};
911914
let mut shell = self.common.shell.write().unwrap();
912-
let workspace = shell.active_space_mut(&focused_output);
915+
let workspace = shell.active_space_mut(&focused_output).unwrap();
913916
let focus_stack = workspace.focus_stack.get(seat);
914917
let focused_window = focus_stack.last().cloned();
915918
if let Some(window) = focused_window {
@@ -922,7 +925,7 @@ impl State {
922925
return;
923926
};
924927
let mut shell = self.common.shell.write().unwrap();
925-
let workspace = shell.active_space(&focused_output);
928+
let workspace = shell.active_space(&focused_output).unwrap();
926929
let focus_stack = workspace.focus_stack.get(seat);
927930
let focused_window = focus_stack.last().cloned();
928931
if let Some(window) = focused_window {
@@ -940,14 +943,14 @@ impl State {
940943
Action::ToggleOrientation => {
941944
let output = seat.active_output();
942945
let mut shell = self.common.shell.write().unwrap();
943-
let workspace = shell.active_space_mut(&output);
946+
let workspace = shell.active_space_mut(&output).unwrap();
944947
workspace.tiling_layer.update_orientation(None, &seat);
945948
}
946949

947950
Action::Orientation(orientation) => {
948951
let output = seat.active_output();
949952
let mut shell = self.common.shell.write().unwrap();
950-
let workspace = shell.active_space_mut(&output);
953+
let workspace = shell.active_space_mut(&output).unwrap();
951954
workspace
952955
.tiling_layer
953956
.update_orientation(Some(orientation), &seat);
@@ -991,7 +994,7 @@ impl State {
991994
} else {
992995
let output = seat.active_output();
993996
let mut shell = self.common.shell.write().unwrap();
994-
let workspace = shell.workspaces.active_mut(&output);
997+
let workspace = shell.workspaces.active_mut(&output).unwrap();
995998
let mut guard = self.common.workspace_state.update();
996999
workspace.toggle_tiling(seat, &mut guard);
9971000
}
@@ -1002,7 +1005,7 @@ impl State {
10021005
return;
10031006
};
10041007
let mut shell = self.common.shell.write().unwrap();
1005-
let workspace = shell.active_space_mut(&output);
1008+
let workspace = shell.active_space_mut(&output).unwrap();
10061009
workspace.toggle_floating_window_focused(seat);
10071010
}
10081011

@@ -1035,7 +1038,7 @@ impl State {
10351038
let (token, data) = (token.clone(), data.clone());
10361039

10371040
let output = shell.seats.last_active().active_output();
1038-
let workspace = shell.active_space_mut(&output);
1041+
let workspace = shell.active_space_mut(&output).unwrap();
10391042
workspace.pending_tokens.insert(token.clone());
10401043
let handle = workspace.handle;
10411044
std::mem::drop(shell);

src/input/mod.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,8 +1760,12 @@ impl State {
17601760
focused_output: &Output,
17611761
) {
17621762
if let Some(focus) = current_focus {
1763-
if let Some(new_descriptor) =
1764-
shell.workspaces.active(&focused_output).1.node_desc(focus)
1763+
if let Some(new_descriptor) = shell
1764+
.workspaces
1765+
.active(&focused_output)
1766+
.unwrap()
1767+
.1
1768+
.node_desc(focus)
17651769
{
17661770
let mut spaces = shell.workspaces.spaces_mut();
17671771
if old_descriptor.handle != new_descriptor.handle {
@@ -1822,7 +1826,7 @@ impl State {
18221826
}
18231827
}
18241828
} else {
1825-
let new_workspace = shell.workspaces.active(&focused_output).1.handle;
1829+
let new_workspace = shell.workspaces.active(&focused_output).unwrap().1.handle;
18261830
if new_workspace != old_descriptor.handle {
18271831
let spaces = shell.workspaces.spaces_mut();
18281832
let (mut old_w, mut other_w) =
@@ -1867,7 +1871,7 @@ impl State {
18671871
output: &Output,
18681872
shell: &Shell,
18691873
) -> Option<KeyboardFocusTarget> {
1870-
let (previous_workspace, workspace) = shell.workspaces.active(output);
1874+
let (previous_workspace, workspace) = shell.workspaces.active(output)?;
18711875
let (previous_idx, idx) = shell.workspaces.active_num(output);
18721876
let previous_workspace = previous_workspace
18731877
.zip(previous_idx)
@@ -1990,7 +1994,7 @@ impl State {
19901994
output: &Output,
19911995
shell: &Shell,
19921996
) -> Option<(PointerFocusTarget, Point<f64, Global>)> {
1993-
let (previous_workspace, workspace) = shell.workspaces.active(output);
1997+
let (previous_workspace, workspace) = shell.workspaces.active(output)?;
19941998
let (previous_idx, idx) = shell.workspaces.active_num(output);
19951999
let previous_workspace = previous_workspace
19962000
.zip(previous_idx)
@@ -2122,22 +2126,26 @@ impl State {
21222126
}
21232127
}
21242128

2125-
fn cursor_sessions_for_output(
2126-
shell: &Shell,
2127-
output: &Output,
2128-
) -> impl Iterator<Item = CursorSession> {
2129-
let workspace = shell.active_space(&output);
2130-
let maybe_fullscreen = workspace.get_fullscreen();
2131-
workspace
2132-
.cursor_sessions()
2129+
fn cursor_sessions_for_output<'a>(
2130+
shell: &'a Shell,
2131+
output: &'a Output,
2132+
) -> impl Iterator<Item = CursorSession> + 'a {
2133+
shell
2134+
.active_space(&output)
21332135
.into_iter()
2134-
.chain(
2135-
maybe_fullscreen
2136-
.map(|w| w.cursor_sessions())
2136+
.flat_map(|workspace| {
2137+
let maybe_fullscreen = workspace.get_fullscreen();
2138+
workspace
2139+
.cursor_sessions()
21372140
.into_iter()
2138-
.flatten(),
2139-
)
2140-
.chain(output.cursor_sessions().into_iter())
2141+
.chain(
2142+
maybe_fullscreen
2143+
.map(|w| w.cursor_sessions())
2144+
.into_iter()
2145+
.flatten(),
2146+
)
2147+
.chain(output.cursor_sessions().into_iter())
2148+
})
21412149
}
21422150

21432151
fn transform_output_mapped_position<'a, B, E>(output: &Output, event: &E) -> Point<f64, Global>

0 commit comments

Comments
 (0)