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
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ pollster = "0.3.0"
[[example]]
name = "wgpu"
required-features = ["system"]

[patch.crates-io]
wayland-client = { git = "https://github.com/smithay/wayland-rs" }
wayland-protocols = { git = "https://github.com/smithay/wayland-rs" }
wayland-protocols-wlr = { git = "https://github.com/smithay/wayland-rs" }
wayland-protocols-misc = { git = "https://github.com/smithay/wayland-rs" }
wayland-protocols-experimental = { git = "https://github.com/smithay/wayland-rs" }
wayland-cursor = { git = "https://github.com/smithay/wayland-rs" }
wayland-backend = { git = "https://github.com/smithay/wayland-rs" }
35 changes: 9 additions & 26 deletions examples/image_viewporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use std::{env, path::Path};

use smithay_client_toolkit::{
compositor::{CompositorHandler, CompositorState},
delegate_registry,
output::{OutputHandler, OutputState},
registry::{ProvidesRegistryState, RegistryState, SimpleGlobal},
registry::SimpleGlobal,
registry_handlers,
shell::{
xdg::{
Expand All @@ -16,7 +15,7 @@ use smithay_client_toolkit::{
shm::{slot::SlotPool, Shm, ShmHandler},
};
use wayland_client::{
globals::registry_queue_init,
globals::{registry_queue_init, GlobalListHandler},
protocol::{wl_output, wl_shm, wl_surface},
Connection, Dispatch, QueueHandle,
};
Expand All @@ -37,7 +36,8 @@ fn main() {

// The compositor (not to be confused with the server which is commonly called the compositor) allows
// configuring surfaces to be presented.
let compositor = CompositorState::bind(&globals, &qh).expect("wl_compositor not available");
let compositor =
CompositorState::bind_singleton(&globals, &qh).expect("wl_compositor not available");
// For desktop platforms, the XDG shell is the standard protocol for creating desktop windows.
let xdg_shell = XdgShell::bind(&globals, &qh).expect("xdg shell is not available");
// Since we are not using the GPU in this example, we use wl_shm to allow software rendering to a buffer
Expand Down Expand Up @@ -112,14 +112,8 @@ fn main() {

let pool = SlotPool::new(pool_size as usize, &shm).expect("Failed to create pool");

let mut state = State {
registry_state: RegistryState::new(&globals),
output_state: OutputState::new(&globals, &qh),
shm,
wp_viewporter,
pool,
windows,
};
let mut state =
State { output_state: OutputState::new(&globals, &qh), shm, wp_viewporter, pool, windows };

// We don't draw immediately, the configure will notify us when to first draw.

Expand All @@ -134,7 +128,6 @@ fn main() {
}

struct State {
registry_state: RegistryState,
output_state: OutputState,
shm: Shm,
wp_viewporter: SimpleGlobal<WpViewporter, 1>,
Expand Down Expand Up @@ -317,15 +310,7 @@ impl State {
}
}

wayland_client::delegate_noop!(State: WpViewporter);

delegate_registry!(State);

impl ProvidesRegistryState for State {
fn registry(&mut self) -> &mut RegistryState {
&mut self.registry_state
}

impl GlobalListHandler for State {
registry_handlers!(OutputState);
}

Expand All @@ -335,12 +320,12 @@ impl AsMut<SimpleGlobal<WpViewporter, 1>> for State {
}
}

impl Dispatch<WpViewport, ()> for State {
impl Dispatch<WpViewport, State> for () {
fn event(
&self,
_: &mut State,
_: &WpViewport,
_: wp_viewport::Event,
_: &(),
_: &Connection,
_: &QueueHandle<State>,
) {
Expand All @@ -353,5 +338,3 @@ impl Drop for ImageViewer {
self.viewport.destroy()
}
}

smithay_client_toolkit::delegate_dispatch2!(State);
27 changes: 2 additions & 25 deletions examples/relative_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

use smithay_client_toolkit::{
compositor::{CompositorHandler, CompositorState, FrameCallbackData},
delegate_registry,
globals::ProvidesBoundGlobal,
output::{OutputHandler, OutputState},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
seat::{
pointer::{PointerEvent, PointerEventKind, PointerHandler},
Expand All @@ -23,7 +21,7 @@ use smithay_client_toolkit::{
shm::{slot::SlotPool, Shm, ShmHandler},
};
use wayland_client::{
globals::registry_queue_init,
globals::{registry_queue_init, GlobalListHandler},
protocol::{wl_output, wl_pointer, wl_region, wl_seat, wl_shm, wl_surface},
Connection, Dispatch, QueueHandle,
};
Expand Down Expand Up @@ -65,7 +63,6 @@ fn main() {
.unwrap();

let mut simple_window = SimpleWindow {
registry_state: RegistryState::new(&globals),
seat_state: SeatState::new(&globals, &qh),
output_state: OutputState::new(&globals, &qh),
compositor_state: CompositorState::bind(&globals, &qh)
Expand Down Expand Up @@ -106,7 +103,6 @@ fn main() {
}

struct SimpleWindow {
registry_state: RegistryState,
seat_state: SeatState,
output_state: OutputState,
compositor_state: CompositorState,
Expand Down Expand Up @@ -544,25 +540,6 @@ impl SimpleWindow {
}
}

delegate_registry!(SimpleWindow);

impl ProvidesRegistryState for SimpleWindow {
fn registry(&mut self) -> &mut RegistryState {
&mut self.registry_state
}
impl GlobalListHandler for SimpleWindow {
registry_handlers![OutputState, SeatState,];
}

impl Dispatch<wl_region::WlRegion, ()> for SimpleWindow {
fn event(
_: &mut Self,
_: &wl_region::WlRegion,
_: wl_region::Event,
_: &(),
_: &Connection,
_: &QueueHandle<SimpleWindow>,
) {
}
}

smithay_client_toolkit::delegate_dispatch2!(SimpleWindow);
15 changes: 2 additions & 13 deletions examples/simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use smithay_client_toolkit::reexports::calloop_wayland_source::WaylandSource;
use smithay_client_toolkit::{
activation::{ActivationHandler, ActivationState},
compositor::{CompositorHandler, CompositorState, FrameCallbackData},
delegate_registry,
output::{OutputHandler, OutputState},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
seat::{
keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers, RawModifiers},
Expand All @@ -28,7 +26,7 @@ use smithay_client_toolkit::{
},
};
use wayland_client::{
globals::registry_queue_init,
globals::{registry_queue_init, GlobalListHandler},
protocol::{wl_keyboard, wl_output, wl_pointer, wl_seat, wl_shm, wl_surface},
Connection, QueueHandle,
};
Expand Down Expand Up @@ -96,7 +94,6 @@ fn main() {
let mut simple_window = SimpleWindow {
// Seats and outputs may be hotplugged at runtime, therefore we need to setup a registry state to
// listen for seats and outputs.
registry_state: RegistryState::new(&globals),
seat_state: SeatState::new(&globals, &qh),
output_state: OutputState::new(&globals, &qh),
shm,
Expand Down Expand Up @@ -128,7 +125,6 @@ fn main() {
}

struct SimpleWindow {
registry_state: RegistryState,
seat_state: SeatState,
output_state: OutputState,
shm: Shm,
Expand Down Expand Up @@ -516,13 +512,6 @@ impl SimpleWindow {
}
}

delegate_registry!(SimpleWindow);

impl ProvidesRegistryState for SimpleWindow {
fn registry(&mut self) -> &mut RegistryState {
&mut self.registry_state
}
impl GlobalListHandler for SimpleWindow {
registry_handlers![OutputState, SeatState,];
}

smithay_client_toolkit::delegate_dispatch2!(SimpleWindow);
11 changes: 5 additions & 6 deletions src/activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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 @@ -55,9 +54,9 @@ impl ActivationState {
qh: &QueueHandle<State>,
) -> Result<ActivationState, BindError>
where
State: Dispatch<xdg_activation_v1::XdgActivationV1, GlobalData, State> + 'static,
State: ActivationHandler + 'static,
{
let xdg_activation = globals.bind(qh, 1..=1, GlobalData)?;
let xdg_activation = globals.bind_singleton(qh, 1..=1, GlobalData)?;
Ok(ActivationState { xdg_activation })
}

Expand All @@ -73,7 +72,7 @@ impl ActivationState {
pub fn request_token<D, U>(&self, qh: &QueueHandle<D>, request_data: RequestData<U>)
where
D: ActivationHandler<RequestUdata = U>,
D: Dispatch<xdg_activation_token_v1::XdgActivationTokenV1, RequestData<U>> + 'static,
D: 'static,
U: Send + Sync + 'static,
{
let token = self.xdg_activation.get_activation_token(qh, request_data);
Expand All @@ -91,7 +90,7 @@ impl ActivationState {
}
}

impl<D> Dispatch2<xdg_activation_v1::XdgActivationV1, D> for GlobalData
impl<D> Dispatch<xdg_activation_v1::XdgActivationV1, D> for GlobalData
where
D: ActivationHandler,
{
Expand All @@ -113,7 +112,7 @@ impl ProvidesBoundGlobal<xdg_activation_v1::XdgActivationV1, 1> for ActivationSt
}
}

impl<D, U> Dispatch2<xdg_activation_token_v1::XdgActivationTokenV1, D> for RequestData<U>
impl<D, U> Dispatch<xdg_activation_token_v1::XdgActivationTokenV1, D> for RequestData<U>
where
D: ActivationHandler<RequestUdata = U>,
{
Expand Down
24 changes: 7 additions & 17 deletions src/background_effect.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use wayland_client::{
globals::GlobalList, protocol::wl_surface, Connection, Dispatch, QueueHandle, WEnum,
globals::GlobalList, protocol::wl_surface, Connection, Dispatch, QueueHandle,
};
use wayland_protocols::ext::background_effect::v1::client::{
ext_background_effect_manager_v1, ext_background_effect_surface_v1,
};

use crate::{dispatch2::Dispatch2, error::GlobalError, globals::GlobalData, registry::GlobalProxy};
use crate::{error::GlobalError, globals::GlobalData, registry::GlobalProxy};

#[derive(Debug)]
pub struct BackgroundEffectState {
Expand All @@ -16,10 +16,9 @@ pub struct BackgroundEffectState {
impl BackgroundEffectState {
pub fn new<D>(globals: &GlobalList, qh: &QueueHandle<D>) -> Self
where
D: Dispatch<ext_background_effect_manager_v1::ExtBackgroundEffectManagerV1, GlobalData>
+ 'static,
D: BackgroundEffectHandler + 'static,
{
let manager = GlobalProxy::from(globals.bind(qh, 1..=1, GlobalData));
let manager = GlobalProxy::from(globals.bind_singleton(qh, 1..=1, GlobalData));
Self { manager, capabilities: None }
}

Expand All @@ -39,8 +38,7 @@ impl BackgroundEffectState {
qh: &QueueHandle<D>,
) -> Result<ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1, GlobalError>
where
D: Dispatch<ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1, GlobalData>
+ 'static,
D: BackgroundEffectHandler + 'static,
{
Ok(self.manager.get()?.get_background_effect(surface, qh, GlobalData))
}
Expand All @@ -62,7 +60,7 @@ pub trait BackgroundEffectHandler {
fn update_capabilities(&mut self);
}

impl<D> Dispatch2<ext_background_effect_manager_v1::ExtBackgroundEffectManagerV1, D> for GlobalData
impl<D> Dispatch<ext_background_effect_manager_v1::ExtBackgroundEffectManagerV1, D> for GlobalData
where
D: BackgroundEffectHandler,
{
Expand All @@ -76,12 +74,6 @@ where
) {
match event {
ext_background_effect_manager_v1::Event::Capabilities { flags } => {
let flags = match flags {
WEnum::Value(value) => value,
WEnum::Unknown(value) => {
ext_background_effect_manager_v1::Capability::from_bits_retain(value)
}
};
data.background_effect_state().capabilities = Some(flags);
data.update_capabilities();
}
Expand All @@ -90,9 +82,7 @@ where
}
}

impl<D> Dispatch2<ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1, D>
for GlobalData
{
impl<D> Dispatch<ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1, D> for GlobalData {
fn event(
&self,
_data: &mut D,
Expand Down
Loading
Loading