Skip to content
This repository has been archived by the owner on Nov 2, 2022. It is now read-only.

Commit

Permalink
Use wayland-rs's display wrapper
Browse files Browse the repository at this point in the history
& upstream wayland-rs
  • Loading branch information
valpackett committed Apr 15, 2018
1 parent f4f0b82 commit 5223e65
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 65 deletions.
16 changes: 11 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
15 changes: 9 additions & 6 deletions weston-rs/examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) };
Expand Down Expand Up @@ -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();
}
13 changes: 6 additions & 7 deletions weston-rs/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 };
Expand All @@ -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 _; }
}
Expand Down
39 changes: 0 additions & 39 deletions weston-rs/src/display.rs

This file was deleted.

11 changes: 9 additions & 2 deletions weston-rs/src/launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self>;
fn connect(compositor: &CompositorRef, event_loop: &mut EventLoopHandle, tty: libc::c_int, seat_id: &CStr, sync_drm: bool) -> Option<Self>;
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;
Expand Down Expand Up @@ -49,7 +50,13 @@ extern "C" fn run_connect<T: Launcher>(
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 {
Expand Down
4 changes: 2 additions & 2 deletions weston-rs/src/launcher_loginw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ pub struct LoginwLauncher {
}

impl Launcher for LoginwLauncher {
fn connect(compositor: &CompositorRef, _tty: libc::c_int, _seat_id: &CStr, _sync_drm: bool) -> Option<Self> {
fn connect(compositor: &CompositorRef, event_loop: &mut EventLoopHandle, _tty: libc::c_int, _seat_id: &CStr, _sync_drm: bool) -> Option<Self> {
env::var("LOGINW_FD").ok().and_then(|fdstr| fdstr.parse::<RawFd>().ok()).map(|fd| {
let sock = Rc::new(Socket::new(fd));
let req = LoginwRequest::new(LoginwRequestType::LoginwAcquireVt);
sock.sendmsg(&req, None).expect(".sendmsg()");
let (resp, _tty_fd) = sock.recvmsg::<LoginwResponse>().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<Socket>, &mut CompositorRef), _fd, _| {
Expand Down
3 changes: 1 addition & 2 deletions weston-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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::*;
Expand Down

0 comments on commit 5223e65

Please sign in to comment.