@@ -90,6 +90,22 @@ const NORMAL_STATE: usize = 1;
90
90
/// application wants to start as an icon
91
91
const ICONIC_STATE : usize = 3 ;
92
92
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
+
93
109
extern "C" fn xerror ( mdpy : * mut Display , ee : * mut XErrorEvent ) -> c_int {
94
110
unsafe {
95
111
let e = * ee;
@@ -122,12 +138,6 @@ extern "C" fn xerrordummy(
122
138
0
123
139
}
124
140
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
-
131
141
const BROKEN : & CStr = c"broken" ;
132
142
133
143
type Atom = c_ulong ;
0 commit comments