diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-06-08 20:41:30 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-06-08 20:41:30 +0200 |
| commit | 779b5bf9056e33ec47c6b0f2b9b2f23379936cb6 (patch) | |
| tree | 5fd6f255e762b9f420978bfeda0eba00de7246d4 /lib/src/turns-turn-order.c | |
| parent | 10b6c46033c6d6caf5be105542a29832e413ce5e (diff) | |
| download | turns-779b5bf9056e33ec47c6b0f2b9b2f23379936cb6.tar.xz turns-779b5bf9056e33ec47c6b0f2b9b2f23379936cb6.zip | |
lib: fix participant insertion logic
Diffstat (limited to 'lib/src/turns-turn-order.c')
| -rw-r--r-- | lib/src/turns-turn-order.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/src/turns-turn-order.c b/lib/src/turns-turn-order.c index ba46da8..6a68145 100644 --- a/lib/src/turns-turn-order.c +++ b/lib/src/turns-turn-order.c @@ -68,15 +68,17 @@ static gint compare_participant(void const * lhs, void const * rhs, void * sort_ return result; } -static void sort_participants(TurnsTurnOrder * self) +static void sort_participants(TurnsTurnOrder * self, bool inserting) { auto const sort_mode = turns_turn_order_get_sort_mode(self); g_ptr_array_sort_values_with_data(self->participants, &compare_participant, (gpointer)sort_mode); - auto const participant_count = turns_turn_order_get_participant_count(self); - - g_list_model_items_changed(G_LIST_MODEL(self), 0, participant_count, participant_count); + if (!inserting) + { + auto const participant_count = turns_turn_order_get_participant_count(self); + g_list_model_items_changed(G_LIST_MODEL(self), 0, participant_count, participant_count); + } } static void clear_participants(TurnsTurnOrder * self) @@ -104,7 +106,7 @@ static void set_running(TurnsTurnOrder * self, gboolean value) static void handle_participant_property_changed(TurnsParticipant const *, GParamSpec *, TurnsTurnOrder * self) { - sort_participants(self); + sort_participants(self, false); } static void turns_turn_order_get_property(GObject * self, guint id, GValue * value, GParamSpec * specification) @@ -245,11 +247,11 @@ void turns_turn_order_add(TurnsTurnOrder * self, TurnsParticipant * participant) g_signal_connect(participant, "notify::priority", (GCallback)&handle_participant_property_changed, self); - auto was_empty = self->participants->len == 0; + auto was_empty = turns_turn_order_get_empty(self); g_ptr_array_add(self->participants, g_object_ref(participant)); - sort_participants(self); + sort_participants(self, true); auto position = 0u; g_ptr_array_find(self->participants, participant, &position); @@ -345,5 +347,5 @@ void turns_turn_order_set_sort_mode(TurnsTurnOrder * self, TurnsTurnOrderSortMod self->sort_mode = sort_mode; g_object_notify_by_pspec(G_OBJECT(self), properties[PROP_SORT_MODE]); - sort_participants(self); + sort_participants(self, false); } |
