Simplify WINGs handlers API and reimplement in Rust #17
Reference in New Issue
Block a user
Delete Branch "trurl/wmaker:refactor/riir.wings-handlers"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR removes a bit of cruft which is not used by Window Maker (most notably, support for calling handlers in response to input on a file descriptor), massages the API slightly to make it easier to rewrite in safe Rust, and moves support for scheduling callbacks on a global queue into
wutil-rs.@@ -0,0 +176,4 @@}}struct TimerHandler {Nit: a couple of do comments on this struct and
callbackwould be nice.Done.
@@ -0,0 +184,4 @@delay: Duration,}struct IdleHandler {(Similarly, a comment here would be nice.)
Done.
@@ -0,0 +200,4 @@mem::swap(&mut idle_handlers, &mut handlers.idle_handlers);idle_handlers});for mut h in handlers.into_iter() {I don't quite get this; it appears to not just check, but consume and drop, global idle handlers. Perhaps the name could be changed to reflect that?
run_global_idle_handlersor something? The repeatedwith_global_handlersblocks are interesting; I believe that's intended for the case where an idle handler is added during processing?The name comes from the original C API, but I agree that it's misleading.
run_global_idle_handlersis certainly better. Change made.Yes. The repeated
with_global_handlersblocks are written that way in case a callback tries to touch the global queue (which would fail if the callback is invoked from withinwith_global_handlersbecause it's inside a mutex). The original C implementation does something similar (copying the globalidleHandlerarray inW_CheckIdleHandlersand iterating over the copy).@@ -0,0 +222,4 @@#[unsafe(no_mangle)]pub unsafe extern "C" fn WMAddTimerHandler(milliseconds: c_int,Is there a good reason not to change the type signature on the C side to make this explicitly unsigned? A negative number there feels relativistically impossible?
I've been trying to keep things compatible with the original headers, but I have definitely broken source-level compatibility. So, yeah, let's use
unsignedwhere appropriate.0457587fedto7c7b9aa97c