Fix immediate crash on udev

This commit is contained in:
Seaotatop 2023-07-02 18:15:44 -05:00
parent 5f8352452b
commit e28998afe4
4 changed files with 622 additions and 435 deletions

View file

@ -225,7 +225,13 @@ pub fn run_udev() -> Result<(), Box<dyn Error>> {
pointer_images: Vec::new(), pointer_images: Vec::new(),
pointer_element: PointerElement::default(), pointer_element: PointerElement::default(),
}; };
let mut state = State::init(
//
//
//
//
let mut state = State::<UdevData>::init(
data, data,
&mut display, &mut display,
event_loop.get_signal(), event_loop.get_signal(),
@ -236,6 +242,39 @@ pub fn run_udev() -> Result<(), Box<dyn Error>> {
* Initialize the udev backend * Initialize the udev backend
*/ */
let udev_backend = UdevBackend::new(state.seat.name())?; let udev_backend = UdevBackend::new(state.seat.name())?;
for (device_id, path) in udev_backend.device_list() {
if let Err(err) = DrmNode::from_dev_id(device_id)
.map_err(DeviceAddError::DrmNode)
.and_then(|node| state.device_added(node, path))
{
tracing::error!("Skipping device {device_id}: {err}");
}
}
event_loop
.handle()
.insert_source(udev_backend, move |event, _, data| match event {
UdevEvent::Added { device_id, path } => {
if let Err(err) = DrmNode::from_dev_id(device_id)
.map_err(DeviceAddError::DrmNode)
.and_then(|node| data.state.device_added(node, &path))
{
tracing::error!("Skipping device {device_id}: {err}");
}
}
UdevEvent::Changed { device_id } => {
if let Ok(node) = DrmNode::from_dev_id(device_id) {
data.state.device_changed(node)
}
}
UdevEvent::Removed { device_id } => {
if let Ok(node) = DrmNode::from_dev_id(device_id) {
data.state.device_removed(node)
}
}
})
.unwrap();
/* /*
* Initialize libinput backend * Initialize libinput backend
*/ */
@ -299,14 +338,6 @@ pub fn run_udev() -> Result<(), Box<dyn Error>> {
}) })
.unwrap(); .unwrap();
for (device_id, path) in udev_backend.device_list() {
if let Err(err) = DrmNode::from_dev_id(device_id)
.map_err(DeviceAddError::DrmNode)
.and_then(|node| state.device_added(node, path))
{
tracing::error!("Skipping device {device_id}: {err}");
}
}
state.shm_state.update_formats( state.shm_state.update_formats(
state state
.backend_data .backend_data
@ -422,30 +453,6 @@ pub fn run_udev() -> Result<(), Box<dyn Error>> {
}); });
}); });
event_loop
.handle()
.insert_source(udev_backend, move |event, _, data| match event {
UdevEvent::Added { device_id, path } => {
if let Err(err) = DrmNode::from_dev_id(device_id)
.map_err(DeviceAddError::DrmNode)
.and_then(|node| data.state.device_added(node, &path))
{
tracing::error!("Skipping device {device_id}: {err}");
}
}
UdevEvent::Changed { device_id } => {
if let Ok(node) = DrmNode::from_dev_id(device_id) {
data.state.device_changed(node)
}
}
UdevEvent::Removed { device_id } => {
if let Ok(node) = DrmNode::from_dev_id(device_id) {
data.state.device_removed(node)
}
}
})
.unwrap();
event_loop.run( event_loop.run(
Some(Duration::from_millis(6)), Some(Duration::from_millis(6)),
&mut CalloopData { state, display }, &mut CalloopData { state, display },
@ -829,6 +836,8 @@ impl State<UdevData> {
); );
let global = output.create_global::<State<UdevData>>(&self.backend_data.display_handle); let global = output.create_global::<State<UdevData>>(&self.backend_data.display_handle);
self.focus_state.focused_output = Some(output.clone());
let x = self.space.outputs().fold(0, |acc, o| { let x = self.space.outputs().fold(0, |acc, o| {
acc + self.space.output_geometry(o).unwrap().size.w acc + self.space.output_geometry(o).unwrap().size.w
}); });

View file

@ -177,7 +177,7 @@ pub fn run_winit() -> Result<(), Box<dyn Error>> {
} }
}; };
let mut state = State::init( let mut state = State::<WinitData>::init(
WinitData { WinitData {
backend: winit_backend, backend: winit_backend,
damage_tracker: OutputDamageTracker::from_output(&output), damage_tracker: OutputDamageTracker::from_output(&output),

View file

@ -245,6 +245,12 @@ impl<B: Backend> State<B> {
.get(&(modifier_mask.into(), raw_sym)) .get(&(modifier_mask.into(), raw_sym))
{ {
return FilterResult::Intercept(*callback_id); return FilterResult::Intercept(*callback_id);
} else if modifiers.ctrl
&& modifiers.shift
&& modifiers.alt
&& keysym.modified_sym() == keysyms::KEY_Escape
{
return FilterResult::Intercept(CallbackId(999999));
} }
} }
@ -267,6 +273,9 @@ impl<B: Backend> State<B> {
self.move_mode = move_mode; self.move_mode = move_mode;
if let Some(callback_id) = action { if let Some(callback_id) = action {
if callback_id.0 == 999999 {
self.loop_signal.stop();
}
if let Some(stream) = self.api_state.stream.as_ref() { if let Some(stream) = self.api_state.stream.as_ref() {
if let Err(err) = crate::api::send_to_client( if let Err(err) = crate::api::send_to_client(
&mut stream.lock().expect("Could not lock stream mutex"), &mut stream.lock().expect("Could not lock stream mutex"),

File diff suppressed because it is too large Load diff