1
0
Fork 0
forked from wry/wry

autocommit 2022-03-13 23:16:26 CET

This commit is contained in:
Julian Orth 2022-03-13 23:16:26 +01:00
parent a15a02a95c
commit 18806a38fb
13 changed files with 77 additions and 16 deletions

View file

@ -5,7 +5,9 @@ use std::rc::Rc;
linear_ids!(OutputIds, OutputId);
linear_ids!(InputDeviceIds, InputDeviceId);
pub trait Backend {}
pub trait Backend {
fn switch_to(&self, vtnr: u32);
}
pub trait Output {
fn id(&self) -> OutputId;

View file

@ -15,7 +15,7 @@ use crate::udev::{UdevError, UdevMonitor};
use crate::utils::copyhashmap::CopyHashMap;
use crate::utils::oserror::OsError;
use crate::utils::syncqueue::SyncQueue;
use crate::{AsyncError, CloneCell, RenderError, State, Udev};
use crate::{AsyncError, CloneCell, ErrorFmt, RenderError, State, Udev};
use std::cell::{Cell, RefCell};
use std::ffi::{CStr, CString};
use std::future::pending;
@ -96,7 +96,15 @@ struct MetalBackend {
drm_ids: DrmIds,
}
impl Backend for MetalBackend {}
impl Backend for MetalBackend {
fn switch_to(&self, vtnr: u32) {
self.session.switch_to(vtnr, move |res| {
if let Err(e) = res {
log::error!("Could not switch to VT {}: {}", vtnr, ErrorFmt(e));
}
})
}
}
async fn run_(state: Rc<State>) -> Result<(), MetalError> {
let socket = match state.dbus.system() {
@ -160,6 +168,7 @@ async fn run_(state: Rc<State>) -> Result<(), MetalError> {
if let Err(e) = metal.enumerate_devices() {
return Err(MetalError::Enumerate(Box::new(e)));
}
state.backend.set(Some(metal.clone()));
pending().await
}

View file

@ -220,7 +220,11 @@ pub struct XorgBackend {
b: Cell<f32>,
}
impl Backend for XorgBackend {}
impl Backend for XorgBackend {
fn switch_to(&self, _vtnr: u32) {
log::error!("Xorg backend cannot switch vts");
}
}
fn get_drm(con: &XcbCon) -> Result<Drm, XorgBackendError> {
unsafe {

View file

@ -337,6 +337,13 @@ impl ConfigProxyHandler {
self.state.el.stop();
}
fn handle_switch_to(&self, vtnr: u32) {
match self.state.backend.get() {
Some(b) => b.switch_to(vtnr),
_ => log::warn!("Cannot switch to VT {}: Backend has not yet started", vtnr),
}
}
fn handle_toggle_floating(&self, seat: Seat) -> Result<(), FocusParentError> {
let seat = self.get_seat(seat)?;
seat.toggle_floating();
@ -472,6 +479,7 @@ impl ConfigProxyHandler {
ClientMessage::FocusParent { seat } => self.handle_focus_parent(seat)?,
ClientMessage::ToggleFloating { seat } => self.handle_toggle_floating(seat)?,
ClientMessage::Quit => self.handle_quit(),
ClientMessage::SwitchTo { vtnr } => self.handle_switch_to(vtnr),
}
Ok(())
}

View file

@ -4,6 +4,7 @@ use crate::{org, FALSE};
use std::rc::Rc;
use thiserror::Error;
use uapi::c;
use crate::org::freedesktop::login1::seat::SwitchToReply;
const LOGIND_NAME: &str = "org.freedesktop.login1";
const MANAGER_PATH: &str = "/org/freedesktop/login1";
@ -22,7 +23,7 @@ pub enum LogindError {
pub struct Session {
socket: Rc<DbusSocket>,
_seat: String,
seat: String,
session_path: String,
}
@ -52,13 +53,13 @@ impl Session {
.get_async::<org::freedesktop::login1::session::Seat>(LOGIND_NAME, &session_path)
.await;
match seat {
Ok(s) => s.get().0.to_string(),
Ok(s) => s.get().1.0.to_string(),
Err(e) => return Err(LogindError::GetSeatName(e)),
}
};
Ok(Self {
socket: socket.clone(),
_seat: seat,
seat,
session_path,
})
}
@ -123,4 +124,15 @@ impl Session {
org::freedesktop::login1::session::PauseDeviceComplete { major, minor },
);
}
pub fn switch_to<F>(&self, vtnr: u32, f: F)
where F: FnOnce(Result<&SwitchToReply, DbusError>) + 'static
{
self.socket.call(
LOGIND_NAME,
&self.seat,
org::freedesktop::login1::seat::SwitchTo { vtnr },
|r| f(r),
);
}
}

View file

@ -150,6 +150,7 @@ fn main_() -> Result<(), MainError> {
let node_ids = NodeIds::default();
let state = Rc::new(State {
xkb_ctx,
backend: Default::default(),
forker: Default::default(),
default_keymap: xkb_keymap,
eng: engine.clone(),

View file

@ -1,7 +1,5 @@
use crate::async_engine::{AsyncEngine, SpawnedFuture};
use crate::backend::{
BackendEvent, InputDevice, InputDeviceId, InputDeviceIds, OutputId, OutputIds,
};
use crate::backend::{Backend, BackendEvent, InputDevice, InputDeviceId, InputDeviceIds, OutputId, OutputIds};
use crate::client::{Client, Clients};
use crate::config::ConfigProxy;
use crate::cursor::ServerCursors;
@ -33,6 +31,7 @@ use std::sync::Arc;
pub struct State {
pub xkb_ctx: XkbContext,
pub backend: CloneCell<Option<Rc<dyn Backend>>>,
pub forker: CloneCell<Option<Rc<ForkerProxy>>>,
pub default_keymap: Rc<XkbKeymap>,
pub eng: Rc<AsyncEngine>,

View file

@ -5,7 +5,10 @@ use std::rc::Rc;
pub async fn start_backend(state: Rc<State>) {
log::info!("Trying to start X backend");
let e = match XorgBackend::new(&state) {
Ok(_b) => pending().await,
Ok(b) => {
state.backend.set(Some(b));
pending().await
},
Err(e) => e,
};
log::warn!("Could not start X backend: {}", ErrorFmt(e));