ObjFW  Diff

Differences From Artifact [ae6b4a8235]:

To Artifact [d2edb1ba13]:


19
20
21
22
23
24
25


26
27
28
29
30
31
32

#include "config.h"

#import "OHEvdevGameControllerProfile.h"
#import "OFDictionary.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"



#include <linux/input.h>

#import "evdev_compat.h"

static OFString *
buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID)







>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

#include "config.h"

#import "OHEvdevGameControllerProfile.h"
#import "OFDictionary.h"
#import "OHGameControllerAxis.h"
#import "OHGameControllerButton.h"
#import "OHGameControllerElement.h"
#import "OHGameControllerElement+Private.h"

#include <linux/input.h>

#import "evdev_compat.h"

static OFString *
buttonToName(uint16_t button, uint16_t vendorID, uint16_t productID)
201
202
203
204
205
206
207
208





209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
		return nil;
	}
}

@implementation OHEvdevGameControllerProfile
@synthesize buttons = _buttons, axes = _axes;

- (instancetype)initWithKeyBits: (unsigned long *)keyBits





			 evBits: (unsigned long *)evBits
			absBits: (unsigned long *)absBits
		       vendorID: (uint16_t)vendorID
		      productID: (uint16_t)productID
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons, *axes;

		buttons = [OFMutableDictionary dictionary];
		for (size_t i = 0; i < OHNumEvdevButtonIDs; i++) {
			if (OFBitSetIsSet(keyBits, OHEvdevButtonIDs[i])) {
				OFString *buttonName;
				OHGameControllerButton *button;

				buttonName = buttonToName(OHEvdevButtonIDs[i],
				    vendorID, productID);
				if (buttonName == nil)
					continue;

				button = [[[OHGameControllerButton alloc]
				    initWithName: buttonName
					  analog: false] autorelease];

				[buttons setObject: button forKey: buttonName];
			}
		}
		[buttons makeImmutable];

		axes = [OFMutableDictionary dictionary];
		if (OFBitSetIsSet(evBits, EV_ABS)) {
			for (size_t i = 0; i < OHNumEvdevAxisIDs; i++) {
				if (OFBitSetIsSet(absBits, OHEvdevAxisIDs[i])) {
					OFString *axisName;
					OHGameControllerAxis *axis;

					axisName =
					    axisToName(OHEvdevAxisIDs[i]);
					if (axisName == nil)
						continue;

					axis = [[[OHGameControllerAxis
					    alloc]
					    initWithName: axisName
						  analog: true] autorelease];

					[axes setObject: axis forKey: axisName];
				}
			}
		}
		[axes makeImmutable];








|
>
>
>
>
>
|
|
|
|


















|
|
|


















|
<
|
|







203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259

260
261
262
263
264
265
266
267
268
		return nil;
	}
}

@implementation OHEvdevGameControllerProfile
@synthesize buttons = _buttons, axes = _axes;

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)oh_initWithKeyBits: (unsigned long *)keyBits
			    evBits: (unsigned long *)evBits
			   absBits: (unsigned long *)absBits
			  vendorID: (uint16_t)vendorID
			 productID: (uint16_t)productID
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFMutableDictionary *buttons, *axes;

		buttons = [OFMutableDictionary dictionary];
		for (size_t i = 0; i < OHNumEvdevButtonIDs; i++) {
			if (OFBitSetIsSet(keyBits, OHEvdevButtonIDs[i])) {
				OFString *buttonName;
				OHGameControllerButton *button;

				buttonName = buttonToName(OHEvdevButtonIDs[i],
				    vendorID, productID);
				if (buttonName == nil)
					continue;

				button = [OHGameControllerButton
				    oh_elementWithName: buttonName
						analog: false];

				[buttons setObject: button forKey: buttonName];
			}
		}
		[buttons makeImmutable];

		axes = [OFMutableDictionary dictionary];
		if (OFBitSetIsSet(evBits, EV_ABS)) {
			for (size_t i = 0; i < OHNumEvdevAxisIDs; i++) {
				if (OFBitSetIsSet(absBits, OHEvdevAxisIDs[i])) {
					OFString *axisName;
					OHGameControllerAxis *axis;

					axisName =
					    axisToName(OHEvdevAxisIDs[i]);
					if (axisName == nil)
						continue;

					axis = [OHGameControllerAxis

					    oh_elementWithName: axisName
							analog: true];

					[axes setObject: axis forKey: axisName];
				}
			}
		}
		[axes makeImmutable];