Skip to content

Commit

Permalink
toplevel-info: Also send workspace info for new windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Apr 11, 2024
1 parent f859110 commit 11a8265
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
9 changes: 6 additions & 3 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,8 +1693,7 @@ impl Shell {
self.pending_layers.retain(|(s, _, _)| s.alive());
self.pending_windows.retain(|(s, _, _)| s.alive());

self.toplevel_info_state
.refresh(Some(&self.workspace_state));
self.toplevel_info_state.refresh(&self.workspace_state);
}

pub fn on_commit(&mut self, surface: &WlSurface) {
Expand Down Expand Up @@ -1867,7 +1866,11 @@ impl Shell {
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
.common
.shell
Expand Down
52 changes: 23 additions & 29 deletions src/wayland/protocols/toplevel_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
) {
let instance = data_init.init(resource, ());
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);
}
Expand Down Expand Up @@ -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
.user_data()
.insert_if_missing(ToplevelState::default);
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());
}
Expand Down Expand Up @@ -265,7 +265,7 @@ where
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| {
let mut state = window
.user_data()
Expand Down Expand Up @@ -305,7 +305,7 @@ where

fn send_toplevel_to_client<D, W: 'static>(
dh: &DisplayHandle,
workspace_state: Option<&WorkspaceState<D>>,
workspace_state: &WorkspaceState<D>,
info: &ZcosmicToplevelInfoV1,
window: &W,
) where
Expand Down Expand Up @@ -422,33 +422,27 @@ fn send_toplevel_to_client<D, W: 'static>(
handle_state.outputs = state.outputs.clone();
}

if let Some(workspace_state) = workspace_state {
for new_workspace in state
.workspaces
.iter()
.filter(|w| !handle_state.workspaces.contains(w))
{
if let Some(handle) =
workspace_state.raw_workspace_handle(&new_workspace, &instance.id())
{
instance.workspace_enter(&handle);
changed = true;
}
for new_workspace in state
.workspaces
.iter()
.filter(|w| !handle_state.workspaces.contains(w))
{
if let Some(handle) = workspace_state.raw_workspace_handle(&new_workspace, &instance.id()) {
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;
}
}
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();
}
handle_state.workspaces = state.workspaces.clone();

if changed {
instance.done();
Expand Down

0 comments on commit 11a8265

Please sign in to comment.