From 26912523fa2427595ef043fe97ac5a5d2f6f9d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 23 Feb 2021 09:01:24 +0100 Subject: [PATCH] native/seat-impl: Add helper for queuing main thread idle callbacks Make the emit main thread signal use it. Will be used for calling code on the main thread from the input thread. Part-of: --- src/backends/native/meta-seat-impl.c | 30 ++++++++++++++++++---------- src/backends/native/meta-seat-impl.h | 5 +++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c index cce7cd33c..e88285419 100644 --- a/src/backends/native/meta-seat-impl.c +++ b/src/backends/native/meta-seat-impl.c @@ -306,6 +306,22 @@ update_button_count (MetaSeatImpl *seat_impl, } } +void +meta_seat_impl_queue_main_thread_idle (MetaSeatImpl *seat_impl, + GSourceFunc func, + gpointer user_data, + GDestroyNotify destroy_notify) +{ + GSource *source; + + source = g_idle_source_new (); + g_source_set_priority (source, G_PRIORITY_HIGH); + g_source_set_callback (source, func, user_data, destroy_notify); + + g_source_attach (source, seat_impl->main_context); + g_source_unref (source); +} + typedef struct { MetaSeatImpl *seat_impl; @@ -337,7 +353,6 @@ emit_signal (MetaSeatImpl *seat_impl, int n_args) { MetaSeatSignalData *emit_signal_data; - GSource *source; GArray *array; GValue self = G_VALUE_INIT; @@ -354,15 +369,10 @@ emit_signal (MetaSeatImpl *seat_impl, emit_signal_data->signal_id = signal_id; emit_signal_data->args = array; - source = g_idle_source_new (); - g_source_set_priority (source, G_PRIORITY_HIGH); - g_source_set_callback (source, - (GSourceFunc) emit_signal_in_main, - emit_signal_data, - (GDestroyNotify) signal_data_free); - - g_source_attach (source, seat_impl->main_context); - g_source_unref (source); + meta_seat_impl_queue_main_thread_idle (seat_impl, + (GSourceFunc) emit_signal_in_main, + emit_signal_data, + (GDestroyNotify) signal_data_free); } void diff --git a/src/backends/native/meta-seat-impl.h b/src/backends/native/meta-seat-impl.h index ec78a9414..d49d1660f 100644 --- a/src/backends/native/meta-seat-impl.h +++ b/src/backends/native/meta-seat-impl.h @@ -264,4 +264,9 @@ void meta_seat_impl_notify_bell_in_impl (MetaSeatImpl *seat_impl); MetaInputSettings * meta_seat_impl_get_input_settings (MetaSeatImpl *seat_impl); +void meta_seat_impl_queue_main_thread_idle (MetaSeatImpl *seat_impl, + GSourceFunc func, + gpointer user_data, + GDestroyNotify destroy_notify); + #endif /* META_SEAT_IMPL_H */