From db8d667238306af49b4b02c0d86ea3614a9957d8 Mon Sep 17 00:00:00 2001 From: david-swift Date: Mon, 29 Jan 2024 22:19:42 +0100 Subject: [PATCH] Improve onClick observer --- .../User Interface/View/ViewStorage.swift | 19 +++++++++---------- .../View/Modifiers/AppearObserver.swift | 3 ++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/Adwaita/Model/User Interface/View/ViewStorage.swift b/Sources/Adwaita/Model/User Interface/View/ViewStorage.swift index ebce24e..5b3aeb7 100644 --- a/Sources/Adwaita/Model/User Interface/View/ViewStorage.swift +++ b/Sources/Adwaita/Model/User Interface/View/ViewStorage.swift @@ -40,7 +40,7 @@ public class ViewStorage { public class SignalData { /// The closure. - public var closure: ([UnsafeMutableRawPointer]) -> Void + public var closure: ([Any]) -> Void /// The closure as a C handler. var handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void { @@ -53,7 +53,7 @@ public class ViewStorage { /// The closure as a C handler with three parameters. var threeParamsHandler: @convention(c) ( UnsafeMutableRawPointer, - UnsafeMutableRawPointer, + UnsafeRawPointer?, UnsafeMutableRawPointer ) -> Void { { _, arg1, data in @@ -65,8 +65,8 @@ public class ViewStorage { /// The closure as a C handler with four parameters. var fourParamsHandler: @convention(c) ( UnsafeMutableRawPointer, - UnsafeMutableRawPointer, - UnsafeMutableRawPointer, + UnsafeRawPointer?, + UnsafeRawPointer?, UnsafeMutableRawPointer ) -> Void { { _, arg1, arg2, data in @@ -78,15 +78,14 @@ public class ViewStorage { /// The closure as a C handler with five parameters. var fiveParamsHandler: @convention(c) ( UnsafeMutableRawPointer, - UnsafeMutableRawPointer, - UnsafeMutableRawPointer, - UnsafeMutableRawPointer, + UnsafeRawPointer?, + Double, + Double, UnsafeMutableRawPointer ) -> Void { { _, arg1, arg2, arg3, data in let data = unsafeBitCast(data, to: SignalData.self) data.closure([arg1, arg2, arg3]) - print("Hi") } } @@ -98,7 +97,7 @@ public class ViewStorage { /// Initialize the signal data. /// - Parameter closure: The signal's closure. - public init(closure: @escaping ([UnsafeMutableRawPointer]) -> Void) { + public init(closure: @escaping ([Any]) -> Void) { self.closure = closure } @@ -151,7 +150,7 @@ public class ViewStorage { id: String = "", connectFlags: GConnectFlags = G_CONNECT_AFTER, argCount: Int = 0, - handler: @escaping ([UnsafeMutableRawPointer]) -> Void + handler: @escaping ([Any]) -> Void ) { if let data = handlers[name + id] { data.closure = handler diff --git a/Sources/Adwaita/View/Modifiers/AppearObserver.swift b/Sources/Adwaita/View/Modifiers/AppearObserver.swift index 3cb4332..e1b9f8a 100644 --- a/Sources/Adwaita/View/Modifiers/AppearObserver.swift +++ b/Sources/Adwaita/View/Modifiers/AppearObserver.swift @@ -59,7 +59,8 @@ extension View { let controller = ViewStorage(gtk_gesture_click_new()) gtk_widget_add_controller(storage.pointer?.cast(), controller.pointer) storage.fields["controller"] = controller - controller.connectSignal(name: "stopped", argCount: 0, handler: handler) + let argCount = 3 + controller.connectSignal(name: "released", argCount: argCount, handler: handler) } }