Make udev example use new auto session
This commit is contained in:
parent
a768e298f2
commit
11c9f2b0fb
|
@ -39,7 +39,7 @@ use smithay::backend::input::{self, Event, InputBackend, InputHandler, KeyState,
|
|||
use smithay::backend::libinput::{libinput_bind, LibinputInputBackend, LibinputSessionInterface,
|
||||
PointerAxisEvent as LibinputPointerAxisEvent};
|
||||
use smithay::backend::session::{Session, SessionNotifier};
|
||||
use smithay::backend::session::direct::{direct_session_bind, DirectSession};
|
||||
use smithay::backend::session::auto::{auto_session_bind, AutoSession};
|
||||
use smithay::backend::udev::{primary_gpu, udev_backend_bind, SessionFdDrmDevice, UdevBackend, UdevHandler};
|
||||
use smithay::wayland::compositor::{CompositorToken, SubsurfaceRole, TraversalAction};
|
||||
use smithay::wayland::compositor::roles::Role;
|
||||
|
@ -67,6 +67,7 @@ struct LibinputInputHandler {
|
|||
pointer_location: Rc<RefCell<(f64, f64)>>,
|
||||
screen_size: (u32, u32),
|
||||
serial: u32,
|
||||
session: AutoSession,
|
||||
running: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
|
@ -93,14 +94,32 @@ impl InputHandler<LibinputInputBackend> for LibinputInputHandler {
|
|||
let keycode = evt.key();
|
||||
let state = evt.state();
|
||||
debug!(self.log, "key"; "keycode" => keycode, "state" => format!("{:?}", state));
|
||||
|
||||
let serial = self.next_serial();
|
||||
|
||||
// we cannot borrow `self` into the closure, because we need self.keyboard.
|
||||
// but rust does not borrow all fields separately, so we need to do that manually...
|
||||
let running = &self.running;
|
||||
let mut session = &mut self.session;
|
||||
let log = &self.log;
|
||||
self.keyboard
|
||||
.input(keycode, state, serial, |modifiers, keysym| {
|
||||
if modifiers.ctrl && modifiers.alt && keysym == xkb::KEY_BackSpace {
|
||||
self.running.store(false, Ordering::SeqCst);
|
||||
.input(keycode, state, serial, move |modifiers, keysym| {
|
||||
debug!(log, "keysym"; "state" => format!("{:?}", state), "mods" => format!("{:?}", modifiers), "keysym" => xkbcommon::xkb::keysym_get_name(keysym));
|
||||
if modifiers.ctrl && modifiers.alt && keysym == xkb::KEY_BackSpace && state == KeyState::Pressed {
|
||||
info!(log, "Stopping example using Ctrl+Alt+Backspace");
|
||||
running.store(false, Ordering::SeqCst);
|
||||
false
|
||||
} else if modifiers.logo && keysym == xkb::KEY_q {
|
||||
info!(log, "Stopping example using Logo+Q");
|
||||
running.store(false, Ordering::SeqCst);
|
||||
false
|
||||
} else if modifiers.ctrl && modifiers.alt && keysym == xkb::KEY_XF86Switch_VT_1 && state == KeyState::Pressed {
|
||||
info!(log, "Trying to switch to vt 1");
|
||||
if let Err(err) = session.change_vt(1) {
|
||||
error!(log, "Error switching to vt 1: {}", err);
|
||||
}
|
||||
false
|
||||
} else if modifiers.logo && keysym == xkb::KEY_Return && state == KeyState::Pressed {
|
||||
info!(log, "Launching terminal");
|
||||
let _ = Command::new("weston-terminal").spawn();
|
||||
false
|
||||
} else {
|
||||
|
@ -228,10 +247,9 @@ fn main() {
|
|||
init_shell(&mut event_loop, log.clone(), active_egl_context.clone());
|
||||
|
||||
/*
|
||||
* Initialize session on the current tty
|
||||
* Initialize session
|
||||
*/
|
||||
let (session, mut notifier) = DirectSession::new(None, log.clone()).unwrap();
|
||||
let session = Rc::new(RefCell::new(session));
|
||||
let (session, mut notifier) = AutoSession::new(log.clone()).unwrap();
|
||||
|
||||
let running = Arc::new(AtomicBool::new(true));
|
||||
let r = running.clone();
|
||||
|
@ -318,8 +336,8 @@ fn main() {
|
|||
* Initialize libinput backend
|
||||
*/
|
||||
let mut libinput_context = Libinput::new_from_udev::<
|
||||
LibinputSessionInterface<Rc<RefCell<DirectSession>>>,
|
||||
>(session.into(), &context);
|
||||
LibinputSessionInterface<AutoSession>,
|
||||
>(session.clone().into(), &context);
|
||||
let libinput_session_id = notifier.register(libinput_context.clone());
|
||||
libinput_context.udev_assign_seat(&seat).unwrap();
|
||||
let mut libinput_backend = LibinputInputBackend::new(libinput_context, log.clone());
|
||||
|
@ -333,12 +351,13 @@ fn main() {
|
|||
pointer_location,
|
||||
screen_size: (w, h),
|
||||
serial: 0,
|
||||
session: session,
|
||||
running: running.clone(),
|
||||
},
|
||||
);
|
||||
let libinput_event_source = libinput_bind(libinput_backend, &mut event_loop).unwrap();
|
||||
|
||||
let session_event_source = direct_session_bind(notifier, &mut event_loop, log.clone()).unwrap();
|
||||
let session_event_source = auto_session_bind(notifier, &mut event_loop).unwrap();
|
||||
let udev_event_source = udev_backend_bind(&mut event_loop, udev_token).unwrap();
|
||||
|
||||
while running.load(Ordering::SeqCst) {
|
||||
|
|
Loading…
Reference in New Issue