wayland: allow binding to removed outputs
This commit is contained in:
parent
4651f760f0
commit
c27bf4d597
4 changed files with 89 additions and 5 deletions
|
|
@ -127,6 +127,7 @@ pub trait Global: GlobalBase {
|
||||||
pub struct Globals {
|
pub struct Globals {
|
||||||
next_name: NumCell<u32>,
|
next_name: NumCell<u32>,
|
||||||
registry: CopyHashMap<GlobalName, Rc<dyn Global>>,
|
registry: CopyHashMap<GlobalName, Rc<dyn Global>>,
|
||||||
|
removed: CopyHashMap<GlobalName, Rc<dyn Global>>,
|
||||||
pub outputs: CopyHashMap<GlobalName, Rc<WlOutputGlobal>>,
|
pub outputs: CopyHashMap<GlobalName, Rc<WlOutputGlobal>>,
|
||||||
pub seats: CopyHashMap<GlobalName, Rc<WlSeatGlobal>>,
|
pub seats: CopyHashMap<GlobalName, Rc<WlSeatGlobal>>,
|
||||||
}
|
}
|
||||||
|
|
@ -136,6 +137,7 @@ impl Globals {
|
||||||
let slf = Self {
|
let slf = Self {
|
||||||
next_name: NumCell::new(1),
|
next_name: NumCell::new(1),
|
||||||
registry: CopyHashMap::new(),
|
registry: CopyHashMap::new(),
|
||||||
|
removed: CopyHashMap::new(),
|
||||||
outputs: Default::default(),
|
outputs: Default::default(),
|
||||||
seats: Default::default(),
|
seats: Default::default(),
|
||||||
};
|
};
|
||||||
|
|
@ -241,9 +243,17 @@ impl Globals {
|
||||||
Ok(global)
|
Ok(global)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove<T: WaylandGlobal>(&self, state: &State, global: &T) -> Result<(), GlobalsError> {
|
pub fn remove<T: RemovableWaylandGlobal>(
|
||||||
|
&self,
|
||||||
|
state: &State,
|
||||||
|
global: &T,
|
||||||
|
) -> Result<(), GlobalsError> {
|
||||||
let _global = self.take(global.name(), true)?;
|
let _global = self.take(global.name(), true)?;
|
||||||
global.remove(self);
|
global.remove(self);
|
||||||
|
let replacement = global.create_replacement();
|
||||||
|
assert_eq!(global.name(), replacement.name());
|
||||||
|
assert_eq!(global.interface().0, replacement.interface().0);
|
||||||
|
self.removed.set(global.name(), replacement);
|
||||||
self.broadcast(state, global.required_caps(), global.xwayland_only(), |r| {
|
self.broadcast(state, global.required_caps(), global.xwayland_only(), |r| {
|
||||||
r.send_global_remove(global.name())
|
r.send_global_remove(global.name())
|
||||||
});
|
});
|
||||||
|
|
@ -295,7 +305,10 @@ impl Globals {
|
||||||
let res = if remove {
|
let res = if remove {
|
||||||
self.registry.remove(&name)
|
self.registry.remove(&name)
|
||||||
} else {
|
} else {
|
||||||
self.registry.get(&name)
|
match self.registry.get(&name) {
|
||||||
|
Some(res) => Some(res),
|
||||||
|
_ => self.removed.get(&name),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
match res {
|
match res {
|
||||||
Some(g) => Ok(g),
|
Some(g) => Ok(g),
|
||||||
|
|
@ -330,3 +343,7 @@ pub trait WaylandGlobal: Global + 'static {
|
||||||
let _ = globals;
|
let _ = globals;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait RemovableWaylandGlobal: WaylandGlobal {
|
||||||
|
fn create_replacement(&self) -> Rc<dyn Global>;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
mod removed_output;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
backend,
|
backend,
|
||||||
|
|
@ -229,13 +231,15 @@ impl WlOutputGlobal {
|
||||||
|
|
||||||
global_base!(WlOutputGlobal, WlOutput, WlOutputError);
|
global_base!(WlOutputGlobal, WlOutput, WlOutputError);
|
||||||
|
|
||||||
|
const OUTPUT_VERSION: u32 = 4;
|
||||||
|
|
||||||
impl Global for WlOutputGlobal {
|
impl Global for WlOutputGlobal {
|
||||||
fn singleton(&self) -> bool {
|
fn singleton(&self) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn version(&self) -> u32 {
|
fn version(&self) -> u32 {
|
||||||
4
|
OUTPUT_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
fn break_loops(&self) {
|
fn break_loops(&self) {
|
||||||
|
|
|
||||||
63
src/ifs/wl_output/removed_output.rs
Normal file
63
src/ifs/wl_output/removed_output.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
use {
|
||||||
|
crate::{
|
||||||
|
client::{Client, ClientError},
|
||||||
|
globals::{Global, GlobalName, RemovableWaylandGlobal},
|
||||||
|
ifs::wl_output::{WlOutput, WlOutputGlobal, OUTPUT_VERSION},
|
||||||
|
object::Version,
|
||||||
|
wire::WlOutputId,
|
||||||
|
},
|
||||||
|
std::rc::Rc,
|
||||||
|
thiserror::Error,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RemovedOutputGlobal {
|
||||||
|
name: GlobalName,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RemovedOutputGlobal {
|
||||||
|
fn bind_(
|
||||||
|
self: Rc<Self>,
|
||||||
|
id: WlOutputId,
|
||||||
|
client: &Rc<Client>,
|
||||||
|
version: Version,
|
||||||
|
) -> Result<(), RemovedOutputError> {
|
||||||
|
let obj = Rc::new(WlOutput {
|
||||||
|
global: Default::default(),
|
||||||
|
id,
|
||||||
|
xdg_outputs: Default::default(),
|
||||||
|
client: client.clone(),
|
||||||
|
version,
|
||||||
|
tracker: Default::default(),
|
||||||
|
});
|
||||||
|
track!(client, obj);
|
||||||
|
client.add_client_obj(&obj)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
global_base!(RemovedOutputGlobal, WlOutput, RemovedOutputError);
|
||||||
|
|
||||||
|
impl Global for RemovedOutputGlobal {
|
||||||
|
fn singleton(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn version(&self) -> u32 {
|
||||||
|
OUTPUT_VERSION
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
simple_add_global!(RemovedOutputGlobal);
|
||||||
|
|
||||||
|
impl RemovableWaylandGlobal for WlOutputGlobal {
|
||||||
|
fn create_replacement(&self) -> Rc<dyn Global> {
|
||||||
|
Rc::new(RemovedOutputGlobal { name: self.name })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
enum RemovedOutputError {
|
||||||
|
#[error(transparent)]
|
||||||
|
ClientError(Box<ClientError>),
|
||||||
|
}
|
||||||
|
efrom!(RemovedOutputError, ClientError);
|
||||||
|
|
@ -22,7 +22,7 @@ use {
|
||||||
SyncFile,
|
SyncFile,
|
||||||
},
|
},
|
||||||
gfx_apis::create_gfx_context,
|
gfx_apis::create_gfx_context,
|
||||||
globals::{Globals, GlobalsError, WaylandGlobal},
|
globals::{Globals, GlobalsError, RemovableWaylandGlobal, WaylandGlobal},
|
||||||
ifs::{
|
ifs::{
|
||||||
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1,
|
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1,
|
||||||
ext_session_lock_v1::ExtSessionLockV1,
|
ext_session_lock_v1::ExtSessionLockV1,
|
||||||
|
|
@ -511,7 +511,7 @@ impl State {
|
||||||
self.globals.add_global(self, global)
|
self.globals.add_global(self, global)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_global<T: WaylandGlobal>(&self, global: &T) -> Result<(), GlobalsError> {
|
pub fn remove_global<T: RemovableWaylandGlobal>(&self, global: &T) -> Result<(), GlobalsError> {
|
||||||
self.globals.remove(self, global)
|
self.globals.remove(self, global)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue