objc2_game_controller/generated/
GCController.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern "C" {
11    /// Use these constants with NSNotificationCenter to listen to connection and disconnection events.
12    ///
13    /// Use GCControllerDidConnectNotification for observing connections of controllers.
14    /// Use GCControllerDidDisconnectNotification for observing disconnections of controllers.
15    ///
16    /// Connections and disconnections of controllers will also be reflected in the controllers array
17    /// of the GCController class.
18    ///
19    /// The 'object' property of the notification will contain the GCController that was connected or disconnected.
20    /// For example:
21    ///
22    /// - (void)controllerDidConnect:(NSNotification *)note {
23    ///
24    /// GCController *controller = note.object;
25    ///
26    /// ....
27    /// }
28    ///
29    ///
30    /// See: NSNotificationCenter
31    ///
32    /// See: GCController.controllers
33    ///
34    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerdidconnectnotification?language=objc)
35    pub static GCControllerDidConnectNotification: &'static NSString;
36}
37
38extern "C" {
39    /// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerdiddisconnectnotification?language=objc)
40    pub static GCControllerDidDisconnectNotification: &'static NSString;
41}
42
43extern "C" {
44    /// Use these constants with NSNotificationCenter to listen to a controller becoming the most recently used controller.
45    /// This is a good time to swap out UI to match the new current controller, and unregister any handlers with
46    /// the old current controller.
47    ///
48    /// The 'object' property of the notification will contain the GCController that became the current controller.
49    /// For example:
50    ///
51    /// - (void)controllerDidBecomeCurrent:(NSNotification *)note {
52    ///
53    /// GCController *controller = note.object;
54    ///
55    /// ...
56    /// }
57    ///
58    /// See: NSNotificationCenter
59    ///
60    /// See: GCController.controllers
61    ///
62    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerdidbecomecurrentnotification?language=objc)
63    pub static GCControllerDidBecomeCurrentNotification: &'static NSString;
64}
65
66extern "C" {
67    /// [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerdidstopbeingcurrentnotification?language=objc)
68    pub static GCControllerDidStopBeingCurrentNotification: &'static NSString;
69}
70
71extern "C" {
72    /// Use this constant with NSNotificationCenter to listen to controller user customization events.
73    ///
74    /// When a user customizes the button mappings or other settings of a controller this notification will be
75    /// posted. This is a good time to swap out UI to match the new user settings. Users can modify game
76    /// controller settings through the Settings app on iOS, tvOS, and macOS.
77    ///
78    /// The 'object' property of the notification will contain the GCController that was customized.
79    /// For example:
80    ///
81    /// - (void)controllerDidConnect:(NSNotification *)note {
82    ///
83    /// GCController *controller = note.object;
84    ///
85    /// ....
86    /// }
87    ///
88    ///
89    /// See: NSNotificationCenter
90    ///
91    /// See: GCController.controllers
92    ///
93    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerusercustomizationsdidchangenotification?language=objc)
94    pub static GCControllerUserCustomizationsDidChangeNotification: &'static NSString;
95}
96
97/// This is the player index that a connected controller will have if it has never been assigned a player index on the current system.
98/// Controllers retain the player index they have been assigned between game sessions, so if you wish to unset the player index of a
99/// controller set it back to this value.
100///
101/// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontrollerplayerindex?language=objc)
102// NS_ENUM
103#[repr(transparent)]
104#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
105pub struct GCControllerPlayerIndex(pub NSInteger);
106impl GCControllerPlayerIndex {
107    #[doc(alias = "GCControllerPlayerIndexUnset")]
108    pub const IndexUnset: Self = Self(-1);
109    #[doc(alias = "GCControllerPlayerIndex1")]
110    pub const Index1: Self = Self(0);
111    #[doc(alias = "GCControllerPlayerIndex2")]
112    pub const Index2: Self = Self(1);
113    #[doc(alias = "GCControllerPlayerIndex3")]
114    pub const Index3: Self = Self(2);
115    #[doc(alias = "GCControllerPlayerIndex4")]
116    pub const Index4: Self = Self(3);
117}
118
119unsafe impl Encode for GCControllerPlayerIndex {
120    const ENCODING: Encoding = NSInteger::ENCODING;
121}
122
123unsafe impl RefEncode for GCControllerPlayerIndex {
124    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
125}
126
127extern_class!(
128    /// Controllers are available to an application that links to GameController.framework. There are 2 ways to access controllers
129    /// paired to the system, adopt both to ensure the best user experience:
130    ///
131    /// 1: Querying for the the current array or controllers using [GCController controllers].
132    /// 2: Registering for Connection/Disconnection notifications from NSNotificationCenter.
133    ///
134    /// Only controllers that support one of the allowed profiles, such as GCExtendedGamepad, will be enumerated. Check for the profile
135    /// supported before using a controller in your application. Ignore a controller that doesn't support a profile that suits
136    /// your application, as the user will expect their controller to either be fully supported or not supported at all.
137    ///
138    /// See also [Apple's documentation](https://developer.apple.com/documentation/gamecontroller/gccontroller?language=objc)
139    #[unsafe(super(NSObject))]
140    #[derive(Debug, PartialEq, Eq, Hash)]
141    pub struct GCController;
142);
143
144#[cfg(feature = "GCDevice")]
145extern_conformance!(
146    unsafe impl GCDevice for GCController {}
147);
148
149extern_conformance!(
150    unsafe impl NSObjectProtocol for GCController {}
151);
152
153impl GCController {
154    extern_methods!(
155        /// Get a list of controllers currently attached to the system.
156        ///
157        ///
158        /// See: GCControllerDidConnectNotification
159        ///
160        /// See: GCControllerDidDisconnectNotification
161        #[unsafe(method(controllers))]
162        #[unsafe(method_family = none)]
163        pub unsafe fn controllers() -> Retained<NSArray<GCController>>;
164
165        /// The most recently used game controller. If a user actuates a game controller
166        /// input, that controller will become the current one.
167        ///
168        ///
169        /// Note: This is useful for single player games where you only care about whether an
170        /// input is pressed, and not where it came from.  You will still need to
171        /// register for changes to GCController.current so that your UI can remain
172        /// up-to-date with the current controller.
173        #[unsafe(method(current))]
174        #[unsafe(method_family = none)]
175        pub unsafe fn current() -> Option<Retained<GCController>>;
176
177        #[cfg(feature = "block2")]
178        /// Set this block to be notified when a user intends to suspend or resume the current game state. A controller will have a button
179        /// dedicated to suspending and resuming play and invoking context sensitive actions. During event handling the system will
180        /// notify the application using this block such that the application can handle the suspension and resumption from the given controller.
181        ///
182        /// Use this to implement your canonical transition to a pause menu for example if that is your application's desired handling
183        /// of suspension in play. You may pause and resume based on game state as well so the event is only called each time the
184        /// pause/resume button is pressed.
185        ///
186        ///
187        /// Note: This handler has been deprecated in favor of the Menu button found on GCMicroGamepad and GCExtendedGamepad.
188        ///
189        /// See: microGamepad
190        ///
191        /// See: extendedGamepad
192        #[deprecated = "Use the Menu button found on the controller's input profile, if it exists."]
193        #[unsafe(method(controllerPausedHandler))]
194        #[unsafe(method_family = none)]
195        pub unsafe fn controllerPausedHandler(
196            &self,
197        ) -> *mut block2::DynBlock<dyn Fn(NonNull<GCController>)>;
198
199        #[cfg(feature = "block2")]
200        /// Setter for [`controllerPausedHandler`][Self::controllerPausedHandler].
201        #[deprecated = "Use the Menu button found on the controller's input profile, if it exists."]
202        #[unsafe(method(setControllerPausedHandler:))]
203        #[unsafe(method_family = none)]
204        pub unsafe fn setControllerPausedHandler(
205            &self,
206            controller_paused_handler: Option<&block2::DynBlock<dyn Fn(NonNull<GCController>)>>,
207        );
208
209        /// Whether the current application should monitor and respond to game controller events when it is not the frontmost application.
210        ///
211        ///
212        /// not be forwarded to the application. Once the application becomes the frontmost application, game controller events will be forwarded.
213        ///
214        ///
215        /// Note: Starting with macOS Big Sur 11.3, shouldMonitorBackgroundEvents will be NO by default. For applications built prior to macOS Big Sur 11.3,
216        /// (or running on devices with an earlier version of macOS), shouldMonitorBackgroundEvents will be YES by default. On iOS and tvOS, this property is ignored.
217        #[unsafe(method(shouldMonitorBackgroundEvents))]
218        #[unsafe(method_family = none)]
219        pub unsafe fn shouldMonitorBackgroundEvents() -> bool;
220
221        /// Setter for [`shouldMonitorBackgroundEvents`][Self::shouldMonitorBackgroundEvents].
222        #[unsafe(method(setShouldMonitorBackgroundEvents:))]
223        #[unsafe(method_family = none)]
224        pub unsafe fn setShouldMonitorBackgroundEvents(should_monitor_background_events: bool);
225
226        /// A controller may be form fitting or otherwise closely attached to the device. This closeness to other inputs on the device
227        /// may suggest that interaction with the device may use other inputs easily. This is presented to developers to allow them to
228        /// make informed decisions about UI and interactions to choose for their game in this situation.
229        #[unsafe(method(isAttachedToDevice))]
230        #[unsafe(method_family = none)]
231        pub unsafe fn isAttachedToDevice(&self) -> bool;
232
233        /// A player index for the controller, defaults to GCControllerPlayerIndexUnset.
234        ///
235        /// This can be set both for the application to keep track of controllers and as a signal to make a controller display a player
236        /// index on a set of LEDs or some other mechanism.
237        ///
238        /// A controller is not guaranteed to have a visual display of the playerIndex, playerIndex does not persist for a controller
239        /// with regards to a system.
240        ///
241        /// Negative values less than GCControllerPlayerIndexUnset will just map back to GCControllerPlayerIndexUnset when read back.
242        #[unsafe(method(playerIndex))]
243        #[unsafe(method_family = none)]
244        pub unsafe fn playerIndex(&self) -> GCControllerPlayerIndex;
245
246        /// Setter for [`playerIndex`][Self::playerIndex].
247        #[unsafe(method(setPlayerIndex:))]
248        #[unsafe(method_family = none)]
249        pub unsafe fn setPlayerIndex(&self, player_index: GCControllerPlayerIndex);
250
251        #[cfg(feature = "GCControllerInput")]
252        /// Gets the input profile for the controller.
253        #[unsafe(method(input))]
254        #[unsafe(method_family = none)]
255        pub unsafe fn input(&self) -> Retained<GCControllerLiveInput>;
256
257        #[cfg(feature = "GCDeviceBattery")]
258        /// Gets the battery information if controller supports one
259        ///
260        /// This property is useful when you try to notify your user to change or charge controller before it runs out of battery life
261        /// or simply display the current battery level and status.
262        #[unsafe(method(battery))]
263        #[unsafe(method_family = none)]
264        pub unsafe fn battery(&self) -> Option<Retained<GCDeviceBattery>>;
265
266        #[cfg(feature = "GCPhysicalInputProfile")]
267        /// Gets the physical input profile for the controller.
268        ///
269        ///
270        /// Note: This is equivalent to the controller's microGamepad, or extendedGamepad instance.
271        ///
272        /// See: microGamepad
273        ///
274        /// See: extendedGamepad
275        #[unsafe(method(physicalInputProfile))]
276        #[unsafe(method_family = none)]
277        pub unsafe fn physicalInputProfile(&self) -> Retained<GCPhysicalInputProfile>;
278
279        #[cfg(all(feature = "GCGamepad", feature = "GCPhysicalInputProfile"))]
280        /// Gets the profile for the controller that suits current application.
281        ///
282        /// There are several supported profiles, with an additional optional profile for motion as well.
283        /// Each controller may be able to map its inputs into all profiles or just one kind of profile. Query for the controller
284        /// profile that suits your game, the simplest kind will be supported by the broadest variety
285        /// of controllers. A controller supporting the Extended Gamepad profile for example supports the Gamepad profile and more.
286        /// As such it can always be used just in the Gamepad profile if that suits the game.
287        ///
288        /// A physical controller that supports a profile must support it completely. That means that all buttons and axis inputs must
289        /// be valid inputs that a developer can utilize.
290        ///
291        /// If a controller does not support the given profile the returned value will be nil. Use this to filter controllers if the
292        /// application requires a specific kind of profile.
293        ///
294        /// See: motion
295        #[deprecated]
296        #[unsafe(method(gamepad))]
297        #[unsafe(method_family = none)]
298        pub unsafe fn gamepad(&self) -> Option<Retained<GCGamepad>>;
299
300        #[cfg(all(feature = "GCMicroGamepad", feature = "GCPhysicalInputProfile"))]
301        #[unsafe(method(microGamepad))]
302        #[unsafe(method_family = none)]
303        pub unsafe fn microGamepad(&self) -> Option<Retained<GCMicroGamepad>>;
304
305        #[cfg(all(feature = "GCExtendedGamepad", feature = "GCPhysicalInputProfile"))]
306        #[unsafe(method(extendedGamepad))]
307        #[unsafe(method_family = none)]
308        pub unsafe fn extendedGamepad(&self) -> Option<Retained<GCExtendedGamepad>>;
309
310        #[cfg(feature = "GCMotion")]
311        /// Gets the motion input profile. This profile is optional and may be available if the controller is attached to a device that supports motion.
312        /// If this is nil the controller does not support motion input and only the gamepad
313        /// &
314        /// extendedGamepad profiles are available.
315        ///
316        /// See: gamepad
317        ///
318        /// See: extendedGamepad
319        #[unsafe(method(motion))]
320        #[unsafe(method_family = none)]
321        pub unsafe fn motion(&self) -> Option<Retained<GCMotion>>;
322
323        #[cfg(feature = "GCDeviceLight")]
324        /// Gets the light for the controller, if one exists.
325        ///
326        /// A controller's light can be used to signal information to the player, such as using different light colors based on the player
327        /// index. It can also be used to react to in-game events and enhance user immersion.
328        #[unsafe(method(light))]
329        #[unsafe(method_family = none)]
330        pub unsafe fn light(&self) -> Option<Retained<GCDeviceLight>>;
331
332        #[cfg(feature = "GCDeviceHaptics")]
333        /// Gets the haptics for the controller, if one exists.
334        ///
335        /// Use this property to create CHHapticEngine instances according to your needs.
336        ///
337        ///
338        /// Note: Haptics are a drain on the controller's battery, and can be distracting when used excessively.
339        #[unsafe(method(haptics))]
340        #[unsafe(method_family = none)]
341        pub unsafe fn haptics(&self) -> Option<Retained<GCDeviceHaptics>>;
342    );
343}
344
345/// Methods declared on superclass `NSObject`.
346impl GCController {
347    extern_methods!(
348        #[unsafe(method(init))]
349        #[unsafe(method_family = init)]
350        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
351
352        #[unsafe(method(new))]
353        #[unsafe(method_family = new)]
354        pub unsafe fn new() -> Retained<Self>;
355    );
356}
357
358/// Snapshot.
359impl GCController {
360    extern_methods!(
361        /// A controller may represent a real device managed by the operating system,
362        /// or a virtual snapshot created by the developer.  If a controller is created
363        /// by the developer, it is considered to be a snapshot, allowing direct writes
364        /// to any GCControllerElement of its profiles.  If the controller is not
365        /// snapshot, the system will reject any write requests to GCControllerElement.
366        ///
367        ///
368        /// See: controllerWithMicroGamepad
369        ///
370        /// See: controllerWithExtendedGamepad
371        ///
372        /// See: capture
373        #[unsafe(method(isSnapshot))]
374        #[unsafe(method_family = none)]
375        pub unsafe fn isSnapshot(&self) -> bool;
376
377        /// Polls the state vector of the controller and saves it to a new and writable
378        /// instance of GCController.
379        ///
380        /// If your application is heavily multithreaded this may also be useful to
381        /// guarantee atomicity of input handling as a snapshot will not change based
382        /// on user input once it is taken.
383        ///
384        ///
385        /// See: snapshot
386        ///
387        /// Returns: A new controller with the duplicated state vector of the current
388        /// controller.
389        #[unsafe(method(capture))]
390        #[unsafe(method_family = none)]
391        pub unsafe fn capture(&self) -> Retained<GCController>;
392
393        /// Creates a controller with a micro gamepad profile.
394        ///
395        /// This controller will be considered a snapshot, allowing developers to write
396        /// to any GCControllerElement of its profiles.
397        ///
398        ///
399        /// See: snapshot
400        ///
401        /// Returns: A new controller with a micro gamepad profile
402        #[unsafe(method(controllerWithMicroGamepad))]
403        #[unsafe(method_family = none)]
404        pub unsafe fn controllerWithMicroGamepad() -> Retained<GCController>;
405
406        /// Creates a controller with an extended gamepad profile.
407        ///
408        /// This controller will be considered a snapshot, allowing developers to write to any GCControllerElement of its profiles.
409        ///
410        ///
411        /// See: snapshot
412        ///
413        /// Returns: A new controller with an extended gamepad profile
414        #[unsafe(method(controllerWithExtendedGamepad))]
415        #[unsafe(method_family = none)]
416        pub unsafe fn controllerWithExtendedGamepad() -> Retained<GCController>;
417    );
418}
419
420/// Discovery.
421impl GCController {
422    extern_methods!(
423        #[cfg(feature = "block2")]
424        /// Start discovery of new wireless controllers that are discoverable. This is an asynchronous and the supplied completionHandler
425        /// will get called once no more devices can be found. If there are already multiple controllers available for use, there
426        /// may be little reason to automatically start discovery of new wireless controllers. In this situation it may be best to
427        /// allow the user to start discovery manually via in-game UI.
428        ///
429        /// Once discovery has started new controllers will notify themselves as connected via GCControllerDidConnectNotification.
430        /// As the notification arrives the controller is also available in the controllers array.
431        ///
432        /// The completionHandler could be used to update UI and/or game state to indicate that no more controllers will be found
433        /// and the current set of controllers is what is available for use in the game.
434        ///
435        /// If a completionHandler was provided, it will be called once when discovery stops. Either from an explicit call to
436        /// stopWirelessControllerDiscovery or from timing out or stopping in its natural course of operation. Thus the
437        /// completionHandler will at most be called once per call to startWirelessControllerDiscoveryWithCompletionHandler:.
438        ///
439        /// The completionHandler may also not get called at all, if for example startWirelessControllerDiscoveryWithCompletionHandler:
440        /// is called multiple times during dicovery. For this case the net effect is that the completionHandler is replaced with each call
441        /// and only the last one set before discovery stops will be called.
442        ///
443        ///
444        /// Parameter `completionHandler`: an optional handler that is called when discovery stops. (may be nil, in which case you will not be notified when discovery stops)
445        ///
446        /// See: stopWirelessControllerDiscovery
447        ///
448        /// See: controllers
449        #[unsafe(method(startWirelessControllerDiscoveryWithCompletionHandler:))]
450        #[unsafe(method_family = none)]
451        pub unsafe fn startWirelessControllerDiscoveryWithCompletionHandler(
452            completion_handler: Option<&block2::DynBlock<dyn Fn()>>,
453        );
454
455        /// If no more controllers are needed, depending on game state or number of controllers supported by a game, the discovery
456        /// process can be stopped. Calling stopWirelessControllerDiscovery when no discovery is currently in progress will return
457        /// immediately without any effect, thus it is safe to call even if the completionHandler of
458        /// startWirelessControllerDiscoveryWithCompletionHandler: has been called.
459        ///
460        ///
461        /// See: startWirelessControllerDiscoveryWithCompletionHandler:
462        #[unsafe(method(stopWirelessControllerDiscovery))]
463        #[unsafe(method_family = none)]
464        pub unsafe fn stopWirelessControllerDiscovery();
465    );
466}