use wayland_client::{protocol::wl_seat::WlSeat, Display, EventQueue, GlobalManager, Main};
use zwp_virtual_keyboard::virtual_keyboard_unstable_v1::zwp_virtual_keyboard_manager_v1::ZwpVirtualKeyboardManagerV1;
fn get_wl_global_mgr(display: Display) -> (EventQueue, GlobalManager) {
let mut event_queue = display.create_event_queue();
let attached_display = display.attach(event_queue.token());
let global_mgr = GlobalManager::new(&attached_display);
event_queue
.sync_roundtrip(
&mut (),
|_, _, _| println!("Event received that was not handled"), )
.unwrap();
(event_queue, global_mgr)
}
pub fn init_wayland() -> (
Display,
EventQueue,
WlSeat,
Main<ZwpVirtualKeyboardManagerV1>,
) {
let display = Display::connect_to_env()
.or_else(|_| Display::connect_to_name("wayland-0"))
.unwrap();
let (event_queue, global_mgr) = get_wl_global_mgr(display.clone());
let seat = global_mgr.instantiate_exact::<WlSeat>(7).unwrap();
let seat: WlSeat = WlSeat::from(seat.as_ref().clone());
let vk_mgr = global_mgr
.instantiate_exact::<ZwpVirtualKeyboardManagerV1>(1)
.expect("Error: Your compositor does not understand the virtual_keyboard protocol!");
(display, event_queue, seat, vk_mgr)
}