/* * Copyright (c) 1991 NeXT Computer, Inc. * Copyright (c) 1996-2000 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ /****************************************************************************** event_status_driver_api.c API for the events status driver. This file implements public API. mpaque 11Oct91 Modified: 29 June 1992 Mike Paquette at NeXT Implemented API for the new Mach based Event Driver. ******************************************************************************/ #include #include #include #include #include #include #include #include /* Definitions specific to the Mach based event driver */ #define BRIGHT_MAX 64 static void secs_to_packed_nsecs(double secs, UInt64 *nsecs) { *nsecs = (1000.0 * 1000.0 * 1000.0 * secs); } static double packed_nsecs_to_secs(UInt64 nsecs) { return( ((double)nsecs) / 1000.0 / 1000.0 / 1000.0); } /* Open and Close */ NXEventHandle NXOpenEventStatus(void) { NXEventHandle handle = MACH_PORT_NULL; register kern_return_t kr; io_service_t service = MACH_PORT_NULL; mach_port_t masterPort; do { kr = IOMasterPort( MACH_PORT_NULL, &masterPort ); if( kr != KERN_SUCCESS) break; service = IORegistryEntryFromPath( masterPort, kIOServicePlane ":/IOResources/IOHIDSystem" ); if( !service) break; kr = IOServiceOpen( service, mach_task_self(), kIOHIDParamConnectType, &handle); IOObjectRelease( service ); } while( false ); return( handle ); } void NXCloseEventStatus(NXEventHandle handle) { IOServiceClose( handle ); } /* Status query */ NXEventSystemInfoType NXEventSystemInfo(NXEventHandle handle, char *flavor, NXEventSystemInfoType evs_info, unsigned int *evs_info_cnt) { kern_return_t kr; NXEventSystemDevice * info = (NXEventSystemDevice *) evs_info; int maxDeviceCount = (*evs_info_cnt) * sizeof( int) / sizeof( NXEventSystemDevice); int deviceCount = 0; int i; io_registry_entry_t hidsystem; CFArrayRef array; CFDictionaryRef dict; CFNumberRef num; SInt32 val; // Translate the one existing old case to new format if ( ((uintptr_t) flavor) == __OLD_NX_EVS_DEVICE_INFO ) flavor = NX_EVS_DEVICE_INFO; if( strcmp( flavor, NX_EVS_DEVICE_INFO)) kr = kIOReturnUnsupported; do { kr = IOConnectGetService( handle, &hidsystem ); if( KERN_SUCCESS != kr ) break; array = IORegistryEntryCreateCFProperty(hidsystem, CFSTR("NXSystemInfo"), kCFAllocatorDefault, kNilOptions); IOObjectRelease( hidsystem ); if( !array ) break; deviceCount = CFArrayGetCount(array); if ( deviceCount > maxDeviceCount ) deviceCount = maxDeviceCount; for ( i=0; i 1) { arrayRef = CFArrayCreateMutable(kCFAllocatorDefault, count, &kCFTypeArrayCallBacks); if ( !arrayRef ) return kIOReturnNoMemory; for (i=0; isize > EVSIOSKM_SIZE ) return (NXKeyMapping *)0; r = NXEvSetParameterChar(handle, CFSTR(EVSIOSKM), (unsigned char *) keymap->mapping, keymap->size); if ( r != kIOReturnSuccess ) return (NXKeyMapping *)0; return keymap; } int NXKeyMappingLength(NXEventHandle handle) { int r; IOByteCount size; r = NXEvGetParameterChar( handle, CFSTR(EVSIOCKM), 0, (unsigned char *) 0, &size ); if ( r != kIOReturnSuccess ) size = 0; return size; } NXKeyMapping * NXGetKeyMapping(NXEventHandle handle, NXKeyMapping *keymap) { int r; r = NXEvGetParameterChar( handle, CFSTR(EVSIOCKM), keymap->size, (unsigned char *) keymap->mapping, (IOByteCount *) &keymap->size ); if ( r != kIOReturnSuccess ) return (NXKeyMapping *)0; return keymap; } /* Mouse */ void NXResetMouse(NXEventHandle handle) { unsigned int params[EVSIORMS_SIZE]; NXEvSetParameterInt(handle, CFSTR(EVSIORMS), params, EVSIORMS_SIZE); } void NXSetClickTime(NXEventHandle handle, double secs) { UInt64 params; secs_to_packed_nsecs( secs, ¶ms ); IOHIDSetParameter(handle, CFSTR(EVSIOSCT), ¶ms, sizeof(params)); } double NXClickTime(NXEventHandle handle) { UInt64 params; IOByteCount rcnt = EVSIOCCT_SIZE; int r; r = IOHIDGetParameter(handle, CFSTR(EVSIOCCT), sizeof(UInt64), ¶ms, &rcnt ); if ( r != kIOReturnSuccess ) return 0.0; return packed_nsecs_to_secs( params ); } void NXSetClickSpace(NXEventHandle handle, _NXSize_ *area) { unsigned int params[EVSIOSCS_SIZE]; params[EVSIOSCS_X] = (unsigned int)(area->width); params[EVSIOSCS_Y] = (unsigned int)(area->height); NXEvSetParameterInt(handle, CFSTR(EVSIOSCS), params, EVSIOSCS_SIZE); } void NXGetClickSpace(NXEventHandle handle, _NXSize_ *area) { unsigned int params[EVSIOCCS_SIZE]; unsigned int rcnt = EVSIOCCS_SIZE; NXEvGetParameterInt(handle, CFSTR(EVSIOCCS), EVSIOCCS_SIZE, params, &rcnt ); area->width = params[EVSIOCCS_X]; area->height = params[EVSIOCCS_Y]; } kern_return_t IOHIDGetScrollAcceleration( io_connect_t handle, double * acceleration ) { kern_return_t kr; unsigned int fixed; IOByteCount rsize; kr = IOHIDGetParameter( handle, CFSTR(kIOHIDScrollAccelerationKey), sizeof( fixed), (unsigned char *) &fixed, &rsize ); if( kr == kIOReturnSuccess) *acceleration = ((double) fixed) / 65536.0; return( kr ); } kern_return_t IOHIDSetScrollAcceleration( io_connect_t handle, double acceleration ) { unsigned int fixed; fixed = (unsigned int) (acceleration * 65536.0); return( IOHIDSetParameter(handle, CFSTR(kIOHIDScrollAccelerationKey), (unsigned char *) &fixed, sizeof(fixed)) ); } kern_return_t IOHIDGetMouseButtonMode( io_connect_t handle, int * mode ) { IOByteCount rsize; return( IOHIDGetParameter( handle, CFSTR(kIOHIDPointerButtonMode), sizeof( *mode), (unsigned char *) mode, &rsize )); } kern_return_t IOHIDSetMouseButtonMode( io_connect_t handle, int mode ) { return( IOHIDSetParameter(handle, CFSTR(kIOHIDPointerButtonMode), (unsigned char *) &mode, sizeof(mode)) ); } kern_return_t IOHIDGetMouseAcceleration( io_connect_t handle, double * acceleration ) { kern_return_t kr; unsigned int fixed; IOByteCount rsize; kr = IOHIDGetParameter( handle, CFSTR(kIOHIDPointerAccelerationKey), sizeof( fixed), (unsigned char *) &fixed, &rsize ); if( kr == kIOReturnSuccess) *acceleration = ((double) fixed) / 65536.0; return( kr ); } kern_return_t IOHIDSetMouseAcceleration( io_connect_t handle, double acceleration ) { unsigned int fixed; fixed = (unsigned int) (acceleration * 65536.0); return( IOHIDSetParameter(handle, CFSTR(kIOHIDPointerAccelerationKey), (unsigned char *) &fixed, sizeof( fixed)) ); } kern_return_t IOHIDGetAccelerationWithKey( io_connect_t handle, CFStringRef key, double * acceleration ) { kern_return_t kr; unsigned int fixed; IOByteCount rsize; kr = IOHIDGetParameter( handle, key, sizeof( fixed), (unsigned char *) &fixed, &rsize ); if( kr == kIOReturnSuccess) *acceleration = ((double) fixed) / 65536.0; return( kr ); } kern_return_t IOHIDSetAccelerationWithKey( io_connect_t handle, CFStringRef key, double acceleration ) { unsigned int fixed; fixed = (unsigned int) (acceleration * 65536.0); return( IOHIDSetParameter(handle, key, (unsigned char *) &fixed, sizeof( fixed)) ); }