Skip to content

Commit

Permalink
Add events support to client traits
Browse files Browse the repository at this point in the history
  • Loading branch information
morr0ne committed Dec 18, 2024
1 parent 1541c09 commit c57f3d7
Show file tree
Hide file tree
Showing 14 changed files with 6,186 additions and 3 deletions.
15 changes: 14 additions & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ impl Dispatcher for Display {
}
}

impl WlDisplay for Display {}
impl WlDisplay for Display {
async fn error(
&self,
object_id: waynest::wire::ObjectId,
code: u32,
message: String,
) -> waynest::client::Result<()> {
todo!()
}

async fn delete_id(&self, id: u32) -> waynest::client::Result<()> {
todo!()
}
}

#[tokio::main]
async fn main() -> Result<()> {
Expand Down
36 changes: 35 additions & 1 deletion gen/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn generate_client_code(current: &[Pair], pairs: &[Pair]) -> TokenStream {
let enums = write_enums(&interface);

let requests = write_requests(pairs, pair, interface);
let events = write_events(pairs, pair, interface);

let imports = if requests.is_empty() {
quote! {}
Expand Down Expand Up @@ -61,7 +62,7 @@ pub fn generate_client_code(current: &[Pair], pairs: &[Pair]) -> TokenStream {
}

#(#requests)*
// #(#events)*
#(#events)*
}
}
})
Expand Down Expand Up @@ -180,3 +181,36 @@ fn write_requests(pairs: &[Pair], pair: &Pair, interface: &Interface) -> Vec<Tok

requests
}

fn write_events(pairs: &[Pair], pair: &Pair, interface: &Interface) -> Vec<TokenStream> {
let mut requests = Vec::new();

for request in &interface.events {
let docs = description_to_docs(request.description.as_ref());
let name = make_ident(request.name.to_snek_case());
let mut args = vec![
quote! {&self },
// quote! {object: &crate::server::Object},
// quote! {client: &mut crate::server::Client},
];

for arg in &request.args {
let mut ty = arg.to_rust_type_token(arg.find_protocol(pairs).as_ref().unwrap_or(pair));

if arg.allow_null {
ty = quote! {Option<#ty>};
}

let name = make_ident(arg.name.to_snek_case());

args.push(quote! {#name: #ty})
}

requests.push(quote! {
#(#docs)*
async fn #name(#(#args),*) -> crate::client::Result<()>;
});
}

requests
}
956 changes: 956 additions & 0 deletions src/client/protocol/core.rs

Large diffs are not rendered by default.

324 changes: 324 additions & 0 deletions src/client/protocol/cosmic.rs

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/client/protocol/frog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,27 @@ pub mod frog_color_management_v1 {
.await
.map_err(crate::client::Error::IoError)
}
#[doc = "Current preferred metadata for a surface."]
#[doc = "The application should use this information to tone-map its buffers"]
#[doc = "to this target before committing."]
#[doc = ""]
#[doc = "This metadata does not necessarily correspond to any physical output, but"]
#[doc = "rather what the compositor thinks would be best for a given surface."]
async fn preferred_metadata(
&self,
transfer_function: TransferFunction,
output_display_primary_red_x: u32,
output_display_primary_red_y: u32,
output_display_primary_green_x: u32,
output_display_primary_green_y: u32,
output_display_primary_blue_x: u32,
output_display_primary_blue_y: u32,
output_white_point_x: u32,
output_white_point_y: u32,
max_luminance: u32,
min_luminance: u32,
max_full_frame_luminance: u32,
) -> crate::client::Result<()>;
}
}
}
Expand Down
87 changes: 87 additions & 0 deletions src/client/protocol/hyprland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ pub mod hyprland_focus_grab_v1 {
.await
.map_err(crate::client::Error::IoError)
}
#[doc = "Sent when an active grab is cancelled by the compositor,"]
#[doc = "regardless of cause."]
async fn cleared(&self) -> crate::client::Result<()>;
}
}
}
Expand Down Expand Up @@ -403,6 +406,24 @@ pub mod hyprland_global_shortcuts_v1 {
.await
.map_err(crate::client::Error::IoError)
}
#[doc = "The keystroke was pressed."]
#[doc = ""]
#[doc = "tv_ values hold the timestamp of the occurrence."]
async fn pressed(
&self,
tv_sec_hi: u32,
tv_sec_lo: u32,
tv_nsec: u32,
) -> crate::client::Result<()>;
#[doc = "The keystroke was released."]
#[doc = ""]
#[doc = "tv_ values hold the timestamp of the occurrence."]
async fn released(
&self,
tv_sec_hi: u32,
tv_sec_lo: u32,
tv_nsec: u32,
) -> crate::client::Result<()>;
}
}
}
Expand Down Expand Up @@ -601,6 +622,72 @@ pub mod hyprland_toplevel_export_v1 {
.await
.map_err(crate::client::Error::IoError)
}
#[doc = "Provides information about wl_shm buffer parameters that need to be"]
#[doc = "used for this frame. This event is sent once after the frame is created"]
#[doc = "if wl_shm buffers are supported."]
async fn buffer(
&self,
format: super::super::super::core::wayland::wl_shm::Format,
width: u32,
height: u32,
stride: u32,
) -> crate::client::Result<()>;
#[doc = "This event is sent right before the ready event when ignore_damage was"]
#[doc = "not set. It may be generated multiple times for each copy"]
#[doc = "request."]
#[doc = ""]
#[doc = "The arguments describe a box around an area that has changed since the"]
#[doc = "last copy request that was derived from the current screencopy manager"]
#[doc = "instance."]
#[doc = ""]
#[doc = "The union of all regions received between the call to copy"]
#[doc = "and a ready event is the total damage since the prior ready event."]
async fn damage(
&self,
x: u32,
y: u32,
width: u32,
height: u32,
) -> crate::client::Result<()>;
#[doc = "Provides flags about the frame. This event is sent once before the"]
#[doc = "\"ready\" event."]
async fn flags(&self, flags: Flags) -> crate::client::Result<()>;
#[doc = "Called as soon as the frame is copied, indicating it is available"]
#[doc = "for reading. This event includes the time at which presentation happened"]
#[doc = "at."]
#[doc = ""]
#[doc = "The timestamp is expressed as tv_sec_hi, tv_sec_lo, tv_nsec triples,"]
#[doc = "each component being an unsigned 32-bit value. Whole seconds are in"]
#[doc = "tv_sec which is a 64-bit value combined from tv_sec_hi and tv_sec_lo,"]
#[doc = "and the additional fractional part in tv_nsec as nanoseconds. Hence,"]
#[doc = "for valid timestamps tv_nsec must be in [0, 999999999]. The seconds part"]
#[doc = "may have an arbitrary offset at start."]
#[doc = ""]
#[doc = "After receiving this event, the client should destroy the object."]
async fn ready(
&self,
tv_sec_hi: u32,
tv_sec_lo: u32,
tv_nsec: u32,
) -> crate::client::Result<()>;
#[doc = "This event indicates that the attempted frame copy has failed."]
#[doc = ""]
#[doc = "After receiving this event, the client should destroy the object."]
async fn failed(&self) -> crate::client::Result<()>;
#[doc = "Provides information about linux-dmabuf buffer parameters that need to"]
#[doc = "be used for this frame. This event is sent once after the frame is"]
#[doc = "created if linux-dmabuf buffers are supported."]
async fn linux_dmabuf(
&self,
format: u32,
width: u32,
height: u32,
) -> crate::client::Result<()>;
#[doc = "This event is sent once after all buffer events have been sent."]
#[doc = ""]
#[doc = "The client should proceed to create a buffer of one of the supported"]
#[doc = "types, and send a \"copy\" request."]
async fn buffer_done(&self) -> crate::client::Result<()>;
}
}
}
Loading

0 comments on commit c57f3d7

Please sign in to comment.