diff --git a/Cargo.lock b/Cargo.lock index a525055..9abb83c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -325,7 +325,7 @@ dependencies = [ "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-sys 0.14.1", + "wayland-sys 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "xkbcommon 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -664,6 +664,7 @@ dependencies = [ [[package]] name = "wayland-scanner" version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "xml-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -671,18 +672,20 @@ dependencies = [ [[package]] name = "wayland-server" version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "token_store 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-scanner 0.14.1", - "wayland-sys 0.14.1", + "wayland-scanner 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wayland-sys" version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -706,8 +709,8 @@ dependencies = [ "mut_static 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "vsprintf 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "wayland-server 0.14.1", - "wayland-sys 0.14.1", + "wayland-server 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "wayland-sys 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "xkbcommon 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -855,6 +858,9 @@ source = "git+https://github.com/nix-rust/nix#97e0c4714859eb0f7d15e5e0eddca2a36c "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum vsprintf 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e3972a36b5053b7dbf84a3cd9328fbf7ec29a8367c4f3c3664884c611b4c0fa" +"checksum wayland-scanner 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2658178362cb4b01c1fe0333ea3e496da88bc0fef859b9fcafc1eab925af34f3" +"checksum wayland-server 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "afc502e2fafe8fd05f8f3c3cdb10e93db52e187a6e0767068bd86bd6779cb5aa" +"checksum wayland-sys 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7c640afde5cb45004baf4cd68c02c74fe4c0e44951a50207171f29d1f8f7d7e6" "checksum which 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e84a603e7e0b1ce1aa1ee2b109c7be00155ce52df5081590d1ffb93f4f515cb2" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" diff --git a/Cargo.toml b/Cargo.toml index c73ab24..78613d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,8 @@ members = ["libweston-sys", "weston-rs"] #libc = { path = "../../rust-lang/libc" } #nix = { path = "../../nix-rust/nix" } nix = { git = "https://github.com/nix-rust/nix" } -wayland-sys = { path = "../../Smithay/wayland-rs/wayland-sys" } -wayland-server = { path = "../../Smithay/wayland-rs/wayland-server" } +#wayland-sys = { path = "../../Smithay/wayland-rs/wayland-sys" } +#wayland-server = { path = "../../Smithay/wayland-rs/wayland-server" } loginw = { path = "../loginw" } #[patch."https://github.com/rust-lang/libc"] diff --git a/weston-rs/examples/simple.rs b/weston-rs/examples/simple.rs index 10f09b8..36649ec 100644 --- a/weston-rs/examples/simple.rs +++ b/weston-rs/examples/simple.rs @@ -250,14 +250,14 @@ fn click_activate(p: &mut PointerRef) { fn main() { weston_rs::log_set_handler(wlog, wlog_continue); - let mut display = Display::new(); - let mut compositor = Compositor::new(&display); + let (mut display, mut event_loop) = create_display(); + let mut compositor = Compositor::new(&display, &mut event_loop); compositor.set_xkb_rule_names(None); // defaults to environment variables // Backend setup if env::var("LOGINW_FD").is_ok() { - let launcher = LoginwLauncher::connect(&compositor, 0, &std::ffi::CString::new("default").unwrap(), false).expect("connect"); + let launcher = LoginwLauncher::connect(&compositor, &mut event_loop, 0, &std::ffi::CString::new("default").unwrap(), false).expect("connect"); compositor.set_launcher(launcher); let _backend = DrmBackend::new(&compositor, DrmBackendConfigBuilder::default().build().unwrap()); let output_api = unsafe { DrmOutputImplRef::from_ptr(compositor.get_drm_output().expect("get_drm_output").as_ptr()) }; @@ -350,12 +350,15 @@ fn main() { // Set environment for spawned processes (namely, the terminal above) env::remove_var("DISPLAY"); - let sock_name = display.add_socket_auto(); - unsafe { libc::setenv(ffi::CString::new("WAYLAND_DISPLAY").expect("CString").as_ptr(), sock_name.as_ptr(), 1); } + let sock_name = display.add_socket_auto().expect("add_socket_auto"); + use std::os::unix::ffi::OsStrExt; + unsafe { libc::setenv( + ffi::CString::new("WAYLAND_DISPLAY").expect("CString").as_ptr(), + sock_name.as_bytes().first().unwrap() as *const u8 as *const _, 1); } // Go! compositor.wake(); COMPOSITOR.set(compositor).expect("compositor MutStatic set"); DESKTOP.set(desktop).expect("desktop MutStatic set"); - display.run(); + event_loop.run(); } diff --git a/weston-rs/src/compositor.rs b/weston-rs/src/compositor.rs index 700af85..6d176b0 100644 --- a/weston-rs/src/compositor.rs +++ b/weston-rs/src/compositor.rs @@ -21,7 +21,7 @@ use xkbcommon::xkb; use xkbcommon::xkb::ffi::{xkb_rule_names, xkb_context_ref}; use wayland_sys::server::wl_signal; use foreign_types::{ForeignType, ForeignTypeRef}; -use ::display::Display; +use wayland_server::{Display, EventLoop}; use ::layer::LayerRef; use ::launcher::Launcher; use ::seat::SeatRef; @@ -68,8 +68,11 @@ foreign_type! { unsafe impl Sync for Compositor {} impl Compositor { - pub fn new(display: &Display) -> Compositor { - let ptr = unsafe { weston_compositor_create(display.as_ptr(), ptr::null_mut()) }; + pub fn new(display: &Display, event_loop: *mut EventLoop) -> Compositor { + let ptr = unsafe { + // The event loop is stored as user data. Used in launcher callbacks. + weston_compositor_create(display.ptr(), event_loop as *mut _) + }; // TODO check ptr != null let mut result = unsafe { Compositor::from_ptr(ptr) }; unsafe { (*result.as_ptr()).user_data = &mut result as *mut _ as *mut libc::c_void }; @@ -90,10 +93,6 @@ impl CompositorRef { output_destroyed_signal, output_moved_signal, output_resized_signal, session_signal); prop_accessors!(i32 | kb_repeat_rate, kb_repeat_delay); - pub fn get_display(&self) -> Display { - unsafe { Display::from_ptr((*self.as_ptr()).wl_display) } - } - pub fn set_session_active(&mut self, active: bool) { unsafe { (*self.as_ptr()).session_active = active as _; } } diff --git a/weston-rs/src/display.rs b/weston-rs/src/display.rs deleted file mode 100644 index 6cf276b..0000000 --- a/weston-rs/src/display.rs +++ /dev/null @@ -1,39 +0,0 @@ -use std::ffi; -use wayland_sys::server::*; -use wayland_server; - -pub struct Display { - ptr: *mut wl_display, -} - -unsafe impl Sync for Display {} - -impl Display { - pub fn new() -> Display { - Display { - ptr: unsafe { wl_display_create() }, - } - } - - pub fn from_ptr(ptr: *mut wl_display) -> Display { - Display { - ptr - } - } - - pub fn add_socket_auto(&mut self) -> ffi::CString { - unsafe { ffi::CStr::from_ptr(wl_display_add_socket_auto(self.ptr)).to_owned() } - } - - pub fn run(&self) { - unsafe { wl_display_run(self.ptr); } - } - - pub fn get_event_loop(&self) -> wayland_server::EventLoop { - unsafe { wayland_server::create_event_loop(wl_display_get_event_loop(self.ptr), Some(self.ptr)) } - } - - pub fn as_ptr(&self) -> *mut wl_display { - self.ptr - } -} diff --git a/weston-rs/src/launcher.rs b/weston-rs/src/launcher.rs index 19644ba..727485d 100644 --- a/weston-rs/src/launcher.rs +++ b/weston-rs/src/launcher.rs @@ -8,10 +8,11 @@ use libweston_sys::{ weston_compositor, }; use foreign_types::ForeignTypeRef; +use wayland_server::{EventLoop, EventLoopHandle}; use ::compositor::CompositorRef; pub trait Launcher where Self: Sized { - fn connect(compositor: &CompositorRef, tty: libc::c_int, seat_id: &CStr, sync_drm: bool) -> Option; + fn connect(compositor: &CompositorRef, event_loop: &mut EventLoopHandle, tty: libc::c_int, seat_id: &CStr, sync_drm: bool) -> Option; fn open(&mut self, path: &CStr, flags: libc::c_int) -> RawFd; fn close(&mut self, fd: RawFd); fn activate_vt(&mut self, vt: libc::c_int) -> bool; @@ -49,7 +50,13 @@ extern "C" fn run_connect( tty: libc::c_int, seat_id: *const libc::c_char, sync_drm: bool) -> libc::c_int { - if let Some(launcher) = T::connect(unsafe { CompositorRef::from_ptr(compositor) }, tty, unsafe { CStr::from_ptr(seat_id) }, sync_drm) { + if let Some(launcher) = T::connect( + unsafe { CompositorRef::from_ptr(compositor) }, + unsafe { &mut *((*compositor).user_data as *mut EventLoop) }, + tty, + unsafe { CStr::from_ptr(seat_id) }, + sync_drm + ) { unsafe { *launcher_out = launcher.into_weston() }; 0 } else { diff --git a/weston-rs/src/launcher_loginw.rs b/weston-rs/src/launcher_loginw.rs index 8ca6d26..2e7d89e 100644 --- a/weston-rs/src/launcher_loginw.rs +++ b/weston-rs/src/launcher_loginw.rs @@ -21,7 +21,7 @@ pub struct LoginwLauncher { } impl Launcher for LoginwLauncher { - fn connect(compositor: &CompositorRef, _tty: libc::c_int, _seat_id: &CStr, _sync_drm: bool) -> Option { + fn connect(compositor: &CompositorRef, event_loop: &mut EventLoopHandle, _tty: libc::c_int, _seat_id: &CStr, _sync_drm: bool) -> Option { env::var("LOGINW_FD").ok().and_then(|fdstr| fdstr.parse::().ok()).map(|fd| { let sock = Rc::new(Socket::new(fd)); let req = LoginwRequest::new(LoginwRequestType::LoginwAcquireVt); @@ -29,7 +29,7 @@ impl Launcher for LoginwLauncher { let (resp, _tty_fd) = sock.recvmsg::().expect(".recvmsg()"); assert!(resp.typ == LoginwResponseType::LoginwPassedFd); - let _ = compositor.get_display().get_event_loop().add_fd_event_source( + let _ = event_loop.add_fd_event_source( sock.fd, sources::FdEventSourceImpl { ready: |_: &mut EventLoopHandle, &mut (ref sock, ref mut compositor): &mut (Rc, &mut CompositorRef), _fd, _| { diff --git a/weston-rs/src/lib.rs b/weston-rs/src/lib.rs index 1d9c5bf..cae48bc 100644 --- a/weston-rs/src/lib.rs +++ b/weston-rs/src/lib.rs @@ -24,6 +24,7 @@ pub use foreign_types::{ForeignType, ForeignTypeRef}; pub use wayland_sys::common::{ wl_fixed_from_int, wl_fixed_to_int, wl_fixed_to_double, wl_fixed_from_double }; +pub use wayland_server::{Display, EventLoop, create_display}; pub use wayland_server::protocol::wl_shell_surface::{Resize, Transient}; pub use xkbcommon::xkb; @@ -107,7 +108,6 @@ macro_rules! wl_container_of { pub mod ev; pub mod matrix; pub mod listener; -pub mod display; pub mod compositor; pub mod launcher; pub mod launcher_loginw; @@ -126,7 +126,6 @@ pub mod desktop; pub use memoffset::*; pub use matrix::*; pub use listener::*; -pub use display::*; pub use compositor::*; pub use launcher::*; pub use launcher_loginw::*;