Use GWeakRef's symmetrically
This may be not needed anymore with !402 (closed), but leaving it here in case we keep with the current time for longer.
When glib#2384 (closed) is fixed, we could be just use this code to handle the toggle events.
diff --git a/gi/toggle.cpp b/gi/toggle.cpp
index f627f3ad..f5c40081 100644
--- a/gi/toggle.cpp
+++ b/gi/toggle.cpp
@@ -117,7 +117,7 @@ bool ToggleQueue::handle_toggle(Handler handler) {
GObject* null_gobj = nullptr;
m_toggling_gobj.compare_exchange_strong(null_gobj, item.gobj);
- if (item.direction == Direction::DOWN) {
+ {
GjsSmartPointer<GObject> gobj(
static_cast<GObject*>(g_weak_ref_get(&item.weak_ref)));
@@ -127,11 +127,6 @@ bool ToggleQueue::handle_toggle(Handler handler) {
} else {
debug("not handling finalized", item.gobj);
}
-
- g_weak_ref_clear(&item.weak_ref);
- } else {
- debug("handle", item.gobj);
- handler(item.gobj, item.direction);
}
m_toggling_gobj = nullptr;
@@ -175,11 +170,11 @@ ToggleQueue::enqueue(GObject *gobj,
* up we already have a strong reference, so there's no much need to do
*/
auto& item = q.emplace_back(gobj, direction);
+ g_weak_ref_init(&item.weak_ref, gobj);
if (direction == UP) {
debug("enqueue UP", gobj);
} else {
- g_weak_ref_init(&item.weak_ref, gobj);
debug("enqueue DOWN", gobj);
}