Skip to content

Commit ed01141

Browse files
committed
Improve error handling and resource cleanup in linux/x11/window.rs
* Fixes registration of event handler for xinput-2 device changes, revealed by this improvement. * Pushes `.unwrap()` panic-ing outwards to callers. * Includes a description of what the X11 call was doing when a failure was encountered. * Fixes a variety of places where the X11 reply wasn't being inspected for failures. * Destroys windows on failure during setup. New structure makes it possible for the caller of `open_window` to carry on despite failures, and so partially initialized window should be removed (though all calls I looked at also panic currently). Considered pushing this through `linux/x11/client.rs` too but figured it'd be nice to minimize merge conflicts with #20853.
1 parent 14ea462 commit ed01141

File tree

3 files changed

+452
-347
lines changed

3 files changed

+452
-347
lines changed

crates/gpui/src/platform/linux/x11/client.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,11 @@ impl X11Client {
776776
},
777777
};
778778
let window = self.get_window(event.window)?;
779-
window.configure(bounds);
779+
window.configure(bounds).unwrap();
780780
}
781781
Event::PropertyNotify(event) => {
782782
let window = self.get_window(event.window)?;
783-
window.property_notify(event);
783+
window.property_notify(event).unwrap();
784784
}
785785
Event::FocusIn(event) => {
786786
let window = self.get_window(event.event)?;
@@ -1258,11 +1258,9 @@ impl LinuxClient for X11Client {
12581258
.iter()
12591259
.enumerate()
12601260
.filter_map(|(root_id, _)| {
1261-
Some(Rc::new(X11Display::new(
1262-
&state.xcb_connection,
1263-
state.scale_factor,
1264-
root_id,
1265-
)?) as Rc<dyn PlatformDisplay>)
1261+
Some(Rc::new(
1262+
X11Display::new(&state.xcb_connection, state.scale_factor, root_id).ok()?,
1263+
) as Rc<dyn PlatformDisplay>)
12661264
})
12671265
.collect()
12681266
}
@@ -1283,11 +1281,9 @@ impl LinuxClient for X11Client {
12831281
fn display(&self, id: DisplayId) -> Option<Rc<dyn PlatformDisplay>> {
12841282
let state = self.0.borrow();
12851283

1286-
Some(Rc::new(X11Display::new(
1287-
&state.xcb_connection,
1288-
state.scale_factor,
1289-
id.0 as usize,
1290-
)?))
1284+
Some(Rc::new(
1285+
X11Display::new(&state.xcb_connection, state.scale_factor, id.0 as usize).ok()?,
1286+
))
12911287
}
12921288

12931289
fn open_window(

crates/gpui/src/platform/linux/x11/display.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ pub(crate) struct X11Display {
1313

1414
impl X11Display {
1515
pub(crate) fn new(
16-
xc: &XCBConnection,
16+
xcb: &XCBConnection,
1717
scale_factor: f32,
1818
x_screen_index: usize,
19-
) -> Option<Self> {
20-
let screen = xc.setup().roots.get(x_screen_index).unwrap();
21-
Some(Self {
19+
) -> anyhow::Result<Self> {
20+
let Some(screen) = xcb.setup().roots.get(x_screen_index) else {
21+
return Err(anyhow::anyhow!(
22+
"No screen found with index {}",
23+
x_screen_index
24+
));
25+
};
26+
Ok(Self {
2227
x_screen_index,
2328
bounds: Bounds {
2429
origin: Default::default(),

0 commit comments

Comments
 (0)