Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit instead of panicking on X11 connection loss. #2

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use calloop::generic::Generic;
use calloop::ping::Ping;
use calloop::{EventLoop as Loop, Readiness};
use libc::{setlocale, LC_CTYPE};
use tracing::warn;
use tracing::{error, warn};

use x11rb::connection::RequestConnection;
use x11rb::errors::{ConnectError, ConnectionError, IdsExhausted, ReplyError};
Expand Down Expand Up @@ -670,6 +670,18 @@ impl ActiveEventLoop {

self.xconn
.select_xinput_events(self.root, ALL_MASTER_DEVICES, mask)
.map_err(|err| {
// Handle loss of connection to the X server by exiting instead of panicking.
if let X11Error::Connection(_) = err {
error!(
"Detected loss of connection to X server while reading window geometry; \
exiting application..."
);
// Use exit code 1 to match the default Xlib I/O error handler.
std::process::exit(1);
}
err
})
.expect_then_ignore_error("Failed to update device event filter");
}

Expand Down
14 changes: 13 additions & 1 deletion src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::Path;
use std::sync::{Arc, Mutex, MutexGuard};
use std::{cmp, env};

use tracing::{debug, info, warn};
use tracing::{debug, error, info, warn};
use x11rb::connection::Connection;
use x11rb::properties::{WmHints, WmSizeHints, WmSizeHintsSpecification};
use x11rb::protocol::shape::SK;
Expand Down Expand Up @@ -1239,6 +1239,18 @@ impl UnownedWindow {
// is BadWindow, and if the window handle is bad we have bigger problems.
self.xconn
.get_geometry(self.xwindow)
.map_err(|err| {
// Handle loss of connection to the X server by exiting instead of panicking.
if let X11Error::Connection(_) = err {
error!(
"Detected loss of connection to X server while reading window geometry; \
exiting application..."
);
// Use exit code 1 to match the default Xlib I/O error handler.
std::process::exit(1);
}
err
})
.map(|geo| (geo.width.into(), geo.height.into()))
.unwrap()
}
Expand Down
Loading