From 282f8449f2a0550d91ab20e80564be1bc148106e Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 31 Oct 2024 22:45:23 +0400 Subject: [PATCH] Don't use GLib helper functions introduced in 2.74 (#17392) --- src/Avalonia.X11/Interop/Glib.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.X11/Interop/Glib.cs b/src/Avalonia.X11/Interop/Glib.cs index fbc92960cdb..543d2892dd6 100644 --- a/src/Avalonia.X11/Interop/Glib.cs +++ b/src/Avalonia.X11/Interop/Glib.cs @@ -43,10 +43,7 @@ private static extern ulong g_signal_connect_object(IntPtr instance, Utf8Buffer [DllImport(GlibName)] public static extern void g_main_loop_unref(IntPtr loop); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void GOnceSourceFunc(IntPtr userData); - + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate int GSourceFunc(IntPtr userData); @@ -54,25 +51,26 @@ private static extern ulong g_signal_connect_object(IntPtr instance, Utf8Buffer public delegate void GDestroyNotify(IntPtr userData); [DllImport(GlibName)] - private static extern int g_idle_add_once(GOnceSourceFunc cb, IntPtr userData); + private static extern int g_idle_add(GSourceFunc cb, IntPtr userData); - private static readonly GOnceSourceFunc s_onceSourceCb = (userData) => + private static readonly GSourceFunc s_onceSourceCb = (userData) => { var h = GCHandle.FromIntPtr(userData); var cb = (Action)h.Target!; h.Free(); cb(); + return 0; }; public static void g_idle_add_once(Action cb) => - g_idle_add_once(s_onceSourceCb, GCHandle.ToIntPtr(GCHandle.Alloc(cb))); + g_idle_add(s_onceSourceCb, GCHandle.ToIntPtr(GCHandle.Alloc(cb))); [DllImport(GlibName)] - private static extern uint g_timeout_add_once(uint interval, GOnceSourceFunc cb, IntPtr userData); + private static extern uint g_timeout_add(uint interval, GSourceFunc cb, IntPtr userData); public static uint g_timeout_add_once(uint interval, Action cb) => - g_timeout_add_once(interval, s_onceSourceCb, GCHandle.ToIntPtr(GCHandle.Alloc(cb))); + g_timeout_add(interval, s_onceSourceCb, GCHandle.ToIntPtr(GCHandle.Alloc(cb))); private static readonly GDestroyNotify s_gcHandleDestroyNotify = handle => GCHandle.FromIntPtr(handle).Free();