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
13 changes: 4 additions & 9 deletions examples/data_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use smithay_client_toolkit::{
data_source::{CopyPasteSource, DataSourceHandler, DragSource},
DataDeviceManagerState, WritePipe,
},
delegate_compositor, delegate_data_device, delegate_keyboard, delegate_output,
delegate_pointer, delegate_primary_selection, delegate_registry, delegate_seat, delegate_shm,
delegate_xdg_shell, delegate_xdg_window,
delegate_compositor, delegate_data_device, delegate_keyboard, delegate_pointer,
delegate_primary_selection, delegate_registry,
output::{OutputHandler, OutputState},
primary_selection::{
device::{PrimarySelectionDevice, PrimarySelectionDeviceHandler},
Expand Down Expand Up @@ -1082,16 +1081,10 @@ struct SeatObject {
}

delegate_compositor!(DataDeviceWindow);
delegate_output!(DataDeviceWindow);
delegate_shm!(DataDeviceWindow);

delegate_seat!(DataDeviceWindow);
delegate_keyboard!(DataDeviceWindow);
delegate_pointer!(DataDeviceWindow);

delegate_xdg_shell!(DataDeviceWindow);
delegate_xdg_window!(DataDeviceWindow);

delegate_data_device!(DataDeviceWindow);

delegate_primary_selection!(DataDeviceWindow);
Expand All @@ -1115,3 +1108,5 @@ fn pick_mime(mime_types: &[String]) -> Option<String> {

None
}

smithay_client_toolkit::delegate_dispatch2!(DataDeviceWindow);
11 changes: 3 additions & 8 deletions examples/generic_simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::convert::TryInto;

use smithay_client_toolkit::{
compositor::{CompositorHandler, CompositorState},
delegate_compositor, delegate_keyboard, delegate_output, delegate_pointer, delegate_registry,
delegate_seat, delegate_shm, delegate_xdg_shell, delegate_xdg_window,
delegate_compositor, delegate_keyboard, delegate_pointer, delegate_registry,
output::{OutputHandler, OutputState},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
Expand Down Expand Up @@ -477,16 +476,10 @@ impl<T: Test + 'static> SimpleWindow<T> {
}

delegate_compositor!(@<T: Test + 'static> SimpleWindow<T>);
delegate_output!(@<T: Test + 'static> SimpleWindow<T>);
delegate_shm!(@<T: Test + 'static> SimpleWindow<T>);

delegate_seat!(@<T: Test + 'static> SimpleWindow<T>);
delegate_keyboard!(@<T: Test + 'static> SimpleWindow<T>);
delegate_pointer!(@<T: Test + 'static> SimpleWindow<T>);

delegate_xdg_shell!(@<T: Test + 'static> SimpleWindow<T>);
delegate_xdg_window!(@<T: Test + 'static> SimpleWindow<T>);

delegate_registry!(@<T: Test + 'static> SimpleWindow<T>);

impl<T: Test + 'static> ProvidesRegistryState for SimpleWindow<T> {
Expand All @@ -495,3 +488,5 @@ impl<T: Test + 'static> ProvidesRegistryState for SimpleWindow<T> {
}
registry_handlers![OutputState, SeatState,];
}

smithay_client_toolkit::delegate_dispatch2!(@<T: Test + 'static> SimpleWindow<T>);
11 changes: 4 additions & 7 deletions examples/simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use smithay_client_toolkit::reexports::calloop_wayland_source::WaylandSource;
use smithay_client_toolkit::{
activation::{ActivationHandler, ActivationState},
compositor::{CompositorHandler, CompositorState},
delegate_activation, delegate_compositor, delegate_keyboard, delegate_output, delegate_pointer,
delegate_registry, delegate_seat, delegate_shm, delegate_xdg_shell, delegate_xdg_window,
delegate_activation, delegate_compositor, delegate_keyboard, delegate_pointer,
delegate_registry,
output::{OutputHandler, OutputState},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
Expand Down Expand Up @@ -517,15 +517,10 @@ impl SimpleWindow {
}

delegate_compositor!(SimpleWindow);
delegate_output!(SimpleWindow);
delegate_shm!(SimpleWindow);

delegate_seat!(SimpleWindow);
delegate_keyboard!(SimpleWindow);
delegate_pointer!(SimpleWindow);

delegate_xdg_shell!(SimpleWindow);
delegate_xdg_window!(SimpleWindow);
delegate_activation!(SimpleWindow);

delegate_registry!(SimpleWindow);
Expand All @@ -536,3 +531,5 @@ impl ProvidesRegistryState for SimpleWindow {
}
registry_handlers![OutputState, SeatState,];
}

smithay_client_toolkit::delegate_dispatch2!(SimpleWindow);
12 changes: 4 additions & 8 deletions src/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use wayland_client::{
use wayland_protocols::xdg::activation::v1::client::{xdg_activation_token_v1, xdg_activation_v1};

use crate::{
dispatch2::Dispatch2,
error::GlobalError,
globals::{GlobalData, ProvidesBoundGlobal},
};
Expand Down Expand Up @@ -129,15 +130,15 @@ impl ActivationState {
}
}

impl<D> Dispatch<xdg_activation_v1::XdgActivationV1, GlobalData, D> for ActivationState
impl<D> Dispatch2<xdg_activation_v1::XdgActivationV1, D> for GlobalData
where
D: Dispatch<xdg_activation_v1::XdgActivationV1, GlobalData> + ActivationHandler,
D: ActivationHandler,
{
fn event(
&self,
_: &mut D,
_: &xdg_activation_v1::XdgActivationV1,
_: <xdg_activation_v1::XdgActivationV1 as Proxy>::Event,
_: &GlobalData,
_: &wayland_client::Connection,
_: &QueueHandle<D>,
) {
Expand Down Expand Up @@ -174,11 +175,6 @@ where
#[macro_export]
macro_rules! delegate_activation {
($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {
$crate::reexports::client::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty:
[
$crate::reexports::protocols::xdg::activation::v1::client::xdg_activation_v1::XdgActivationV1: $crate::globals::GlobalData
] => $crate::activation::ActivationState
);
$crate::reexports::client::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty:
[
$crate::reexports::protocols::xdg::activation::v1::client::xdg_activation_token_v1::XdgActivationTokenV1: $crate::activation::RequestData
Expand Down
12 changes: 4 additions & 8 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use wayland_client::{
};

use crate::{
dispatch2::Dispatch2,
error::GlobalError,
globals::{GlobalData, ProvidesBoundGlobal},
output::{OutputData, OutputHandler, OutputState, ScaleWatcherHandle},
Expand Down Expand Up @@ -269,11 +270,6 @@ macro_rules! delegate_compositor {
$crate::delegate_compositor!(@{ $(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty }; surface: [ $($surface),* ]);
};
(@{$($ty:tt)*}; surface: []) => {
$crate::reexports::client::delegate_dispatch!($($ty)*:
[
$crate::reexports::client::protocol::wl_compositor::WlCompositor: $crate::globals::GlobalData
] => $crate::compositor::CompositorState
);
$crate::reexports::client::delegate_dispatch!($($ty)*:
[
$crate::reexports::client::protocol::wl_callback::WlCallback: $crate::reexports::client::protocol::wl_surface::WlSurface
Expand Down Expand Up @@ -481,15 +477,15 @@ impl wayland_client::backend::ObjectData for RegionData {
fn destroyed(&self, _: wayland_client::backend::ObjectId) {}
}

impl<D> Dispatch<wl_compositor::WlCompositor, GlobalData, D> for CompositorState
impl<D> Dispatch2<wl_compositor::WlCompositor, D> for GlobalData
where
D: Dispatch<wl_compositor::WlCompositor, GlobalData> + CompositorHandler,
D: CompositorHandler,
{
fn event(
&self,
_: &mut D,
_: &wl_compositor::WlCompositor,
_: wl_compositor::Event,
_: &GlobalData,
_: &Connection,
_: &QueueHandle<D>,
) {
Expand Down
47 changes: 47 additions & 0 deletions src/dispatch2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use std::sync::Arc;
use wayland_client::backend::ObjectData;
use wayland_client::{Connection, Proxy, QueueHandle};

pub trait Dispatch2<I: Proxy, State> {
fn event(
&self,
_: &mut State,
_: &I,
_: <I as Proxy>::Event,
_: &Connection,
_: &QueueHandle<State>,
);

fn event_created_child(opcode: u16, _qh: &QueueHandle<State>) -> Arc<dyn ObjectData> {
panic!(
"Missing event_created_child specialization for event opcode {} of {}",
opcode,
I::interface().name
);
}
}

#[macro_export]
macro_rules! delegate_dispatch2 {
($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {
impl<$( $( $lt $( : $clt $(+ $dlt )* )? ),+, )? I, UserData> $crate::reexports::client::Dispatch<I, UserData> for $ty
where
I: $crate::reexports::client::Proxy,
UserData: $crate::dispatch2::Dispatch2<I, $ty> {
fn event(
state: &mut $ty,
proxy: &I,
event: <I as $crate::reexports::client::Proxy>::Event,
data: &UserData,
conn: &$crate::reexports::client::Connection,
qh: &QueueHandle<$ty>,
) {
data.event(state, proxy, event, conn, qh);
}

fn event_created_child(opcode: u16, qh: &$crate::reexports::client::QueueHandle<$ty>) -> ::std::sync::Arc<dyn $crate::reexports::client::backend::ObjectData> {
UserData::event_created_child(opcode, qh)
}
}
};
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod reexports {
pub mod activation;
pub mod compositor;
pub mod data_device_manager;
pub mod dispatch2;
pub mod dmabuf;
pub mod error;
pub mod foreign_toplevel_list;
Expand Down
38 changes: 12 additions & 26 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
};

use crate::{
dispatch2::Dispatch2,
globals::GlobalData,
registry::{GlobalProxy, ProvidesRegistryState, RegistryHandler},
};
Expand Down Expand Up @@ -69,7 +70,7 @@
/// use smithay_client_toolkit::registry::{ProvidesRegistryState,RegistryHandler};
/// # use smithay_client_toolkit::registry::RegistryState;
/// use smithay_client_toolkit::{registry_handlers,delegate_output, delegate_registry};
/// use wayland_client::{Connection,QueueHandle,protocol::wl_output};

Check failure on line 73 in src/output.rs

View workflow job for this annotation

GitHub Actions / test (beta)

unresolved import `smithay_client_toolkit::delegate_output`

Check failure on line 73 in src/output.rs

View workflow job for this annotation

GitHub Actions / test (stable)

unresolved import `smithay_client_toolkit::delegate_output`
///
/// struct ExampleState {
/// # registry_state: RegistryState,
Expand Down Expand Up @@ -105,7 +106,7 @@
/// // ...
///
/// registry_handlers!(OutputState);
/// }

Check failure on line 109 in src/output.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the trait bound `ExampleState: Dispatch<ZxdgOutputManagerV1, GlobalData>` is not satisfied

Check failure on line 109 in src/output.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the trait bound `ExampleState: Dispatch<ZxdgOutputV1, OutputData>` is not satisfied

Check failure on line 109 in src/output.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the trait bound `ExampleState: Dispatch<WlOutput, OutputData>` is not satisfied

Check failure on line 109 in src/output.rs

View workflow job for this annotation

GitHub Actions / test (stable)

the trait bound `ExampleState: Dispatch<ZxdgOutputManagerV1, GlobalData>` is not satisfied

Check failure on line 109 in src/output.rs

View workflow job for this annotation

GitHub Actions / test (stable)

the trait bound `ExampleState: Dispatch<ZxdgOutputV1, OutputData>` is not satisfied

Check failure on line 109 in src/output.rs

View workflow job for this annotation

GitHub Actions / test (stable)

the trait bound `ExampleState: Dispatch<WlOutput, OutputData>` is not satisfied
/// ```
pub struct OutputState {
xdg: GlobalProxy<ZxdgOutputManagerV1>,
Expand Down Expand Up @@ -391,30 +392,15 @@
pub description: Option<String>,
}

#[macro_export]
macro_rules! delegate_output {
($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {
$crate::reexports::client::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
$crate::reexports::client::protocol::wl_output::WlOutput: $crate::output::OutputData
] => $crate::output::OutputState);
$crate::reexports::client::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
$crate::reexports::protocols::xdg::xdg_output::zv1::client::zxdg_output_manager_v1::ZxdgOutputManagerV1: $crate::globals::GlobalData
] => $crate::output::OutputState);
$crate::reexports::client::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
$crate::reexports::protocols::xdg::xdg_output::zv1::client::zxdg_output_v1::ZxdgOutputV1: $crate::output::OutputData
] => $crate::output::OutputState);
};
}

impl<D> Dispatch<wl_output::WlOutput, OutputData, D> for OutputState
impl<D> Dispatch2<wl_output::WlOutput, D> for OutputData
where
D: Dispatch<wl_output::WlOutput, OutputData> + OutputHandler + 'static,
D: OutputHandler + 'static,
{
fn event(
&self,
state: &mut D,
output: &wl_output::WlOutput,
event: wl_output::Event,
data: &OutputData,
conn: &Connection,
qh: &QueueHandle<D>,
) {
Expand Down Expand Up @@ -519,7 +505,7 @@
inner.pending_wl = false;

// Set the user data, see if we need to run scale callbacks
let run_callbacks = data.set(info);
let run_callbacks = self.set(info);

// Don't call `new_output` until we have xdg output info
if !inner.pending_xdg {
Expand All @@ -545,31 +531,31 @@
}
}

impl<D> Dispatch<zxdg_output_manager_v1::ZxdgOutputManagerV1, GlobalData, D> for OutputState
impl<D> Dispatch2<zxdg_output_manager_v1::ZxdgOutputManagerV1, D> for GlobalData
where
D: Dispatch<zxdg_output_manager_v1::ZxdgOutputManagerV1, GlobalData> + OutputHandler,
D: OutputHandler,
{
fn event(
&self,
_: &mut D,
_: &zxdg_output_manager_v1::ZxdgOutputManagerV1,
_: zxdg_output_manager_v1::Event,
_: &GlobalData,
_: &Connection,
_: &QueueHandle<D>,
) {
unreachable!("zxdg_output_manager_v1 has no events")
}
}

impl<D> Dispatch<zxdg_output_v1::ZxdgOutputV1, OutputData, D> for OutputState
impl<D> Dispatch2<zxdg_output_v1::ZxdgOutputV1, D> for OutputData
where
D: Dispatch<zxdg_output_v1::ZxdgOutputV1, OutputData> + OutputHandler,
D: OutputHandler,
{
fn event(
&self,
state: &mut D,
output: &zxdg_output_v1::ZxdgOutputV1,
event: zxdg_output_v1::Event,
data: &OutputData,
conn: &Connection,
qh: &QueueHandle<D>,
) {
Expand Down Expand Up @@ -631,7 +617,7 @@
inner.pending_xdg = false;

// Set the user data
data.set(info);
self.set(info);

let pending_wl = inner.pending_wl;
let just_created = inner.just_created;
Expand Down
Loading
Loading