-
-
Notifications
You must be signed in to change notification settings - Fork 662
Hidden workspaces #2997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Hidden workspaces #2997
Changes from all commits
2a10e2b
3e18de5
193f855
d82fcbc
187457a
afc8a94
a762c18
0cb2199
fd8d6ca
466c0cf
e9f6cd4
7d172b3
8c972b8
7410e1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,6 +278,18 @@ async fn process(ctx: &ClientCtx, request: Request) -> Reply { | |
| Response::Outputs(outputs.collect()) | ||
| } | ||
| Request::Workspaces => { | ||
| let state = ctx.event_stream_state.borrow(); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not include hidden workspaces in normal workspace requests. If consumers want to access hidden workspaces, they'll need to use the new endpoint. |
||
| let workspaces = state | ||
| .workspaces | ||
| .workspaces | ||
| .values() | ||
| .filter(|workspace| !workspace.is_hidden) | ||
| .cloned() | ||
| .collect(); | ||
| Response::Workspaces(workspaces) | ||
| } | ||
|
|
||
| Request::WorkspacesWithHidden => { | ||
| let state = ctx.event_stream_state.borrow(); | ||
| let workspaces = state.workspaces.workspaces.values().cloned().collect(); | ||
| Response::Workspaces(workspaces) | ||
|
|
@@ -595,21 +607,32 @@ impl State { | |
| // Check for workspace changes. | ||
| let mut seen = HashSet::new(); | ||
| let mut need_workspaces_changed = false; | ||
| let mut last_output: Option<String> = None; | ||
| let mut visible_idx = 0usize; | ||
| for (mon, ws_idx, ws) in layout.workspaces() { | ||
| let id = ws.id().get(); | ||
| seen.insert(id); | ||
|
|
||
| if ws.hidden { | ||
| continue; | ||
| } | ||
|
|
||
| let output_name = mon.map(|mon| mon.output_name().clone()); | ||
| if last_output != output_name { | ||
| visible_idx = 0; | ||
| last_output = output_name.clone(); | ||
| } | ||
|
|
||
| let Some(ipc_ws) = state.workspaces.get(&id) else { | ||
| // A new workspace was added. | ||
| need_workspaces_changed = true; | ||
| break; | ||
| }; | ||
|
|
||
| // Check for any changes that we can't signal as individual events. | ||
| let output_name = mon.map(|mon| mon.output_name()); | ||
| if ipc_ws.idx != u8::try_from(ws_idx + 1).unwrap_or(u8::MAX) | ||
| if ipc_ws.idx != u8::try_from(visible_idx + 1).unwrap_or(u8::MAX) | ||
| || ipc_ws.name.as_ref() != ws.name() | ||
| || ipc_ws.output.as_ref() != output_name | ||
| || ipc_ws.output.as_ref() != output_name.as_ref() | ||
| { | ||
| need_workspaces_changed = true; | ||
| break; | ||
|
|
@@ -633,6 +656,7 @@ impl State { | |
| let is_focused = Some(id) == focused_ws_id; | ||
| if is_focused && !ipc_ws.is_focused { | ||
| events.push(Event::WorkspaceActivated { id, focused: true }); | ||
| visible_idx += 1; | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -641,30 +665,52 @@ impl State { | |
| if is_active && !ipc_ws.is_active { | ||
| events.push(Event::WorkspaceActivated { id, focused: false }); | ||
| } | ||
|
|
||
| visible_idx += 1; | ||
| } | ||
|
|
||
| // Check if any workspaces were removed. | ||
| if !need_workspaces_changed && state.workspaces.keys().any(|id| !seen.contains(id)) { | ||
| // Check if any workspaces were removed that weren't also hidden. | ||
| if !need_workspaces_changed | ||
| && state.workspaces.keys().any(|id| { | ||
| !seen.contains(id) && state.workspaces.get(id).is_some_and(|ws| !ws.is_hidden) | ||
| }) | ||
| { | ||
| need_workspaces_changed = true; | ||
| } | ||
|
|
||
| if need_workspaces_changed { | ||
| events.clear(); | ||
|
|
||
| let mut last_output: Option<String> = None; | ||
| let mut visible_idx = 0usize; | ||
| let workspaces = layout | ||
| .workspaces() | ||
| .map(|(mon, ws_idx, ws)| { | ||
| .filter_map(|(mon, ws_idx, ws)| { | ||
| if ws.hidden { | ||
| return None; | ||
| } | ||
|
|
||
| let output_name = mon.map(|mon| mon.output_name().clone()); | ||
| if last_output != output_name { | ||
| visible_idx = 0; | ||
| last_output = output_name.clone(); | ||
| } | ||
|
|
||
| let id = ws.id().get(); | ||
| Workspace { | ||
| let result = Workspace { | ||
| id, | ||
| idx: u8::try_from(ws_idx + 1).unwrap_or(u8::MAX), | ||
| idx: u8::try_from(visible_idx + 1).unwrap_or(u8::MAX), | ||
| name: ws.name().cloned(), | ||
| output: mon.map(|mon| mon.output_name().clone()), | ||
| output: output_name, | ||
| is_urgent: ws.is_urgent(), | ||
| is_active: mon.is_some_and(|mon| mon.active_workspace_idx() == ws_idx), | ||
| is_focused: Some(id) == focused_ws_id, | ||
| is_hidden: ws.hidden, | ||
| active_window_id: ws.active_window().map(|win| win.id().get()), | ||
| } | ||
| }; | ||
|
|
||
| visible_idx += 1; | ||
| Some(result) | ||
| }) | ||
| .collect(); | ||
|
|
||
|
|
@@ -675,6 +721,26 @@ impl State { | |
| state.apply(event.clone()); | ||
| server.send_event(event); | ||
| } | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I played around with different methods to keep hidden workspaces out of event stream while still keeping it for the state, this just ended up being the only one I could get to work without horrible things happening. |
||
| for (mon, ws_idx, ws) in layout.workspaces() { | ||
| if !ws.hidden { | ||
| continue; | ||
| } | ||
| let id = ws.id().get(); | ||
| let output_name = mon.map(|mon| mon.output_name().clone()); | ||
| let hidden_ws = Workspace { | ||
| id, | ||
| idx: u8::try_from(ws_idx + 1).unwrap_or(u8::MAX), | ||
| name: ws.name().cloned(), | ||
| output: output_name, | ||
| is_urgent: ws.is_urgent(), | ||
| is_active: false, | ||
| is_focused: false, | ||
| is_hidden: true, | ||
| active_window_id: ws.active_window().map(|win| win.id().get()), | ||
| }; | ||
| state.workspaces.insert(id, hidden_ws); | ||
| } | ||
| } | ||
|
|
||
| fn ipc_refresh_windows(&mut self) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I had added options to Workspaces for different filtering options with Hidden workspaces, but this method seems better since it won't break projects that use the rust_ipc crate as it's opt in.