Skip to content

Commit

Permalink
move xerrorlib where it's used and document its necessity
Browse files Browse the repository at this point in the history
  • Loading branch information
ntBre committed Dec 7, 2024
1 parent 32db786 commit cb5ddac
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ const NORMAL_STATE: usize = 1;
/// application wants to start as an icon
const ICONIC_STATE: usize = 3;

/// Unfortunately this can't be packed into the State struct since it needs to
/// be accessed here in `xerror`, where I don't get a chance to pass State.
///
/// What's going on here is that `checkotherwm` calls `XSetErrorHandler` to set
/// the handler temporarily to `xerrorstart`. `XSetErrorHandler` returns the
/// previous handler fn, which we store here. At the end of `checkotherwm`, we
/// then set the error handler to `xerror`, which, via `XERRORLIB`, is just a
/// wrapper around the original X error handler with a little logging and an
/// early return to allow certain kinds of errors.
///
/// Obviously it would be nice to handle this with a closure in `checkotherwm`,
/// but `XSetErrorHandler` requires an `unsafe extern "C" fn`, not any old Fn.
static mut XERRORXLIB: Option<
unsafe extern "C" fn(*mut Display, *mut XErrorEvent) -> i32,
> = None;

extern "C" fn xerror(mdpy: *mut Display, ee: *mut XErrorEvent) -> c_int {
unsafe {
let e = *ee;
Expand Down Expand Up @@ -122,12 +138,6 @@ extern "C" fn xerrordummy(
0
}

/// I hate to start using globals already, but I'm not sure how else to do it.
/// maybe we can pack this stuff into a struct eventually
static mut XERRORXLIB: Option<
unsafe extern "C" fn(*mut Display, *mut XErrorEvent) -> i32,
> = None;

const BROKEN: &CStr = c"broken";

type Atom = c_ulong;
Expand Down

0 comments on commit cb5ddac

Please sign in to comment.