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" }
20 changes: 5 additions & 15 deletions examples/data_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ use smithay_client_toolkit::{
data_source::{CopyPasteSource, DataSourceHandler, DragSource},
DataDeviceManagerState, WritePipe,
},
delegate_registry,
output::{OutputHandler, OutputState},
primary_selection::{
device::{PrimarySelectionDevice, PrimarySelectionDeviceHandler},
offer::PrimarySelectionOffer,
selection::{PrimarySelectionSource, PrimarySelectionSourceHandler},
PrimarySelectionManagerState,
},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
seat::{
keyboard::{KeyEvent, KeyboardHandler, Keysym, Modifiers, RawModifiers},
Expand All @@ -46,7 +44,7 @@ use smithay_client_toolkit::{
},
};
use wayland_client::{
globals::registry_queue_init,
globals::{GlobalList, GlobalListHandler},
protocol::{
wl_data_device::WlDataDevice,
wl_data_device_manager::DndAction,
Expand All @@ -72,11 +70,12 @@ fn main() {
env_logger::init();

// All Wayland apps start by connecting the compositor (server).
let conn = Connection::connect_to_env().unwrap();
let conn = unsafe { Connection::connect_to_env().unwrap() };

// Enumerate the list of globals to get the protocols the server implements.
let (globals, event_queue) = registry_queue_init(&conn).unwrap();
let event_queue = conn.new_event_queue();
let qh = event_queue.handle();
let globals = GlobalList::init(&conn, &qh).unwrap();
let mut event_loop: EventLoop<DataDeviceWindow> =
EventLoop::try_new().expect("Failed to initialize the event loop!");
let loop_handle = event_loop.handle();
Expand Down Expand Up @@ -117,7 +116,6 @@ fn main() {

let mut simple_window = DataDeviceWindow {
compositor,
registry_state: RegistryState::new(&globals),
seat_state: SeatState::new(&globals, &qh),
output_state: OutputState::new(&globals, &qh),
shm_state: shm,
Expand Down Expand Up @@ -163,7 +161,6 @@ fn main() {

struct DataDeviceWindow {
compositor: CompositorState,
registry_state: RegistryState,
seat_state: SeatState,
output_state: OutputState,
shm_state: Shm,
Expand Down Expand Up @@ -1064,10 +1061,7 @@ impl PrimarySelectionSourceHandler for DataDeviceWindow {
}
}

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

Expand All @@ -1079,8 +1073,6 @@ struct SeatObject {
primary_device: Option<PrimarySelectionDevice>,
}

delegate_registry!(DataDeviceWindow);

const SUPPORTED_MIME_TYPES: &[&str; 6] = &[
"text/plain;charset=utf-8",
"text/plain;charset=UTF-8",
Expand All @@ -1098,5 +1090,3 @@ fn pick_mime(mime_types: &[String]) -> Option<String> {

None
}

smithay_client_toolkit::delegate_dispatch2!(DataDeviceWindow);
21 changes: 5 additions & 16 deletions examples/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use smithay_client_toolkit::seat::{Capability, SeatHandler, SeatState};
use smithay_client_toolkit::shell::xdg::dialog::{Dialog, DialogHandler};
use smithay_client_toolkit::{
compositor::{CompositorHandler, CompositorState, FrameCallbackData},
delegate_registry,
output::{OutputHandler, OutputState},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
shell::{
xdg::{
Expand All @@ -23,7 +21,7 @@ use smithay_client_toolkit::{
use wayland_client::protocol::wl_keyboard;
use wayland_client::protocol::wl_seat;
use wayland_client::{
globals::registry_queue_init,
globals::{GlobalList, GlobalListHandler},
protocol::{wl_output, wl_shm, wl_surface},
Connection, QueueHandle,
};
Expand Down Expand Up @@ -53,7 +51,6 @@ struct Viewer {
}

struct State {
registry_state: RegistryState,
output_state: OutputState,
compositor_state: CompositorState,
shm_state: Shm,
Expand All @@ -75,16 +72,16 @@ struct State {
fn main() {
env_logger::init();

let conn = Connection::connect_to_env().unwrap();
let conn = unsafe { Connection::connect_to_env().unwrap() };

let (globals, mut event_queue) = registry_queue_init(&conn).unwrap();
let mut event_queue = conn.new_event_queue();
let qh: QueueHandle<State> = event_queue.handle();
let globals = GlobalList::init(&conn, &qh).unwrap();

let event_loop: EventLoop<State> =
EventLoop::try_new().expect("Failed to initialize the event loop!");

let mut state = State {
registry_state: RegistryState::new(&globals),
output_state: OutputState::new(&globals, &qh),
compositor_state: CompositorState::bind(&globals, &qh)
.expect("wl_compositor not available"),
Expand Down Expand Up @@ -540,14 +537,6 @@ impl ShmHandler for State {
}
}

delegate_registry!(State);

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

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

smithay_client_toolkit::delegate_dispatch2!(State);
32 changes: 10 additions & 22 deletions examples/dmabuf_formats.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use drm_fourcc::{DrmFourcc, DrmModifier};
use smithay_client_toolkit::{
dmabuf::{DmabufFeedback, DmabufFormat, DmabufHandler, DmabufState},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
use smithay_client_toolkit::dmabuf::{DmabufFeedback, DmabufFormat, DmabufHandler, DmabufState};
use wayland_client::{
globals::{GlobalList, GlobalListHandler},
protocol::wl_buffer,
Connection, QueueHandle,
};
use wayland_client::{globals::registry_queue_init, protocol::wl_buffer, Connection, QueueHandle};
use wayland_protocols::wp::linux_dmabuf::zv1::client::{
zwp_linux_buffer_params_v1, zwp_linux_dmabuf_feedback_v1,
};

struct AppData {
registry_state: RegistryState,
dmabuf_state: DmabufState,
feedback: Option<DmabufFeedback>,
}
Expand Down Expand Up @@ -56,26 +55,18 @@ impl DmabufHandler for AppData {
}
}

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

fn main() {
env_logger::init();

let conn = Connection::connect_to_env().unwrap();
let conn = unsafe { Connection::connect_to_env().unwrap() };

let (globals, mut event_queue) = registry_queue_init(&conn).unwrap();
let mut event_queue = conn.new_event_queue();
let qh = event_queue.handle();
let globals = GlobalList::init(&conn, &qh).unwrap();

let mut app_data = AppData {
registry_state: RegistryState::new(&globals),
dmabuf_state: DmabufState::new(&globals, &qh),
feedback: None,
};
let mut app_data = AppData { dmabuf_state: DmabufState::new(&globals, &qh), feedback: None };

match app_data.dmabuf_state.version() {
None => println!("`zwp_linux_dmabuf_v1` version `>3` not supported by compositor."),
Expand Down Expand Up @@ -126,6 +117,3 @@ fn print_format(format: &DmabufFormat) {
}
println!(", Modifier: {:?}", DrmModifier::from(format.modifier));
}

smithay_client_toolkit::delegate_registry!(AppData);
smithay_client_toolkit::delegate_dispatch2!(AppData);
32 changes: 11 additions & 21 deletions examples/foreign-toplevel-monitor.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
use std::error::Error;

use smithay_client_toolkit::{
delegate_registry,
foreign_toplevel_list::{ForeignToplevelList, ForeignToplevelListHandler},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
use smithay_client_toolkit::foreign_toplevel_list::{
ForeignToplevelList, ForeignToplevelListHandler,
};
use wayland_client::{
globals::{GlobalList, GlobalListHandler},
Connection, QueueHandle,
};
use wayland_client::{globals::registry_queue_init, Connection, QueueHandle};
use wayland_protocols::ext::foreign_toplevel_list::v1::client::ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1;

struct State {
registry_state: RegistryState,
foreign_toplevel_list: ForeignToplevelList,
}

fn main() -> Result<(), Box<dyn Error>> {
let conn = Connection::connect_to_env()?;
let (globals, mut event_queue) = registry_queue_init(&conn)?;
let conn = unsafe { Connection::connect_to_env()? };
let mut event_queue = conn.new_event_queue();
let qh = event_queue.handle();
let registry_state = RegistryState::new(&globals);
let globals = GlobalList::init(&conn, &qh).unwrap();
let foreign_toplevel_list = ForeignToplevelList::new(&globals, &qh);

let mut state = State { registry_state, foreign_toplevel_list };
let mut state = State { foreign_toplevel_list };
loop {
event_queue.blocking_dispatch(&mut state)?;
}
}

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

registry_handlers! {}
}
impl GlobalListHandler for State {}

impl ForeignToplevelListHandler for State {
fn foreign_toplevel_list_state(&mut self) -> &mut ForeignToplevelList {
Expand Down Expand Up @@ -76,6 +69,3 @@ impl ForeignToplevelListHandler for State {
println!("Close toplevel: {:?}", info);
}
}

delegate_registry!(State);
smithay_client_toolkit::delegate_dispatch2!(State);
30 changes: 10 additions & 20 deletions examples/generic_list_seats.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
use smithay_client_toolkit::{
delegate_registry,
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
seat::{Capability, SeatHandler, SeatState},
};
use wayland_client::{globals::registry_queue_init, protocol::wl_seat, Connection, QueueHandle};
use wayland_client::{
globals::{GlobalList, GlobalListHandler},
protocol::wl_seat,
Connection, QueueHandle,
};

fn main() {
env_logger::init();

let conn = Connection::connect_to_env().unwrap();
let conn = unsafe { Connection::connect_to_env().unwrap() };

let (globals, mut event_queue) = registry_queue_init(&conn).unwrap();
let mut event_queue = conn.new_event_queue();
let qh = event_queue.handle();
let globals = GlobalList::init(&conn, &qh).unwrap();

let mut list_seats = ListSeats {
registry_state: RegistryState::new(&globals),
seat_state: SeatState::new(&globals, &qh),
_dummy: MyTest {},
};
let mut list_seats = ListSeats { seat_state: SeatState::new(&globals, &qh), _dummy: MyTest {} };

event_queue.roundtrip(&mut list_seats).unwrap();

Expand All @@ -43,7 +42,6 @@ impl Test for MyTest {}

struct ListSeats<T: Test + 'static> {
seat_state: SeatState,
registry_state: RegistryState,
_dummy: T,
}

Expand Down Expand Up @@ -81,14 +79,6 @@ impl<T: Test + 'static> SeatHandler for ListSeats<T> {
}
}

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

impl<T: Test + 'static> ProvidesRegistryState for ListSeats<T> {
fn registry(&mut self) -> &mut RegistryState {
&mut self.registry_state
}

impl<T: Test + 'static> GlobalListHandler for ListSeats<T> {
registry_handlers!(SeatState);
}

smithay_client_toolkit::delegate_dispatch2!(@<T: Test + 'static> ListSeats<T>);
Loading
Loading