protocols: implement `ext-foreign-toplevel-list-v1`
Browse files at this commitce9dd33213ed02693bddcce096f00a48ae0bacfaParent: 10995ec2 changed files +256 -36
- src/protocols/foreign_toplevel.rs +238 -36
- src/window/mapped.rs +18 -0
src/protocols/foreign_toplevel.rsmodified+238 -36
| @@ -1,10 +1,16 @@ | |||
| 1 | use std::collections::hash_map::Entry; | 1 | use std::collections::hash_map::Entry; |
| 2 | -use std::collections::HashMap; | 2 | +use std::collections::{HashMap, HashSet}; |
| 3 | +use std::sync::Arc; | ||
| 3 | 4 | ||
| 4 | use arrayvec::ArrayVec; | 5 | use arrayvec::ArrayVec; |
| 5 | use smithay::output::Output; | 6 | use smithay::output::Output; |
| 7 | +use smithay::reexports::wayland_protocols::ext::foreign_toplevel_list::v1::server::{ | ||
| 8 | + ext_foreign_toplevel_handle_v1::{self, ExtForeignToplevelHandleV1}, ext_foreign_toplevel_list_v1::{self, ExtForeignToplevelListV1}, | ||
| 9 | +}; | ||
| 6 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | 10 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; |
| 7 | -use smithay::reexports::wayland_protocols_wlr; | 11 | +use smithay::reexports::wayland_protocols_wlr::foreign_toplevel::v1::server::{ |
| 12 | + zwlr_foreign_toplevel_handle_v1::{self, ZwlrForeignToplevelHandleV1}, zwlr_foreign_toplevel_manager_v1::{self, ZwlrForeignToplevelManagerV1}, | ||
| 13 | +}; | ||
| 8 | use smithay::reexports::wayland_server::backend::ClientId; | 14 | use smithay::reexports::wayland_server::backend::ClientId; |
| 9 | use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; | 15 | use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; |
| 10 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 16 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| @@ -12,22 +18,20 @@ use smithay::reexports::wayland_server::{ | |||
| 12 | Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, | 18 | Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, |
| 13 | }; | 19 | }; |
| 14 | use smithay::wayland::shell::xdg::{ | 20 | use smithay::wayland::shell::xdg::{ |
| 15 | - ToplevelState, ToplevelStateSet, XdgToplevelSurfaceRoleAttributes, | 21 | + ToplevelState, ToplevelStateSet, XdgToplevelSurfaceRoleAttributes |
| 16 | }; | 22 | }; |
| 17 | -use wayland_protocols_wlr::foreign_toplevel::v1::server::{ | ||
| 18 | - zwlr_foreign_toplevel_handle_v1, zwlr_foreign_toplevel_manager_v1, | ||
| 19 | -}; | ||
| 20 | -use zwlr_foreign_toplevel_handle_v1::ZwlrForeignToplevelHandleV1; | ||
| 21 | -use zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1; | ||
| 22 | 23 | ||
| 23 | use crate::niri::State; | 24 | use crate::niri::State; |
| 25 | +use crate::window::mapped::MappedId; | ||
| 24 | use crate::utils::with_toplevel_role_and_current; | 26 | use crate::utils::with_toplevel_role_and_current; |
| 25 | 27 | ||
| 26 | -const VERSION: u32 = 3; | 28 | +const EXT_LIST_VERSION: u32 = 1; |
| 29 | +const WLR_MANAGEMENT_VERSION: u32 = 3; | ||
| 27 | 30 | ||
| 28 | pub struct ForeignToplevelManagerState { | 31 | pub struct ForeignToplevelManagerState { |
| 29 | display: DisplayHandle, | 32 | display: DisplayHandle, |
| 30 | - instances: Vec<ZwlrForeignToplevelManagerV1>, | 33 | + ext_list_instances: HashSet<ExtForeignToplevelListV1>, |
| 34 | + wlr_management_instances: HashSet<ZwlrForeignToplevelManagerV1>, | ||
| 31 | toplevels: HashMap<WlSurface, ToplevelData>, | 35 | toplevels: HashMap<WlSurface, ToplevelData>, |
| 32 | } | 36 | } |
| 33 | 37 | ||
| @@ -42,33 +46,45 @@ pub trait ForeignToplevelHandler { | |||
| 42 | } | 46 | } |
| 43 | 47 | ||
| 44 | struct ToplevelData { | 48 | struct ToplevelData { |
| 49 | + identifier: MappedId, | ||
| 45 | title: Option<String>, | 50 | title: Option<String>, |
| 46 | app_id: Option<String>, | 51 | app_id: Option<String>, |
| 47 | states: ArrayVec<u32, 3>, | 52 | states: ArrayVec<u32, 3>, |
| 48 | output: Option<Output>, | 53 | output: Option<Output>, |
| 49 | - instances: HashMap<ZwlrForeignToplevelHandleV1, Vec<WlOutput>>, | 54 | + |
| 55 | + ext_list_instances: HashSet<ExtForeignToplevelHandleV1>, | ||
| 56 | + wlr_management_instances: HashMap<ZwlrForeignToplevelHandleV1, Vec<WlOutput>>, | ||
| 50 | // FIXME: parent. | 57 | // FIXME: parent. |
| 51 | } | 58 | } |
| 52 | 59 | ||
| 60 | +#[derive(Clone)] | ||
| 53 | pub struct ForeignToplevelGlobalData { | 61 | pub struct ForeignToplevelGlobalData { |
| 54 | - filter: Box<dyn for<'c> Fn(&'c Client) -> bool + Send + Sync>, | 62 | + filter: Arc<dyn for<'c> Fn(&'c Client) -> bool + Send + Sync>, |
| 55 | } | 63 | } |
| 56 | 64 | ||
| 57 | impl ForeignToplevelManagerState { | 65 | impl ForeignToplevelManagerState { |
| 58 | pub fn new<D, F>(display: &DisplayHandle, filter: F) -> Self | 66 | pub fn new<D, F>(display: &DisplayHandle, filter: F) -> Self |
| 59 | where | 67 | where |
| 60 | D: GlobalDispatch<ZwlrForeignToplevelManagerV1, ForeignToplevelGlobalData>, | 68 | D: GlobalDispatch<ZwlrForeignToplevelManagerV1, ForeignToplevelGlobalData>, |
| 69 | + D: GlobalDispatch<ExtForeignToplevelListV1, ForeignToplevelGlobalData>, | ||
| 61 | D: Dispatch<ZwlrForeignToplevelManagerV1, ()>, | 70 | D: Dispatch<ZwlrForeignToplevelManagerV1, ()>, |
| 71 | + D: Dispatch<ExtForeignToplevelListV1, ()>, | ||
| 62 | D: 'static, | 72 | D: 'static, |
| 63 | F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, | 73 | F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, |
| 64 | { | 74 | { |
| 65 | let global_data = ForeignToplevelGlobalData { | 75 | let global_data = ForeignToplevelGlobalData { |
| 66 | - filter: Box::new(filter), | 76 | + filter: Arc::new(filter), |
| 67 | }; | 77 | }; |
| 68 | - display.create_global::<D, ZwlrForeignToplevelManagerV1, _>(VERSION, global_data); | 78 | + display |
| 79 | + .create_global::<D, ExtForeignToplevelListV1, _>(EXT_LIST_VERSION, global_data.clone()); | ||
| 80 | + display.create_global::<D, ZwlrForeignToplevelManagerV1, _>( | ||
| 81 | + WLR_MANAGEMENT_VERSION, | ||
| 82 | + global_data, | ||
| 83 | + ); | ||
| 69 | Self { | 84 | Self { |
| 70 | display: display.clone(), | 85 | display: display.clone(), |
| 71 | - instances: Vec::new(), | 86 | + ext_list_instances: HashSet::new(), |
| 87 | + wlr_management_instances: HashSet::new(), | ||
| 72 | toplevels: HashMap::new(), | 88 | toplevels: HashMap::new(), |
| 73 | } | 89 | } |
| 74 | } | 90 | } |
| @@ -85,7 +101,11 @@ pub fn refresh(state: &mut State) { | |||
| 85 | return true; | 101 | return true; |
| 86 | } | 102 | } |
| 87 | 103 | ||
| 88 | - for instance in data.instances.keys() { | 104 | + for instance in data.ext_list_instances.iter() { |
| 105 | + instance.closed(); | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + for instance in data.wlr_management_instances.keys() { | ||
| 89 | instance.closed(); | 109 | instance.closed(); |
| 90 | } | 110 | } |
| 91 | 111 | ||
| @@ -107,15 +127,23 @@ pub fn refresh(state: &mut State) { | |||
| 107 | }; | 127 | }; |
| 108 | 128 | ||
| 109 | if state.niri.keyboard_focus.surface() == Some(wl_surface) { | 129 | if state.niri.keyboard_focus.surface() == Some(wl_surface) { |
| 110 | - focused = Some((mapped.window.clone(), output.cloned())); | 130 | + focused = Some((mapped.id(), mapped.window.clone(), output.cloned())); |
| 111 | } else { | 131 | } else { |
| 112 | - refresh_toplevel(protocol_state, wl_surface, role, cur, output, false); | 132 | + refresh_toplevel( |
| 133 | + protocol_state, | ||
| 134 | + wl_surface, | ||
| 135 | + mapped.id(), | ||
| 136 | + role, | ||
| 137 | + cur, | ||
| 138 | + output, | ||
| 139 | + false, | ||
| 140 | + ); | ||
| 113 | } | 141 | } |
| 114 | }); | 142 | }); |
| 115 | }); | 143 | }); |
| 116 | 144 | ||
| 117 | // Finally, refresh the focused window. | 145 | // Finally, refresh the focused window. |
| 118 | - if let Some((window, output)) = focused { | 146 | + if let Some((identifier, window, output)) = focused { |
| 119 | let toplevel = window.toplevel().expect("no X11 support"); | 147 | let toplevel = window.toplevel().expect("no X11 support"); |
| 120 | let wl_surface = toplevel.wl_surface(); | 148 | let wl_surface = toplevel.wl_surface(); |
| 121 | with_toplevel_role_and_current(toplevel, |role, cur| { | 149 | with_toplevel_role_and_current(toplevel, |role, cur| { |
| @@ -124,7 +152,15 @@ pub fn refresh(state: &mut State) { | |||
| 124 | return; | 152 | return; |
| 125 | }; | 153 | }; |
| 126 | 154 | ||
| 127 | - refresh_toplevel(protocol_state, wl_surface, role, cur, output.as_ref(), true); | 155 | + refresh_toplevel( |
| 156 | + protocol_state, | ||
| 157 | + wl_surface, | ||
| 158 | + identifier, | ||
| 159 | + role, | ||
| 160 | + cur, | ||
| 161 | + output.as_ref(), | ||
| 162 | + true, | ||
| 163 | + ); | ||
| 128 | }); | 164 | }); |
| 129 | } | 165 | } |
| 130 | } | 166 | } |
| @@ -142,7 +178,7 @@ pub fn on_output_bound(state: &mut State, output: &Output, wl_output: &WlOutput) | |||
| 142 | continue; | 178 | continue; |
| 143 | } | 179 | } |
| 144 | 180 | ||
| 145 | - for (instance, outputs) in &mut data.instances { | 181 | + for (instance, outputs) in &mut data.wlr_management_instances { |
| 146 | if instance.client().as_ref() != Some(&client) { | 182 | if instance.client().as_ref() != Some(&client) { |
| 147 | continue; | 183 | continue; |
| 148 | } | 184 | } |
| @@ -157,6 +193,7 @@ pub fn on_output_bound(state: &mut State, output: &Output, wl_output: &WlOutput) | |||
| 157 | fn refresh_toplevel( | 193 | fn refresh_toplevel( |
| 158 | protocol_state: &mut ForeignToplevelManagerState, | 194 | protocol_state: &mut ForeignToplevelManagerState, |
| 159 | wl_surface: &WlSurface, | 195 | wl_surface: &WlSurface, |
| 196 | + identifier: MappedId, | ||
| 160 | role: &XdgToplevelSurfaceRoleAttributes, | 197 | role: &XdgToplevelSurfaceRoleAttributes, |
| 161 | current: &ToplevelState, | 198 | current: &ToplevelState, |
| 162 | output: Option<&Output>, | 199 | output: Option<&Output>, |
| @@ -201,11 +238,24 @@ fn refresh_toplevel( | |||
| 201 | output_changed = true; | 238 | output_changed = true; |
| 202 | } | 239 | } |
| 203 | 240 | ||
| 204 | - let something_changed = | 241 | + let something_changed_for_ext = new_title.is_some() || new_app_id.is_some(); |
| 242 | + let something_changed_for_wlr = | ||
| 205 | new_title.is_some() || new_app_id.is_some() || states_changed || output_changed; | 243 | new_title.is_some() || new_app_id.is_some() || states_changed || output_changed; |
| 206 | 244 | ||
| 207 | - if something_changed { | 245 | + if something_changed_for_ext { |
| 208 | - for (instance, outputs) in &mut data.instances { | 246 | + for instance in &data.ext_list_instances { |
| 247 | + if let Some(new_title) = new_title { | ||
| 248 | + instance.title(new_title.to_owned()); | ||
| 249 | + } | ||
| 250 | + if let Some(new_app_id) = new_app_id { | ||
| 251 | + instance.app_id(new_app_id.to_owned()); | ||
| 252 | + } | ||
| 253 | + instance.done(); | ||
| 254 | + } | ||
| 255 | + } | ||
| 256 | + | ||
| 257 | + if something_changed_for_wlr { | ||
| 258 | + for (instance, outputs) in &mut data.wlr_management_instances { | ||
| 209 | if let Some(new_title) = new_title { | 259 | if let Some(new_title) = new_title { |
| 210 | instance.title(new_title.to_owned()); | 260 | instance.title(new_title.to_owned()); |
| 211 | } | 261 | } |
| @@ -232,7 +282,7 @@ fn refresh_toplevel( | |||
| 232 | } | 282 | } |
| 233 | } | 283 | } |
| 234 | 284 | ||
| 235 | - for outputs in data.instances.values_mut() { | 285 | + for outputs in data.wlr_management_instances.values_mut() { |
| 236 | // Clean up dead wl_outputs. | 286 | // Clean up dead wl_outputs. |
| 237 | outputs.retain(|x| x.is_alive()); | 287 | outputs.retain(|x| x.is_alive()); |
| 238 | } | 288 | } |
| @@ -240,16 +290,24 @@ fn refresh_toplevel( | |||
| 240 | Entry::Vacant(entry) => { | 290 | Entry::Vacant(entry) => { |
| 241 | // New window, start tracking it. | 291 | // New window, start tracking it. |
| 242 | let mut data = ToplevelData { | 292 | let mut data = ToplevelData { |
| 293 | + identifier, | ||
| 243 | title: role.title.clone(), | 294 | title: role.title.clone(), |
| 244 | app_id: role.app_id.clone(), | 295 | app_id: role.app_id.clone(), |
| 245 | states, | 296 | states, |
| 246 | output: output.cloned(), | 297 | output: output.cloned(), |
| 247 | - instances: HashMap::new(), | 298 | + ext_list_instances: HashSet::new(), |
| 299 | + wlr_management_instances: HashMap::new(), | ||
| 248 | }; | 300 | }; |
| 249 | 301 | ||
| 250 | - for manager in &protocol_state.instances { | 302 | + for manager in &protocol_state.ext_list_instances { |
| 303 | + if let Some(client) = manager.client() { | ||
| 304 | + data.add_ext_instance::<State>(&protocol_state.display, &client, manager); | ||
| 305 | + } | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + for manager in &protocol_state.wlr_management_instances { | ||
| 251 | if let Some(client) = manager.client() { | 309 | if let Some(client) = manager.client() { |
| 252 | - data.add_instance::<State>(&protocol_state.display, &client, manager); | 310 | + data.add_wlr_instance::<State>(&protocol_state.display, &client, manager); |
| 253 | } | 311 | } |
| 254 | } | 312 | } |
| 255 | 313 | ||
| @@ -259,7 +317,35 @@ fn refresh_toplevel( | |||
| 259 | } | 317 | } |
| 260 | 318 | ||
| 261 | impl ToplevelData { | 319 | impl ToplevelData { |
| 262 | - fn add_instance<D>( | 320 | + fn add_ext_instance<D>( |
| 321 | + &mut self, | ||
| 322 | + handle: &DisplayHandle, | ||
| 323 | + client: &Client, | ||
| 324 | + manager: &ExtForeignToplevelListV1, | ||
| 325 | + ) where | ||
| 326 | + D: Dispatch<ExtForeignToplevelHandleV1, ()>, | ||
| 327 | + D: 'static, | ||
| 328 | + { | ||
| 329 | + let toplevel = client | ||
| 330 | + .create_resource::<ExtForeignToplevelHandleV1, _, D>(handle, manager.version(), ()) | ||
| 331 | + .unwrap(); | ||
| 332 | + manager.toplevel(&toplevel); | ||
| 333 | + | ||
| 334 | + toplevel.identifier(self.identifier.to_protocol_identifier()); | ||
| 335 | + | ||
| 336 | + if let Some(title) = &self.title { | ||
| 337 | + toplevel.title(title.clone()); | ||
| 338 | + } | ||
| 339 | + if let Some(app_id) = &self.app_id { | ||
| 340 | + toplevel.app_id(app_id.clone()); | ||
| 341 | + } | ||
| 342 | + | ||
| 343 | + toplevel.done(); | ||
| 344 | + | ||
| 345 | + self.ext_list_instances.insert(toplevel); | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + fn add_wlr_instance<D>( | ||
| 263 | &mut self, | 349 | &mut self, |
| 264 | handle: &DisplayHandle, | 350 | handle: &DisplayHandle, |
| 265 | client: &Client, | 351 | client: &Client, |
| @@ -292,7 +378,111 @@ impl ToplevelData { | |||
| 292 | 378 | ||
| 293 | toplevel.done(); | 379 | toplevel.done(); |
| 294 | 380 | ||
| 295 | - self.instances.insert(toplevel, outputs); | 381 | + self.wlr_management_instances.insert(toplevel, outputs); |
| 382 | + } | ||
| 383 | +} | ||
| 384 | + | ||
| 385 | +impl<D> GlobalDispatch<ExtForeignToplevelListV1, ForeignToplevelGlobalData, D> | ||
| 386 | + for ForeignToplevelManagerState | ||
| 387 | +where | ||
| 388 | + D: GlobalDispatch<ExtForeignToplevelListV1, ForeignToplevelGlobalData>, | ||
| 389 | + D: Dispatch<ExtForeignToplevelListV1, ()>, | ||
| 390 | + D: Dispatch<ExtForeignToplevelHandleV1, ()>, | ||
| 391 | + D: ForeignToplevelHandler, | ||
| 392 | +{ | ||
| 393 | + fn bind( | ||
| 394 | + state: &mut D, | ||
| 395 | + handle: &DisplayHandle, | ||
| 396 | + client: &Client, | ||
| 397 | + resource: New<ExtForeignToplevelListV1>, | ||
| 398 | + _global_data: &ForeignToplevelGlobalData, | ||
| 399 | + data_init: &mut DataInit<'_, D>, | ||
| 400 | + ) { | ||
| 401 | + let manager = data_init.init(resource, ()); | ||
| 402 | + | ||
| 403 | + let state = state.foreign_toplevel_manager_state(); | ||
| 404 | + | ||
| 405 | + for data in state.toplevels.values_mut() { | ||
| 406 | + data.add_ext_instance::<D>(handle, client, &manager); | ||
| 407 | + } | ||
| 408 | + | ||
| 409 | + state.ext_list_instances.insert(manager); | ||
| 410 | + } | ||
| 411 | + | ||
| 412 | + fn can_view(client: Client, global_data: &ForeignToplevelGlobalData) -> bool { | ||
| 413 | + (global_data.filter)(&client) | ||
| 414 | + } | ||
| 415 | +} | ||
| 416 | + | ||
| 417 | +impl<D> Dispatch<ExtForeignToplevelListV1, (), D> for ForeignToplevelManagerState | ||
| 418 | +where | ||
| 419 | + D: Dispatch<ExtForeignToplevelListV1, ()>, | ||
| 420 | + D: ForeignToplevelHandler, | ||
| 421 | +{ | ||
| 422 | + fn request( | ||
| 423 | + state: &mut D, | ||
| 424 | + _client: &Client, | ||
| 425 | + resource: &ExtForeignToplevelListV1, | ||
| 426 | + request: <ExtForeignToplevelListV1 as Resource>::Request, | ||
| 427 | + _data: &(), | ||
| 428 | + _dhandle: &DisplayHandle, | ||
| 429 | + _data_init: &mut DataInit<'_, D>, | ||
| 430 | + ) { | ||
| 431 | + match request { | ||
| 432 | + ext_foreign_toplevel_list_v1::Request::Stop => { | ||
| 433 | + resource.finished(); | ||
| 434 | + | ||
| 435 | + // remove the instance here so we won't send any more events. | ||
| 436 | + let state = state.foreign_toplevel_manager_state(); | ||
| 437 | + state.ext_list_instances.remove(resource); | ||
| 438 | + } | ||
| 439 | + ext_foreign_toplevel_list_v1::Request::Destroy => {} | ||
| 440 | + _ => unreachable!(), | ||
| 441 | + } | ||
| 442 | + } | ||
| 443 | + | ||
| 444 | + fn destroyed( | ||
| 445 | + state: &mut D, | ||
| 446 | + _client: ClientId, | ||
| 447 | + resource: &ExtForeignToplevelListV1, | ||
| 448 | + _data: &(), | ||
| 449 | + ) { | ||
| 450 | + // also remove the instance here, in case `stop` was never sent, e.g. sudden disconnect. | ||
| 451 | + let state = state.foreign_toplevel_manager_state(); | ||
| 452 | + state.ext_list_instances.remove(resource); | ||
| 453 | + } | ||
| 454 | +} | ||
| 455 | + | ||
| 456 | +impl<D> Dispatch<ExtForeignToplevelHandleV1, (), D> for ForeignToplevelManagerState | ||
| 457 | +where | ||
| 458 | + D: Dispatch<ExtForeignToplevelHandleV1, ()>, | ||
| 459 | + D: ForeignToplevelHandler, | ||
| 460 | +{ | ||
| 461 | + fn request( | ||
| 462 | + _state: &mut D, | ||
| 463 | + _client: &Client, | ||
| 464 | + _resource: &ExtForeignToplevelHandleV1, | ||
| 465 | + request: <ExtForeignToplevelHandleV1 as Resource>::Request, | ||
| 466 | + _data: &(), | ||
| 467 | + _dhandle: &DisplayHandle, | ||
| 468 | + _data_init: &mut DataInit<'_, D>, | ||
| 469 | + ) { | ||
| 470 | + match request { | ||
| 471 | + ext_foreign_toplevel_handle_v1::Request::Destroy => {} | ||
| 472 | + _ => unreachable!(), | ||
| 473 | + } | ||
| 474 | + } | ||
| 475 | + | ||
| 476 | + fn destroyed( | ||
| 477 | + state: &mut D, | ||
| 478 | + _client: ClientId, | ||
| 479 | + resource: &ExtForeignToplevelHandleV1, | ||
| 480 | + _data: &(), | ||
| 481 | + ) { | ||
| 482 | + let state = state.foreign_toplevel_manager_state(); | ||
| 483 | + for data in state.toplevels.values_mut() { | ||
| 484 | + data.ext_list_instances.remove(resource); | ||
| 485 | + } | ||
| 296 | } | 486 | } |
| 297 | } | 487 | } |
| 298 | 488 | ||
| @@ -317,10 +507,10 @@ where | |||
| 317 | let state = state.foreign_toplevel_manager_state(); | 507 | let state = state.foreign_toplevel_manager_state(); |
| 318 | 508 | ||
| 319 | for data in state.toplevels.values_mut() { | 509 | for data in state.toplevels.values_mut() { |
| 320 | - data.add_instance::<D>(handle, client, &manager); | 510 | + data.add_wlr_instance::<D>(handle, client, &manager); |
| 321 | } | 511 | } |
| 322 | 512 | ||
| 323 | - state.instances.push(manager); | 513 | + state.wlr_management_instances.insert(manager); |
| 324 | } | 514 | } |
| 325 | 515 | ||
| 326 | fn can_view(client: Client, global_data: &ForeignToplevelGlobalData) -> bool { | 516 | fn can_view(client: Client, global_data: &ForeignToplevelGlobalData) -> bool { |
| @@ -346,8 +536,9 @@ where | |||
| 346 | zwlr_foreign_toplevel_manager_v1::Request::Stop => { | 536 | zwlr_foreign_toplevel_manager_v1::Request::Stop => { |
| 347 | resource.finished(); | 537 | resource.finished(); |
| 348 | 538 | ||
| 539 | + // remove the instance here so we won't send any more events. | ||
| 349 | let state = state.foreign_toplevel_manager_state(); | 540 | let state = state.foreign_toplevel_manager_state(); |
| 350 | - state.instances.retain(|x| x != resource); | 541 | + state.wlr_management_instances.remove(resource); |
| 351 | } | 542 | } |
| 352 | _ => unreachable!(), | 543 | _ => unreachable!(), |
| 353 | } | 544 | } |
| @@ -359,8 +550,9 @@ where | |||
| 359 | resource: &ZwlrForeignToplevelManagerV1, | 550 | resource: &ZwlrForeignToplevelManagerV1, |
| 360 | _data: &(), | 551 | _data: &(), |
| 361 | ) { | 552 | ) { |
| 553 | + // also remove the instance here, in case `stop` was never sent, e.g. sudden disconnect. | ||
| 362 | let state = state.foreign_toplevel_manager_state(); | 554 | let state = state.foreign_toplevel_manager_state(); |
| 363 | - state.instances.retain(|x| x != resource); | 555 | + state.wlr_management_instances.remove(resource); |
| 364 | } | 556 | } |
| 365 | } | 557 | } |
| 366 | 558 | ||
| @@ -383,7 +575,7 @@ where | |||
| 383 | let Some((surface, _)) = protocol_state | 575 | let Some((surface, _)) = protocol_state |
| 384 | .toplevels | 576 | .toplevels |
| 385 | .iter() | 577 | .iter() |
| 386 | - .find(|(_, data)| data.instances.contains_key(resource)) | 578 | + .find(|(_, data)| data.wlr_management_instances.contains_key(resource)) |
| 387 | else { | 579 | else { |
| 388 | return; | 580 | return; |
| 389 | }; | 581 | }; |
| @@ -422,7 +614,7 @@ where | |||
| 422 | ) { | 614 | ) { |
| 423 | let state = state.foreign_toplevel_manager_state(); | 615 | let state = state.foreign_toplevel_manager_state(); |
| 424 | for data in state.toplevels.values_mut() { | 616 | for data in state.toplevels.values_mut() { |
| 425 | - data.instances.retain(|instance, _| instance != resource); | 617 | + data.wlr_management_instances.remove(resource); |
| 426 | } | 618 | } |
| 427 | } | 619 | } |
| 428 | } | 620 | } |
| @@ -454,6 +646,16 @@ fn to_state_vec(states: &ToplevelStateSet, has_focus: bool) -> ArrayVec<u32, 3> | |||
| 454 | #[macro_export] | 646 | #[macro_export] |
| 455 | macro_rules! delegate_foreign_toplevel { | 647 | macro_rules! delegate_foreign_toplevel { |
| 456 | ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { | 648 | ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { |
| 649 | + smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ | ||
| 650 | + smithay::reexports::wayland_protocols::ext::foreign_toplevel_list::v1::server::ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1: $crate::protocols::foreign_toplevel::ForeignToplevelGlobalData | ||
| 651 | + ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); | ||
| 652 | + smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ | ||
| 653 | + smithay::reexports::wayland_protocols::ext::foreign_toplevel_list::v1::server::ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1: () | ||
| 654 | + ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); | ||
| 655 | + smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ | ||
| 656 | + smithay::reexports::wayland_protocols::ext::foreign_toplevel_list::v1::server::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1: () | ||
| 657 | + ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); | ||
| 658 | + | ||
| 457 | smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ | 659 | smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ |
| 458 | smithay::reexports::wayland_protocols_wlr::foreign_toplevel::v1::server::zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1: $crate::protocols::foreign_toplevel::ForeignToplevelGlobalData | 660 | smithay::reexports::wayland_protocols_wlr::foreign_toplevel::v1::server::zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1: $crate::protocols::foreign_toplevel::ForeignToplevelGlobalData |
| 459 | ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); | 661 | ] => $crate::protocols::foreign_toplevel::ForeignToplevelManagerState); |
src/window/mapped.rsmodified+18 -0
| @@ -216,6 +216,24 @@ impl MappedId { | |||
| 216 | pub fn get(self) -> u64 { | 216 | pub fn get(self) -> u64 { |
| 217 | self.0 | 217 | self.0 |
| 218 | } | 218 | } |
| 219 | + | ||
| 220 | + /// Converts the ID to a string that can be used as an identifier in | ||
| 221 | + /// ext_foreign_toplevel_handle_v1::identifier | ||
| 222 | + /// | ||
| 223 | + /// > An identifier is a string that contains up to 32 printable ASCII bytes. | ||
| 224 | + /// > An identifier must not be an empty string. | ||
| 225 | + /// | ||
| 226 | + /// Since the ID is exposed to IPC, it's useful for this conversion to be stable and reversible. | ||
| 227 | + /// That way, clients can associate a foreign toplevel handle with an IPC window ID. | ||
| 228 | + /// | ||
| 229 | + /// We use the decimal representation of the ID, which is up to 20 characters long for u64::MAX. | ||
| 230 | + /// This is within the 32-character limit, and is nice because it matches up with how `niri msg` | ||
| 231 | + /// prints the IDs to the console. | ||
| 232 | + /// | ||
| 233 | + /// This namespace can be extended in the future, with any non-numeric prefix to disambiguate. | ||
| 234 | + pub fn to_protocol_identifier(self) -> String { | ||
| 235 | + format!("{}", self.0) | ||
| 236 | + } | ||
| 219 | } | 237 | } |
| 220 | 238 | ||
| 221 | /// Interactive resize state. | 239 | /// Interactive resize state. |