Skip to content

Commit cb5ddac

Browse files
committed
move xerrorlib where it's used and document its necessity
1 parent 32db786 commit cb5ddac

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/main.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ const NORMAL_STATE: usize = 1;
9090
/// application wants to start as an icon
9191
const ICONIC_STATE: usize = 3;
9292

93+
/// Unfortunately this can't be packed into the State struct since it needs to
94+
/// be accessed here in `xerror`, where I don't get a chance to pass State.
95+
///
96+
/// What's going on here is that `checkotherwm` calls `XSetErrorHandler` to set
97+
/// the handler temporarily to `xerrorstart`. `XSetErrorHandler` returns the
98+
/// previous handler fn, which we store here. At the end of `checkotherwm`, we
99+
/// then set the error handler to `xerror`, which, via `XERRORLIB`, is just a
100+
/// wrapper around the original X error handler with a little logging and an
101+
/// early return to allow certain kinds of errors.
102+
///
103+
/// Obviously it would be nice to handle this with a closure in `checkotherwm`,
104+
/// but `XSetErrorHandler` requires an `unsafe extern "C" fn`, not any old Fn.
105+
static mut XERRORXLIB: Option<
106+
unsafe extern "C" fn(*mut Display, *mut XErrorEvent) -> i32,
107+
> = None;
108+
93109
extern "C" fn xerror(mdpy: *mut Display, ee: *mut XErrorEvent) -> c_int {
94110
unsafe {
95111
let e = *ee;
@@ -122,12 +138,6 @@ extern "C" fn xerrordummy(
122138
0
123139
}
124140

125-
/// I hate to start using globals already, but I'm not sure how else to do it.
126-
/// maybe we can pack this stuff into a struct eventually
127-
static mut XERRORXLIB: Option<
128-
unsafe extern "C" fn(*mut Display, *mut XErrorEvent) -> i32,
129-
> = None;
130-
131141
const BROKEN: &CStr = c"broken";
132142

133143
type Atom = c_ulong;

0 commit comments

Comments
 (0)