initial commit
This commit is contained in:
commit
a35996c519
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
1339
Cargo.lock
generated
Normal file
1339
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "tilers"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies.smithay]
|
||||
version = "0.3.0"
|
||||
default-features = false
|
||||
features = ["wayland_frontend"]
|
||||
|
||||
[features]
|
||||
default = ["winit", "egl"]
|
||||
winit = ["smithay/backend_winit"]
|
||||
egl = ["smithay/use_system_lib", "smithay/backend_egl"]
|
66
src/main.rs
Normal file
66
src/main.rs
Normal file
@ -0,0 +1,66 @@
|
||||
pub const OUTPUT_NAME: &str = "winit";
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use smithay::{backend::{renderer::{ImportDma, ImportEgl}, winit}, reexports::wayland_server::Display, wayland::{dmabuf::init_dmabuf_global, output::Mode}};
|
||||
|
||||
mod state;
|
||||
use crate::state::*;
|
||||
|
||||
#[cfg(feature = "winit")]
|
||||
pub struct WinitData;
|
||||
|
||||
#[cfg(feature = "winit")]
|
||||
impl Backend for WinitData {
|
||||
fn seat_name(&self) -> String {
|
||||
"winit".into()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
#[cfg(feature = "winit")]
|
||||
fn run_winit() {
|
||||
let mut event_loop = smithay::reexports::calloop::EventLoop::try_new().unwrap();
|
||||
let display = Rc::new(RefCell::new(Display::new()));
|
||||
|
||||
let (renderer, mut input) = match winit::init(None) {
|
||||
Ok(ret) => ret,
|
||||
Err(_) => return
|
||||
};
|
||||
|
||||
let renderer = Rc::new(RefCell::new(renderer));
|
||||
|
||||
if renderer
|
||||
.borrow_mut()
|
||||
.renderer()
|
||||
.bind_wl_display(&display.borrow()).is_ok() {
|
||||
dbg!("EGL hardware-acceleration enabled");
|
||||
let dmabuf_formats = renderer
|
||||
.borrow_mut()
|
||||
.renderer()
|
||||
.dmabuf_formats()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let renderer = renderer.clone();
|
||||
init_dmabuf_global(
|
||||
&mut *display.borrow_mut(),
|
||||
dmabuf_formats,
|
||||
move |buffer, _| renderer.borrow_mut().renderer().import_dmabuf(buffer).is_ok(),
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
let size = renderer.borrow().window_size().physical_size;
|
||||
|
||||
let data = WinitData{};
|
||||
|
||||
let mut state = State::init(display.clone(), event_loop.handle(), data);
|
||||
|
||||
let mode = Mode {
|
||||
size,
|
||||
refresh: 60_000
|
||||
};
|
||||
}
|
91
src/state.rs
Normal file
91
src/state.rs
Normal file
@ -0,0 +1,91 @@
|
||||
pub const OUTPUT_NAME: &str = "winit";
|
||||
use std::{cell::RefCell, rc::Rc, sync::{Arc, Mutex}, sync::atomic::{AtomicBool, Ordering}, time::Duration};
|
||||
|
||||
use smithay::{reexports::{calloop::{Mode, Interest, LoopHandle, PostAction, generic::Generic}, wayland_server::{Display, protocol::wl_surface::WlSurface}}, utils::{Logical, Point}, wayland::{data_device::{DataDeviceEvent, default_action_chooser, init_data_device, set_data_device_focus}, output::xdg::init_xdg_output_manager, seat::{CursorImageStatus, KeyboardHandle, PointerHandle, Seat, XkbConfig}, shm::init_shm_global}};
|
||||
|
||||
pub struct State<BackendData> {
|
||||
pub backend_data: BackendData,
|
||||
pub cursor_status: Arc<Mutex<CursorImageStatus>>,
|
||||
pub display: Rc<RefCell<Display>>,
|
||||
pub dnd_icon: Arc<Mutex<Option<WlSurface>>>,
|
||||
pub keyboard: KeyboardHandle,
|
||||
pub loop_handle: LoopHandle<'static, State<BackendData>>,
|
||||
pub pointer_location: Point<f64, Logical>,
|
||||
pub pointer: PointerHandle,
|
||||
pub running: Arc<AtomicBool>,
|
||||
pub seat_name: String,
|
||||
pub seat: Seat,
|
||||
}
|
||||
|
||||
impl<BackendData: Backend + 'static> State<BackendData> {
|
||||
pub fn init(display: Rc<RefCell<Display>>, loop_handle: LoopHandle<'static, State<BackendData>>, backend_data: BackendData) -> Self {
|
||||
loop_handle.insert_source(
|
||||
Generic::from_fd(display.borrow().get_poll_fd(), Interest::READ, Mode::Level),
|
||||
move |_,_, state: &mut State<BackendData>| {
|
||||
let display = state.display.clone();
|
||||
let mut display = display.borrow_mut();
|
||||
match display.dispatch(Duration::from_millis(0), state) {
|
||||
Ok(_) => Ok(PostAction::Continue),
|
||||
Err(e) => {
|
||||
dbg!("I/O Error on Display {}", &e);
|
||||
state.running.store(false, Ordering::SeqCst);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}).expect("Wayland Eventsource init failed");
|
||||
|
||||
init_shm_global(&mut display.borrow_mut(), Vec::new(), None);
|
||||
|
||||
//let shell_handles = init_shell()
|
||||
init_xdg_output_manager(&mut display.borrow_mut(), None);
|
||||
|
||||
let socket_name = display.borrow_mut().add_socket_auto().unwrap().into_string().unwrap();
|
||||
std::env::set_var("WAYLAND_DISPLAY", &socket_name);
|
||||
|
||||
let dnd_icon = Arc::new(Mutex::new(None));
|
||||
let dnd_icon2 = dnd_icon.clone();
|
||||
init_data_device(
|
||||
&mut display.borrow_mut(),
|
||||
move |event| match event {
|
||||
DataDeviceEvent::DnDStarted { icon, .. } => {
|
||||
*dnd_icon2.lock().unwrap() = icon;
|
||||
}
|
||||
DataDeviceEvent::DnDDropped => {
|
||||
*dnd_icon2.lock().unwrap() = None;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
default_action_chooser,
|
||||
None,
|
||||
);
|
||||
|
||||
let seat_name = backend_data.seat_name();
|
||||
|
||||
let (mut seat, _) = Seat::new(&mut display.borrow_mut(), seat_name.clone(), None);
|
||||
|
||||
let cursor_status = Arc::new(Mutex::new(CursorImageStatus::Default));
|
||||
let cursor_status2 = cursor_status.clone();
|
||||
let pointer = seat.add_pointer(move |new_status| { *cursor_status2.lock().unwrap() = new_status});
|
||||
let keyboard = seat.add_keyboard(XkbConfig::default(), 200, 25, |seat, focus| {
|
||||
set_data_device_focus(seat, focus.and_then(|s| s.as_ref().client()))
|
||||
}).expect("Could not initialize keyboard");
|
||||
|
||||
Self {
|
||||
backend_data,
|
||||
running: Arc::new(AtomicBool::new(true)),
|
||||
display,
|
||||
loop_handle,
|
||||
cursor_status,
|
||||
dnd_icon,
|
||||
keyboard,
|
||||
pointer_location: (0.0,0.0).into(),
|
||||
pointer,
|
||||
seat_name,
|
||||
seat,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Backend {
|
||||
fn seat_name(&self) -> String;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user