Rewrite WUtils notification.c in Rust #7
Reference in New Issue
Block a user
Delete Branch "trurl/wmaker:refactor/wutil-rs-notification"
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?
Most of the work here was in figuring out what exactly the notification code was being used for (and removing things that weren't being used anymore or refactoring to eliminate API surface area). This rewrite may not be 100% identical, in that every possible combination of API invocations in the old code will result in the same behavior if they're made against the new code, but I think it will do the right thing for current use of the
WMNotificationAPI.@@ -907,3 +901,3 @@paintTextField(tPtr);NOTIFY(tPtr, didBeginEditing, WMTextDidBeginEditingNotification, NULL);if (tPtr->delegate && tPtr->delegate->didBeginEditing) {Is it just me, or is the formatting here kind of off?
It's not you. This was a tabs/spaces thing. I think I've fixed it in the .c files I touched in this PR.
@@ -906,7 +900,10 @@ static void handleEvents(XEvent * event, void *data)paintTextField(tPtr);NOTIFY(tPtr, didBeginEditing, WMTextDidBeginEditingNotification, NULL);I'm mildly bummed out that this went away, because it's decently concise, which is nice.
But if one digs into the macro, it seems like it does three things:
These are all conceptually separate steps, but what kind of bums me out is that (2) has now inlined everywhere.
One imagines, perhaps, a better design might abstract the delegation machinery by providing a thunk that polls for delegation, instead of a macro expanding into a bespoke condition on a specific structure member.
It is not entirely clear to me if this delegation machinery is going to stick around, so I don't want to spend time on making it nicer to use right now. (As far as I can tell, it is partially used by WPrefs.app, and it could just as easily have added a notification listener instead of using the
WMTextFieldDelegateinterface.)@@ -0,0 +49,4 @@/// Wraps a type-erased pointer (which it does not own) and marks it as `Send`.////// The `Send`-ability of the wrapped pointer must be guaranteed code that"...must be guaranteed by code..." (missing the word "by").
Done. Thanks!
@@ -0,0 +79,4 @@#[derive(Default)]pub struct NotificationCenter {/// Notification subscriptions that match on name and source.exact: HashMap<(&'static CStr, Sendable), Vec<(Option<Sendable>, Action)>>,It strikes me that if you used
BTreeMaphere instead ofHashMap, you could make the constructor forNotificationCenterbypub const fn new()and do away with theOnceLockbits inwith_global_default, instead using a staticMutex<NotificationCenter>.Ok, that makes sense.
@@ -0,0 +119,4 @@observer: Option<Sendable>,action: Action,) {match self.exact.entry((name, source)) {The actions in the
matchhere are repeated verbatim in all cases (I think). Perhaps delegate to a small helper function that implements just that logic?Sure. Done.
050daba36dto0893be1cea