View
@@ -1,4 +1,4 @@
use std::ptr;
use std::{mem, ptr};
use libc;
use libweston_sys::{
weston_compositor, weston_compositor_create, weston_compositor_destroy,
@@ -20,146 +20,133 @@ use libweston_sys::{
use xkbcommon::xkb;
use xkbcommon::xkb::ffi::{xkb_rule_names, xkb_context_ref};
use wayland_sys::server::wl_signal;
use ::WestonObject;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::display::Display;
use ::layer::Layer;
use ::layer::LayerRef;
use ::launcher::Launcher;
use ::seat::Seat;
use ::pointer::{Pointer, PointerAxisEvent, Axis};
use ::keyboard::{Keyboard, KeyboardModifier};
use ::touch::Touch;
use ::seat::SeatRef;
use ::pointer::{PointerRef, PointerAxisEvent, Axis};
use ::keyboard::{KeyboardRef, KeyboardModifier};
use ::touch::TouchRef;
/// Opaque reference to a key/modifier/button/touch/axis/debug binding.
/// Hold on to it if you want to later destroy the binding.
pub struct Binding(*mut weston_binding);
extern "C" fn run_key_binding<F: FnMut(Keyboard, &libc::timespec, u32)>(keyboard: *mut weston_keyboard, time: *const libc::timespec, key: u32, data: *mut libc::c_void) {
extern "C" fn run_key_binding<F: FnMut(&mut KeyboardRef, &libc::timespec, u32)>(keyboard: *mut weston_keyboard, time: *const libc::timespec, key: u32, data: *mut libc::c_void) {
let cb = unsafe { &mut *(data as *mut F) };
cb(Keyboard::from_ptr_temporary(keyboard), unsafe { &*time }, key);
cb(unsafe { KeyboardRef::from_ptr_mut(keyboard) }, unsafe { &*time }, key);
}
extern "C" fn run_modifier_binding<F: FnMut(Keyboard, KeyboardModifier)>(keyboard: *mut weston_keyboard, modifier: weston_keyboard_modifier, data: *mut libc::c_void) {
extern "C" fn run_modifier_binding<F: FnMut(&mut KeyboardRef, KeyboardModifier)>(keyboard: *mut weston_keyboard, modifier: weston_keyboard_modifier, data: *mut libc::c_void) {
let cb = unsafe { &mut *(data as *mut F) };
cb(Keyboard::from_ptr_temporary(keyboard), KeyboardModifier::from_bits_truncate(modifier));
cb(unsafe { KeyboardRef::from_ptr_mut(keyboard) }, KeyboardModifier::from_bits_truncate(modifier));
}
extern "C" fn run_button_binding<F: FnMut(Pointer, &libc::timespec, u32)>(pointer: *mut weston_pointer, time: *const libc::timespec, button: u32, data: *mut libc::c_void) {
extern "C" fn run_button_binding<F: FnMut(&mut PointerRef, &libc::timespec, u32)>(pointer: *mut weston_pointer, time: *const libc::timespec, button: u32, data: *mut libc::c_void) {
let cb = unsafe { &mut *(data as *mut F) };
cb(Pointer::from_ptr_temporary(pointer), unsafe { &*time }, button);
cb(unsafe { PointerRef::from_ptr_mut(pointer) }, unsafe { &*time }, button);
}
extern "C" fn run_touch_binding<F: FnMut(Touch, &libc::timespec)>(touch: *mut weston_touch, time: *const libc::timespec, data: *mut libc::c_void) {
extern "C" fn run_touch_binding<F: FnMut(&mut TouchRef, &libc::timespec)>(touch: *mut weston_touch, time: *const libc::timespec, data: *mut libc::c_void) {
let cb = unsafe { &mut *(data as *mut F) };
cb(Touch::from_ptr_temporary(touch), unsafe { &*time });
cb(unsafe { TouchRef::from_ptr_mut(touch) }, unsafe { &*time });
}
extern "C" fn run_axis_binding<F: FnMut(Pointer, &libc::timespec, PointerAxisEvent)>(pointer: *mut weston_pointer, time: *const libc::timespec, event: *mut weston_pointer_axis_event , data: *mut libc::c_void) {
extern "C" fn run_axis_binding<F: FnMut(&mut PointerRef, &libc::timespec, PointerAxisEvent)>(pointer: *mut weston_pointer, time: *const libc::timespec, event: *mut weston_pointer_axis_event , data: *mut libc::c_void) {
let cb = unsafe { &mut *(data as *mut F) };
cb(Pointer::from_ptr_temporary(pointer), unsafe { &*time }, unsafe { &*event }.into());
cb(unsafe { PointerRef::from_ptr_mut(pointer) }, unsafe { &*time }, unsafe { &*event }.into());
}
pub struct Compositor {
ptr: *mut weston_compositor,
temp: bool,
foreign_type! {
type CType = weston_compositor;
fn drop = weston_compositor_destroy;
pub struct Compositor;
pub struct CompositorRef;
}
unsafe impl Sync for Compositor {}
weston_object!(Compositor << weston_compositor);
impl Compositor {
pub fn new(display: &Display) -> Compositor {
let ptr = unsafe { weston_compositor_create(display.ptr(), ptr::null_mut()) };
let ptr = unsafe { weston_compositor_create(display.as_ptr(), ptr::null_mut()) };
// TODO check ptr != null
let mut result = Compositor::from_ptr(ptr);
unsafe { (*result.ptr).user_data = &mut result as *mut _ as *mut libc::c_void };
let mut result = unsafe { Compositor::from_ptr(ptr) };
unsafe { (*result.as_ptr()).user_data = &mut result as *mut _ as *mut libc::c_void };
result
}
}
pub fn temp_clone(&self) -> Compositor {
Compositor {
ptr: self.ptr,
temp: true,
}
}
impl CompositorRef {
pub fn get_display(&self) -> Display {
Display::from_ptr_temporary(unsafe { (*self.ptr).wl_display })
unsafe { Display::from_ptr((*self.as_ptr()).wl_display) }
}
pub fn set_session_active(&self, active: bool) {
unsafe { (*self.ptr).session_active = active as _; }
unsafe { (*self.as_ptr()).session_active = active as _; }
}
pub fn set_launcher<T: Launcher>(&self, launcher: T) {
unsafe { (*self.ptr).launcher = launcher.into_weston(); }
unsafe { (*self.as_ptr()).launcher = launcher.into_weston(); }
}
pub fn get_xkb_context(&self) -> xkb::Context {
unsafe { xkb::Context::from_raw_ptr(xkb_context_ref((*self.ptr).xkb_context)) }
unsafe { xkb::Context::from_raw_ptr(xkb_context_ref((*self.as_ptr()).xkb_context)) }
}
pub fn set_xkb_rule_names(&self, names: Option<*mut xkb_rule_names>) {
unsafe { weston_compositor_set_xkb_rule_names(self.ptr, names.unwrap_or(ptr::null_mut())); }
unsafe { weston_compositor_set_xkb_rule_names(self.as_ptr(), names.unwrap_or(ptr::null_mut())); }
}
pub fn schedule_repaint(&self) {
unsafe { weston_compositor_schedule_repaint(self.ptr); }
unsafe { weston_compositor_schedule_repaint(self.as_ptr()); }
}
pub fn pending_output_coldplug(&self) {
unsafe { weston_pending_output_coldplug(self.ptr); }
unsafe { weston_pending_output_coldplug(self.as_ptr()); }
}
pub fn wake(&self) {
unsafe { weston_compositor_wake(self.ptr); }
unsafe { weston_compositor_wake(self.as_ptr()); }
}
pub fn shutdown(&self) {
unsafe { weston_compositor_shutdown(self.ptr); }
unsafe { weston_compositor_shutdown(self.as_ptr()); }
}
pub fn add_key_binding<'comp, F: FnMut(Keyboard, &libc::timespec, u32)>(&'comp self, key: u32, modifier: KeyboardModifier, handler: &'comp F) {
unsafe { weston_compositor_add_key_binding(self.ptr, key, modifier.bits(), Some(run_key_binding::<F>), handler as *const _ as *mut libc::c_void); }
pub fn add_key_binding<'comp, F: FnMut(&mut KeyboardRef, &libc::timespec, u32)>(&'comp self, key: u32, modifier: KeyboardModifier, handler: &'comp F) {
unsafe { weston_compositor_add_key_binding(self.as_ptr(), key, modifier.bits(), Some(run_key_binding::<F>), handler as *const _ as *mut libc::c_void); }
}
pub fn add_modifier_binding<'comp, F: FnMut(Keyboard, KeyboardModifier)>(&'comp self, modifier: KeyboardModifier, handler: &'comp F) {
unsafe { weston_compositor_add_modifier_binding(self.ptr, modifier.bits(), Some(run_modifier_binding::<F>), handler as *const _ as *mut libc::c_void); }
pub fn add_modifier_binding<'comp, F: FnMut(&mut KeyboardRef, KeyboardModifier)>(&'comp self, modifier: KeyboardModifier, handler: &'comp F) {
unsafe { weston_compositor_add_modifier_binding(self.as_ptr(), modifier.bits(), Some(run_modifier_binding::<F>), handler as *const _ as *mut libc::c_void); }
}
pub fn add_button_binding<'comp, F: FnMut(Pointer, &libc::timespec, u32)>(&'comp self, button: u32, modifier: KeyboardModifier, handler: &'comp F) {
unsafe { weston_compositor_add_button_binding(self.ptr, button, modifier.bits(), Some(run_button_binding::<F>), handler as *const _ as *mut libc::c_void); }
pub fn add_button_binding<'comp, F: FnMut(&mut PointerRef, &libc::timespec, u32)>(&'comp self, button: u32, modifier: KeyboardModifier, handler: &'comp F) {
unsafe { weston_compositor_add_button_binding(self.as_ptr(), button, modifier.bits(), Some(run_button_binding::<F>), handler as *const _ as *mut libc::c_void); }
}
pub fn add_touch_binding<'comp, F: FnMut(Touch, &libc::timespec)>(&'comp self, modifier: KeyboardModifier, handler: &'comp F) {
unsafe { weston_compositor_add_touch_binding(self.ptr, modifier.bits(), Some(run_touch_binding::<F>), handler as *const _ as *mut libc::c_void); }
pub fn add_touch_binding<'comp, F: FnMut(&mut TouchRef, &libc::timespec)>(&'comp self, modifier: KeyboardModifier, handler: &'comp F) {
unsafe { weston_compositor_add_touch_binding(self.as_ptr(), modifier.bits(), Some(run_touch_binding::<F>), handler as *const _ as *mut libc::c_void); }
}
pub fn add_axis_binding<'comp, F: FnMut(Pointer, &libc::timespec, PointerAxisEvent)>(&'comp self, axis: Axis, modifier: KeyboardModifier, handler: &'comp F) {
unsafe { weston_compositor_add_axis_binding(self.ptr, axis.to_raw(), modifier.bits(), Some(run_axis_binding::<F>), handler as *const _ as *mut libc::c_void); }
pub fn add_axis_binding<'comp, F: FnMut(&mut PointerRef, &libc::timespec, PointerAxisEvent)>(&'comp self, axis: Axis, modifier: KeyboardModifier, handler: &'comp F) {
unsafe { weston_compositor_add_axis_binding(self.as_ptr(), axis.to_raw(), modifier.bits(), Some(run_axis_binding::<F>), handler as *const _ as *mut libc::c_void); }
}
pub fn add_debug_binding<'comp, F: FnMut(Keyboard, &libc::timespec, u32)>(&'comp self, key: u32, handler: &'comp F) {
unsafe { weston_compositor_add_debug_binding(self.ptr, key, Some(run_key_binding::<F>), handler as *const _ as *mut libc::c_void); }
pub fn add_debug_binding<'comp, F: FnMut(&mut KeyboardRef, &libc::timespec, u32)>(&'comp self, key: u32, handler: &'comp F) {
unsafe { weston_compositor_add_debug_binding(self.as_ptr(), key, Some(run_key_binding::<F>), handler as *const _ as *mut libc::c_void); }
}
obj_accessors!(Layer |
fade_layer = |&this| { &mut (*this.ptr).fade_layer },
cursor_layer = |&this| { &mut (*this.ptr).cursor_layer });
obj_accessors!(opt Seat |
first_seat = |&this| { wl_container_of!((*this.ptr).seat_list.next, weston_seat, link) });
obj_accessors!(LayerRef |
fade_layer = |&this| { &mut (*this.as_ptr()).fade_layer },
cursor_layer = |&this| { &mut (*this.as_ptr()).cursor_layer });
obj_accessors!(opt SeatRef |
first_seat = |&this| { wl_container_of!((*this.as_ptr()).seat_list.next, weston_seat, link) });
prop_accessors!(
ptr wl_signal | destroy_signal, create_surface_signal, activate_signal, transform_signal,
kill_signal, idle_signal, wake_signal, show_input_panel_signal, hide_input_panel_signal,
update_input_panel_signal, seat_created_signal, output_pending_signal, output_created_signal,
output_destroyed_signal, output_moved_signal, output_resized_signal, session_signal);
prop_accessors!(i32 | kb_repeat_rate, kb_repeat_delay);
}
impl Drop for Compositor {
fn drop(&mut self) {
if !self.temp {
unsafe { weston_compositor_destroy(self.ptr); }
}
}
}
View
@@ -5,37 +5,37 @@ use libweston_sys::{
weston_desktop_api, weston_desktop_surface, weston_desktop_client,
weston_seat, weston_output,
};
use ::WestonObject;
use ::output::Output;
use ::seat::Seat;
use super::surface::{DesktopSurface, SurfaceEdge};
use super::client::DesktopClient;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::output::OutputRef;
use ::seat::SeatRef;
use super::surface::{DesktopSurfaceRef, SurfaceEdge};
use super::client::DesktopClientRef;
pub trait DesktopApi<SC> {
fn ping_timeout(&mut self, client: DesktopClient) {}
fn ping_timeout(&mut self, client: &mut DesktopClientRef) {}
fn pong(&mut self, client: DesktopClient) {}
fn pong(&mut self, client: &mut DesktopClientRef) {}
fn surface_added(&mut self, surface: DesktopSurface<SC>);
fn surface_added(&mut self, surface: &mut DesktopSurfaceRef<SC>);
fn surface_removed(&mut self, surface: DesktopSurface<SC>);
fn surface_removed(&mut self, surface: &mut DesktopSurfaceRef<SC>);
fn committed(&mut self, _surface: DesktopSurface<SC>, _sx: i32, _sy: i32) {}
fn committed(&mut self, _surface: &mut DesktopSurfaceRef<SC>, _sx: i32, _sy: i32) {}
fn show_window_menu(&mut self, _surface: DesktopSurface<SC>, _seat: Seat, _x: i32, _y: i32) {}
fn show_window_menu(&mut self, _surface: &mut DesktopSurfaceRef<SC>, _seat: &mut SeatRef, _x: i32, _y: i32) {}
fn set_parent(&mut self, _surface: DesktopSurface<SC>, _parent: DesktopSurface<SC>) {}
fn set_parent(&mut self, _surface: &mut DesktopSurfaceRef<SC>, _parent: &mut DesktopSurfaceRef<SC>) {}
/// Named like that because `move` is a Rust keyword
fn moove(&mut self, _surface: DesktopSurface<SC>, _seat: Seat, _serial: u32) {}
fn moove(&mut self, _surface: &mut DesktopSurfaceRef<SC>, _seat: &mut SeatRef, _serial: u32) {}
fn resize(&mut self, _surface: DesktopSurface<SC>, _seat: Seat, _serial: u32, _edges: SurfaceEdge) {}
fn resize(&mut self, _surface: &mut DesktopSurfaceRef<SC>, _seat: &mut SeatRef, _serial: u32, _edges: SurfaceEdge) {}
fn fullscreen_requested(&mut self, _surface: DesktopSurface<SC>, _fullscreen: bool, _output: Output) {}
fn fullscreen_requested(&mut self, _surface: &mut DesktopSurfaceRef<SC>, _fullscreen: bool, _output: &mut OutputRef) {}
fn maximized_requested(&mut self, _surface: DesktopSurface<SC>, _maximized: bool) {}
fn maximized_requested(&mut self, _surface: &mut DesktopSurfaceRef<SC>, _maximized: bool) {}
fn minimized_requested(&mut self, _surface: DesktopSurface<SC>) {}
fn minimized_requested(&mut self, _surface: &mut DesktopSurfaceRef<SC>) {}
/// Position suggestion for an Xwayland window
///
@@ -58,88 +58,88 @@ pub trait DesktopApi<SC> {
/// relative to the X11 root window. Care should be taken to ensure the
/// window gets mapped to coordinates that correspond to the proposed
/// position from the X11 client perspective.
fn set_xwayland_position(&mut self, _surface: DesktopSurface<SC>, _x: i32, _y: i32) {}
fn set_xwayland_position(&mut self, _surface: &mut DesktopSurfaceRef<SC>, _x: i32, _y: i32) {}
}
pub extern "C" fn run_ping_timeout<SC>(client: *mut weston_desktop_client, user_data: *mut libc::c_void) {
let client = DesktopClient::from_ptr_temporary(client);
let client = unsafe { DesktopClientRef::from_ptr_mut(client) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.ping_timeout(client);
}
pub extern "C" fn run_pong<SC>(client: *mut weston_desktop_client, user_data: *mut libc::c_void) {
let client = DesktopClient::from_ptr_temporary(client);
let client = unsafe { DesktopClientRef::from_ptr_mut(client) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.pong(client);
}
pub extern "C" fn run_surface_added<SC>(surface: *mut weston_desktop_surface, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.surface_added(surface);
}
pub extern "C" fn run_surface_removed<SC>(surface: *mut weston_desktop_surface, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.surface_removed(surface);
}
pub extern "C" fn run_committed<SC>(surface: *mut weston_desktop_surface, sx: i32, sy: i32, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.committed(surface, sx, sy);
}
pub extern "C" fn run_show_window_menu<SC>(surface: *mut weston_desktop_surface, seat: *mut weston_seat, x: i32, y: i32, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let seat = Seat::from_ptr_temporary(seat);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let seat = unsafe { SeatRef::from_ptr_mut(seat) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.show_window_menu(surface, seat, x, y);
}
pub extern "C" fn run_set_parent<SC>(surface: *mut weston_desktop_surface, parent: *mut weston_desktop_surface, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let parent = DesktopSurface::from_ptr_temporary(parent);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let parent = unsafe { DesktopSurfaceRef::from_ptr_mut(parent) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.set_parent(surface, parent);
}
pub extern "C" fn run_move<SC>(surface: *mut weston_desktop_surface, seat: *mut weston_seat, serial: u32, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let seat = Seat::from_ptr_temporary(seat);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let seat = unsafe { SeatRef::from_ptr_mut(seat) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.moove(surface, seat, serial);
}
pub extern "C" fn run_resize<SC>(surface: *mut weston_desktop_surface, seat: *mut weston_seat, serial: u32, edges: u32, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let seat = Seat::from_ptr_temporary(seat);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let seat = unsafe { SeatRef::from_ptr_mut(seat) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.resize(surface, seat, serial, SurfaceEdge::from_u32(edges).unwrap_or(SurfaceEdge::None));
}
pub extern "C" fn run_fullscreen_requested<SC>(surface: *mut weston_desktop_surface, fullscreen: bool, output: *mut weston_output, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let output = Output::from_ptr_temporary(output);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let output = unsafe { OutputRef::from_ptr_mut(output) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.fullscreen_requested(surface, fullscreen, output);
}
pub extern "C" fn run_maximized_requested<SC>(surface: *mut weston_desktop_surface, maximized: bool, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.maximized_requested(surface, maximized);
}
pub extern "C" fn run_minimized_requested<SC>(surface: *mut weston_desktop_surface, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.minimized_requested(surface);
}
pub extern "C" fn run_set_xwayland_position<SC>(surface: *mut weston_desktop_surface, x: i32, y: i32, user_data: *mut libc::c_void) {
let surface = DesktopSurface::from_ptr_temporary(surface);
let surface = unsafe { DesktopSurfaceRef::from_ptr_mut(surface) };
let api = unsafe { &mut *(user_data as *mut Box<DesktopApi<SC>>) };
api.set_xwayland_position(surface, x, y);
}
View
@@ -1,3 +1,4 @@
use std::mem;
use libc;
use libweston_sys::{
weston_desktop_client,
@@ -6,32 +7,35 @@ use libweston_sys::{
weston_desktop_surface,
};
use wayland_server;
use ::WestonObject;
use super::surface::DesktopSurface;
use foreign_types::{ForeignType, ForeignTypeRef};
use super::surface::DesktopSurfaceRef;
pub struct DesktopClient {
ptr: *mut weston_desktop_client,
temp: bool,
}
// The desktop_client is not a create/destroy thing really
fn noop_destroy(_: *mut weston_desktop_client) {}
weston_object!(DesktopClient << weston_desktop_client);
foreign_type! {
type CType = weston_desktop_client;
fn drop = noop_destroy;
pub struct DesktopClient;
pub struct DesktopClientRef;
}
impl DesktopClient {
impl DesktopClientRef {
pub fn get_client(&self) -> wayland_server::Client {
unsafe { wayland_server::Client::from_ptr(weston_desktop_client_get_client(self.ptr)) }
unsafe { wayland_server::Client::from_ptr(weston_desktop_client_get_client(self.as_ptr())) }
}
pub fn for_each_surface<SC, T: FnMut(DesktopSurface<SC>)>(&self, callback: T) {
unsafe { weston_desktop_client_for_each_surface(self.ptr, Some(run_callback::<SC, T>), &callback as *const _ as *mut libc::c_void) }
pub fn for_each_surface<SC, T: FnMut(&mut DesktopSurfaceRef<SC>)>(&self, callback: T) {
unsafe { weston_desktop_client_for_each_surface(self.as_ptr(), Some(run_callback::<SC, T>), &callback as *const _ as *mut libc::c_void) }
}
pub fn ping(&self) -> libc::c_int {
unsafe { weston_desktop_client_ping(self.ptr) }
unsafe { weston_desktop_client_ping(self.as_ptr()) }
}
}
#[allow(unused_unsafe)]
extern "C" fn run_callback<SC, T: FnMut(DesktopSurface<SC>)>(surface: *mut weston_desktop_surface, user_data: *mut libc::c_void) {
extern "C" fn run_callback<SC, T: FnMut(&mut DesktopSurfaceRef<SC>)>(surface: *mut weston_desktop_surface, user_data: *mut libc::c_void) {
let cb = unsafe { &mut *(user_data as *mut T) };
cb(DesktopSurface::from_ptr_temporary(surface));
cb(unsafe { DesktopSurfaceRef::from_ptr_mut(surface) });
}
View
@@ -4,32 +4,32 @@ use libweston_sys::{
weston_desktop, weston_desktop_create, weston_desktop_destroy,
weston_desktop_api,
};
use ::WestonObject;
use ::compositor::Compositor;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::compositor::CompositorRef;
pub mod api;
pub mod client;
pub mod surface;
pub use self::api::DesktopApi;
pub use self::client::DesktopClient;
pub use self::surface::DesktopSurface;
pub use self::client::{DesktopClient, DesktopClientRef};
pub use self::surface::DesktopSurfaceRef;
pub struct Desktop<'comp, SC> {
ptr: *mut weston_desktop,
wapi: Box<weston_desktop_api>,
api: Box<Box<DesktopApi<SC>>>, // heard you like boxes :D
// but the outer one gets turned into a raw pointer and we get the inner one in callbacks
phantom: marker::PhantomData<(&'comp Compositor, SC)>,
phantom: marker::PhantomData<(&'comp CompositorRef, SC)>,
}
impl<'comp, SC> Desktop<'comp, SC> {
pub fn new(compositor: &'comp Compositor, api: Box<DesktopApi<SC>>) -> Desktop<'comp, SC> {
pub fn new(compositor: &'comp CompositorRef, api: Box<DesktopApi<SC>>) -> Desktop<'comp, SC> {
let wapi = self::api::make_weston_api::<SC>();
let mut api = Box::new(api);
Desktop {
ptr: unsafe { weston_desktop_create(compositor.ptr(), &*wapi, &mut *api as *mut _ as *mut libc::c_void) },
ptr: unsafe { weston_desktop_create(compositor.as_ptr(), &*wapi, &mut *api as *mut _ as *mut libc::c_void) },
wapi,
api,
phantom: marker::PhantomData,
View
@@ -1,5 +1,5 @@
use libc;
use std::{ptr, ffi, marker};
use std::{mem, ptr, ffi, marker};
use libweston_sys::{
weston_desktop_surface,
weston_desktop_surface_get_user_data, weston_desktop_surface_set_user_data,
@@ -25,10 +25,11 @@ use libweston_sys::{
weston_desktop_surface_edge_WESTON_DESKTOP_SURFACE_EDGE_TOP_RIGHT,
weston_desktop_surface_edge_WESTON_DESKTOP_SURFACE_EDGE_BOTTOM_RIGHT
};
use ::{WestonObject, Geometry, Size};
use ::surface::Surface;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::{Geometry, Size};
use ::surface::SurfaceRef;
use ::view::View;
use super::client::DesktopClient;
use super::client::DesktopClientRef;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Primitive)]
@@ -45,54 +46,48 @@ pub enum SurfaceEdge {
}
#[allow(dead_code)]
pub struct DesktopSurface<T> {
#[repr(C)] // prevent reordering to allow ForeignTypeRef to cast self (== first field) to the ptr
pub struct DesktopSurfaceRef<T> {
ptr: *mut weston_desktop_surface,
temp: bool,
phantom: marker::PhantomData<T>,
}
weston_object!(DesktopSurface<T> << weston_desktop_surface);
impl<T> ForeignTypeRef for DesktopSurfaceRef<T> {
type CType = weston_desktop_surface;
}
impl<T> DesktopSurface<T> {
obj_accessors!(DesktopClient | get_client = |&this| { weston_desktop_surface_get_client(this.ptr) });
obj_accessors!(Surface | get_surface = |&this| { weston_desktop_surface_get_surface(this.ptr) });
impl<T> DesktopSurfaceRef<T> {
obj_accessors!(DesktopClientRef | get_client = |&this| { weston_desktop_surface_get_client(this.as_ptr()) });
obj_accessors!(SurfaceRef | get_surface = |&this| { weston_desktop_surface_get_surface(this.as_ptr()) });
pub fn from_surface(surface: &Surface) -> Option<DesktopSurface<T>> {
if unsafe { weston_surface_is_desktop_surface(surface.ptr()) } {
return Some(DesktopSurface::from_ptr_temporary(unsafe { weston_surface_get_desktop_surface(surface.ptr()) }))
pub fn from_surface(surface: &SurfaceRef) -> Option<&mut DesktopSurfaceRef<T>> {
if unsafe { weston_surface_is_desktop_surface(surface.as_ptr()) } {
return Some(unsafe { DesktopSurfaceRef::from_ptr_mut(weston_surface_get_desktop_surface(surface.as_ptr())) })
}
None
}
pub fn temp_clone(&self) -> DesktopSurface<T> {
DesktopSurface {
ptr: self.ptr,
temp: true,
phantom: marker::PhantomData::<T>,
}
}
pub fn set_user_data(&self, data: Box<T>) -> Option<Box<T>> {
let prev = self.get_user_data();
unsafe { weston_desktop_surface_set_user_data(self.ptr, Box::into_raw(data) as *mut libc::c_void); }
unsafe { weston_desktop_surface_set_user_data(self.as_ptr(), Box::into_raw(data) as *mut libc::c_void); }
prev
}
pub fn get_user_data(&self) -> Option<Box<T>> {
unsafe {
let ptr = weston_desktop_surface_get_user_data(self.ptr) as *mut T;
let ptr = weston_desktop_surface_get_user_data(self.as_ptr()) as *mut T;
if ptr.is_null() {
return None
}
let bx = Box::from_raw(ptr);
weston_desktop_surface_set_user_data(self.ptr, ptr::null_mut());
weston_desktop_surface_set_user_data(self.as_ptr(), ptr::null_mut());
Some(bx)
}
}
pub fn borrow_user_data(&self) -> Option<&mut T> {
unsafe {
let ptr = weston_desktop_surface_get_user_data(self.ptr) as *mut T;
let ptr = weston_desktop_surface_get_user_data(self.as_ptr()) as *mut T;
if ptr.is_null() {
return None
}
@@ -101,78 +96,78 @@ impl<T> DesktopSurface<T> {
}
pub fn create_view(&self) -> View {
View::from_ptr(unsafe { weston_desktop_surface_create_view(self.ptr) })
unsafe { View::from_ptr(weston_desktop_surface_create_view(self.as_ptr())) }
}
pub fn unlink_view(&self, view: &mut View) {
unsafe { weston_desktop_surface_unlink_view(view.ptr()); }
unsafe { weston_desktop_surface_unlink_view(view.as_ptr()); }
}
pub fn propagate_layer(&self) {
unsafe { weston_desktop_surface_propagate_layer(self.ptr); }
unsafe { weston_desktop_surface_propagate_layer(self.as_ptr()); }
}
pub fn set_activated(&self, activated: bool) {
unsafe { weston_desktop_surface_set_activated(self.ptr, activated); }
unsafe { weston_desktop_surface_set_activated(self.as_ptr(), activated); }
}
pub fn set_fullscreen(&self, fullscreen: bool) {
unsafe { weston_desktop_surface_set_fullscreen(self.ptr, fullscreen); }
unsafe { weston_desktop_surface_set_fullscreen(self.as_ptr(), fullscreen); }
}
pub fn set_maximized(&self, maximized: bool) {
unsafe { weston_desktop_surface_set_maximized(self.ptr, maximized); }
unsafe { weston_desktop_surface_set_maximized(self.as_ptr(), maximized); }
}
pub fn set_resizing(&self, resizing: bool) {
unsafe { weston_desktop_surface_set_resizing(self.ptr, resizing); }
unsafe { weston_desktop_surface_set_resizing(self.as_ptr(), resizing); }
}
pub fn set_size(&self, width: i32, height: i32) {
unsafe { weston_desktop_surface_set_size(self.ptr, width, height); }
unsafe { weston_desktop_surface_set_size(self.as_ptr(), width, height); }
}
pub fn close(&self) {
unsafe { weston_desktop_surface_close(self.ptr); }
unsafe { weston_desktop_surface_close(self.as_ptr()); }
}
pub fn get_title(&self) -> &ffi::CStr {
unsafe { ffi::CStr::from_ptr(weston_desktop_surface_get_title(self.ptr)) }
unsafe { ffi::CStr::from_ptr(weston_desktop_surface_get_title(self.as_ptr())) }
}
pub fn get_app_id(&self) -> &ffi::CStr {
unsafe { ffi::CStr::from_ptr(weston_desktop_surface_get_app_id(self.ptr)) }
unsafe { ffi::CStr::from_ptr(weston_desktop_surface_get_app_id(self.as_ptr())) }
}
pub fn get_pid(&self) -> libc::pid_t {
unsafe { weston_desktop_surface_get_pid(self.ptr) }
unsafe { weston_desktop_surface_get_pid(self.as_ptr()) }
}
pub fn get_activated(&self) -> bool {
unsafe { weston_desktop_surface_get_activated(self.ptr) }
unsafe { weston_desktop_surface_get_activated(self.as_ptr()) }
}
pub fn get_maximized(&self) -> bool {
unsafe { weston_desktop_surface_get_maximized(self.ptr) }
unsafe { weston_desktop_surface_get_maximized(self.as_ptr()) }
}
pub fn get_fullscreen(&self) -> bool {
unsafe { weston_desktop_surface_get_fullscreen(self.ptr) }
unsafe { weston_desktop_surface_get_fullscreen(self.as_ptr()) }
}
pub fn get_resizing(&self) -> bool {
unsafe { weston_desktop_surface_get_resizing(self.ptr) }
unsafe { weston_desktop_surface_get_resizing(self.as_ptr()) }
}
pub fn get_geometry(&self) -> Geometry {
unsafe { weston_desktop_surface_get_geometry(self.ptr) }
unsafe { weston_desktop_surface_get_geometry(self.as_ptr()) }
}
pub fn get_max_size(&self) -> Size {
unsafe { weston_desktop_surface_get_max_size(self.ptr) }
unsafe { weston_desktop_surface_get_max_size(self.as_ptr()) }
}
pub fn get_min_size(&self) -> Size {
unsafe { weston_desktop_surface_get_min_size(self.ptr) }
unsafe { weston_desktop_surface_get_min_size(self.as_ptr()) }
}
}
View
@@ -15,7 +15,7 @@ impl Display {
}
}
pub fn from_ptr_temporary(ptr: *mut wl_display) -> Display {
pub fn from_ptr(ptr: *mut wl_display) -> Display {
Display {
ptr
}
@@ -33,7 +33,7 @@ impl Display {
unsafe { wayland_server::create_event_loop(wl_display_get_event_loop(self.ptr), Some(self.ptr)) }
}
pub fn ptr(&self) -> *mut wl_display {
pub fn as_ptr(&self) -> *mut wl_display {
self.ptr
}
}
View
@@ -1,3 +1,4 @@
use std::mem;
use libc;
use libweston_sys::{
weston_keyboard_modifier_MODIFIER_CTRL,
@@ -18,9 +19,9 @@ use libweston_sys::{
};
use wayland_sys::server::wl_signal;
pub use wayland_server::protocol::wl_keyboard::KeyState;
use ::WestonObject;
use ::seat::Seat;
use ::surface::Surface;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::seat::SeatRef;
use ::surface::SurfaceRef;
bitflags! {
#[derive(Default)]
@@ -50,11 +51,11 @@ bitflags! {
}
pub trait KeyboardGrab where Self: Sized {
fn key(&mut self, keyboard: &mut Keyboard, time: &libc::timespec, key: u32, state: KeyState) {}
fn modifiers(&mut self, keyboard: &mut Keyboard, serial: u32,
fn key(&mut self, keyboard: &mut KeyboardRef, time: &libc::timespec, key: u32, state: KeyState) {}
fn modifiers(&mut self, keyboard: &mut KeyboardRef, serial: u32,
mods_depressed: KeyboardModifier, mods_latched: KeyboardModifier,
mods_locked: KeyboardModifier, group: u32);
fn cancel(&mut self, keyboard: &mut Keyboard);
fn cancel(&mut self, keyboard: &mut KeyboardRef);
unsafe fn into_weston(self) -> *mut weston_keyboard_grab_interface {
let wrapper = Box::new(KeyboardGrabWrapper {
@@ -80,7 +81,7 @@ struct KeyboardGrabWrapper<T: KeyboardGrab> {
extern "C" fn run_key<T: KeyboardGrab>(grab: *mut weston_keyboard_grab, time: *const libc::timespec, key: u32, state: u32) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), KeyboardGrabWrapper<T>, base) };
wrapper.user.key(
&mut Keyboard::from_ptr_temporary(unsafe { (*grab).keyboard }),
unsafe { KeyboardRef::from_ptr_mut((*grab).keyboard) },
unsafe { &*time },
key,
KeyState::from_raw(state).unwrap_or(KeyState::Released)
@@ -92,7 +93,7 @@ extern "C" fn run_modifiers<T: KeyboardGrab>(grab: *mut weston_keyboard_grab, se
mods_depressed: u32, mods_latched: u32, mods_locked: u32, group: u32) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), KeyboardGrabWrapper<T>, base) };
wrapper.user.modifiers(
&mut Keyboard::from_ptr_temporary(unsafe { (*grab).keyboard }),
unsafe { KeyboardRef::from_ptr_mut((*grab).keyboard) },
serial,
KeyboardModifier::from_bits_truncate(mods_depressed),
KeyboardModifier::from_bits_truncate(mods_latched),
@@ -104,61 +105,53 @@ extern "C" fn run_modifiers<T: KeyboardGrab>(grab: *mut weston_keyboard_grab, se
#[allow(unused_unsafe)]
extern "C" fn run_cancel<T: KeyboardGrab>(grab: *mut weston_keyboard_grab) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), KeyboardGrabWrapper<T>, base) };
wrapper.user.cancel(&mut Keyboard::from_ptr_temporary(unsafe { (*grab).keyboard }));
wrapper.user.cancel(unsafe { KeyboardRef::from_ptr_mut((*grab).keyboard) });
}
pub struct Keyboard {
ptr: *mut weston_keyboard,
temp: bool,
foreign_type! {
type CType = weston_keyboard;
fn drop = weston_keyboard_destroy;
pub struct Keyboard;
pub struct KeyboardRef;
}
weston_object!(Keyboard << weston_keyboard);
impl Keyboard {
obj_accessors!(Seat | seat = |&this| { (*this.ptr).seat });
obj_accessors!(opt Surface | focus = |&this| { (*this.ptr).focus });
impl KeyboardRef {
obj_accessors!(SeatRef | seat = |&this| { (*this.as_ptr()).seat });
obj_accessors!(opt SurfaceRef | focus = |&this| { (*this.as_ptr()).focus });
prop_accessors!(u32 | focus_serial, grab_key, grab_serial);
prop_accessors!(ptr wl_signal | focus_signal);
pub fn set_focus(&self, surface: &Surface) {
unsafe { weston_keyboard_set_focus(self.ptr, surface.ptr()); }
pub fn set_focus(&self, surface: &SurfaceRef) {
unsafe { weston_keyboard_set_focus(self.as_ptr(), surface.as_ptr()); }
}
pub fn set_locks(&self, mask: KeyboardLock, value: KeyboardLock) -> bool {
unsafe { weston_keyboard_set_locks(self.ptr, mask.bits(), value.bits()) == 0 }
unsafe { weston_keyboard_set_locks(self.as_ptr(), mask.bits(), value.bits()) == 0 }
}
pub fn has_focus_resource(&self) -> bool {
unsafe { weston_keyboard_has_focus_resource(self.ptr) }
unsafe { weston_keyboard_has_focus_resource(self.as_ptr()) }
}
pub fn send_key(&self, time: &libc::timespec, key: u32, state: KeyState) {
unsafe { weston_keyboard_send_key(self.ptr, time, key, state.to_raw()); }
unsafe { weston_keyboard_send_key(self.as_ptr(), time, key, state.to_raw()); }
}
pub fn send_modifiers(&self, serial: u32, mods_depressed: KeyboardModifier,
mods_latched: KeyboardModifier, mods_locked: KeyboardModifier, group: u32) {
unsafe { weston_keyboard_send_modifiers(self.ptr, serial, mods_depressed.bits(), mods_latched.bits(), mods_locked.bits(), group); }
unsafe { weston_keyboard_send_modifiers(self.as_ptr(), serial, mods_depressed.bits(), mods_latched.bits(), mods_locked.bits(), group); }
}
pub fn start_grab<T: KeyboardGrab>(&self, grab: T) {
// XXX: leaks the wrapper
let silly_wrapper = Box::new(weston_keyboard_grab {
interface: unsafe { grab.into_weston() },
keyboard: self.ptr, // weston will set that to the same value lol
keyboard: self.as_ptr(), // weston will set that to the same value lol
});
unsafe { weston_keyboard_start_grab(self.ptr, Box::into_raw(silly_wrapper)); }
unsafe { weston_keyboard_start_grab(self.as_ptr(), Box::into_raw(silly_wrapper)); }
}
pub fn end_grab(&self) {
unsafe { weston_keyboard_end_grab(self.ptr); }
}
}
impl Drop for Keyboard {
fn drop(&mut self) {
if !self.temp {
unsafe { weston_keyboard_destroy(self.ptr); }
}
unsafe { weston_keyboard_end_grab(self.as_ptr()); }
}
}
View
@@ -7,11 +7,11 @@ use libweston_sys::{
weston_launcher,
weston_compositor,
};
use ::WestonObject;
use ::compositor::Compositor;
use foreign_types::ForeignTypeRef;
use ::compositor::CompositorRef;
pub trait Launcher where Self: Sized {
fn connect(compositor: &Compositor, tty: libc::c_int, seat_id: &CStr, sync_drm: bool) -> Option<Self>;
fn connect(compositor: &CompositorRef, 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;
@@ -49,7 +49,7 @@ 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(&Compositor::from_ptr_temporary(compositor), tty, unsafe { CStr::from_ptr(seat_id) }, sync_drm) {
if let Some(launcher) = T::connect(unsafe { CompositorRef::from_ptr(compositor) }, tty, unsafe { CStr::from_ptr(seat_id) }, sync_drm) {
unsafe { *launcher_out = launcher.into_weston() };
0
} else {
View
@@ -1,11 +1,12 @@
use libc;
use std::env;
use std::rc::Rc;
use std::io::Write;
use std::ffi::CStr;
use std::os::raw;
use std::os::unix::io::RawFd;
use ::WestonObject;
use ::compositor::Compositor;
use foreign_types::ForeignTypeRef;
use ::compositor::CompositorRef;
use ::launcher::Launcher;
use wayland_sys::server::signal::wl_signal_emit;
@@ -14,15 +15,15 @@ use loginw::protocol::*;
use loginw::socket::*;
pub struct LoginwLauncher {
sock: Socket,
sock: Rc<Socket>,
tty_fd: RawFd,
vt_num: libc::c_int,
}
impl Launcher for LoginwLauncher {
fn connect(compositor: &Compositor, _tty: libc::c_int, _seat_id: &CStr, _sync_drm: bool) -> Option<Self> {
fn connect(compositor: &CompositorRef, _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 = Socket::new(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()");
@@ -31,16 +32,16 @@ impl Launcher for LoginwLauncher {
compositor.get_display().get_event_loop().add_fd_event_source(
sock.fd,
sources::FdEventSourceImpl {
ready: |_: &mut EventLoopHandle, &mut (ref sock, ref compositor): &mut (Socket, Compositor), fd, _| {
ready: |_: &mut EventLoopHandle, &mut (ref sock, ref mut compositor): &mut (Rc<Socket>, &mut CompositorRef), fd, _| {
let (resp, _) = sock.recvmsg::<LoginwResponse>().expect(".recvmsg()");
match resp.typ {
LoginwResponseType::LoginwActivated => {
compositor.set_session_active(true);
unsafe { wl_signal_emit(compositor.session_signal(), compositor.ptr() as *mut raw::c_void); }
unsafe { wl_signal_emit(compositor.session_signal(), compositor.as_ptr() as *mut raw::c_void); }
},
LoginwResponseType::LoginwDeactivated => {
compositor.set_session_active(false);
unsafe { wl_signal_emit(compositor.session_signal(), compositor.ptr() as *mut raw::c_void); }
unsafe { wl_signal_emit(compositor.session_signal(), compositor.as_ptr() as *mut raw::c_void); }
},
_ => {
},
@@ -50,7 +51,7 @@ impl Launcher for LoginwLauncher {
// TODO: restore the tty
},
},
(sock.temp_clone(), compositor.temp_clone()),
(Rc::clone(&sock), unsafe { CompositorRef::from_ptr_mut(compositor.as_ptr()) }),
sources::FdInterest::READ,
);
View
@@ -14,7 +14,7 @@ use libweston_sys::{
weston_layer_position_WESTON_LAYER_POSITION_FADE,
weston_layer_entry_insert
};
use ::WestonObject;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::compositor::Compositor;
use ::view::View;
@@ -35,47 +35,35 @@ pub const POSITION_LOCK: LayerPosition = weston_layer_position_WESTON_LAYER_POSI
pub const POSITION_CURSOR: LayerPosition = weston_layer_position_WESTON_LAYER_POSITION_CURSOR;
pub const POSITION_FADE: LayerPosition = weston_layer_position_WESTON_LAYER_POSITION_FADE;
pub struct Layer<'comp> {
ptr: *mut weston_layer,
phantom: marker::PhantomData<&'comp Compositor>,
fn drop_layer(ptr: *mut weston_layer) {
let _ = unsafe { Box::from_raw(ptr) };
}
unsafe impl<'comp> Sync for Layer<'comp> {}
impl<'comp> WestonObject for Layer<'comp> {
type T = weston_layer;
foreign_type! {
type CType = weston_layer;
fn drop = drop_layer;
pub struct Layer;
pub struct LayerRef;
}
fn from_ptr(ptr: *mut Self::T) -> Self {
Self::from_ptr_temporary(ptr)
}
unsafe impl Sync for Layer {}
fn from_ptr_temporary(ptr: *mut Self::T) -> Self {
Layer {
ptr,
phantom: marker::PhantomData,
impl Layer {
pub fn new(compositor: &Compositor) -> Layer {
let ptr = Box::into_raw(Box::new(unsafe { mem::zeroed() }));
unsafe {
weston_layer_init(ptr, compositor.as_ptr());
Layer::from_ptr(ptr)
}
}
fn ptr(&self) -> *mut weston_layer {
self.ptr
}
}
impl<'comp> Layer<'comp> {
pub fn new(compositor: &'comp Compositor) -> Layer<'comp> {
let result = Layer {
ptr: Box::into_raw(Box::new(unsafe { mem::zeroed() })),
phantom: marker::PhantomData,
};
unsafe { weston_layer_init(result.ptr, compositor.ptr()); }
result
}
impl LayerRef {
pub fn set_position(&mut self, position: LayerPosition) {
unsafe { weston_layer_set_position(self.ptr, position as weston_layer_position); }
unsafe { weston_layer_set_position(self.as_ptr(), position as weston_layer_position); }
}
pub fn entry_insert(&mut self, view: &mut View) {
unsafe { weston_layer_entry_insert(&mut (*self.ptr).view_list, view.layer_link()); }
unsafe { weston_layer_entry_insert(&mut (*self.as_ptr()).view_list, view.layer_link()); }
}
}
View
@@ -6,6 +6,8 @@ pub extern crate xkbcommon;
pub extern crate libc;
pub extern crate vsprintf;
#[macro_use]
extern crate foreign_types;
#[macro_use]
extern crate enum_primitive_derive;
extern crate num_traits;
#[macro_use]
@@ -18,6 +20,7 @@ extern crate bitflags;
extern crate derive_builder;
extern crate loginw;
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
};
@@ -30,132 +33,40 @@ pub type Geometry = libweston_sys::weston_geometry;
pub type Position = libweston_sys::weston_position;
pub type Size = libweston_sys::weston_size;
pub trait WestonObject where Self: Sized {
type T;
fn from_ptr(ptr: *mut Self::T) -> Self;
fn from_ptr_temporary(ptr: *mut Self::T) -> Self;
fn ptr(&self) -> *mut Self::T;
fn from_void_ptr(ptr: *mut c_void) -> Self {
Self::from_ptr(ptr as *mut Self::T)
}
fn from_void_ptr_temporary(ptr: *mut c_void) -> Self {
Self::from_ptr_temporary(ptr as *mut Self::T)
}
fn same_as<U>(&self, other: U) -> bool where U: Sized + Borrow<Self> {
self.ptr() == other.borrow().ptr()
}
}
/// For listeners without args
impl WestonObject for () {
type T = ();
fn from_ptr(_ptr: *mut Self::T) -> Self {
()
}
fn from_ptr_temporary(_ptr: *mut Self::T) -> Self {
()
}
fn ptr(&self) -> *mut Self::T {
ptr::null_mut()
}
}
macro_rules! weston_object {
($wrap:ident << $typ:ident $($k:ident : $v:expr),*) => {
impl ::WestonObject for $wrap {
type T = $typ;
#[inline] fn from_ptr(ptr: *mut $typ) -> $wrap {
$wrap {
ptr,
temp: false,
$($k: $v)*
}
}
#[inline] fn from_ptr_temporary(ptr: *mut $typ) -> $wrap {
$wrap {
ptr,
temp: true,
$($k: $v)*
}
}
#[inline] fn ptr(&self) -> *mut $typ {
self.ptr
}
}
};
($wrap:ident<$tvar:ident> << $typ:ident $($k:ident : $v:expr),*) => {
impl<$tvar> ::WestonObject for $wrap<$tvar> {
type T = $typ;
#[inline] fn from_ptr(ptr: *mut $typ) -> $wrap<$tvar> {
$wrap {
ptr,
temp: false,
phantom: ::std::marker::PhantomData::<$tvar>,
$($k: $v)*
}
}
#[inline] fn from_ptr_temporary(ptr: *mut $typ) -> $wrap<$tvar> {
$wrap {
ptr,
temp: true,
phantom: ::std::marker::PhantomData::<$tvar>,
$($k: $v)*
}
}
#[inline] fn ptr(&self) -> *mut $typ {
self.ptr
}
}
};
}
macro_rules! prop_accessors {
($typ:ty | $($prop:ident),+) => {
$(#[inline] pub fn $prop(&self) -> $typ {
unsafe { (*self.ptr).$prop }
unsafe { (*self.as_ptr()).$prop }
})+
};
(ptr $typ:ty | $($prop:ident),+) => {
$(#[inline] pub fn $prop(&self) -> &mut $typ {
unsafe { &mut (*self.ptr).$prop }
unsafe { &mut (*self.as_ptr()).$prop }
})+
}
}
macro_rules! obj_accessors {
($typ:ident | $($prop:ident = |&$self:ident| $acc:block),+) => {
$(#[inline] pub fn $prop<'a>(&'a self) -> $typ {
use ::WestonObject;
$typ::from_ptr_temporary(unsafe { let $self = &self; $acc })
$(#[inline] pub fn $prop<'a>(&'a self) -> &mut $typ {
use foreign_types::ForeignTypeRef;
unsafe { $typ::from_ptr_mut({ let $self = &self; $acc }) }
})+
};
($typ:ident<$typp:tt> | $($prop:ident = |&$self:ident| $acc:block),+) => {
$(#[inline] pub fn $prop<'a, $typp>(&'a self) -> $typ<$typp> {
use ::WestonObject;
$typ::from_ptr_temporary(unsafe { let $self = &self; $acc })
$(#[inline] pub fn $prop<'a, $typp>(&'a self) -> &mut $typ<$typp> {
use foreign_types::ForeignTypeRef;
unsafe { $typ::from_ptr_mut({ let $self = &self; $acc }) }
})+
};
(opt $typ:ident | $($prop:ident = |&$self:ident| $acc:block),+) => {
$(#[inline] pub fn $prop<'a>(&'a self) -> Option<$typ> {
use ::WestonObject;
$(#[inline] pub fn $prop<'a>(&'a self) -> Option<&mut $typ> {
use foreign_types::ForeignTypeRef;
let ptr = unsafe { let $self = &self; $acc };
if ptr.is_null() {
None
} else {
Some($typ::from_ptr_temporary(ptr))
Some(unsafe { $typ::from_ptr_mut({ let $self = &self; $acc }) })
}
})+
}
View
@@ -1,21 +1,21 @@
use std::mem;
use std::os::raw::c_void;
use foreign_types::ForeignTypeRef;
use wayland_sys::server::{signal, wl_signal, wl_listener, wl_list_init};
use ::WestonObject;
pub struct WlListener<T: WestonObject> {
cb: Box<FnMut(T)>,
pub struct WlListener<T: ForeignTypeRef> {
cb: Box<FnMut(&mut T)>,
wll: wl_listener,
}
#[allow(unused_unsafe)]
extern "C" fn run_wl_listener<T: WestonObject>(listener: *mut wl_listener, data: *mut c_void) {
extern "C" fn run_wl_listener<T: ForeignTypeRef>(listener: *mut wl_listener, data: *mut c_void) {
let wrapper = unsafe { &mut *wl_container_of!(listener, WlListener<T>, wll) };
(*wrapper.cb)(T::from_void_ptr_temporary(data));
(*wrapper.cb)(unsafe { T::from_ptr_mut(data as *mut T::CType) });
}
impl<T: WestonObject> WlListener<T> {
pub fn new(cb: Box<FnMut(T)>) -> mem::ManuallyDrop<Box<WlListener<T>>> {
impl<T: ForeignTypeRef> WlListener<T> {
pub fn new(cb: Box<FnMut(&mut T)>) -> mem::ManuallyDrop<Box<WlListener<T>>> {
let mut result = Box::new(WlListener {
cb,
wll: unsafe { mem::zeroed() },
View
@@ -6,43 +6,36 @@ use libweston_sys::{
weston_output_release
};
use wayland_sys::server::wl_signal;
use foreign_types::ForeignTypeRef;
pub struct Output {
ptr: *mut weston_output,
temp: bool,
foreign_type! {
type CType = weston_output;
fn drop = weston_output_release;
pub struct Output;
pub struct OutputRef;
}
weston_object!(Output << weston_output);
impl Output {
impl OutputRef {
pub fn set_scale(&self, scale: libc::c_int) {
unsafe { weston_output_set_scale(self.ptr, scale); }
unsafe { weston_output_set_scale(self.as_ptr(), scale); }
}
pub fn set_extra_scale(&self, scale: libc::c_float) {
unsafe { weston_output_set_extra_scale(self.ptr, scale); }
unsafe { weston_output_set_extra_scale(self.as_ptr(), scale); }
}
pub fn set_transform(&self, transform: libc::c_uint) {
unsafe { weston_output_set_transform(self.ptr, transform); }
unsafe { weston_output_set_transform(self.as_ptr(), transform); }
}
pub fn enable(&self) -> bool {
unsafe { weston_output_enable(self.ptr) == 0 }
unsafe { weston_output_enable(self.as_ptr()) == 0 }
}
pub fn disable(&self) {
unsafe { weston_output_disable(self.ptr); }
unsafe { weston_output_disable(self.as_ptr()); }
}
prop_accessors!(ptr wl_signal | frame_signal, destroy_signal);
}
impl Drop for Output {
fn drop(&mut self) {
if !self.temp {
unsafe { weston_output_release(self.ptr); }
}
}
}
View
@@ -7,9 +7,9 @@ use libweston_sys::{
weston_drm_backend_output_mode_WESTON_DRM_BACKEND_OUTPUT_CURRENT,
weston_drm_backend_output_mode_WESTON_DRM_BACKEND_OUTPUT_PREFERRED,
};
use ::WestonObject;
use ::compositor::Compositor;
use ::output::Output;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::compositor::CompositorRef;
use ::output::OutputRef;
const_cstr!{
DRM_OUTPUT_API_NAME = "weston_drm_output_api_v1";
@@ -24,71 +24,57 @@ pub enum DrmBackendOutputMode {
}
pub trait DrmOutput {
fn set_mode(&self, output: &Output, mode: DrmBackendOutputMode, modeline: Option<&str>) -> bool;
fn set_gbm_format(&self, output: &Output, gbm_format: Option<&str>);
fn set_seat(&self, output: &Output, seat: Option<&str>);
fn set_mode(&self, output: &OutputRef, mode: DrmBackendOutputMode, modeline: Option<&str>) -> bool;
fn set_gbm_format(&self, output: &OutputRef, gbm_format: Option<&str>);
fn set_seat(&self, output: &OutputRef, seat: Option<&str>);
}
pub struct DrmOutputImpl<'comp> {
ptr: *mut weston_drm_output_api,
phantom: marker::PhantomData<&'comp Compositor>,
// The API impl is not a create/destroy thing really
fn noop_destroy(_: *mut weston_drm_output_api) {}
foreign_type! {
type CType = weston_drm_output_api;
fn drop = noop_destroy;
pub struct DrmOutputImpl;
pub struct DrmOutputImplRef;
}
impl<'comp> DrmOutput for DrmOutputImpl<'comp> {
fn set_mode(&self, output: &Output, mode: DrmBackendOutputMode, modeline: Option<&str>) -> bool {
impl DrmOutput for DrmOutputImplRef {
fn set_mode(&self, output: &OutputRef, mode: DrmBackendOutputMode, modeline: Option<&str>) -> bool {
let modeline = modeline.map(|m| ffi::CString::new(m).expect("CString"));
unsafe { (*self.ptr).set_mode.expect("set_mode ptr")(output.ptr(), mode as weston_drm_backend_output_mode, modeline.map(|m| m.as_ptr()).unwrap_or(ptr::null())) == 0 }
unsafe { (*self.as_ptr()).set_mode.expect("set_mode ptr")(output.as_ptr(), mode as weston_drm_backend_output_mode, modeline.map(|m| m.as_ptr()).unwrap_or(ptr::null())) == 0 }
}
fn set_gbm_format(&self, output: &Output, gbm_format: Option<&str>) {
fn set_gbm_format(&self, output: &OutputRef, gbm_format: Option<&str>) {
let gbm_format = gbm_format.map(|f| ffi::CString::new(f).expect("CString"));
unsafe { (*self.ptr).set_gbm_format.expect("set_gbm_format ptr")(output.ptr(), gbm_format.map(|f| f.as_ptr()).unwrap_or(ptr::null())) }
unsafe { (*self.as_ptr()).set_gbm_format.expect("set_gbm_format ptr")(output.as_ptr(), gbm_format.map(|f| f.as_ptr()).unwrap_or(ptr::null())) }
}
fn set_seat(&self, output: &Output, seat: Option<&str>) {
fn set_seat(&self, output: &OutputRef, seat: Option<&str>) {
let seat = seat.map(|s| ffi::CString::new(s).expect("CString"));
unsafe { (*self.ptr).set_seat.expect("set_gbm_format ptr")(output.ptr(), seat.map(|s| s.as_ptr()).unwrap_or(ptr::null())) }
}
}
impl<'comp> WestonObject for DrmOutputImpl<'comp> {
type T = weston_drm_output_api;
fn from_ptr(ptr: *mut Self::T) -> Self {
Self::from_ptr_temporary(ptr)
}
fn from_ptr_temporary(ptr: *mut Self::T) -> Self {
DrmOutputImpl {
ptr,
phantom: marker::PhantomData,
}
}
fn ptr(&self) -> *mut Self::T {
self.ptr
unsafe { (*self.as_ptr()).set_seat.expect("set_gbm_format ptr")(output.as_ptr(), seat.map(|s| s.as_ptr()).unwrap_or(ptr::null())) }
}
}
pub trait HasDrmOutput<'t> {
pub trait HasDrmOutput {
type Impl: DrmOutput;
fn get_drm_output(&self) -> Option<Self::Impl>;
fn get_drm_output(&self) -> Option<&mut Self::Impl>;
}
impl<'comp, C: borrow::Borrow<Compositor>> HasDrmOutput<'comp> for C {
type Impl = DrmOutputImpl<'comp>;
impl HasDrmOutput for CompositorRef {
type Impl = DrmOutputImplRef;
fn get_drm_output(&self) -> Option<Self::Impl> {
fn get_drm_output(&self) -> Option<&mut Self::Impl> {
let ptr = unsafe {
weston_plugin_api_get(
self.borrow().ptr(),
self.as_ptr(),
DRM_OUTPUT_API_NAME.as_ptr(),
mem::size_of::<weston_drm_output_api>())
} as *mut weston_drm_output_api;
if ptr.is_null() {
return None
}
Some(DrmOutputImpl::from_ptr_temporary(ptr))
Some(unsafe { DrmOutputImplRef::from_ptr_mut(ptr) })
}
}
View
@@ -3,73 +3,59 @@ use libweston_sys::{
weston_plugin_api_get,
weston_windowed_output_api,
};
use ::WestonObject;
use ::compositor::Compositor;
use ::output::Output;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::compositor::CompositorRef;
use ::output::OutputRef;
const_cstr!{
WINDOWED_OUTPUT_API_NAME = "weston_windowed_output_api_v1";
}
pub trait WindowedOutput<'comp> {
fn output_set_size(&self, output: &Output, width: u32, height: u32) -> bool;
fn output_create(&self, compositor: &'comp Compositor, name: &str) -> bool;
pub trait WindowedOutput {
fn output_set_size(&self, output: &OutputRef, width: u32, height: u32) -> bool;
fn output_create(&self, compositor: &CompositorRef, name: &str) -> bool;
}
pub struct WindowedOutputImpl<'comp> {
ptr: *mut weston_windowed_output_api,
phantom: marker::PhantomData<&'comp Compositor>,
}
impl<'comp> WindowedOutput<'comp> for WindowedOutputImpl<'comp> {
fn output_set_size(&self, output: &Output, width: u32, height: u32) -> bool {
unsafe { (*self.ptr).output_set_size.expect("output_set_size ptr")(output.ptr(), width as _, height as _) == 0 }
}
// The API impl is not a create/destroy thing really
fn noop_destroy(_: *mut weston_windowed_output_api) {}
fn output_create(&self, compositor: &'comp Compositor, name: &str) -> bool {
let name = ffi::CString::new(name).expect("CString");
unsafe { (*self.ptr).output_create.expect("output_create ptr")(compositor.ptr(), name.as_ptr()) == 0 }
}
foreign_type! {
type CType = weston_windowed_output_api;
fn drop = noop_destroy;
pub struct WindowedOutputImpl;
pub struct WindowedOutputImplRef;
}
impl<'comp> WestonObject for WindowedOutputImpl<'comp> {
type T = weston_windowed_output_api;
fn from_ptr(ptr: *mut Self::T) -> Self {
Self::from_ptr_temporary(ptr)
impl WindowedOutput for WindowedOutputImplRef {
fn output_set_size(&self, output: &OutputRef, width: u32, height: u32) -> bool {
unsafe { (*self.as_ptr()).output_set_size.expect("output_set_size ptr")(output.as_ptr(), width as _, height as _) == 0 }
}
fn from_ptr_temporary(ptr: *mut Self::T) -> Self {
WindowedOutputImpl {
ptr,
phantom: marker::PhantomData,
}
}
fn ptr(&self) -> *mut Self::T {
self.ptr
fn output_create(&self, compositor: &CompositorRef, name: &str) -> bool {
let name = ffi::CString::new(name).expect("CString");
unsafe { (*self.as_ptr()).output_create.expect("output_create ptr")(compositor.as_ptr(), name.as_ptr()) == 0 }
}
}
pub trait HasWindowedOutput<'t> {
type Impl: WindowedOutput<'t>;
pub trait HasWindowedOutput {
type Impl: WindowedOutput;
fn get_windowed_output(&'t self) -> Option<Self::Impl>;
fn get_windowed_output(&self) -> Option<&mut Self::Impl>;
}
impl<'comp, C: borrow::Borrow<Compositor>> HasWindowedOutput<'comp> for C {
type Impl = WindowedOutputImpl<'comp>;
impl HasWindowedOutput for CompositorRef {
type Impl = WindowedOutputImplRef;
fn get_windowed_output(&self) -> Option<Self::Impl> {
fn get_windowed_output(&self) -> Option<&mut Self::Impl> {
let ptr = unsafe {
weston_plugin_api_get(
self.borrow().ptr(),
self.as_ptr(),
WINDOWED_OUTPUT_API_NAME.as_ptr(),
mem::size_of::<weston_windowed_output_api>())
} as *mut weston_windowed_output_api;
if ptr.is_null() {
return None
}
Some(WindowedOutputImpl::from_ptr_temporary(ptr))
Some(unsafe { WindowedOutputImplRef::from_ptr_mut(ptr) })
}
}
View
@@ -1,3 +1,4 @@
use std::mem;
use libc;
use libweston_sys::{
weston_pointer_motion_mask_WESTON_POINTER_MOTION_ABS,
@@ -18,9 +19,9 @@ use libweston_sys::{
use wayland_sys::common::wl_fixed_t;
use wayland_sys::server::wl_signal;
pub use wayland_server::protocol::wl_pointer::{Axis, AxisSource, ButtonState};
use ::WestonObject;
use ::seat::Seat;
use ::view::View;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::seat::SeatRef;
use ::view::ViewRef;
bitflags! {
#[derive(Default)]
@@ -88,13 +89,13 @@ impl Into<weston_pointer_axis_event> for PointerAxisEvent {
}
pub trait PointerGrab where Self: Sized {
fn focus(&mut self, pointer: &mut Pointer) {}
fn motion(&mut self, pointer: &mut Pointer, time: &libc::timespec, event: PointerMotionEvent) {}
fn button(&mut self, pointer: &mut Pointer, time: &libc::timespec, button: u32, state: ButtonState) {}
fn axis(&mut self, pointer: &mut Pointer, time: &libc::timespec, event: PointerAxisEvent) {}
fn axis_source(&mut self, pointer: &mut Pointer, source: AxisSource) {}
fn frame(&mut self, pointer: &mut Pointer) {}
fn cancel(&mut self, pointer: &mut Pointer) {}
fn focus(&mut self, pointer: &mut PointerRef) {}
fn motion(&mut self, pointer: &mut PointerRef, time: &libc::timespec, event: PointerMotionEvent) {}
fn button(&mut self, pointer: &mut PointerRef, time: &libc::timespec, button: u32, state: ButtonState) {}
fn axis(&mut self, pointer: &mut PointerRef, time: &libc::timespec, event: PointerAxisEvent) {}
fn axis_source(&mut self, pointer: &mut PointerRef, source: AxisSource) {}
fn frame(&mut self, pointer: &mut PointerRef) {}
fn cancel(&mut self, pointer: &mut PointerRef) {}
unsafe fn into_weston(self) -> *mut weston_pointer_grab_interface {
let wrapper = Box::new(PointerGrabWrapper {
@@ -123,14 +124,14 @@ struct PointerGrabWrapper<T: PointerGrab> {
#[allow(unused_unsafe)]
extern "C" fn run_focus<T: PointerGrab>(grab: *mut weston_pointer_grab) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), PointerGrabWrapper<T>, base) };
wrapper.user.focus(&mut Pointer::from_ptr_temporary(unsafe { (*grab).pointer }));
wrapper.user.focus(unsafe { PointerRef::from_ptr_mut((*grab).pointer) });
}
#[allow(unused_unsafe)]
extern "C" fn run_motion<T: PointerGrab>(grab: *mut weston_pointer_grab, time: *const libc::timespec, event: *mut weston_pointer_motion_event) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), PointerGrabWrapper<T>, base) };
wrapper.user.motion(
&mut Pointer::from_ptr_temporary(unsafe { (*grab).pointer }),
unsafe { PointerRef::from_ptr_mut((*grab).pointer) },
unsafe { &*time },
unsafe { (&*event).into() },
);
@@ -140,7 +141,7 @@ extern "C" fn run_motion<T: PointerGrab>(grab: *mut weston_pointer_grab, time: *
extern "C" fn run_button<T: PointerGrab>(grab: *mut weston_pointer_grab, time: *const libc::timespec, button: u32, state: u32) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), PointerGrabWrapper<T>, base) };
wrapper.user.button(
&mut Pointer::from_ptr_temporary(unsafe { (*grab).pointer }),
unsafe { PointerRef::from_ptr_mut((*grab).pointer) },
unsafe { &*time },
button,
ButtonState::from_raw(state).unwrap_or(ButtonState::Released),
@@ -151,7 +152,7 @@ extern "C" fn run_button<T: PointerGrab>(grab: *mut weston_pointer_grab, time: *
extern "C" fn run_axis<T: PointerGrab>(grab: *mut weston_pointer_grab, time: *const libc::timespec, event: *mut weston_pointer_axis_event) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), PointerGrabWrapper<T>, base) };
wrapper.user.axis(
&mut Pointer::from_ptr_temporary(unsafe { (*grab).pointer }),
unsafe { PointerRef::from_ptr_mut((*grab).pointer) },
unsafe { &*time },
unsafe { (&*event).into() },
);
@@ -161,35 +162,35 @@ extern "C" fn run_axis<T: PointerGrab>(grab: *mut weston_pointer_grab, time: *co
extern "C" fn run_axis_source<T: PointerGrab>(grab: *mut weston_pointer_grab, source: u32) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), PointerGrabWrapper<T>, base) };
wrapper.user.axis_source(
&mut Pointer::from_ptr_temporary(unsafe { (*grab).pointer }),
unsafe { PointerRef::from_ptr_mut((*grab).pointer) },
AxisSource::from_raw(source).unwrap_or(AxisSource::Wheel)
);
}
#[allow(unused_unsafe)]
extern "C" fn run_frame<T: PointerGrab>(grab: *mut weston_pointer_grab) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), PointerGrabWrapper<T>, base) };
wrapper.user.frame(&mut Pointer::from_ptr_temporary(unsafe { (*grab).pointer }));
wrapper.user.frame(unsafe { PointerRef::from_ptr_mut((*grab).pointer) });
}
#[allow(unused_unsafe)]
extern "C" fn run_cancel<T: PointerGrab>(grab: *mut weston_pointer_grab) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), PointerGrabWrapper<T>, base) };
wrapper.user.cancel(&mut Pointer::from_ptr_temporary(unsafe { (*grab).pointer }));
wrapper.user.cancel(unsafe { PointerRef::from_ptr_mut((*grab).pointer) });
}
pub struct Pointer {
ptr: *mut weston_pointer,
temp: bool,
foreign_type! {
type CType = weston_pointer;
fn drop = weston_pointer_destroy;
pub struct Pointer;
pub struct PointerRef;
}
weston_object!(Pointer << weston_pointer);
impl Pointer {
obj_accessors!(Seat | seat = |&this| { (*this.ptr).seat });
obj_accessors!(opt View |
focus = |&this| { (*this.ptr).focus },
sprite = |&this| { (*this.ptr).sprite });
impl PointerRef {
obj_accessors!(SeatRef | seat = |&this| { (*this.as_ptr()).seat });
obj_accessors!(opt ViewRef |
focus = |&this| { (*this.as_ptr()).focus },
sprite = |&this| { (*this.as_ptr()).sprite });
prop_accessors!(u32 | focus_serial, grab_button, grab_serial, button_count);
prop_accessors!(i32 | hotspot_x, hotspot_y);
prop_accessors!(wl_fixed_t | grab_x, grab_y, x, y, sx, sy);
@@ -199,79 +200,71 @@ impl Pointer {
pub fn motion_to_abs(&self, event: PointerMotionEvent) -> (wl_fixed_t, wl_fixed_t) {
let mut x = 0;
let mut y = 0;
unsafe { weston_pointer_motion_to_abs(self.ptr, &mut event.into(), &mut x, &mut y); }
unsafe { weston_pointer_motion_to_abs(self.as_ptr(), &mut event.into(), &mut x, &mut y); }
(x, y)
}
pub fn send_motion(&self, time: &libc::timespec, event: PointerMotionEvent) {
unsafe { weston_pointer_send_motion(self.ptr, time, &mut event.into()); }
unsafe { weston_pointer_send_motion(self.as_ptr(), time, &mut event.into()); }
}
pub fn has_focus_resource(&self) -> bool {
unsafe { weston_pointer_has_focus_resource(self.ptr) }
unsafe { weston_pointer_has_focus_resource(self.as_ptr()) }
}
pub fn send_button(&self, time: &libc::timespec, button: u32, state_w: ButtonState) {
unsafe { weston_pointer_send_button(self.ptr, time, button, state_w.to_raw()); }
unsafe { weston_pointer_send_button(self.as_ptr(), time, button, state_w.to_raw()); }
}
pub fn send_axis(&self, time: &libc::timespec, event: PointerAxisEvent) {
unsafe { weston_pointer_send_axis(self.ptr, time, &mut event.into()); }
unsafe { weston_pointer_send_axis(self.as_ptr(), time, &mut event.into()); }
}
pub fn send_axis_source(&self, source: u32) {
unsafe { weston_pointer_send_axis_source(self.ptr, source); }
unsafe { weston_pointer_send_axis_source(self.as_ptr(), source); }
}
pub fn send_frame(&self) {
unsafe { weston_pointer_send_frame(self.ptr); }
unsafe { weston_pointer_send_frame(self.as_ptr()); }
}
pub fn set_focus(&self, view: &View, sx: wl_fixed_t, sy: wl_fixed_t) {
unsafe { weston_pointer_set_focus(self.ptr, view.ptr(), sx, sy); }
pub fn set_focus(&self, view: &ViewRef, sx: wl_fixed_t, sy: wl_fixed_t) {
unsafe { weston_pointer_set_focus(self.as_ptr(), view.as_ptr(), sx, sy); }
}
pub fn clear_focus(&self) {
unsafe { weston_pointer_clear_focus(self.ptr); }
unsafe { weston_pointer_clear_focus(self.as_ptr()); }
}
pub fn start_grab<T: PointerGrab>(&self, grab: T) {
// XXX: leaks the wrapper
let silly_wrapper = Box::new(weston_pointer_grab {
interface: unsafe { grab.into_weston() },
pointer: self.ptr, // weston will set that to the same value lol
pointer: self.as_ptr(), // weston will set that to the same value lol
});
unsafe { weston_pointer_start_grab(self.ptr, Box::into_raw(silly_wrapper)); }
unsafe { weston_pointer_start_grab(self.as_ptr(), Box::into_raw(silly_wrapper)); }
}
pub fn end_grab(&self) {
unsafe { weston_pointer_end_grab(self.ptr); }
unsafe { weston_pointer_end_grab(self.as_ptr()); }
}
pub fn set_default_grab<T: PointerGrab>(&self, grab: T) {
unsafe { weston_pointer_set_default_grab(self.ptr, grab.into_weston()); }
unsafe { weston_pointer_set_default_grab(self.as_ptr(), grab.into_weston()); }
}
pub fn clamp(&self) -> (wl_fixed_t, wl_fixed_t) {
let mut x = 0;
let mut y = 0;
unsafe { weston_pointer_clamp(self.ptr, &mut x, &mut y); }
unsafe { weston_pointer_clamp(self.as_ptr(), &mut x, &mut y); }
(x, y)
}
pub fn moove(&self, event: PointerMotionEvent) {
unsafe { weston_pointer_move(self.ptr, &mut event.into()); }
unsafe { weston_pointer_move(self.as_ptr(), &mut event.into()); }
}
pub fn is_default_grab(&self) -> bool {
return unsafe { (*self.ptr).grab == &mut (*self.ptr).default_grab };
}
}
impl Drop for Pointer {
fn drop(&mut self) {
if !self.temp {
unsafe { weston_pointer_destroy(self.ptr); }
}
return unsafe { (*self.as_ptr()).grab == &mut (*self.as_ptr()).default_grab };
}
}
View
@@ -6,47 +6,32 @@ use libweston_sys::{
weston_seat_set_keyboard_focus,
};
use wayland_sys::server::wl_signal;
use ::WestonObject;
use ::pointer::Pointer;
use ::keyboard::{KeyboardModifier, Keyboard};
use ::touch::Touch;
use ::surface::Surface;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::pointer::PointerRef;
use ::keyboard::{KeyboardModifier, KeyboardRef};
use ::touch::TouchRef;
use ::surface::SurfaceRef;
pub struct Seat {
ptr: *mut weston_seat,
temp: bool,
foreign_type! {
type CType = weston_seat;
fn drop = weston_seat_release;
pub struct Seat;
pub struct SeatRef;
}
weston_object!(Seat << weston_seat);
impl Seat {
pub fn temp_clone(&self) -> Seat {
Seat {
ptr: self.ptr,
temp: true,
}
}
obj_accessors!(opt Pointer | get_pointer = |&this| { weston_seat_get_pointer(this.ptr) });
obj_accessors!(opt Keyboard | get_keyboard = |&this| { weston_seat_get_keyboard(this.ptr) });
obj_accessors!(opt Touch | get_touch = |&this| { weston_seat_get_touch(this.ptr) });
obj_accessors!(opt Surface | saved_kbd_focus = |&this| { (*this.ptr).saved_kbd_focus });
impl SeatRef {
obj_accessors!(opt PointerRef | get_pointer = |&this| { weston_seat_get_pointer(this.as_ptr()) });
obj_accessors!(opt KeyboardRef | get_keyboard = |&this| { weston_seat_get_keyboard(this.as_ptr()) });
obj_accessors!(opt TouchRef | get_touch = |&this| { weston_seat_get_touch(this.as_ptr()) });
obj_accessors!(opt SurfaceRef | saved_kbd_focus = |&this| { (*this.as_ptr()).saved_kbd_focus });
prop_accessors!(ptr wl_signal | destroy_signal, updated_caps_signal, selection_signal);
prop_accessors!(libc::c_int | pointer_device_count, keyboard_device_count, touch_device_count);
pub fn modifier_state(&self) -> KeyboardModifier {
KeyboardModifier::from_bits_truncate(unsafe { (*self.ptr).modifier_state })
KeyboardModifier::from_bits_truncate(unsafe { (*self.as_ptr()).modifier_state })
}
pub fn set_keyboard_focus(&self, surface: &Surface) {
unsafe { weston_seat_set_keyboard_focus(self.ptr, surface.ptr()); }
}
}
impl Drop for Seat {
fn drop(&mut self) {
if !self.temp {
unsafe { weston_seat_release(self.ptr); }
}
pub fn set_keyboard_focus(&self, surface: &SurfaceRef) {
unsafe { weston_seat_set_keyboard_focus(self.as_ptr(), surface.as_ptr()); }
}
}
View
@@ -8,71 +8,65 @@ use libweston_sys::{
weston_surface_get_main_surface,
};
use wayland_sys::server::wl_signal;
use ::WestonObject;
use ::compositor::Compositor;
use ::output::Output;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::compositor::CompositorRef;
use ::output::OutputRef;
pub struct Surface {
ptr: *mut weston_surface,
temp: bool,
foreign_type! {
type CType = weston_surface;
fn drop = weston_surface_destroy;
pub struct Surface;
pub struct SurfaceRef;
}
weston_object!(Surface << weston_surface);
impl Surface {
pub fn new(compositor: &Compositor) -> Surface {
Surface::from_ptr(unsafe { weston_surface_create(compositor.ptr()) })
pub fn new(compositor: &CompositorRef) -> Surface {
unsafe { Surface::from_ptr(weston_surface_create(compositor.as_ptr())) }
}
}
impl SurfaceRef {
pub fn set_size(&self, width: i32, height: i32) {
unsafe { weston_surface_set_size(self.ptr, width, height); }
unsafe { weston_surface_set_size(self.as_ptr(), width, height); }
}
pub fn set_color(&self, red: f32, green: f32, blue: f32, alpha: f32) {
unsafe { weston_surface_set_color(self.ptr, red, green, blue, alpha); }
unsafe { weston_surface_set_color(self.as_ptr(), red, green, blue, alpha); }
}
pub fn to_buffer_float(&self, x: f32, y: f32) -> (f32, f32) {
let mut bx = 0.0;
let mut by = 0.0;
unsafe { weston_surface_to_buffer_float(self.ptr, x, y, &mut bx, &mut by); }
unsafe { weston_surface_to_buffer_float(self.as_ptr(), x, y, &mut bx, &mut by); }
(bx, by)
}
pub fn is_mapped(&self) -> bool {
unsafe { weston_surface_is_mapped(self.ptr) }
unsafe { weston_surface_is_mapped(self.as_ptr()) }
}
pub fn schedule_repaint(&self) {
unsafe { weston_surface_schedule_repaint(self.ptr); }
unsafe { weston_surface_schedule_repaint(self.as_ptr()); }
}
pub fn damage(&self) {
unsafe { weston_surface_damage(self.ptr); }
unsafe { weston_surface_damage(self.as_ptr()); }
}
pub fn unmap(&self) {
unsafe { weston_surface_unmap(self.ptr); }
unsafe { weston_surface_unmap(self.as_ptr()); }
}
pub fn get_content_size(&self) -> (libc::c_int, libc::c_int) {
let mut width = 0;
let mut height = 0;
unsafe { weston_surface_get_content_size(self.ptr, &mut width, &mut height); }
unsafe { weston_surface_get_content_size(self.as_ptr(), &mut width, &mut height); }
(width, height)
}
obj_accessors!(Surface | get_main_surface = |&this| { weston_surface_get_main_surface(this.ptr) });
obj_accessors!(Output | output = |&this| { (*this.ptr).output });
obj_accessors!(Compositor | compositor = |&this| { (*this.ptr).compositor });
obj_accessors!(SurfaceRef | get_main_surface = |&this| { weston_surface_get_main_surface(this.as_ptr()) });
obj_accessors!(OutputRef | output = |&this| { (*this.as_ptr()).output });
obj_accessors!(CompositorRef | compositor = |&this| { (*this.as_ptr()).compositor });
prop_accessors!(u32 | output_mask);
prop_accessors!(ptr wl_signal | destroy_signal, commit_signal);
}
impl Drop for Surface {
fn drop(&mut self) {
if !self.temp {
unsafe { weston_surface_destroy(self.ptr); }
}
}
}
View
@@ -1,3 +1,4 @@
use std::mem;
use libc;
use libweston_sys::{
weston_touch_grab, weston_touch_grab_interface,
@@ -9,16 +10,16 @@ use libweston_sys::{
};
use wayland_sys::common::wl_fixed_t;
use wayland_sys::server::wl_signal;
use ::WestonObject;
use ::seat::Seat;
use ::view::View;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::seat::SeatRef;
use ::view::ViewRef;
pub trait TouchGrab where Self: Sized {
fn down(&mut self, touch: &mut Touch, time: &libc::timespec, touch_id: libc::c_int, sx: wl_fixed_t, sy: wl_fixed_t) {}
fn up(&mut self, touch: &mut Touch, time: &libc::timespec, touch_id: libc::c_int) {}
fn motion(&mut self, touch: &mut Touch, time: &libc::timespec, touch_id: libc::c_int, sx: wl_fixed_t, sy: wl_fixed_t) {}
fn frame(&mut self, touch: &mut Touch);
fn cancel(&mut self, touch: &mut Touch);
fn down(&mut self, touch: &mut TouchRef, time: &libc::timespec, touch_id: libc::c_int, sx: wl_fixed_t, sy: wl_fixed_t) {}
fn up(&mut self, touch: &mut TouchRef, time: &libc::timespec, touch_id: libc::c_int) {}
fn motion(&mut self, touch: &mut TouchRef, time: &libc::timespec, touch_id: libc::c_int, sx: wl_fixed_t, sy: wl_fixed_t) {}
fn frame(&mut self, touch: &mut TouchRef);
fn cancel(&mut self, touch: &mut TouchRef);
unsafe fn into_weston(self) -> *mut weston_touch_grab_interface {
let wrapper = Box::new(TouchGrabWrapper {
@@ -45,88 +46,80 @@ struct TouchGrabWrapper<T: TouchGrab> {
#[allow(unused_unsafe)]
extern "C" fn run_down<T: TouchGrab>(grab: *mut weston_touch_grab, time: *const libc::timespec, touch_id: libc::c_int, sx: wl_fixed_t, sy: wl_fixed_t) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), TouchGrabWrapper<T>, base) };
wrapper.user.down(&mut Touch::from_ptr_temporary(unsafe { (*grab).touch }), unsafe { &*time }, touch_id, sx, sy);
wrapper.user.down(unsafe { TouchRef::from_ptr_mut((*grab).touch) }, unsafe { &*time }, touch_id, sx, sy);
}
#[allow(unused_unsafe)]
extern "C" fn run_up<T: TouchGrab>(grab: *mut weston_touch_grab, time: *const libc::timespec, touch_id: libc::c_int) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), TouchGrabWrapper<T>, base) };
wrapper.user.up(&mut Touch::from_ptr_temporary(unsafe { (*grab).touch }), unsafe { &*time }, touch_id);
wrapper.user.up(unsafe { TouchRef::from_ptr_mut((*grab).touch) }, unsafe { &*time }, touch_id);
}
#[allow(unused_unsafe)]
extern "C" fn run_motion<T: TouchGrab>(grab: *mut weston_touch_grab, time: *const libc::timespec, touch_id: libc::c_int, sx: wl_fixed_t, sy: wl_fixed_t) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), TouchGrabWrapper<T>, base) };
wrapper.user.motion(&mut Touch::from_ptr_temporary(unsafe { (*grab).touch }), unsafe { &*time }, touch_id, sx, sy);
wrapper.user.motion(unsafe { TouchRef::from_ptr_mut((*grab).touch) }, unsafe { &*time }, touch_id, sx, sy);
}
#[allow(unused_unsafe)]
extern "C" fn run_frame<T: TouchGrab>(grab: *mut weston_touch_grab) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), TouchGrabWrapper<T>, base) };
wrapper.user.frame(&mut Touch::from_ptr_temporary(unsafe { (*grab).touch }));
wrapper.user.frame(unsafe { TouchRef::from_ptr_mut((*grab).touch) });
}
#[allow(unused_unsafe)]
extern "C" fn run_cancel<T: TouchGrab>(grab: *mut weston_touch_grab) {
let wrapper = unsafe { &mut *wl_container_of!(((*grab).interface), TouchGrabWrapper<T>, base) };
wrapper.user.cancel(&mut Touch::from_ptr_temporary(unsafe { (*grab).touch }));
wrapper.user.cancel(unsafe { TouchRef::from_ptr_mut((*grab).touch) });
}
pub struct Touch {
ptr: *mut weston_touch,
temp: bool,
foreign_type! {
type CType = weston_touch;
fn drop = weston_touch_destroy;
pub struct Touch;
pub struct TouchRef;
}
weston_object!(Touch << weston_touch);
impl Touch {
obj_accessors!(Seat | seat = |&this| { (*this.ptr).seat });
obj_accessors!(opt View | focus = |&this| { (*this.ptr).focus });
impl TouchRef {
obj_accessors!(SeatRef | seat = |&this| { (*this.as_ptr()).seat });
obj_accessors!(opt ViewRef | focus = |&this| { (*this.as_ptr()).focus });
prop_accessors!(u32 | focus_serial, num_tp, grab_serial);
prop_accessors!(ptr wl_signal | focus_signal);
pub fn set_focus(&self, view: &View) {
unsafe { weston_touch_set_focus(self.ptr, view.ptr()); }
pub fn set_focus(&self, view: &ViewRef) {
unsafe { weston_touch_set_focus(self.as_ptr(), view.as_ptr()); }
}
pub fn start_grab<T: TouchGrab>(&self, grab: T) {
// XXX: leaks the wrapper
let silly_wrapper = Box::new(weston_touch_grab {
interface: unsafe { grab.into_weston() },
touch: self.ptr, // weston will set that to the same value lol
touch: self.as_ptr(), // weston will set that to the same value lol
});
unsafe { weston_touch_start_grab(self.ptr, Box::into_raw(silly_wrapper)); }
unsafe { weston_touch_start_grab(self.as_ptr(), Box::into_raw(silly_wrapper)); }
}
pub fn end_grab(&self) {
unsafe { weston_touch_end_grab(self.ptr); }
unsafe { weston_touch_end_grab(self.as_ptr()); }
}
pub fn has_focus_resource(&self) -> bool {
unsafe { weston_touch_has_focus_resource(self.ptr) }
unsafe { weston_touch_has_focus_resource(self.as_ptr()) }
}
pub fn send_down(&self, time: &libc::timespec, touch_id: libc::c_int, sx: wl_fixed_t, sy: wl_fixed_t) {
unsafe { weston_touch_send_down(self.ptr, time, touch_id, sx, sy); }
unsafe { weston_touch_send_down(self.as_ptr(), time, touch_id, sx, sy); }
}
pub fn send_up(&self, time: &libc::timespec, touch_id: libc::c_int) {
unsafe { weston_touch_send_up(self.ptr, time, touch_id); }
unsafe { weston_touch_send_up(self.as_ptr(), time, touch_id); }
}
pub fn send_motion(&self, time: &libc::timespec, touch_id: libc::c_int, sx: wl_fixed_t, sy: wl_fixed_t) {
unsafe { weston_touch_send_motion(self.ptr, time, touch_id, sx, sy); }
unsafe { weston_touch_send_motion(self.as_ptr(), time, touch_id, sx, sy); }
}
pub fn send_frame(&self) {
unsafe { weston_touch_send_frame(self.ptr); }
}
}
impl Drop for Touch {
fn drop(&mut self) {
if !self.temp {
unsafe { weston_touch_destroy(self.ptr); }
}
unsafe { weston_touch_send_frame(self.as_ptr()); }
}
}
View
@@ -16,10 +16,10 @@ use libweston_sys::{
};
use wayland_sys::common::wl_fixed_t;
use wayland_sys::server::wl_signal;
use ::WestonObject;
use ::surface::Surface;
use ::output::Output;
use ::seat::Seat;
use foreign_types::{ForeignType, ForeignTypeRef};
use ::surface::SurfaceRef;
use ::output::OutputRef;
use ::seat::SeatRef;
bitflags! {
#[derive(Default)]
@@ -30,110 +30,104 @@ bitflags! {
}
}
pub struct View {
ptr: *mut weston_view,
temp: bool,
foreign_type! {
type CType = weston_view;
fn drop = weston_view_destroy;
pub struct View;
pub struct ViewRef;
}
weston_object!(View << weston_view);
impl View {
pub fn new(surface: &Surface) -> View {
View::from_ptr(unsafe { weston_view_create(surface.ptr()) })
pub fn new(surface: &SurfaceRef) -> View {
unsafe { View::from_ptr(weston_view_create(surface.as_ptr())) }
}
}
impl ViewRef {
pub fn get_position(&self) -> (f32, f32) {
unsafe { ((*self.ptr).geometry.x, (*self.ptr).geometry.y) }
unsafe { ((*self.as_ptr()).geometry.x, (*self.as_ptr()).geometry.y) }
}
pub fn set_position(&self, x: f32, y: f32) {
unsafe { weston_view_set_position(self.ptr, x, y); }
unsafe { weston_view_set_position(self.as_ptr(), x, y); }
}
pub fn set_transform_parent(&self, parent: &View) {
unsafe { weston_view_set_transform_parent(self.ptr, parent.ptr()); }
pub fn set_transform_parent(&self, parent: &ViewRef) {
unsafe { weston_view_set_transform_parent(self.as_ptr(), parent.as_ptr()); }
}
pub fn set_mask(&self, x: libc::c_int, y: libc::c_int, width: libc::c_int, height: libc::c_int) {
unsafe { weston_view_set_mask(self.ptr, x, y, width, height); }
unsafe { weston_view_set_mask(self.as_ptr(), x, y, width, height); }
}
pub fn set_mask_infinite(&self) {
unsafe { weston_view_set_mask_infinite(self.ptr); }
unsafe { weston_view_set_mask_infinite(self.as_ptr()); }
}
pub fn is_mapped(&self) -> bool {
unsafe { weston_view_is_mapped(self.ptr) }
unsafe { weston_view_is_mapped(self.as_ptr()) }
}
pub fn schedule_repaint(&self) {
unsafe { weston_view_schedule_repaint(self.ptr); }
unsafe { weston_view_schedule_repaint(self.as_ptr()); }
}
pub fn damage_below(&self) {
unsafe { weston_view_damage_below(self.ptr); }
unsafe { weston_view_damage_below(self.as_ptr()); }
}
// TODO weston_view_move_to_plane
pub fn unmap(&self) {
unsafe { weston_view_unmap(self.ptr); }
unsafe { weston_view_unmap(self.as_ptr()); }
}
pub fn update_transform(&self) {
unsafe { weston_view_update_transform(self.ptr); }
unsafe { weston_view_update_transform(self.as_ptr()); }
}
pub fn to_global_fixed(&self, sx: wl_fixed_t, sy: wl_fixed_t) -> (wl_fixed_t, wl_fixed_t) {
let mut x = 0;
let mut y = 0;
unsafe { weston_view_to_global_fixed(self.ptr, sx, sy, &mut x, &mut y); }
unsafe { weston_view_to_global_fixed(self.as_ptr(), sx, sy, &mut x, &mut y); }
(x, y)
}
pub fn to_global_float(&self, sx: f32, sy: f32) -> (f32, f32) {
let mut x = 0.0;
let mut y = 0.0;
unsafe { weston_view_to_global_float(self.ptr, sx, sy, &mut x, &mut y); }
unsafe { weston_view_to_global_float(self.as_ptr(), sx, sy, &mut x, &mut y); }
(x, y)
}
pub fn from_global_float(&self, x: f32, y: f32) -> (f32, f32) {
let mut vx = 0.0;
let mut vy = 0.0;
unsafe { weston_view_from_global_float(self.ptr, x, y, &mut vx, &mut vy); }
unsafe { weston_view_from_global_float(self.as_ptr(), x, y, &mut vx, &mut vy); }
(vx, vy)
}
pub fn from_global(&self, x: i32, y: i32) -> (i32, i32) {
let mut vx = 0;
let mut vy = 0;
unsafe { weston_view_from_global(self.ptr, x, y, &mut vx, &mut vy); }
unsafe { weston_view_from_global(self.as_ptr(), x, y, &mut vx, &mut vy); }
(vx, vy)
}
pub fn from_global_fixed(&self, x: wl_fixed_t, y: wl_fixed_t) -> (wl_fixed_t, wl_fixed_t) {
let mut vx = 0;
let mut vy = 0;
unsafe { weston_view_from_global_fixed(self.ptr, x, y, &mut vx, &mut vy); }
unsafe { weston_view_from_global_fixed(self.as_ptr(), x, y, &mut vx, &mut vy); }
(vx, vy)
}
pub fn activate(&self, seat: &Seat, flags: ActivateFlag) {
unsafe { weston_view_activate(self.ptr, seat.ptr(), flags.bits()); }
pub fn activate(&self, seat: &SeatRef, flags: ActivateFlag) {
unsafe { weston_view_activate(self.as_ptr(), seat.as_ptr(), flags.bits()); }
}
obj_accessors!(View | parent_view = |&this| { (*this.ptr).parent_view });
obj_accessors!(Surface | surface = |&this| { (*this.ptr).surface });
obj_accessors!(Output | output = |&this| { (*this.ptr).output });
obj_accessors!(ViewRef | parent_view = |&this| { (*this.as_ptr()).parent_view });
obj_accessors!(SurfaceRef | surface = |&this| { (*this.as_ptr()).surface });
obj_accessors!(OutputRef | output = |&this| { (*this.as_ptr()).output });
prop_accessors!(ptr weston_layer_entry | layer_link);
prop_accessors!(ptr wl_signal | destroy_signal);
}
impl Drop for View {
fn drop(&mut self) {
if !self.temp {
unsafe { weston_view_destroy(self.ptr); }
}
}
}