Merge branch 'remove_inputd_g' into 'master'

Remove inputd -G

See merge request redox-os/drivers!185
This commit is contained in:
Jeremy Soller
2024-07-19 19:19:38 +00:00
6 changed files with 16 additions and 90 deletions
+1 -4
View File
@@ -57,10 +57,7 @@ fn inner(daemon: redox_daemon::Daemon, vt_ids: &[usize]) -> ! {
daemon.ready().expect("failed to notify parent");
scheme
.inputd_handle
.activate(1, inputd::VtMode::Default)
.unwrap();
scheme.inputd_handle.activate(1).unwrap();
let mut blocked = Vec::new();
+1 -1
View File
@@ -92,7 +92,7 @@ fn inner(daemon: redox_daemon::Daemon, framebuffers: Vec<FrameBuffer>, spec: &[(
daemon.ready().expect("failed to notify parent");
scheme.inputd_handle.activate(1, inputd::VtMode::Default).unwrap();
scheme.inputd_handle.activate(1).unwrap();
let mut blocked = Vec::new();
loop {
+1 -1
View File
@@ -279,7 +279,7 @@ impl SchemeMut for DisplayScheme {
let command = inputd::parse_command(buf).unwrap();
match command {
DisplayCommand::Activate { vt, mode: _ } => {
DisplayCommand::Activate { vt } => {
let vt_i = VtIndex(vt);
if let Some(screens) = self.vts.get_mut(&vt_i) {
+2 -3
View File
@@ -409,13 +409,12 @@ impl<'a> SchemeMut for Scheme<'a> {
}
Handle::Input => {
use inputd::{Cmd as DisplayCommand, VtMode};
use inputd::Cmd as DisplayCommand;
let command = inputd::parse_command(buf).unwrap();
match command {
DisplayCommand::Activate { mode, vt } => {
assert!(mode == VtMode::Graphic || mode == VtMode::Default);
DisplayCommand::Activate { vt } => {
let target_vt = vt;
for handle in self.handles.values() {
+5 -17
View File
@@ -7,18 +7,10 @@ unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
::core::slice::from_raw_parts((p as *const T) as *const u8, ::core::mem::size_of::<T>())
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[repr(usize)]
pub enum VtMode {
Graphic = 1,
Default = 2,
}
#[derive(Debug, Clone)]
#[repr(C)]
pub struct VtActivate {
pub vt: usize,
pub mode: VtMode,
}
pub struct Handle(File);
@@ -35,8 +27,8 @@ impl Handle {
self.0.read(&mut [])
}
pub fn activate(&mut self, vt: usize, mode: VtMode) -> Result<usize, Error> {
let cmd = VtActivate { vt, mode };
pub fn activate(&mut self, vt: usize) -> Result<usize, Error> {
let cmd = VtActivate { vt };
self.0.write(unsafe { any_as_u8_slice(&cmd) })
}
}
@@ -67,7 +59,6 @@ pub enum Cmd {
// TODO(andypython): #VT should really need to be a `u8`.
Activate {
vt: usize,
mode: VtMode,
},
Deactivate(usize /* #VT */),
@@ -98,8 +89,8 @@ pub fn send_comand(file: &mut File, command: Cmd) -> Result<(), libredox::error:
result.push(command.ty() as u8);
match command {
Cmd::Activate { vt, mode } => {
let cmd = VtActivate { vt, mode };
Cmd::Activate { vt } => {
let cmd = VtActivate { vt };
let bytes = unsafe { any_as_u8_slice(&cmd) };
result.extend_from_slice(bytes);
@@ -138,10 +129,7 @@ pub fn parse_command(buffer: &[u8]) -> Option<Cmd> {
match command {
CmdTy::Activate => {
let cmd = unsafe { &*buffer.as_ptr().offset(1).cast::<VtActivate>() };
Some(Cmd::Activate {
vt: cmd.vt,
mode: cmd.mode,
})
Some(Cmd::Activate { vt: cmd.vt })
}
CmdTy::Deactivate => Some(Cmd::Deactivate(vt)),
+6 -64
View File
@@ -18,7 +18,7 @@ use std::os::fd::AsRawFd;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use inputd::{Cmd, VtActivate, VtMode};
use inputd::{Cmd, VtActivate};
use spin::Mutex;
@@ -50,7 +50,6 @@ impl Handle {
/// requires the system call to return first. Otherwise, it will block indefinitely.
struct VtInner {
handle_file: File,
mode: VtMode,
}
struct Vt {
@@ -74,10 +73,7 @@ impl Vt {
pub fn inner(&self) -> &Mutex<VtInner> {
self.inner.call_once(|| {
let handle_file = File::open(format!("/scheme/{}/handle", self.display)).unwrap();
Mutex::new(VtInner {
handle_file,
mode: VtMode::Default,
})
Mutex::new(VtInner { handle_file })
})
}
}
@@ -292,7 +288,6 @@ impl SchemeMut for InputScheme {
&mut vt_inner.handle_file,
Cmd::Activate {
vt: new_active.index,
mode: VtMode::Default,
},
)?;
self.active_vt = Some(new_active.clone());
@@ -379,17 +374,12 @@ fn deamon(deamon: redox_daemon::Daemon) -> anyhow::Result<()> {
let mut vt_inner = vt.inner().lock();
// Failing to activate a VT is not a fatal error.
if let Err(err) = inputd::send_comand(
&mut vt_inner.handle_file,
Cmd::Activate {
vt: vt.index,
mode: cmd.mode,
},
) {
if let Err(err) =
inputd::send_comand(&mut vt_inner.handle_file, Cmd::Activate { vt: vt.index })
{
log::error!("inputd: failed to activate VT #{}: {err}", vt.index)
}
vt_inner.mode = cmd.mode;
scheme.active_vt = Some(vt.clone());
}
@@ -481,52 +471,6 @@ pub fn main() {
if let Some(val) = args.next() {
match val.as_ref() {
// Sets the VT mode of the specified VT to [`VtMode::Graphic`].
"-G" => {
let vt = args.next().unwrap().parse::<usize>().unwrap();
// On startup, the VESA display driver is started which basically makes use of the framebuffer
// provided by the firmware. The GPU devices are latter started by `pcid` (such as `virtio-gpu`).
let mut devices = vec![];
let schemes = std::fs::read_dir(":").unwrap();
for entry in schemes {
let path = entry.unwrap().path();
let path_str = path
.into_os_string()
.into_string()
.expect("inputd: failed to convert path to string");
if path_str.contains("display") {
println!("inputd: found display scheme {}", path_str);
devices.push(path_str);
}
}
if devices.is_empty() {
// No display devices found.
return;
}
let device = devices
.iter()
.filter(|d| !d.contains("vesa"))
.collect::<Vec<_>>();
let device = if device.is_empty() {
"vesa"
} else {
// TODO: What should we do when there are multiple display devices?
device[0][2..].split('.').nth(1).unwrap()
};
let mut handle =
inputd::Handle::new(device).expect("inputd: failed to open display handle");
handle
.activate(vt, VtMode::Graphic)
.expect("inputd: failed to activate VT in graphic mode");
}
// Activates a VT.
"-A" => {
let vt = args.next().unwrap().parse::<usize>().unwrap();
@@ -555,9 +499,7 @@ pub fn main() {
let mut handle = inputd::Handle::new(display_scheme)
.expect("inputd: failed to open display handle");
handle
.activate(vt, VtMode::Default)
.expect("inputd: failed to activate VT");
handle.activate(vt).expect("inputd: failed to activate VT");
}
_ => panic!("inputd: invalid argument: {}", val),