1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern "C" {
    pub static GCControllerDidConnectNotification: &'static NSString;
}

extern "C" {
    pub static GCControllerDidDisconnectNotification: &'static NSString;
}

extern "C" {
    pub static GCControllerDidBecomeCurrentNotification: &'static NSString;
}

extern "C" {
    pub static GCControllerDidStopBeingCurrentNotification: &'static NSString;
}

extern "C" {
    pub static GCControllerUserCustomizationsDidChangeNotification: &'static NSString;
}

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct GCControllerPlayerIndex(pub NSInteger);
impl GCControllerPlayerIndex {
    #[doc(alias = "GCControllerPlayerIndexUnset")]
    pub const Unset: Self = Self(-1);
    pub const GCControllerPlayerIndex1: Self = Self(0);
    pub const GCControllerPlayerIndex2: Self = Self(1);
    pub const GCControllerPlayerIndex3: Self = Self(2);
    pub const GCControllerPlayerIndex4: Self = Self(3);
}

unsafe impl Encode for GCControllerPlayerIndex {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for GCControllerPlayerIndex {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct GCController;

    unsafe impl ClassType for GCController {
        type Super = NSObject;
        type Mutability = InteriorMutable;
    }
);

#[cfg(feature = "GCDevice")]
unsafe impl GCDevice for GCController {}

unsafe impl NSObjectProtocol for GCController {}

extern_methods!(
    unsafe impl GCController {
        #[cfg(feature = "block2")]
        #[deprecated = "controllerPausedHandler has been deprecated. Use the Menu button found on the controller's profile, if it exists."]
        #[method(controllerPausedHandler)]
        pub unsafe fn controllerPausedHandler(
            &self,
        ) -> *mut block2::Block<dyn Fn(NonNull<GCController>)>;

        #[cfg(feature = "block2")]
        #[deprecated = "controllerPausedHandler has been deprecated. Use the Menu button found on the controller's profile, if it exists."]
        #[method(setControllerPausedHandler:)]
        pub unsafe fn setControllerPausedHandler(
            &self,
            controller_paused_handler: Option<&block2::Block<dyn Fn(NonNull<GCController>)>>,
        );

        #[method_id(@__retain_semantics Other current)]
        pub unsafe fn current() -> Option<Retained<GCController>>;

        #[method(shouldMonitorBackgroundEvents)]
        pub unsafe fn shouldMonitorBackgroundEvents() -> bool;

        #[method(setShouldMonitorBackgroundEvents:)]
        pub unsafe fn setShouldMonitorBackgroundEvents(should_monitor_background_events: bool);

        #[method(isAttachedToDevice)]
        pub unsafe fn isAttachedToDevice(&self) -> bool;

        #[method(isSnapshot)]
        pub unsafe fn isSnapshot(&self) -> bool;

        #[method(playerIndex)]
        pub unsafe fn playerIndex(&self) -> GCControllerPlayerIndex;

        #[method(setPlayerIndex:)]
        pub unsafe fn setPlayerIndex(&self, player_index: GCControllerPlayerIndex);

        #[cfg(feature = "GCControllerInput")]
        #[method_id(@__retain_semantics Other input)]
        pub unsafe fn input(&self) -> Retained<GCControllerLiveInput>;

        #[cfg(feature = "GCDeviceBattery")]
        #[method_id(@__retain_semantics Other battery)]
        pub unsafe fn battery(&self) -> Option<Retained<GCDeviceBattery>>;

        #[cfg(feature = "GCPhysicalInputProfile")]
        #[method_id(@__retain_semantics Other physicalInputProfile)]
        pub unsafe fn physicalInputProfile(&self) -> Retained<GCPhysicalInputProfile>;

        #[cfg(all(feature = "GCGamepad", feature = "GCPhysicalInputProfile"))]
        #[deprecated]
        #[method_id(@__retain_semantics Other gamepad)]
        pub unsafe fn gamepad(&self) -> Option<Retained<GCGamepad>>;

        #[cfg(all(feature = "GCMicroGamepad", feature = "GCPhysicalInputProfile"))]
        #[method_id(@__retain_semantics Other microGamepad)]
        pub unsafe fn microGamepad(&self) -> Option<Retained<GCMicroGamepad>>;

        #[cfg(all(feature = "GCExtendedGamepad", feature = "GCPhysicalInputProfile"))]
        #[method_id(@__retain_semantics Other extendedGamepad)]
        pub unsafe fn extendedGamepad(&self) -> Option<Retained<GCExtendedGamepad>>;

        #[cfg(feature = "GCMotion")]
        #[method_id(@__retain_semantics Other motion)]
        pub unsafe fn motion(&self) -> Option<Retained<GCMotion>>;

        #[cfg(feature = "GCDeviceLight")]
        #[method_id(@__retain_semantics Other light)]
        pub unsafe fn light(&self) -> Option<Retained<GCDeviceLight>>;

        #[cfg(feature = "GCDeviceHaptics")]
        #[method_id(@__retain_semantics Other haptics)]
        pub unsafe fn haptics(&self) -> Option<Retained<GCDeviceHaptics>>;

        #[method_id(@__retain_semantics Other capture)]
        pub unsafe fn capture(&self) -> Retained<GCController>;

        #[method_id(@__retain_semantics Other controllers)]
        pub unsafe fn controllers() -> Retained<NSArray<GCController>>;

        #[cfg(feature = "block2")]
        #[method(startWirelessControllerDiscoveryWithCompletionHandler:)]
        pub unsafe fn startWirelessControllerDiscoveryWithCompletionHandler(
            completion_handler: Option<&block2::Block<dyn Fn()>>,
        );

        #[method(stopWirelessControllerDiscovery)]
        pub unsafe fn stopWirelessControllerDiscovery();

        #[method_id(@__retain_semantics Other controllerWithMicroGamepad)]
        pub unsafe fn controllerWithMicroGamepad() -> Retained<GCController>;

        #[method_id(@__retain_semantics Other controllerWithExtendedGamepad)]
        pub unsafe fn controllerWithExtendedGamepad() -> Retained<GCController>;
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl GCController {
        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new() -> Retained<Self>;
    }
);