toplevel-info: Also send workspace info for new windows

This commit is contained in:
Victoria Brekenfeld 2024-04-03 16:54:14 +02:00 • committed by Victoria Brekenfeld
parent f85911020a
commit 11a8265145
2 changed files with 30 additions and 33 deletions

View file

@ -1693,8 +1693,7 @@ impl Shell {
self.pending_layers.retain(|(s, _, _)| s.alive()); self.pending_layers.retain(|(s, _, _)| s.alive());
self.pending_windows.retain(|(s, _, _)| s.alive()); self.pending_windows.retain(|(s, _, _)| s.alive());
self.toplevel_info_state self.toplevel_info_state.refresh(&self.workspace_state);
.refresh(Some(&self.workspace_state));
} }
pub fn on_commit(&mut self, surface: &WlSurface) { pub fn on_commit(&mut self, surface: &WlSurface) {
@ -1867,7 +1866,11 @@ impl Shell {
state.common.shell.workspaces.active_mut(&output) state.common.shell.workspaces.active_mut(&output)
}; };
state.common.shell.toplevel_info_state.new_toplevel(&window); state
.common
.shell
.toplevel_info_state
.new_toplevel(&window, &state.common.shell.workspace_state);
state state
.common .common
.shell .shell

View file

@ -100,7 +100,7 @@ where
) { ) {
let instance = data_init.init(resource, ()); let instance = data_init.init(resource, ());
for window in &state.toplevel_info_state().toplevels { for window in &state.toplevel_info_state().toplevels {
send_toplevel_to_client::<D, W>(dh, Some(state.workspace_state()), &instance, window); send_toplevel_to_client::<D, W>(dh, state.workspace_state(), &instance, window);
} }
state.toplevel_info_state_mut().instances.push(instance); state.toplevel_info_state_mut().instances.push(instance);
} }
@ -213,12 +213,12 @@ where
} }
} }
pub fn new_toplevel(&mut self, toplevel: &W) { pub fn new_toplevel(&mut self, toplevel: &W, workspace_state: &WorkspaceState<D>) {
toplevel toplevel
.user_data() .user_data()
.insert_if_missing(ToplevelState::default); .insert_if_missing(ToplevelState::default);
for instance in &self.instances { for instance in &self.instances {
send_toplevel_to_client::<D, W>(&self.dh, None, instance, toplevel); send_toplevel_to_client::<D, W>(&self.dh, workspace_state, instance, toplevel);
} }
self.toplevels.push(toplevel.clone()); self.toplevels.push(toplevel.clone());
} }
@ -265,7 +265,7 @@ where
self.toplevels.retain(|w| w != toplevel); self.toplevels.retain(|w| w != toplevel);
} }
pub fn refresh(&mut self, workspace_state: Option<&WorkspaceState<D>>) { pub fn refresh(&mut self, workspace_state: &WorkspaceState<D>) {
self.toplevels.retain(|window| { self.toplevels.retain(|window| {
let mut state = window let mut state = window
.user_data() .user_data()
@ -305,7 +305,7 @@ where
fn send_toplevel_to_client<D, W: 'static>( fn send_toplevel_to_client<D, W: 'static>(
dh: &DisplayHandle, dh: &DisplayHandle,
workspace_state: Option<&WorkspaceState<D>>, workspace_state: &WorkspaceState<D>,
info: &ZcosmicToplevelInfoV1, info: &ZcosmicToplevelInfoV1,
window: &W, window: &W,
) where ) where
@ -422,33 +422,27 @@ fn send_toplevel_to_client<D, W: 'static>(
handle_state.outputs = state.outputs.clone(); handle_state.outputs = state.outputs.clone();
} }
if let Some(workspace_state) = workspace_state { for new_workspace in state
for new_workspace in state .workspaces
.workspaces .iter()
.iter() .filter(|w| !handle_state.workspaces.contains(w))
.filter(|w| !handle_state.workspaces.contains(w)) {
{ if let Some(handle) = workspace_state.raw_workspace_handle(&new_workspace, &instance.id()) {
if let Some(handle) = instance.workspace_enter(&handle);
workspace_state.raw_workspace_handle(&new_workspace, &instance.id()) changed = true;
{
instance.workspace_enter(&handle);
changed = true;
}
} }
for old_workspace in handle_state
.workspaces
.iter()
.filter(|w| !state.workspaces.contains(w))
{
if let Some(handle) =
workspace_state.raw_workspace_handle(&old_workspace, &instance.id())
{
instance.workspace_leave(&handle);
changed = true;
}
}
handle_state.workspaces = state.workspaces.clone();
} }
for old_workspace in handle_state
.workspaces
.iter()
.filter(|w| !state.workspaces.contains(w))
{
if let Some(handle) = workspace_state.raw_workspace_handle(&old_workspace, &instance.id()) {
instance.workspace_leave(&handle);
changed = true;
}
}
handle_state.workspaces = state.workspaces.clone();
if changed { if changed {
instance.done(); instance.done();