Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ impl Clients {
changed_properties: Default::default(),
destroyed: Default::default(),
acceptor: acceptor.clone(),
has_display_upgrade: Default::default(),
});
track!(data, data);
global.update_capabilities(&data, bounding_caps, set_bounding_caps_for_children);
Expand Down Expand Up @@ -345,6 +346,7 @@ pub struct Client {
pub changed_properties: Cell<ClMatcherChange>,
pub destroyed: CopyHashMap<CritMatcherId, Weak<dyn CritDestroyListener<Rc<Self>>>>,
pub acceptor: Rc<AcceptorMetadata>,
pub has_display_upgrade: Cell<bool>,
}

pub const NUM_CACHED_SERIAL_RANGES: usize = 64;
Expand Down
4 changes: 4 additions & 0 deletions src/client/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl Objects {
}
}

pub fn len(&self) -> usize {
self.registry.len()
}

pub fn destroy(&self) {
for surface in self.surfaces.lock().values() {
if let Some(tl) = surface.get_toplevel() {
Expand Down
2 changes: 2 additions & 0 deletions src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use {
jay_popup_ext_manager_v1::JayPopupExtManagerV1Global,
org_kde_kwin_server_decoration_manager::OrgKdeKwinServerDecorationManagerGlobal,
wl_compositor::WlCompositorGlobal,
wl_display_upgrade::WlDisplayUpgradeGlobal,
wl_drm::WlDrmGlobal,
wl_fixes::WlFixesGlobal,
wl_output::WlOutputGlobal,
Expand Down Expand Up @@ -248,6 +249,7 @@ singletons! {
ZwpLinuxDmabufV1,
WpLinuxDrmSyncobjManagerV1,
WpPresentation,
WlDisplayUpgrade,
}

pub struct Globals {
Expand Down
1 change: 1 addition & 0 deletions src/ifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub mod wl_buffer;
pub mod wl_callback;
pub mod wl_compositor;
pub mod wl_display;
pub mod wl_display_upgrade;
pub mod wl_drm;
pub mod wl_fixes;
pub mod wl_output;
Expand Down
15 changes: 12 additions & 3 deletions src/ifs/wl_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
object::{Object, ObjectId, Version, WL_DISPLAY_ID},
wire::{WlDisplayId, wl_display::*},
},
std::rc::Rc,
std::{cell::Cell, rc::Rc},
thiserror::Error,
};

Expand All @@ -16,10 +16,14 @@ const INVALID_METHOD: u32 = 1;
const NO_MEMORY: u32 = 2;
const IMPLEMENTATION: u32 = 3;

pub const MIN_DISPLAY_VERSION: Version = Version(1);
pub const MAX_DISPLAY_VERSION: Version = Version(2);

pub struct WlDisplay {
pub id: WlDisplayId,
pub client: Rc<Client>,
pub tracker: Tracker<WlDisplay>,
pub version: Cell<Version>,
}

impl WlDisplay {
Expand All @@ -28,6 +32,7 @@ impl WlDisplay {
id: WL_DISPLAY_ID,
client: client.clone(),
tracker: Default::default(),
version: Cell::new(MIN_DISPLAY_VERSION),
}
}
}
Expand All @@ -45,7 +50,11 @@ impl WlDisplayRequestHandler for WlDisplay {
}

fn get_registry(&self, req: GetRegistry, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let registry = Rc::new(WlRegistry::new(req.registry, &self.client));
let registry = Rc::new(WlRegistry::new(
req.registry,
self.version.get(),
&self.client,
));
track!(self.client, registry);
self.client.add_client_obj(&registry)?;
self.client.state.globals.notify_all(&registry);
Expand Down Expand Up @@ -93,7 +102,7 @@ impl WlDisplay {

object_base! {
self = WlDisplay;
version = Version(1);
version = self.version.get();
}

impl Object for WlDisplay {}
Expand Down
105 changes: 105 additions & 0 deletions src/ifs/wl_display_upgrade.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use {
crate::{
client::{Client, ClientError},
globals::{Global, GlobalName},
ifs::wl_display::{MAX_DISPLAY_VERSION, MIN_DISPLAY_VERSION},
leaks::Tracker,
object::{Object, Version},
wire::{WlDisplayUpgradeId, wl_display_upgrade::*},
},
std::rc::Rc,
thiserror::Error,
};

pub struct WlDisplayUpgradeGlobal {
pub name: GlobalName,
}

impl WlDisplayUpgradeGlobal {
pub fn new(name: GlobalName) -> Self {
Self { name }
}

fn bind_(
self: Rc<Self>,
id: WlDisplayUpgradeId,
client: &Rc<Client>,
version: Version,
) -> Result<(), WlDisplayUpgradeError> {
if client.has_display_upgrade.replace(true) {
return Err(WlDisplayUpgradeError::HasDisplayUpgrade);
}
let mgr = Rc::new(WlDisplayUpgrade {
id,
client: client.clone(),
tracker: Default::default(),
version,
});
track!(client, mgr);
client.add_client_obj(&mgr)?;
client.event(MaxVersion {
self_id: id,
version: MAX_DISPLAY_VERSION.0,
});
Ok(())
}
}

global_base!(
WlDisplayUpgradeGlobal,
WlDisplayUpgrade,
WlDisplayUpgradeError
);

simple_add_global!(WlDisplayUpgradeGlobal);

impl Global for WlDisplayUpgradeGlobal {
fn version(&self) -> u32 {
1
}
}

pub struct WlDisplayUpgrade {
pub id: WlDisplayUpgradeId,
pub client: Rc<Client>,
pub tracker: Tracker<Self>,
pub version: Version,
}

impl WlDisplayUpgradeRequestHandler for WlDisplayUpgrade {
type Error = WlDisplayUpgradeError;

fn upgrade(&self, req: Upgrade, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client.remove_obj(self)?;
if self.client.objects.len() > 1 {
return Err(WlDisplayUpgradeError::HasObjects);
}
if req.version < MIN_DISPLAY_VERSION.0 || req.version > MAX_DISPLAY_VERSION.0 {
return Err(WlDisplayUpgradeError::OutOfBounds);
}
self.client.display()?.version.set(Version(req.version));
Ok(())
}
}

object_base! {
self = WlDisplayUpgrade;
version = self.version;
}

impl Object for WlDisplayUpgrade {}

simple_add_obj!(WlDisplayUpgrade);

#[derive(Debug, Error)]
pub enum WlDisplayUpgradeError {
#[error("Tried to bind wl_display_upgrade more than once")]
HasDisplayUpgrade,
#[error("Tried to upgrade with existing objects")]
HasObjects,
#[error("The requested version is out of bounds")]
OutOfBounds,
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(WlDisplayUpgradeError, ClientError);
16 changes: 13 additions & 3 deletions src/ifs/wl_registry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::{
client::Client,
client::{Client, ClientError},
globals::{Global, GlobalName, GlobalsError, Singleton},
leaks::Tracker,
object::{Interface, Object, Version},
Expand All @@ -15,15 +15,17 @@ pub struct WlRegistry {
id: WlRegistryId,
pub client: Rc<Client>,
pub tracker: Tracker<Self>,
pub version: Version,
advertised: StaticMap<Singleton, Cell<bool>>,
}

impl WlRegistry {
pub fn new(id: WlRegistryId, client: &Rc<Client>) -> Self {
pub fn new(id: WlRegistryId, version: Version, client: &Rc<Client>) -> Self {
Self {
id,
client: client.clone(),
tracker: Default::default(),
version,
advertised: Default::default(),
}
}
Expand Down Expand Up @@ -84,11 +86,16 @@ impl WlRegistryRequestHandler for WlRegistry {
global.bind(&self.client, bind.id, Version(bind.version))?;
Ok(())
}

fn release(&self, _req: Release, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client.remove_obj(self)?;
Ok(())
}
}

object_base! {
self = WlRegistry;
version = Version(1);
version = self.version;
}

impl Object for WlRegistry {}
Expand All @@ -97,6 +104,8 @@ dedicated_add_obj!(WlRegistry, WlRegistryId, registries);

#[derive(Debug, Error)]
pub enum WlRegistryError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error(transparent)]
GlobalsError(Box<GlobalsError>),
#[error("Tried to bind to global {} of type {} using interface {}", .0.name, .0.interface.name(), .0.actual)]
Expand All @@ -105,6 +114,7 @@ pub enum WlRegistryError {
InvalidVersion(VersionError),
}
efrom!(WlRegistryError, GlobalsError);
efrom!(WlRegistryError, ClientError);

#[derive(Debug)]
pub struct InterfaceError {
Expand Down
7 changes: 7 additions & 0 deletions wire/wl_display_upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
event max_version {
version: u32,
}

request upgrade (destructor) {
version: u32,
}
3 changes: 3 additions & 0 deletions wire/wl_registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ event global {
event global_remove {
name: u32,
}

request release (destructor, since = 2) {
}
Loading