From b3ebe17b46735c90ae3ffbf647e3cd766c9eb61e Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 24 Apr 2024 09:01:08 -0700 Subject: [PATCH] WIP wl-fixes protocol --- wayland-client/wayland.xml | 55 ++++- wayland-scanner/src/server_gen.rs | 8 +- .../tests/scanner_assets/test-server-code.rs | 207 ++++++++++++++++++ wayland-server/wayland.xml | 55 ++++- 4 files changed, 315 insertions(+), 10 deletions(-) diff --git a/wayland-client/wayland.xml b/wayland-client/wayland.xml index 9418c62f3f6..f32918e9f98 100644 --- a/wayland-client/wayland.xml +++ b/wayland-client/wayland.xml @@ -1832,6 +1832,9 @@ x and y, combined with the new surface size define in which directions the surface's size changes. + The exact semantics of wl_surface.offset are role-specific. Refer to + the documentation of specific roles for more information. + Surface location offset is double-buffered state, see wl_surface.commit. @@ -1880,7 +1883,7 @@ - + A seat is a group of keyboards, pointer and touch devices. This object is published as a global during start up, or when such a @@ -2013,7 +2016,7 @@ - + The wl_pointer interface represents one or more input devices, such as mice, which control the pointer location and pointer_focus @@ -2426,7 +2429,7 @@ - + The wl_keyboard interface represents one or more keyboards associated with a seat. @@ -2479,6 +2482,9 @@ the surface argument and the keys currently logically down to the keys in the keys argument. The compositor must not send this event if the wl_keyboard already had an active surface immediately before this event. + + Clients should not use the list of pressed keys to emulate key-press + events. The order of keys in the list is unspecified. @@ -2505,9 +2511,18 @@ Describes the physical state of a key that produced the key event. + + Since version 10, the key can be in a "repeated" pseudo-state which + means the same as "pressed", but is used to signal repetition in the + key event. + + The key may only enter the repeated state after entering the pressed + state and before entering the released state. This event may be + generated multiple times while the key is down. + @@ -2530,6 +2545,11 @@ compositor must not send this event if state is pressed (resp. released) and the key was already logically down (resp. was not logically down) immediately before this event. + + Since version 10, compositors may send key events with the "repeated" + key state when a wl_keyboard.repeat_info event with a rate argument of + 0 has been received. This allows the compositor to take over the + responsibility of key repetition. @@ -2590,7 +2610,7 @@ - + The wl_touch interface represents a touchscreen associated with a seat. @@ -3245,4 +3265,31 @@ + + + This global fixes problems with other core-protocol interfaces that + cannot be fixed in these interfaces themselves. + + + + + + + + + This request destroys a wl_registry object. + + The client should no longer use the wl_registry after making this + request. + + The compositor will emit a wl_display.delete_id event with the object ID + of the registry and will no longer emit any events on the registry. The + client should re-use the object ID once it receives the + wl_display.delete_id event. + + + + + diff --git a/wayland-scanner/src/server_gen.rs b/wayland-scanner/src/server_gen.rs index af13af35e52..a562be9c8e7 100644 --- a/wayland-scanner/src/server_gen.rs +++ b/wayland-scanner/src/server_gen.rs @@ -12,7 +12,7 @@ pub fn generate_server_objects(protocol: &Protocol) -> TokenStream { protocol .interfaces .iter() - .filter(|iface| iface.name != "wl_display" && iface.name != "wl_registry") + .filter(|iface| iface.name != "wl_display") .map(generate_objects_for) .collect() } @@ -39,7 +39,11 @@ fn generate_objects_for(interface: &Interface) -> TokenStream { &interface.events, ); - let parse_body = crate::common::gen_parse_body(interface, Side::Server); + let parse_body = if interface.name == "wl_registry" { + quote! { unimplemented!("`wl_registry` is implemented internally in `wayland-server`") } + } else { + crate::common::gen_parse_body(interface, Side::Server) + }; let write_body = crate::common::gen_write_body(interface, Side::Server); let methods = gen_methods(interface); diff --git a/wayland-scanner/tests/scanner_assets/test-server-code.rs b/wayland-scanner/tests/scanner_assets/test-server-code.rs index 495fe6d5eaa..b600075f918 100644 --- a/wayland-scanner/tests/scanner_assets/test-server-code.rs +++ b/wayland-scanner/tests/scanner_assets/test-server-code.rs @@ -1,3 +1,210 @@ +#[doc = "global registry object\n\nThe singleton global registry object. The server has a number of\nglobal objects that are available to all clients. These objects\ntypically represent an actual object in the server (for example,\nan input device) or they are singleton objects that provide\nextension functionality.\n\nWhen a client creates a registry object, the registry object\nwill emit a global event for each global currently in the\nregistry. Globals come and go as a result of device or\nmonitor hotplugs, reconfiguration or other events, and the\nregistry will send out global and global_remove events to\nkeep the client up to date with the changes. To mark the end\nof the initial burst of events, the client can use the\nwl_display.sync request immediately after calling\nwl_display.get_registry.\n\nA client can bind to a global object by using the bind\nrequest. This creates a client-side handle that lets the object\nemit events to the client and lets the client invoke requests on\nthe object."] +pub mod wl_registry { + use super::wayland_server::{ + backend::{ + protocol::{same_interface, Argument, Interface, Message, WEnum}, + smallvec, InvalidId, ObjectData, ObjectId, WeakHandle, + }, + Dispatch, DispatchError, DisplayHandle, New, Resource, ResourceData, Weak, + }; + use std::os::unix::io::OwnedFd; + use std::sync::Arc; + #[doc = r" The minimal object version supporting this request"] + pub const REQ_BIND_SINCE: u32 = 1u32; + #[doc = r" The wire opcode for this request"] + pub const REQ_BIND_OPCODE: u16 = 0u16; + #[doc = r" The minimal object version supporting this event"] + pub const EVT_GLOBAL_SINCE: u32 = 1u32; + #[doc = r" The wire opcode for this event"] + pub const EVT_GLOBAL_OPCODE: u16 = 0u16; + #[doc = r" The minimal object version supporting this event"] + pub const EVT_GLOBAL_REMOVE_SINCE: u32 = 1u32; + #[doc = r" The wire opcode for this event"] + pub const EVT_GLOBAL_REMOVE_OPCODE: u16 = 1u16; + #[derive(Debug)] + #[non_exhaustive] + pub enum Request { + #[doc = "bind an object to the display\n\nBinds a new, client-created object to the server using the\nspecified name as the identifier."] + Bind { + #[doc = "unique numeric name of the object"] + name: u32, + #[doc = "bounded object"] + id: (String, u32, super::wayland_server::ObjectId), + }, + } + impl Request { + #[doc = "Get the opcode number of this message"] + pub fn opcode(&self) -> u16 { + match *self { + Request::Bind { .. } => 0u16, + } + } + } + #[derive(Debug)] + #[non_exhaustive] + pub enum Event<'a> { + #[doc = "announce global object\n\nNotify the client of global objects.\n\nThe event notifies the client that a global object with\nthe given name is now available, and it implements the\ngiven version of the given interface."] + Global { + #[doc = "numeric name of the global object"] + name: u32, + #[doc = "interface implemented by the object"] + interface: String, + #[doc = "interface version"] + version: u32, + }, + #[doc = "announce removal of global object\n\nNotify the client of removed global objects.\n\nThis event notifies the client that the global identified\nby name is no longer available. If the client bound to\nthe global using the bind request, the client should now\ndestroy that object.\n\nThe object remains valid and requests to the object will be\nignored until the client destroys it, to avoid races between\nthe global going away and a client sending a request to it."] + GlobalRemove { + #[doc = "numeric name of the global object"] + name: u32, + }, + #[doc(hidden)] + __phantom_lifetime { + phantom: std::marker::PhantomData<&'a ()>, + never: std::convert::Infallible, + }, + } + impl<'a> Event<'a> { + #[doc = "Get the opcode number of this message"] + pub fn opcode(&self) -> u16 { + match *self { + Event::Global { .. } => 0u16, + Event::GlobalRemove { .. } => 1u16, + Event::__phantom_lifetime { never, .. } => match never {}, + } + } + } + #[doc = "global registry object\n\nThe singleton global registry object. The server has a number of\nglobal objects that are available to all clients. These objects\ntypically represent an actual object in the server (for example,\nan input device) or they are singleton objects that provide\nextension functionality.\n\nWhen a client creates a registry object, the registry object\nwill emit a global event for each global currently in the\nregistry. Globals come and go as a result of device or\nmonitor hotplugs, reconfiguration or other events, and the\nregistry will send out global and global_remove events to\nkeep the client up to date with the changes. To mark the end\nof the initial burst of events, the client can use the\nwl_display.sync request immediately after calling\nwl_display.get_registry.\n\nA client can bind to a global object by using the bind\nrequest. This creates a client-side handle that lets the object\nemit events to the client and lets the client invoke requests on\nthe object.\n\nSee also the [Request] enum for this interface."] + #[derive(Debug, Clone)] + pub struct WlRegistry { + id: ObjectId, + version: u32, + data: Option>, + handle: WeakHandle, + } + impl std::cmp::PartialEq for WlRegistry { + #[inline] + fn eq(&self, other: &WlRegistry) -> bool { + self.id == other.id + } + } + impl std::cmp::Eq for WlRegistry {} + impl PartialEq> for WlRegistry { + #[inline] + fn eq(&self, other: &Weak) -> bool { + self.id == other.id() + } + } + impl std::borrow::Borrow for WlRegistry { + #[inline] + fn borrow(&self) -> &ObjectId { + &self.id + } + } + impl std::hash::Hash for WlRegistry { + #[inline] + fn hash(&self, state: &mut H) { + self.id.hash(state) + } + } + impl super::wayland_server::Resource for WlRegistry { + type Request = Request; + type Event<'event> = Event<'event>; + #[inline] + fn interface() -> &'static Interface { + &super::WL_REGISTRY_INTERFACE + } + #[inline] + fn id(&self) -> ObjectId { + self.id.clone() + } + #[inline] + fn version(&self) -> u32 { + self.version + } + #[inline] + fn data(&self) -> Option<&U> { + self.data + .as_ref() + .and_then(|arc| (&**arc).downcast_ref::>()) + .map(|data| &data.udata) + } + #[inline] + fn object_data(&self) -> Option<&Arc> { + self.data.as_ref() + } + fn handle(&self) -> &WeakHandle { + &self.handle + } + #[inline] + fn from_id(conn: &DisplayHandle, id: ObjectId) -> Result { + if !same_interface(id.interface(), Self::interface()) && !id.is_null() { + return Err(InvalidId); + } + let version = conn.object_info(id.clone()).map(|info| info.version).unwrap_or(0); + let data = conn.get_object_data(id.clone()).ok(); + Ok(WlRegistry { id, data, version, handle: conn.backend_handle().downgrade() }) + } + fn send_event(&self, evt: Self::Event<'_>) -> Result<(), InvalidId> { + let handle = DisplayHandle::from(self.handle.upgrade().ok_or(InvalidId)?); + handle.send_event(self, evt) + } + fn parse_request( + conn: &DisplayHandle, + msg: Message, + ) -> Result<(Self, Self::Request), DispatchError> { + unimplemented!("`wl_registry` is implemented internally in `wayland-server`") + } + fn write_event<'a>( + &self, + conn: &DisplayHandle, + msg: Self::Event<'a>, + ) -> Result>, InvalidId> { + match msg { + Event::Global { name, interface, version } => Ok(Message { + sender_id: self.id.clone(), + opcode: 0u16, + args: { + let mut vec = smallvec::SmallVec::new(); + vec.push(Argument::Uint(name)); + vec.push(Argument::Str(Some(Box::new( + std::ffi::CString::new(interface).unwrap(), + )))); + vec.push(Argument::Uint(version)); + vec + }, + }), + Event::GlobalRemove { name } => Ok(Message { + sender_id: self.id.clone(), + opcode: 1u16, + args: { + let mut vec = smallvec::SmallVec::new(); + vec.push(Argument::Uint(name)); + vec + }, + }), + Event::__phantom_lifetime { never, .. } => match never {}, + } + } + fn __set_object_data( + &mut self, + odata: std::sync::Arc, + ) { + self.data = Some(odata); + } + } + impl WlRegistry { + #[doc = "announce global object\n\nNotify the client of global objects.\n\nThe event notifies the client that a global object with\nthe given name is now available, and it implements the\ngiven version of the given interface."] + #[allow(clippy::too_many_arguments)] + pub fn global(&self, name: u32, interface: String, version: u32) { + let _ = self.send_event(Event::Global { name, interface, version }); + } + #[doc = "announce removal of global object\n\nNotify the client of removed global objects.\n\nThis event notifies the client that the global identified\nby name is no longer available. If the client bound to\nthe global using the bind request, the client should now\ndestroy that object.\n\nThe object remains valid and requests to the object will be\nignored until the client destroys it, to avoid races between\nthe global going away and a client sending a request to it."] + #[allow(clippy::too_many_arguments)] + pub fn global_remove(&self, name: u32) { + let _ = self.send_event(Event::GlobalRemove { name }); + } + } +} #[doc = "callback object\n\nClients can handle the 'done' event to get notified when\nthe related request is done."] pub mod wl_callback { use super::wayland_server::{ diff --git a/wayland-server/wayland.xml b/wayland-server/wayland.xml index 9418c62f3f6..f32918e9f98 100644 --- a/wayland-server/wayland.xml +++ b/wayland-server/wayland.xml @@ -1832,6 +1832,9 @@ x and y, combined with the new surface size define in which directions the surface's size changes. + The exact semantics of wl_surface.offset are role-specific. Refer to + the documentation of specific roles for more information. + Surface location offset is double-buffered state, see wl_surface.commit. @@ -1880,7 +1883,7 @@ - + A seat is a group of keyboards, pointer and touch devices. This object is published as a global during start up, or when such a @@ -2013,7 +2016,7 @@ - + The wl_pointer interface represents one or more input devices, such as mice, which control the pointer location and pointer_focus @@ -2426,7 +2429,7 @@ - + The wl_keyboard interface represents one or more keyboards associated with a seat. @@ -2479,6 +2482,9 @@ the surface argument and the keys currently logically down to the keys in the keys argument. The compositor must not send this event if the wl_keyboard already had an active surface immediately before this event. + + Clients should not use the list of pressed keys to emulate key-press + events. The order of keys in the list is unspecified. @@ -2505,9 +2511,18 @@ Describes the physical state of a key that produced the key event. + + Since version 10, the key can be in a "repeated" pseudo-state which + means the same as "pressed", but is used to signal repetition in the + key event. + + The key may only enter the repeated state after entering the pressed + state and before entering the released state. This event may be + generated multiple times while the key is down. + @@ -2530,6 +2545,11 @@ compositor must not send this event if state is pressed (resp. released) and the key was already logically down (resp. was not logically down) immediately before this event. + + Since version 10, compositors may send key events with the "repeated" + key state when a wl_keyboard.repeat_info event with a rate argument of + 0 has been received. This allows the compositor to take over the + responsibility of key repetition. @@ -2590,7 +2610,7 @@ - + The wl_touch interface represents a touchscreen associated with a seat. @@ -3245,4 +3265,31 @@ + + + This global fixes problems with other core-protocol interfaces that + cannot be fixed in these interfaces themselves. + + + + + + + + + This request destroys a wl_registry object. + + The client should no longer use the wl_registry after making this + request. + + The compositor will emit a wl_display.delete_id event with the object ID + of the registry and will no longer emit any events on the registry. The + client should re-use the object ID once it receives the + wl_display.delete_id event. + + + + +