Skip to content

Commit

Permalink
WIP wl-fixes protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Dec 24, 2024
1 parent 10b6ff0 commit b3ebe17
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 10 deletions.
55 changes: 51 additions & 4 deletions wayland-client/wayland.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -1880,7 +1883,7 @@
</event>
</interface>

<interface name="wl_seat" version="9">
<interface name="wl_seat" version="10">
<description summary="group of input devices">
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
Expand Down Expand Up @@ -2013,7 +2016,7 @@

</interface>

<interface name="wl_pointer" version="9">
<interface name="wl_pointer" version="10">
<description summary="pointer input device">
The wl_pointer interface represents one or more input devices,
such as mice, which control the pointer location and pointer_focus
Expand Down Expand Up @@ -2426,7 +2429,7 @@
</event>
</interface>

<interface name="wl_keyboard" version="9">
<interface name="wl_keyboard" version="10">
<description summary="keyboard input device">
The wl_keyboard interface represents one or more keyboards
associated with a seat.
Expand Down Expand Up @@ -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.
</description>
<arg name="serial" type="uint" summary="serial number of the enter event"/>
<arg name="surface" type="object" interface="wl_surface" summary="surface gaining keyboard focus"/>
Expand All @@ -2505,9 +2511,18 @@
<enum name="key_state">
<description summary="physical key state">
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.
</description>
<entry name="released" value="0" summary="key is not pressed"/>
<entry name="pressed" value="1" summary="key is pressed"/>
<entry name="repeated" value="2" summary="key was repeated" since="10"/>
</enum>

<event name="key">
Expand All @@ -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.
</description>
<arg name="serial" type="uint" summary="serial number of the key event"/>
<arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
Expand Down Expand Up @@ -2590,7 +2610,7 @@
</event>
</interface>

<interface name="wl_touch" version="9">
<interface name="wl_touch" version="10">
<description summary="touchscreen input device">
The wl_touch interface represents a touchscreen
associated with a seat.
Expand Down Expand Up @@ -3245,4 +3265,31 @@
</request>
</interface>

<interface name="wl_fixes" version="1">
<description summary="wayland protocol fixes">
This global fixes problems with other core-protocol interfaces that
cannot be fixed in these interfaces themselves.
</description>

<request name="destroy" type="destructor">
<description summary="destroys this object"/>
</request>

<request name="destroy_registry">
<description summary="destroy a wl_registry">
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.
</description>
<arg name="registry" type="object" interface="wl_registry"
summary="the registry to destroy"/>
</request>
</interface>

</protocol>
8 changes: 6 additions & 2 deletions wayland-scanner/src/server_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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);

Expand Down
207 changes: 207 additions & 0 deletions wayland-scanner/tests/scanner_assets/test-server-code.rs
Original file line number Diff line number Diff line change
@@ -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<Arc<dyn std::any::Any + Send + Sync + 'static>>,
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<Weak<WlRegistry>> for WlRegistry {
#[inline]
fn eq(&self, other: &Weak<WlRegistry>) -> bool {
self.id == other.id()
}
}
impl std::borrow::Borrow<ObjectId> for WlRegistry {
#[inline]
fn borrow(&self) -> &ObjectId {
&self.id
}
}
impl std::hash::Hash for WlRegistry {
#[inline]
fn hash<H: std::hash::Hasher>(&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<U: 'static>(&self) -> Option<&U> {
self.data
.as_ref()
.and_then(|arc| (&**arc).downcast_ref::<ResourceData<Self, U>>())
.map(|data| &data.udata)
}
#[inline]
fn object_data(&self) -> Option<&Arc<dyn std::any::Any + Send + Sync>> {
self.data.as_ref()
}
fn handle(&self) -> &WeakHandle {
&self.handle
}
#[inline]
fn from_id(conn: &DisplayHandle, id: ObjectId) -> Result<Self, InvalidId> {
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<ObjectId, OwnedFd>,
) -> 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<Message<ObjectId, std::os::unix::io::BorrowedFd<'a>>, 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<dyn std::any::Any + Send + Sync + 'static>,
) {
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::{
Expand Down
Loading

0 comments on commit b3ebe17

Please sign in to comment.