Darwin: Cleaned up keyboard interface headers

This commit is contained in:
Jeremy Huddleston 2007-12-04 23:18:37 -08:00
parent e8399fd4d6
commit 141f69dc3d
6 changed files with 101 additions and 102 deletions

View File

@ -46,7 +46,6 @@ typedef struct {
int bitsPerComponent; int bitsPerComponent;
} DarwinFramebufferRec, *DarwinFramebufferPtr; } DarwinFramebufferRec, *DarwinFramebufferPtr;
// From darwin.c // From darwin.c
void DarwinPrintBanner(void); void DarwinPrintBanner(void);
int DarwinParseModifierList(const char *constmodifiers); int DarwinParseModifierList(const char *constmodifiers);
@ -59,14 +58,6 @@ void DarwinEQEnqueue(const xEvent *e);
void DarwinEQPointerPost(xEvent *e); void DarwinEQPointerPost(xEvent *e);
void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX); void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
// From darwinKeyboard.c
int DarwinModifierNXKeyToNXKeycode(int key, int side);
void DarwinKeyboardInit(DeviceIntPtr pDev);
int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide);
int DarwinModifierNXKeyToNXMask(int key);
int DarwinModifierNXMaskToNXKey(int mask);
int DarwinModifierStringToNXKey(const char *string);
// Mode specific functions // Mode specific functions
Bool DarwinModeAddScreen(int index, ScreenPtr pScreen); Bool DarwinModeAddScreen(int index, ScreenPtr pScreen);
Bool DarwinModeSetupScreen(int index, ScreenPtr pScreen); Bool DarwinModeSetupScreen(int index, ScreenPtr pScreen);

View File

@ -71,7 +71,6 @@ typedef struct _EventQueue {
} EventQueueRec, *EventQueuePtr; } EventQueueRec, *EventQueuePtr;
static EventQueueRec darwinEventQueue; static EventQueueRec darwinEventQueue;
extern darwinKeyboardInfo keyInfo;
#define KeyPressed(k) (((DeviceIntPtr)darwinEventQueue.pKbd)->key->down[k >> 3] & (1 << (k & 7))) #define KeyPressed(k) (((DeviceIntPtr)darwinEventQueue.pKbd)->key->down[k >> 3] & (1 << (k & 7)))
#ifdef NX_DEVICELCTLKEYMASK #ifdef NX_DEVICELCTLKEYMASK

View File

@ -179,7 +179,7 @@ static KeySym const next_to_x[256] = {
static KeySym const symbol_to_x[] = { static KeySym const symbol_to_x[] = {
XK_Left, XK_Up, XK_Right, XK_Down XK_Left, XK_Up, XK_Right, XK_Down
}; };
int const NUM_SYMBOL = sizeof(symbol_to_x) / sizeof(symbol_to_x[0]); static int const NUM_SYMBOL = sizeof(symbol_to_x) / sizeof(symbol_to_x[0]);
#define MIN_FUNCKEY 0x20 #define MIN_FUNCKEY 0x20
static KeySym const funckey_to_x[] = { static KeySym const funckey_to_x[] = {
@ -190,7 +190,7 @@ static KeySym const funckey_to_x[] = {
XK_Page_Up, XK_Page_Down, XK_F13, XK_F14, XK_Page_Up, XK_Page_Down, XK_F13, XK_F14,
XK_F15 XK_F15
}; };
int const NUM_FUNCKEY = sizeof(funckey_to_x) / sizeof(funckey_to_x[0]); static int const NUM_FUNCKEY = sizeof(funckey_to_x) / sizeof(funckey_to_x[0]);
typedef struct { typedef struct {
KeySym normalSym; KeySym normalSym;
@ -216,7 +216,7 @@ static darwinKeyPad_t const normal_to_keypad[] = {
{ XK_period, XK_KP_Decimal }, { XK_period, XK_KP_Decimal },
{ XK_slash, XK_KP_Divide } { XK_slash, XK_KP_Divide }
}; };
int const NUM_KEYPAD = sizeof(normal_to_keypad) / sizeof(normal_to_keypad[0]); static int const NUM_KEYPAD = sizeof(normal_to_keypad) / sizeof(normal_to_keypad[0]);
static void DarwinChangeKeyboardControl( DeviceIntPtr device, KeybdCtrl *ctrl ) static void DarwinChangeKeyboardControl( DeviceIntPtr device, KeybdCtrl *ctrl )
{ {
@ -232,35 +232,32 @@ static char *inBuffer = NULL;
// Can be configured to treat embedded "numbers" as being composed of // Can be configured to treat embedded "numbers" as being composed of
// either 1, 2, or 4 bytes, apiece. // either 1, 2, or 4 bytes, apiece.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
typedef struct _DataStream typedef struct _DataStream {
{
unsigned char const *data; unsigned char const *data;
unsigned char const *data_end; unsigned char const *data_end;
short number_size; // Size in bytes of a "number" in the stream. short number_size; // Size in bytes of a "number" in the stream.
} DataStream; } DataStream;
static DataStream* new_data_stream( unsigned char const* data, int size ) static DataStream* new_data_stream(unsigned char const* data, int size) {
{
DataStream* s = (DataStream*)xalloc( sizeof(DataStream) ); DataStream* s = (DataStream*)xalloc( sizeof(DataStream) );
s->data = data; if(s) {
s->data_end = data + size; s->data = data;
s->number_size = 1; // Default to byte-sized numbers. s->data_end = data + size;
s->number_size = 1; // Default to byte-sized numbers.
}
return s; return s;
} }
static void destroy_data_stream( DataStream* s ) static void destroy_data_stream(DataStream* s) {
{
xfree(s); xfree(s);
} }
static unsigned char get_byte( DataStream* s ) static unsigned char get_byte(DataStream* s) {
{
assert(s->data + 1 <= s->data_end); assert(s->data + 1 <= s->data_end);
return *s->data++; return *s->data++;
} }
static short get_word( DataStream* s ) static short get_word(DataStream* s) {
{
short hi, lo; short hi, lo;
assert(s->data + 2 <= s->data_end); assert(s->data + 2 <= s->data_end);
hi = *s->data++; hi = *s->data++;
@ -268,8 +265,7 @@ static short get_word( DataStream* s )
return ((hi << 8) | lo); return ((hi << 8) | lo);
} }
static int get_dword( DataStream* s ) static int get_dword(DataStream* s) {
{
int b1, b2, b3, b4; int b1, b2, b3, b4;
assert(s->data + 4 <= s->data_end); assert(s->data + 4 <= s->data_end);
b4 = *s->data++; b4 = *s->data++;
@ -279,8 +275,7 @@ static int get_dword( DataStream* s )
return ((b4 << 24) | (b3 << 16) | (b2 << 8) | b1); return ((b4 << 24) | (b3 << 16) | (b2 << 8) | b1);
} }
static int get_number( DataStream* s ) static int get_number(DataStream* s) {
{
switch (s->number_size) { switch (s->number_size) {
case 4: return get_dword(s); case 4: return get_dword(s);
case 2: return get_word(s); case 2: return get_word(s);
@ -296,8 +291,7 @@ static int get_number( DataStream* s )
* bits_set * bits_set
* Calculate number of bits set in the modifier mask. * Calculate number of bits set in the modifier mask.
*/ */
static short bits_set( short mask ) static short bits_set(short mask) {
{
short n = 0; short n = 0;
for ( ; mask != 0; mask >>= 1) for ( ; mask != 0; mask >>= 1)
@ -311,10 +305,7 @@ static short bits_set( short mask )
* Read the next character code from the Darwin keymapping * Read the next character code from the Darwin keymapping
* and write it to the X keymap. * and write it to the X keymap.
*/ */
static void parse_next_char_code( static void parse_next_char_code(DataStream *s, KeySym *k) {
DataStream *s,
KeySym *k )
{
const short charSet = get_number(s); const short charSet = get_number(s);
const short charCode = get_number(s); const short charCode = get_number(s);
@ -337,9 +328,7 @@ static void parse_next_char_code(
* DarwinReadKeymapFile * DarwinReadKeymapFile
* Read the appropriate keymapping from a keymapping file. * Read the appropriate keymapping from a keymapping file.
*/ */
Bool DarwinReadKeymapFile( Bool DarwinReadKeymapFile(NXKeyMapping *keyMap) {
NXKeyMapping *keyMap)
{
struct stat st; struct stat st;
NXEventSystemDevice info[20]; NXEventSystemDevice info[20];
int interface = 0, handler_id = 0; int interface = 0, handler_id = 0;
@ -448,9 +437,7 @@ Bool DarwinReadKeymapFile(
/* /*
* DarwinParseNXKeyMapping * DarwinParseNXKeyMapping
*/ */
Bool DarwinParseNXKeyMapping( Bool DarwinParseNXKeyMapping(darwinKeyboardInfo *info) {
darwinKeyboardInfo *info)
{
KeySym *k; KeySym *k;
int i; int i;
short numMods, numKeys, numPadKeys = 0; short numMods, numKeys, numPadKeys = 0;
@ -649,8 +636,7 @@ Bool DarwinParseNXKeyMapping(
* Use the keyMap field of keyboard info structure to populate * Use the keyMap field of keyboard info structure to populate
* the modMap and modifierKeycodes fields. * the modMap and modifierKeycodes fields.
*/ */
static void static void DarwinBuildModifierMaps(darwinKeyboardInfo *info) {
DarwinBuildModifierMaps(darwinKeyboardInfo *info) {
int i; int i;
KeySym *k; KeySym *k;
@ -743,12 +729,7 @@ DarwinBuildModifierMaps(darwinKeyboardInfo *info) {
* Load the keyboard map from a file or system and convert * Load the keyboard map from a file or system and convert
* it to an equivalent X keyboard map and modifier map. * it to an equivalent X keyboard map and modifier map.
*/ */
static void static void DarwinLoadKeyboardMapping(KeySymsRec *keySyms) {
DarwinLoadKeyboardMapping(KeySymsRec *keySyms)
{
int i;
KeySym *k;
memset(keyInfo.keyMap, 0, sizeof(keyInfo.keyMap)); memset(keyInfo.keyMap, 0, sizeof(keyInfo.keyMap));
/* TODO: Clean this up /* TODO: Clean this up
@ -765,6 +746,8 @@ DarwinLoadKeyboardMapping(KeySymsRec *keySyms)
DarwinBuildModifierMaps(&keyInfo); DarwinBuildModifierMaps(&keyInfo);
#ifdef DUMP_DARWIN_KEYMAP #ifdef DUMP_DARWIN_KEYMAP
int i;
KeySym *k;
DEBUG_LOG("Darwin -> X converted keyboard map\n"); DEBUG_LOG("Darwin -> X converted keyboard map\n");
for (i = 0, k = keyInfo.keyMap; i < NX_NUMKEYCODES; for (i = 0, k = keyInfo.keyMap; i < NX_NUMKEYCODES;
i++, k += GLYPHS_PER_KEY) i++, k += GLYPHS_PER_KEY)
@ -793,9 +776,7 @@ DarwinLoadKeyboardMapping(KeySymsRec *keySyms)
* X keyboard map and modifier map. Set the new keyboard * X keyboard map and modifier map. Set the new keyboard
* device structure. * device structure.
*/ */
void DarwinKeyboardInit( void DarwinKeyboardInit(DeviceIntPtr pDev) {
DeviceIntPtr pDev )
{
KeySymsRec keySyms; KeySymsRec keySyms;
// Open a shared connection to the HID System. // Open a shared connection to the HID System.
@ -816,9 +797,7 @@ void DarwinKeyboardInit(
/* Borrowed from dix/devices.c */ /* Borrowed from dix/devices.c */
static Bool static Bool InitModMap(register KeyClassPtr keyc) {
InitModMap(register KeyClassPtr keyc)
{
int i, j; int i, j;
CARD8 keysPerModifier[8]; CARD8 keysPerModifier[8];
CARD8 mask; CARD8 mask;
@ -863,9 +842,7 @@ InitModMap(register KeyClassPtr keyc)
} }
void void DarwinKeyboardReload(DeviceIntPtr pDev) {
DarwinKeyboardReload(DeviceIntPtr pDev)
{
KeySymsRec keySyms; KeySymsRec keySyms;
DarwinLoadKeyboardMapping(&keySyms); DarwinLoadKeyboardMapping(&keySyms);
@ -898,8 +875,7 @@ DarwinKeyboardReload(DeviceIntPtr pDev)
* side = 0 for left or 1 for right. * side = 0 for left or 1 for right.
* Returns 0 if key+side is not a known modifier. * Returns 0 if key+side is not a known modifier.
*/ */
int DarwinModifierNXKeyToNXKeycode(int key, int side) int DarwinModifierNXKeyToNXKeycode(int key, int side) {
{
return keyInfo.modifierKeycodes[key][side]; return keyInfo.modifierKeycodes[key][side];
} }
@ -908,8 +884,7 @@ int DarwinModifierNXKeyToNXKeycode(int key, int side)
* Returns -1 if keycode+side is not a modifier key * Returns -1 if keycode+side is not a modifier key
* outSide may be NULL, else it gets 0 for left and 1 for right. * outSide may be NULL, else it gets 0 for left and 1 for right.
*/ */
int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide) int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide) {
{
int key, side; int key, side;
keycode += MIN_KEYCODE; keycode += MIN_KEYCODE;
@ -928,8 +903,7 @@ int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide)
* DarwinModifierNXMaskToNXKey * DarwinModifierNXMaskToNXKey
* Returns -1 if mask is not a known modifier mask. * Returns -1 if mask is not a known modifier mask.
*/ */
int DarwinModifierNXMaskToNXKey(int mask) int DarwinModifierNXMaskToNXKey(int mask) {
{
switch (mask) { switch (mask) {
case NX_ALPHASHIFTMASK: return NX_MODIFIERKEY_ALPHALOCK; case NX_ALPHASHIFTMASK: return NX_MODIFIERKEY_ALPHALOCK;
case NX_SHIFTMASK: return NX_MODIFIERKEY_SHIFT; case NX_SHIFTMASK: return NX_MODIFIERKEY_SHIFT;
@ -959,8 +933,7 @@ int DarwinModifierNXMaskToNXKey(int mask)
return -1; return -1;
} }
const char *DarwinModifierNXMaskTostring(int mask) const char *DarwinModifierNXMaskTostring(int mask) {
{
switch (mask) { switch (mask) {
case NX_ALPHASHIFTMASK: return "NX_ALPHASHIFTMASK"; case NX_ALPHASHIFTMASK: return "NX_ALPHASHIFTMASK";
case NX_SHIFTMASK: return "NX_SHIFTMASK"; case NX_SHIFTMASK: return "NX_SHIFTMASK";
@ -986,8 +959,7 @@ const char *DarwinModifierNXMaskTostring(int mask)
* DarwinModifierNXKeyToNXMask * DarwinModifierNXKeyToNXMask
* Returns 0 if key is not a known modifier key. * Returns 0 if key is not a known modifier key.
*/ */
int DarwinModifierNXKeyToNXMask(int key) int DarwinModifierNXKeyToNXMask(int key) {
{
switch (key) { switch (key) {
case NX_MODIFIERKEY_ALPHALOCK: return NX_ALPHASHIFTMASK; case NX_MODIFIERKEY_ALPHALOCK: return NX_ALPHASHIFTMASK;
case NX_MODIFIERKEY_SHIFT: return NX_SHIFTMASK; case NX_MODIFIERKEY_SHIFT: return NX_SHIFTMASK;
@ -1017,8 +989,7 @@ int DarwinModifierNXKeyToNXMask(int key)
* DarwinModifierStringToNXKey * DarwinModifierStringToNXKey
* Returns -1 if string is not a known modifier. * Returns -1 if string is not a known modifier.
*/ */
int DarwinModifierStringToNXKey(const char *str) int DarwinModifierStringToNXKey(const char *str) {
{
if (!strcasecmp(str, "shift")) return NX_MODIFIERKEY_SHIFT; if (!strcasecmp(str, "shift")) return NX_MODIFIERKEY_SHIFT;
else if (!strcasecmp(str, "control")) return NX_MODIFIERKEY_CONTROL; else if (!strcasecmp(str, "control")) return NX_MODIFIERKEY_CONTROL;
else if (!strcasecmp(str, "option")) return NX_MODIFIERKEY_ALTERNATE; else if (!strcasecmp(str, "option")) return NX_MODIFIERKEY_ALTERNATE;

View File

@ -27,25 +27,19 @@
#ifndef DARWIN_KEYBOARD_H #ifndef DARWIN_KEYBOARD_H
#define DARWIN_KEYBOARD_H 1 #define DARWIN_KEYBOARD_H 1
#define XK_TECHNICAL // needed to get XK_Escape #include "darwinKeyboard_interface.h"
#define XK_PUBLISHING
#include "X11/keysym.h"
#include "inputstr.h"
// Each key can generate 4 glyphs. They are, in order:
// unshifted, shifted, modeswitch unshifted, modeswitch shifted
#define GLYPHS_PER_KEY 4
#define NUM_KEYCODES 248 // NX_NUMKEYCODES might be better
#define MAX_KEYCODE NUM_KEYCODES + MIN_KEYCODE - 1
typedef struct darwinKeyboardInfo_struct {
CARD8 modMap[MAP_LENGTH];
KeySym keyMap[MAP_LENGTH * GLYPHS_PER_KEY];
unsigned char modifierKeycodes[32][2];
} darwinKeyboardInfo;
/* Provided for darwinEvents.c */
extern darwinKeyboardInfo keyInfo;
void DarwinKeyboardReload(DeviceIntPtr pDev); void DarwinKeyboardReload(DeviceIntPtr pDev);
unsigned int DarwinModeSystemKeymapSeed(void); void DarwinKeyboardInit(DeviceIntPtr pDev);
Bool DarwinModeReadSystemKeymap(darwinKeyboardInfo *info); int DarwinModifierNXKeycodeToNXKey(unsigned char keycode, int *outSide);
int DarwinModifierNXKeyToNXKeycode(int key, int side);
int DarwinModifierNXKeyToNXMask(int key);
int DarwinModifierNXMaskToNXKey(int mask);
int DarwinModifierStringToNXKey(const char *string);
/* Provided for darwin.c */
void DarwinKeyboardInit(DeviceIntPtr pDev);
#endif /* DARWIN_KEYBOARD_H */ #endif /* DARWIN_KEYBOARD_H */

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2003-2004 Torrey T. Lyons. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name(s) of the above copyright
* holders shall not be used in advertising or otherwise to promote the sale,
* use or other dealings in this Software without prior written authorization.
*/
#ifndef DARWIN_KEYBOARD_INTERFACE_H
#define DARWIN_KEYBOARD_INTERFACE_H 1
#define XK_TECHNICAL // needed to get XK_Escape
#define XK_PUBLISHING
#include "X11/keysym.h"
#include "inputstr.h"
// Each key can generate 4 glyphs. They are, in order:
// unshifted, shifted, modeswitch unshifted, modeswitch shifted
#define GLYPHS_PER_KEY 4
#define NUM_KEYCODES 248 // NX_NUMKEYCODES might be better
#define MAX_KEYCODE NUM_KEYCODES + MIN_KEYCODE - 1
typedef struct darwinKeyboardInfo_struct {
CARD8 modMap[MAP_LENGTH];
KeySym keyMap[MAP_LENGTH * GLYPHS_PER_KEY];
unsigned char modifierKeycodes[32][2];
} darwinKeyboardInfo;
/* These functions need to be implemented by XQuartz, XDarwin, etc. */
void DarwinKeyboardReload(DeviceIntPtr pDev);
Bool DarwinModeReadSystemKeymap(darwinKeyboardInfo *info);
unsigned int DarwinModeSystemKeymapSeed(void);
#endif /* DARWIN_KEYBOARD_INTERFACE_H */

View File

@ -40,7 +40,7 @@
#include <CoreServices/CoreServices.h> #include <CoreServices/CoreServices.h>
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#include "darwinKeyboard.h" #include "darwinKeyboard_interface.h"
#include "X11/keysym.h" #include "X11/keysym.h"
#include "keysym2ucs.h" #include "keysym2ucs.h"
@ -146,9 +146,7 @@ const static struct {
{UKEYSYM (0x31b), XK_dead_horn}, /* COMBINING HORN */ {UKEYSYM (0x31b), XK_dead_horn}, /* COMBINING HORN */
}; };
unsigned int unsigned int DarwinModeSystemKeymapSeed(void) {
DarwinModeSystemKeymapSeed (void)
{
static unsigned int seed; static unsigned int seed;
static KeyboardLayoutRef last_key_layout; static KeyboardLayoutRef last_key_layout;
KeyboardLayoutRef key_layout; KeyboardLayoutRef key_layout;
@ -160,9 +158,7 @@ DarwinModeSystemKeymapSeed (void)
return seed; return seed;
} }
static inline UniChar static inline UniChar macroman2ucs(unsigned char c) {
macroman2ucs (unsigned char c)
{
/* Precalculated table mapping MacRoman-128 to Unicode. Generated /* Precalculated table mapping MacRoman-128 to Unicode. Generated
by creating single element CFStringRefs then extracting the by creating single element CFStringRefs then extracting the
first character. */ first character. */
@ -190,9 +186,7 @@ macroman2ucs (unsigned char c)
else return table[c - 128]; else return table[c - 128];
} }
static KeySym static KeySym make_dead_key(KeySym in) {
make_dead_key (KeySym in)
{
int i; int i;
for (i = 0; i < sizeof (dead_keys) / sizeof (dead_keys[0]); i++) for (i = 0; i < sizeof (dead_keys) / sizeof (dead_keys[0]); i++)
@ -201,9 +195,7 @@ make_dead_key (KeySym in)
return in; return in;
} }
Bool Bool DarwinModeReadSystemKeymap(darwinKeyboardInfo *info) {
DarwinModeReadSystemKeymap (darwinKeyboardInfo *info)
{
KeyboardLayoutRef key_layout; KeyboardLayoutRef key_layout;
const void *chr_data = NULL; const void *chr_data = NULL;
int num_keycodes = NUM_KEYCODES; int num_keycodes = NUM_KEYCODES;